Skip to content

Commit

Permalink
vtd: add page allocation check for root_table & context_table
Browse files Browse the repository at this point in the history
if failed to allocate page structure for root_table or context_table,
ASSERT system and return.

Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com>
Acked-by: Tian, Kevin <kevin.tian@intel.com>
  • Loading branch information
JasonChenCJ authored and jren1 committed May 15, 2018
1 parent 4ea7588 commit 1e2c201
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions hypervisor/arch/x86/vtd.c
Expand Up @@ -965,27 +965,42 @@ static int add_iommu_device(struct iommu_domain *domain, uint16_t segment,
}

if (dmar_uint->root_table_addr == 0) {
dmar_uint->root_table_addr = HVA2HPA(alloc_paging_struct());
void *root_table_vaddr = alloc_paging_struct();

if (root_table_vaddr) {
dmar_uint->root_table_addr = HVA2HPA(root_table_vaddr);
} else {
ASSERT(0, "failed to allocate root table!");
return 1;
}
}

root_table = (uint64_t *)HPA2HVA(dmar_uint->root_table_addr);

root_entry = (struct dmar_root_entry *)&root_table[bus * 2];

if (!DMAR_GET_BITSLICE(root_entry->lower, ROOT_ENTRY_LOWER_PRESENT)) {
/* create context table for the bus if not present */
context_table_addr = HVA2HPA(alloc_paging_struct());
void *vaddr = alloc_paging_struct();

context_table_addr = context_table_addr >> 12;
if (vaddr) {
/* create context table for the bus if not present */
context_table_addr = HVA2HPA(vaddr);

lower = DMAR_SET_BITSLICE(lower, ROOT_ENTRY_LOWER_CTP,
context_table_addr);
lower = DMAR_SET_BITSLICE(lower, ROOT_ENTRY_LOWER_PRESENT, 1);
context_table_addr = context_table_addr >> 12;

root_entry->upper = 0;
root_entry->lower = lower;
iommu_flush_cache(dmar_uint, root_entry,
lower = DMAR_SET_BITSLICE(lower, ROOT_ENTRY_LOWER_CTP,
context_table_addr);
lower = DMAR_SET_BITSLICE(lower,
ROOT_ENTRY_LOWER_PRESENT, 1);

root_entry->upper = 0;
root_entry->lower = lower;
iommu_flush_cache(dmar_uint, root_entry,
sizeof(struct dmar_root_entry));
} else {
ASSERT(0, "failed to allocate context table!");
return 1;
}
} else {
context_table_addr = DMAR_GET_BITSLICE(root_entry->lower,
ROOT_ENTRY_LOWER_CTP);
Expand Down

0 comments on commit 1e2c201

Please sign in to comment.