From 0a9aeaa10eac84cfda48c05a7298f5340fb6ef29 Mon Sep 17 00:00:00 2001 From: Binbin Wu Date: Tue, 12 Mar 2019 16:16:00 +0800 Subject: [PATCH] hv: vtd: check bus limit when add/remove device Check bus limit when add/remove device in iommu. Tracked-On: #2743 Signed-off-by: Binbin Wu --- hypervisor/arch/x86/vtd.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hypervisor/arch/x86/vtd.c b/hypervisor/arch/x86/vtd.c index ed84a438a..e1365edd9 100644 --- a/hypervisor/arch/x86/vtd.c +++ b/hypervisor/arch/x86/vtd.c @@ -959,6 +959,11 @@ static int32_t remove_iommu_device(const struct iommu_domain *domain, uint16_t s return -EINVAL; } + if (dmar_unit->drhd->ignore) { + dev_dbg(ACRN_DBG_IOMMU, "device is ignored :0x%x:%x.%x", bus, pci_slot(devfun), pci_func(devfun)); + return -EINVAL; + } + root_table = (struct dmar_root_entry *)hpa2hva(dmar_unit->root_table_addr); root_entry = root_table + bus; @@ -1057,6 +1062,11 @@ int32_t assign_iommu_device(struct iommu_domain *domain, uint8_t bus, uint8_t de /* TODO: check if the device assigned */ + if ((uint16_t)bus >= CONFIG_IOMMU_BUS_NUM) { + pr_err("bus 0x%x out of range", bus); + return -EINVAL; + } + if (vm0_domain != NULL) { status = remove_iommu_device(vm0_domain, 0U, bus, devfun); if (status != 0) { @@ -1071,6 +1081,11 @@ int32_t unassign_iommu_device(const struct iommu_domain *domain, uint8_t bus, ui { int32_t status = 0; + if ((uint16_t)bus >= CONFIG_IOMMU_BUS_NUM) { + pr_err("bus 0x%x out of range", bus); + return -EINVAL; + } + /* TODO: check if the device assigned */ status = remove_iommu_device(domain, 0U, bus, devfun); if (status != 0) {