From: Shameerali Kolothum Thodi via <qemu-arm@nongnu.org>
To: "qemu-arm@nongnu.org" <qemu-arm@nongnu.org>,
"Michael S . Tsirkin" <mst@redhat.com>,
Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Cc: "eric.auger@redhat.com" <eric.auger@redhat.com>,
"peter.maydell@linaro.org" <peter.maydell@linaro.org>,
"jgg@nvidia.com" <jgg@nvidia.com>,
"nicolinc@nvidia.com" <nicolinc@nvidia.com>,
"ddutile@redhat.com" <ddutile@redhat.com>,
"berrange@redhat.com" <berrange@redhat.com>,
"imammedo@redhat.com" <imammedo@redhat.com>,
"nathanc@nvidia.com" <nathanc@nvidia.com>,
"mochs@nvidia.com" <mochs@nvidia.com>,
"smostafa@google.com" <smostafa@google.com>,
"gustavo.romero@linaro.org" <gustavo.romero@linaro.org>,
Linuxarm <linuxarm@huawei.com>,
"Wangzhou (B)" <wangzhou1@hisilicon.com>,
jiangkunkun <jiangkunkun@huawei.com>,
Jonathan Cameron <jonathan.cameron@huawei.com>,
"zhangfei.gao@linaro.org" <zhangfei.gao@linaro.org>
Subject: RE: [PATCH v5 06/11] hw/pci: Introduce pci_setup_iommu_per_bus() for per-bus IOMMU ops retrieval
Date: Mon, 30 Jun 2025 07:37:17 +0000 [thread overview]
Message-ID: <3253e85fbabe4207bba56378f241e68e@huawei.com> (raw)
In-Reply-To: <20250623094230.76084-7-shameerali.kolothum.thodi@huawei.com>
Hi,
> -----Original Message-----
> From: qemu-devel-
> bounces+shameerali.kolothum.thodi=huawei.com@nongnu.org <qemu-
> devel-bounces+shameerali.kolothum.thodi=huawei.com@nongnu.org> On
> Behalf Of Shameer Kolothum via
> Sent: Monday, June 23, 2025 10:42 AM
> To: qemu-arm@nongnu.org; qemu-devel@nongnu.org
> Cc: eric.auger@redhat.com; peter.maydell@linaro.org; jgg@nvidia.com;
> nicolinc@nvidia.com; ddutile@redhat.com; berrange@redhat.com;
> imammedo@redhat.com; nathanc@nvidia.com; mochs@nvidia.com;
> smostafa@google.com; gustavo.romero@linaro.org; Linuxarm
> <linuxarm@huawei.com>; Wangzhou (B) <wangzhou1@hisilicon.com>;
> jiangkunkun <jiangkunkun@huawei.com>; Jonathan Cameron
> <jonathan.cameron@huawei.com>; zhangfei.gao@linaro.org
> Subject: [PATCH v5 06/11] hw/pci: Introduce pci_setup_iommu_per_bus()
> for per-bus IOMMU ops retrieval
+ PCI maintainers to the thread (Sorry I missed that and thanks to Eric for
the reminder).
Background:
This patch series adds support for creating multiple arm-smmuv3 devices,
each tied to a specific PCIe root complex on the virt board. This lays the
groundwork for upcoming support for accelerated SMMUv3, where we
intend to leverage the host's nested SMMUv3 configuration-for VFIO-PCI
passthrough device assignment.
For the context on the issue addressed in this patch, please refer to the
commit message below and the cover letter here[0].
Please take a look and let me know.
Thanks,
Shameer
[0] https://lore.kernel.org/qemu-devel/20250623094230.76084-1-shameerali.kolothum.thodi@huawei.com/
> Currently, pci_setup_iommu() registers IOMMU ops for a given PCIBus.
> However, when retrieving IOMMU ops for a device using
> pci_device_get_iommu_bus_devfn(), the function checks the parent_dev
> and fetches IOMMU ops from the parent device, even if the current
> bus does not have any associated IOMMU ops.
>
> This behavior works for now because QEMU's IOMMU implementations are
> globally scoped, and host bridges rely on the bypass_iommu property
> to skip IOMMU translation when needed.
>
> However, this model will break with the soon to be introduced
> arm-smmuv3 device, which allows users to associate the IOMMU
> with a specific PCIe root complex (e.g., the default pcie.0
> or a pxb-pcie root complex).
>
> For example, consider the following setup with multiple root
> complexes:
>
> -device arm-smmuv3,primary-bus=pcie.0,id=smmuv3.0 \
> ...
> -device pxb-pcie,id=pcie.1,bus_nr=8,bus=pcie.0 \
> -device pcie-root-port,id=pcie.port1,bus=pcie.1 \
> -device virtio-net-pci,bus=pcie.port1
>
> In Qemu, pxb-pcie acts as a special root complex whose parent is
> effectively the default root complex(pcie.0). Hence, though pcie.1
> has no associated SMMUv3 as per above,
> pci_device_get_iommu_bus_devfn()
> will incorrectly return the IOMMU ops from pcie.0 due to the fallback
> via parent_dev.
>
> To fix this, introduce a new helper pci_setup_iommu_per_bus() that
> explicitly sets the new iommu_per_bus field in the PCIBus structure.
> Update pci_device_get_iommu_bus_devfn() to use this when determining
> the correct IOMMU ops, ensuring accurate behavior for per-bus IOMMUs.
>
> Signed-off-by: Shameer Kolothum
> <shameerali.kolothum.thodi@huawei.com>
> ---
> Please refer cover letter for more details on the issue that
> this is trying to fix.
> ---
> hw/pci/pci.c | 25 +++++++++++++++++++++++++
> include/hw/pci/pci.h | 2 ++
> include/hw/pci/pci_bus.h | 1 +
> 3 files changed, 28 insertions(+)
>
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index c70b5ceeba..e1940c05d9 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -2909,6 +2909,19 @@ static void
> pci_device_get_iommu_bus_devfn(PCIDevice *dev,
> }
> }
>
> + /*
> + * When multiple PCI Express Root Buses are defined using pxb-pcie,
> + * the IOMMU configuration may be specific to each root bus.
> However,
> + * pxb-pcie acts as a special root complex whose parent is effectively
> + * the default root complex(pcie.0). Ensure that we retrieve the
> + * correct IOMMU ops(if any) in such cases.
> + */
> + if (pci_bus_is_express(iommu_bus) && pci_bus_is_root(iommu_bus))
> {
> + if (!iommu_bus->iommu_per_bus && parent_bus-
> >iommu_per_bus) {
> + break;
> + }
> + }
> +
> iommu_bus = parent_bus;
> }
>
> @@ -3169,6 +3182,18 @@ void pci_setup_iommu(PCIBus *bus, const
> PCIIOMMUOps *ops, void *opaque)
> bus->iommu_opaque = opaque;
> }
>
> +/*
> + * This is same as pci_setup_iommu() except it sets the iommu_per_bus
> + * to true indicating the iommu is specific to this bus and
> + * not applicable to any parent or child.
> + */
> +void pci_setup_iommu_per_bus(PCIBus *bus, const PCIIOMMUOps *ops,
> + void *opaque)
> +{
> + pci_setup_iommu(bus, ops, opaque);
> + bus->iommu_per_bus = true;
> +}
> +
> 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 df3cc7b875..a3e0870a15 100644
> --- a/include/hw/pci/pci.h
> +++ b/include/hw/pci/pci.h
> @@ -764,6 +764,8 @@ 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);
> +
> 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 2261312546..c738446788 100644
> --- a/include/hw/pci/pci_bus.h
> +++ b/include/hw/pci/pci_bus.h
> @@ -35,6 +35,7 @@ struct PCIBus {
> enum PCIBusFlags flags;
> const PCIIOMMUOps *iommu_ops;
> void *iommu_opaque;
> + bool iommu_per_bus;
> uint8_t devfn_min;
> uint32_t slot_reserved_mask;
> pci_set_irq_fn set_irq;
> --
> 2.34.1
>
next prev parent reply other threads:[~2025-06-30 7:38 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-23 9:42 [PATCH v5 00/11] hw/arm/virt: Add support for user creatable SMMUv3 device Shameer Kolothum via
2025-06-23 9:42 ` Shameer Kolothum via
2025-06-23 9:42 ` [PATCH v5 01/11] hw/arm/smmu-common: Check SMMU has PCIe Root Complex association Shameer Kolothum via
2025-06-23 9:42 ` Shameer Kolothum via
2025-06-23 11:32 ` Jonathan Cameron via
2025-06-23 11:32 ` Jonathan Cameron via
2025-06-27 11:52 ` Eric Auger
2025-06-30 7:01 ` Shameerali Kolothum Thodi via
2025-06-30 7:01 ` Shameerali Kolothum Thodi via
2025-07-01 6:31 ` Eric Auger
2025-06-23 9:42 ` [PATCH v5 02/11] hw/arm/virt-acpi-build: Re-arrange SMMUv3 IORT build Shameer Kolothum via
2025-06-23 9:42 ` Shameer Kolothum via
2025-06-27 11:54 ` Eric Auger
2025-06-23 9:42 ` [PATCH v5 03/11] hw/arm/virt-acpi-build: Update IORT for multiple smmuv3 devices Shameer Kolothum via
2025-06-23 9:42 ` Shameer Kolothum via
2025-06-23 9:42 ` [PATCH v5 04/11] hw/arm/virt: Factor out common SMMUV3 dt bindings code Shameer Kolothum via
2025-06-23 9:42 ` Shameer Kolothum via
2025-06-23 9:42 ` [PATCH v5 05/11] hw/arm/virt: Add an SMMU_IO_LEN macro Shameer Kolothum via
2025-06-23 9:42 ` Shameer Kolothum via
2025-06-23 11:35 ` Jonathan Cameron via
2025-06-23 9:42 ` [PATCH v5 06/11] hw/pci: Introduce pci_setup_iommu_per_bus() for per-bus IOMMU ops retrieval Shameer Kolothum via
2025-06-23 9:42 ` Shameer Kolothum via
2025-06-23 11:39 ` Jonathan Cameron via
2025-06-27 12:04 ` Eric Auger
2025-06-30 7:05 ` Shameerali Kolothum Thodi via
2025-06-30 7:05 ` Shameerali Kolothum Thodi via
2025-06-30 7:37 ` Shameerali Kolothum Thodi via [this message]
2025-06-23 9:42 ` [PATCH v5 07/11] hw/arm/virt: Allow user-creatable SMMUv3 dev instantiation Shameer Kolothum via
2025-06-23 9:42 ` Shameer Kolothum via
2025-06-23 11:46 ` Jonathan Cameron via
2025-06-23 11:46 ` Jonathan Cameron via
2025-06-27 12:05 ` Eric Auger
2025-06-23 9:42 ` [PATCH v5 08/11] qemu-options.hx: Document the arm-smmuv3 device Shameer Kolothum via
2025-06-23 9:42 ` Shameer Kolothum via
2025-06-23 11:47 ` Jonathan Cameron via
2025-06-23 11:47 ` Jonathan Cameron via
2025-06-27 12:08 ` Eric Auger
2025-06-23 9:42 ` [PATCH v5 09/11] bios-tables-test: Allow for smmuv3 test data Shameer Kolothum via
2025-06-23 11:49 ` Jonathan Cameron via
2025-06-27 12:14 ` Eric Auger
2025-06-23 9:42 ` [PATCH v5 10/11] qtest/bios-tables-test: Add tests for legacy smmuv3 and smmuv3 device Shameer Kolothum via
2025-06-23 11:57 ` Jonathan Cameron via
2025-06-23 11:57 ` Jonathan Cameron via
2025-06-27 12:34 ` Eric Auger
2025-06-30 7:08 ` Shameerali Kolothum Thodi via
2025-06-30 7:08 ` Shameerali Kolothum Thodi via
2025-06-23 9:42 ` [PATCH v5 11/11] qtest/bios-tables-test: Update tables for smmuv3 tests Shameer Kolothum via
2025-06-23 12:00 ` Jonathan Cameron via
2025-06-23 12:00 ` Jonathan Cameron via
2025-06-27 12:36 ` Eric Auger
2025-06-30 7:11 ` Shameerali Kolothum Thodi via
2025-06-30 7:11 ` Shameerali Kolothum Thodi via
2025-07-01 6:35 ` Eric Auger
2025-06-27 12:36 ` [PATCH v5 00/11] hw/arm/virt: Add support for user creatable SMMUv3 device Eric Auger
2025-06-30 7:12 ` Shameerali Kolothum Thodi via
2025-06-30 7:12 ` Shameerali Kolothum Thodi via
2025-07-01 6:37 ` Eric Auger
2025-07-02 1:01 ` Nathan Chen
2025-07-02 15:08 ` Shameerali Kolothum Thodi via
2025-07-02 15:08 ` Shameerali Kolothum Thodi via
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=3253e85fbabe4207bba56378f241e68e@huawei.com \
--to=qemu-arm@nongnu.org \
--cc=berrange@redhat.com \
--cc=ddutile@redhat.com \
--cc=eric.auger@redhat.com \
--cc=gustavo.romero@linaro.org \
--cc=imammedo@redhat.com \
--cc=jgg@nvidia.com \
--cc=jiangkunkun@huawei.com \
--cc=jonathan.cameron@huawei.com \
--cc=linuxarm@huawei.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mochs@nvidia.com \
--cc=mst@redhat.com \
--cc=nathanc@nvidia.com \
--cc=nicolinc@nvidia.com \
--cc=peter.maydell@linaro.org \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=smostafa@google.com \
--cc=wangzhou1@hisilicon.com \
--cc=zhangfei.gao@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.