qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 5/5] pc/q35: Add pre-plug hook for x86-iommu


From: Peter Xu
Subject: Re: [PATCH v2 5/5] pc/q35: Add pre-plug hook for x86-iommu
Date: Fri, 29 Oct 2021 10:53:07 +0800

On Thu, Oct 28, 2021 at 10:11:35AM -0600, Alex Williamson wrote:
> Better.  Like the class layering proposal, a downside is that the
> driver needs to be aware that it's imposing this requirement to be able
> to mark it in the class init function rather than some automatic means,
> like an "as_object_consumed" flag set automatically on the device
> structure via accessors like pci_device_iommu_address_space().  Thanks,

Do you mean something like this?

---8<---
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 258290f4eb..969f4c85fd 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -2729,6 +2729,10 @@ AddressSpace *pci_device_iommu_address_space(PCIDevice 
*dev)
     PCIBus *iommu_bus = bus;
     uint8_t devfn = dev->devfn;

+    if (!dev->address_space_consumed) {
+        dev->address_space_consumed = true;
+    }
+
     while (iommu_bus && !iommu_bus->iommu_fn && iommu_bus->parent_dev) {
         PCIBus *parent_bus = pci_get_bus(iommu_bus->parent_dev);

diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 6813f128e0..704c9bdc6e 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -268,6 +268,13 @@ typedef struct PCIReqIDCache PCIReqIDCache;
 struct PCIDevice {
     DeviceState qdev;
     bool partially_hotplugged;
+    /*
+     * This will be set after the 1st time the device implementation fetches
+     * its dma address space from pci_device_iommu_address_space().  It's used
+     * as a sanity check for platform devices like vIOMMU to detect incorrect
+     * ordering of device realization.
+     */
+    bool address_space_consumed;

     /* PCI config space */
     uint8_t *config;
---8<---

Then sanity check in pre-plug of vIOMMU.

The flag will be a bit more "misterious" than the previous approach, imho, as
the name of it will be even further from the problem it's going to solve.
However it looks at least clean on the changeset and it looks working too.

Thanks,

-- 
Peter Xu




reply via email to

[Prev in Thread] Current Thread [Next in Thread]