hw/pci/pci: Enforce pci_setup_iommu_per_bus() is called only once per bus
PATCH v2 1/1 hw/pci/pci: Enforce pci_setup_iommu_per_bus() is called only once per bus
Currently it is possible to attach several arm-smmuv3 devices to the same bus although it is a wrong setup.
Change the prototype of pci_setup_iommu_per_bus to pass an error handle. This latter is set when iommu_per_bus is already set and used by the single caller (smmu_base_realize) to report a useful error to the end-user.
While at it document pci_setup_iommu_per_bus callback in the header.
---
v1 -> v2:
- in smmu_base_realize, return if pci_setup_iommu_per_bus returns false (Philippe)
--- include/hw/pci/pci.h | 16 +++++++++++++++- hw/arm/smmu-common.c | 4 +++- hw/pci/pci.c | 9 +++++++-- 3 files changed, 25 insertions(+), 4 deletions(-)
include/hw/pci/pci.h +15 -1
@@ -863,7 +863,21 @@ int pci_iommu_unregister_iotlb_notifier(PCIDevice *dev, uint32_t pasid,*/ void pci_setup_iommu (PCIBus *bus,const PCIIOMMUOps *ops,void *opaque); -void pci_setup_iommu_per_bus (PCIBus *bus,const PCIIOMMUOps *ops,void *opaque); +/** +* pci_setup_iommu_per_bus: Initialize specific IOMMU handlers for a PCIBus +* +* Similar to pci_setup_iommu but enforces that the iommu only protects +* @bus downstream end points and no other bus hierarchy +* +* @bus: the #PCIBus being updated. +* @ops: the #PCIIOMMUOps +* @opaque: passed to callbacks of the @ops structure. +* @errp: error handle +* +* Returns false on failure with @errp set, true on success +*/ +bool pci_setup_iommu_per_bus (PCIBus *bus,const PCIIOMMUOps *ops, +void *opaque,Error **errp);pcibus_t pci_bar_address (PCIDevice *d,int reg,uint8_t type,pcibus_t size);
hw/arm/smmu-common.c +3 -1
@@ -981,7 +981,9 @@ static void smmu_base_realize(DeviceState *dev, Error **errp) }if (s->smmu_per_bus) { -pci_setup_iommu_per_bus (pci_bus, s->iommu_ops, s); +if (!pci_setup_iommu_per_bus (pci_bus, s->iommu_ops, s, errp)) { +return ; + } }else {pci_setup_iommu (pci_bus, s->iommu_ops, s); }
hw/pci/pci.c +7 -2
@@ -3307,11 +3307,16 @@ void pci_setup_iommu(PCIBus *bus, const PCIIOMMUOps *ops, void *opaque)* IOMMU ops are returned, avoiding the use of the parent’s IOMMU when * it's not appropriate. */ -void pci_setup_iommu_per_bus (PCIBus *bus,const PCIIOMMUOps *ops, -void *opaque) +bool pci_setup_iommu_per_bus (PCIBus *bus,const PCIIOMMUOps *ops, +void *opaque,Error **errp) { +if (bus->iommu_per_bus) { +error_setg (errp,"An iommu is already attached to this bus" ); +return false; + }pci_setup_iommu (bus, ops, opaque); bus->iommu_per_bus = true; +return true; }static void pci_dev_get_w64 (PCIBus *b,PCIDevice *dev,void *opaque)
Signature · 1 line
2.53.0
Quoted 18 lines · Eric Auger
Currently it is possible to attach several arm-smmuv3 devices to the same bus although it is a wrong setup.
Change the prototype of
pci_setup_iommu_per_busto pass an error handle. This latter is set wheniommu_per_busis already set and used by the single caller (smmu_base_realize) to report a useful error to the end-user.While at it document
pci_setup_iommu_per_buscallback in the header.Fixes 66d2f665e163 ("hw/arm/virt: Allow user-creatable SMMUv3 dev instantiation")Signed-off-by Eric Auger <[email protected]>Tested-by Nathan Chen <[email protected]>Reviewed-by Shameer Kolothum <[email protected]>Reviewed-by Nicolin Chen <[email protected]>---
Quoted 8 lines
v1 -> v2:
- insmmu_base_realize, return ifpci_setup_iommu_per_busreturns false (Philippe)--- include/hw/pci/pci.h | 16 +++++++++++++++- hw/arm/smmu-common.c | 4 +++- hw/pci/pci.c | 9 +++++++-- 3 files changed, 25 insertions(+), 4 deletions(-)
Quoted 9 lines · Eric Auger
Currently it is possible to attach several arm-smmuv3 devices to the same bus although it is a wrong setup.
Change the prototype of
pci_setup_iommu_per_busto pass an error handle. This latter is set wheniommu_per_busis already set and used by the single caller (smmu_base_realize) to report a useful error to the end-user.
Quoted 7 lines
While at it document
pci_setup_iommu_per_buscallback in the header.Fixes 66d2f665e163 ("hw/arm/virt: Allow user-creatable SMMUv3 dev instantiation")Signed-off-by Eric Auger <[email protected]>Tested-by Nathan Chen <[email protected]>Reviewed-by Shameer Kolothum <[email protected]>Reviewed-by Nicolin Chen <[email protected]>
I'll take this into target-arm.next as it's a fix for a function that's only used by the arm SMMU.
thanks
-- PMM
Michael S. Tsirkin
Acked-byQuoted 18 lines · Peter Maydell
Quoted 9 lines · Eric Auger
Currently it is possible to attach several arm-smmuv3 devices to the same bus although it is a wrong setup.
Change the prototype of
pci_setup_iommu_per_busto pass an error handle. This latter is set wheniommu_per_busis already set and used by the single caller (smmu_base_realize) to report a useful error to the end-user.Quoted 7 lines
While at it document
pci_setup_iommu_per_buscallback in the header.Fixes 66d2f665e163 ("hw/arm/virt: Allow user-creatable SMMUv3 dev instantiation")Signed-off-by Eric Auger <[email protected]>Tested-by Nathan Chen <[email protected]>Reviewed-by Shameer Kolothum <[email protected]>Reviewed-by Nicolin Chen <[email protected]>
Quoted 5 lines
I'll take this into target-arm.next as it's a fix for a function that's only used by the arm SMMU.
thanks
-- PMM
Pls do.
Signature · 1 line
MST