qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Joao Martins <joao.m.martins@oracle.com>
To: qemu-devel@nongnu.org
Cc: Alex Williamson <alex.williamson@redhat.com>,
	Cedric Le Goater <clg@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>,
	David Hildenbrand <david@redhat.com>,
	Philippe Mathieu-Daude <philmd@linaro.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
	Jason Wang <jasowang@redhat.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	Eduardo Habkost <eduardo@habkost.net>,
	Avihai Horon <avihaih@nvidia.com>,
	Jason Gunthorpe <jgg@nvidia.com>,
	Joao Martins <joao.m.martins@oracle.com>
Subject: [PATCH v3 02/15] hw/pci: Add a pci_setup_iommu_info() helper
Date: Tue, 30 May 2023 18:59:24 +0100	[thread overview]
Message-ID: <20230530175937.24202-3-joao.m.martins@oracle.com> (raw)
In-Reply-To: <20230530175937.24202-1-joao.m.martins@oracle.com>

Provide a second PCI iommu bus initialization function which returns
PCIAddressSpace rather than an AddressSpace. The function is meant to
superseed pci_setup_iommu().

Under the hood in pci_device_iommu_info() if the new function pointer is
set in the device bus, use that instead and return the new object.

This is preparation for vIOMMU MR to be stored in PCIAddressSpace, thus
made available regardless of guest behaviour.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
---
 hw/pci/pci.c             | 14 ++++++++++++--
 include/hw/pci/pci.h     |  2 ++
 include/hw/pci/pci_bus.h |  1 +
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index ecf8a543aa77..ac10333b5097 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -2681,8 +2681,12 @@ PCIAddressSpace pci_device_iommu_info(PCIDevice *dev)
     }
 
     as = &address_space_memory;
-    if (!pci_bus_bypass_iommu(bus) && iommu_bus && iommu_bus->iommu_fn) {
-        as = iommu_bus->iommu_fn(bus, iommu_bus->iommu_opaque, devfn);
+    if (!pci_bus_bypass_iommu(bus) && iommu_bus) {
+        if (iommu_bus->iommu_fn) {
+            as = iommu_bus->iommu_fn(bus, iommu_bus->iommu_opaque, devfn);
+        } else if (iommu_bus->iommu_as_fn) {
+            return iommu_bus->iommu_as_fn(bus, iommu_bus->iommu_opaque, devfn);
+        }
     }
     return as_to_pci_as(as);
 }
@@ -2693,6 +2697,12 @@ void pci_setup_iommu(PCIBus *bus, PCIIOMMUFunc fn, void *opaque)
     bus->iommu_opaque = opaque;
 }
 
+void pci_setup_iommu_info(PCIBus *bus, PCIIOMMUASFunc fn, void *opaque)
+{
+    bus->iommu_as_fn = fn;
+    bus->iommu_opaque = opaque;
+}
+
 static void pci_dev_get_w64(PCIBus *b, PCIDevice *dev, void *opaque)
 {
     Range *range = opaque;
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 9ffaf47fe2ab..d2c87d87a24e 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -368,6 +368,7 @@ typedef struct PCIAddressSpace {
 } PCIAddressSpace;
 
 typedef AddressSpace *(*PCIIOMMUFunc)(PCIBus *, void *, int);
+typedef PCIAddressSpace (*PCIIOMMUASFunc)(PCIBus *, void *, int);
 static inline PCIAddressSpace as_to_pci_as(AddressSpace *as)
 {
     PCIAddressSpace ret = { .as = as };
@@ -386,6 +387,7 @@ static inline AddressSpace *pci_device_iommu_address_space(PCIDevice *dev)
 }
 
 void pci_setup_iommu(PCIBus *bus, PCIIOMMUFunc fn, void *opaque);
+void pci_setup_iommu_info(PCIBus *bus, PCIIOMMUASFunc fn, void *opaque);
 
 pcibus_t pci_bar_address(PCIDevice *d,
                          int reg, uint8_t type, pcibus_t size);
diff --git a/include/hw/pci/pci_bus.h b/include/hw/pci/pci_bus.h
index 56531759578f..a2795b23a3b0 100644
--- a/include/hw/pci/pci_bus.h
+++ b/include/hw/pci/pci_bus.h
@@ -34,6 +34,7 @@ struct PCIBus {
     BusState qbus;
     enum PCIBusFlags flags;
     PCIIOMMUFunc iommu_fn;
+    PCIIOMMUASFunc iommu_as_fn;
     void *iommu_opaque;
     uint8_t devfn_min;
     uint32_t slot_reserved_mask;
-- 
2.39.3



  parent reply	other threads:[~2023-05-30 18:00 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30 17:59 [PATCH v3 00/15] vfio: VFIO migration support with vIOMMU Joao Martins
2023-05-30 17:59 ` [PATCH v3 01/15] hw/pci: Refactor pci_device_iommu_address_space() Joao Martins
2023-05-30 22:04   ` Philippe Mathieu-Daudé
2023-05-31 10:03     ` Joao Martins
2023-06-22 20:50       ` Michael S. Tsirkin
2023-06-22 21:01         ` Joao Martins
2023-05-30 17:59 ` Joao Martins [this message]
2023-05-30 17:59 ` [PATCH v3 03/15] hw/pci: Add a pci_device_iommu_memory_region() helper Joao Martins
2023-06-05 16:57   ` Peter Xu
2023-06-06 11:22     ` Joao Martins
2023-06-06 15:03       ` Peter Xu
2023-06-06 15:05         ` Peter Xu
2023-06-06 17:44           ` Joao Martins
2023-05-30 17:59 ` [PATCH v3 04/15] intel-iommu: Switch to pci_setup_iommu_info() Joao Martins
2023-05-30 17:59 ` [PATCH v3 05/15] vfio/common: Track the IOMMU MR behind the device in addition to the AS Joao Martins
2023-05-30 17:59 ` [PATCH v3 06/15] memory/iommu: Add IOMMU_ATTR_DMA_TRANSLATION attribute Joao Martins
2023-05-30 17:59 ` [PATCH v3 07/15] intel-iommu: Implement get_attr() method Joao Martins
2023-05-30 17:59 ` [PATCH v3 08/15] vfio/common: Relax vIOMMU detection when DMA translation is off Joao Martins
2023-05-30 21:39   ` Philippe Mathieu-Daudé
2023-05-31  9:39     ` Joao Martins
2023-05-30 17:59 ` [PATCH v3 09/15] memory/iommu: Add IOMMU_ATTR_MAX_IOVA attribute Joao Martins
2023-05-30 17:59 ` [PATCH v3 10/15] intel-iommu: Implement IOMMU_ATTR_MAX_IOVA get_attr() attribute Joao Martins
2023-05-30 21:45   ` Philippe Mathieu-Daudé
2023-05-31  9:54     ` Joao Martins
2023-05-31 13:59       ` Philippe Mathieu-Daudé
2023-05-30 17:59 ` [PATCH v3 11/15] vfio/common: Move dirty tracking ranges update to helper Joao Martins
2023-05-30 17:59 ` [PATCH v3 12/15] vfio/common: Support device dirty page tracking with vIOMMU Joao Martins
2023-05-30 17:59 ` [PATCH v3 13/15] vfio/common: Extract vIOMMU code from vfio_sync_dirty_bitmap() Joao Martins
2023-05-30 17:59 ` [PATCH v3 14/15] vfio/common: Optimize device dirty page tracking with vIOMMU Joao Martins
2023-05-30 17:59 ` [PATCH v3 15/15] vfio/common: Block migration with vIOMMUs without address width limits Joao Martins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230530175937.24202-3-joao.m.martins@oracle.com \
    --to=joao.m.martins@oracle.com \
    --cc=alex.williamson@redhat.com \
    --cc=avihaih@nvidia.com \
    --cc=clg@redhat.com \
    --cc=david@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=jasowang@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).