hw/arm/virt: Add support for user-creatable accelerated SMMUv3
v6 cover hw/arm/virt: Add support for user-creatable accelerated SMMUv3
Hi,
Changes from v5:
https://lore.kernel.org/qemu-devel/[email protected]/
- Addressed feedback from v5 and picked up R-by tags. Thanks to all!
- The previously split out _DSM fix mini-series is now accepted [0].
- Improved documentation about the rationale behind the design choice of returning an address space aliased to the system address space for vfio-pci endpoint devices (patch #10).
- Added error propagation support for smmuv3_cmdq_consume() (patch #13).
- Updated vSTE based HWPT installation to check the SMMU enabled case (patch #14).
- Introduced an optional callback to PCIIOMMUOps to retrieve the MSI doorbell GPA directly, allowing us to avoid unsafe page table walks for MSI translation in accelerated SMMUv3 cases (patch #16).
- GBPA-based vSTE update depends on Nicolin's kernel patch [1].
- VFIO/IOMMUFD has dependency on Zhenzhong's patches: 4/5/8 from the pass-through support series [2].
PATCH organization:
1–26: Enables accelerated SMMUv3 with features based on default QEMU SMMUv3,
including IORT RMR based MSI support.
27–29: Adds options for specifying RIL, ATS, and OAS features. 30–33: Adds PASID support, including VFIO changes.
Tests:
Performed basic sanity tests on an NVIDIA GRACE platform with GPU device assignments. A CUDA test application was used to verify the SVA use case. Further tests are always welcome.
Eg: Qemu Cmd line:
qemu-system-aarch64 -machine virt,gic-version=3,highmem-mmio-size=2T \
-cpu host -smp cpus=4 -m size=16G,slots=2,maxmem=66G -nographic \
-bios QEMU_EFI.fd -object iommufd,id=iommufd0 -enable-kvm \
-object memory-backend-ram,size=8G,id=m0 \
-object memory-backend-ram,size=8G,id=m1 \
-numa node,memdev=m0,cpus=0-3,nodeid=0 -numa node,memdev=m1,nodeid=1 \
-numa node,nodeid=2 -numa node,nodeid=3 -numa node,nodeid=4 -numa node,nodeid=5 \
-numa node,nodeid=6 -numa node,nodeid=7 -numa node,nodeid=8 -numa node,nodeid=9 \
-device pxb-pcie,id=pcie.1,bus_nr=1,bus=pcie.0 \
-device arm-smmuv3,primary-bus=pcie.1,id=smmuv3.0,accel=on,ats=on,ril=off,pasid=on,oas=48 \
-device pcie-root-port,id=pcie.port1,bus=pcie.1,chassis=1,pref64-reserve=512G,id=dev0 \
-device vfio-pci,host=0019:06:00.0,rombar=0,id=dev0,iommufd=iommufd0,bus=pcie.port1 \
-object acpi-generic-initiator,id=gi0,pci-dev=dev0,node=2 \
...
-object acpi-generic-initiator,id=gi7,pci-dev=dev0,node=9 \
-device pxb-pcie,id=pcie.2,bus_nr=8,bus=pcie.0 \
-device arm-smmuv3,primary-bus=pcie.2,id=smmuv3.1,accel=on,ats=on,ril=off,pasid=on \
-device pcie-root-port,id=pcie.port2,bus=pcie.2,chassis=2,pref64-reserve=512G \
-device vfio-pci,host=0018:06:00.0,rombar=0,id=dev1,iommufd=iommufd0,bus=pcie.port2 \
-device virtio-blk-device,drive=fs \
-drive file=image.qcow2,index=0,media=disk,format=qcow2,if=none,id=fs \
-net none \
-nographic
A complete branch can be found here,
https://github.com/shamiali2008/qemu-master master-smmuv3-accel-v6
Please take a look and let me know your feedback.
Thanks,
Shameer
[0] https://lore.kernel.org/qemu-devel/[email protected]/
[1] https://lore.kernel.org/linux-iommu/[email protected]/
[2] https://lore.kernel.org/qemu-devel/[email protected]/
Details from RFCv3 Cover letter:
-------------------------------
https://lore.kernel.org/qemu-devel/[email protected]/
This patch series introduces initial support for a user-creatable, accelerated SMMUv3 device (-device arm-smmuv3,accel=on) in QEMU.
This is based on the user-creatable SMMUv3 device series [0].
Why this is needed:
On ARM, to enable vfio-pci pass-through devices in a VM, the host SMMUv3 must be set up in nested translation mode (Stage 1 + Stage 2), with Stage 1 (S1) controlled by the guest and Stage 2 (S2) managed by the host.
This series introduces an optional accel property for the SMMUv3 device, indicating that the guest will try to leverage host SMMUv3 features for acceleration. By default, enabling accel configures the host SMMUv3 in nested mode to support vfio-pci pass-through.
This new accelerated, user-creatable SMMUv3 device lets you:
-Set up a VM with multiple SMMUv3s, each tied to a different physical SMMUv3
on the host. Typically, you’d have multiple PCIe PXB root complexes in the VM (one per virtual NUMA node), and each of them can have its own SMMUv3. This setup mirrors the host's layout, where each NUMA node has its own SMMUv3, and helps build VMs that are more aligned with the host's NUMA topology.
-The host–guest SMMUv3 association results in reduced invalidation broadcasts
and lookups for devices behind different physical SMMUv3s.
-Simplifies handling of host SMMUv3s with differing feature sets.
-Lays the groundwork for additional capabilities like vCMDQ support.
-------------------------------
Eric Auger (2):
hw/pci-host/gpex: Allow to generate preserve boot config DSM #5 hw/arm/virt-acpi-build: Add IORT RMR regions to handle MSI nested
binding
Nicolin Chen (4):
backends/iommufd: Introduce iommufd_backend_alloc_viommu backends/iommufd: Introduce iommufd_backend_alloc_vdev hw/arm/smmuv3-accel: Add set/unset_iommu_device callback hw/arm/smmuv3-accel: Add nested vSTE install/uninstall support
Shameer Kolothum (26):
hw/arm/smmu-common: Factor out common helper functions and export hw/arm/smmu-common: Make iommu ops part of SMMUState hw/arm/smmuv3-accel: Introduce smmuv3 accel device hw/arm/smmuv3-accel: Initialize shared system address space hw/pci/pci: Move pci_init_bus_master() after adding device to bus hw/pci/pci: Add optional supports_address_space() callback hw/pci-bridge/pci_expander_bridge: Move TYPE_PXB_PCIE_DEV to header hw/arm/smmuv3-accel: Restrict accelerated SMMUv3 to vfio-pci endpoints
with iommufd
hw/arm/smmuv3: Implement get_viommu_cap() callback hw/arm/smmuv3: propagate smmuv3_cmdq_consume() errors to caller hw/arm/smmuv3-accel: Install SMMUv3 GBPA based hwpt hw/pci/pci: Introduce a callback to retrieve the MSI doorbell GPA
directly
hw/arm/smmuv3: Add support for providing a direct MSI doorbell GPA hw/arm/smmuv3-accel: Add support to issue invalidation cmd to host hw/arm/smmuv3: Initialize ID registers early during realize() hw/arm/smmuv3-accel: Get host SMMUv3 hw info and validate hw/arm/virt: Set PCI preserve_config for accel SMMUv3 tests/qtest/bios-tables-test: Prepare for IORT revison upgrade tests/qtest/bios-tables-test: Update IORT blobs after revision upgrade hw/arm/smmuv3: Add accel property for SMMUv3 device hw/arm/smmuv3-accel: Add a property to specify RIL support hw/arm/smmuv3-accel: Add support for ATS hw/arm/smmuv3-accel: Add property to specify OAS bits backends/iommufd: Retrieve PASID width from
iommufd_backend_get_device_info()
Extend get_cap() callback to support PASID hw/arm/smmuv3-accel: Add support for PASID enable
Yi Liu (1):
vfio: Synthesize vPASID capability to VM
backends/iommufd.c | 82 +- backends/trace-events | 2 + hw/arm/Kconfig | 5 + hw/arm/meson.build | 3 +- hw/arm/smmu-common.c | 51 +- hw/arm/smmuv3-accel.c | 756 ++++++++++++++++++ hw/arm/smmuv3-accel.h | 86 ++ hw/arm/smmuv3-internal.h | 27 +- hw/arm/smmuv3.c | 206 ++++- hw/arm/trace-events | 6 + hw/arm/virt-acpi-build.c | 127 ++- hw/arm/virt.c | 30 + hw/i386/intel_iommu.c | 8 +- hw/pci-bridge/pci_expander_bridge.c | 1 - hw/pci-host/gpex-acpi.c | 29 +- hw/pci/pci.c | 43 +- hw/vfio/container-legacy.c | 8 +- hw/vfio/iommufd.c | 7 +- hw/vfio/pci.c | 38 + include/hw/arm/smmu-common.h | 7 + include/hw/arm/smmuv3.h | 10 + include/hw/arm/virt.h | 1 + include/hw/iommu.h | 1 + include/hw/pci-host/gpex.h | 1 + include/hw/pci/pci.h | 34 + include/hw/pci/pci_bridge.h | 1 + include/system/host_iommu_device.h | 21 +- include/system/iommufd.h | 29 +- target/arm/kvm.c | 18 +- tests/data/acpi/aarch64/virt/IORT | Bin 128 -> 128 bytes tests/data/acpi/aarch64/virt/IORT.its_off | Bin 172 -> 172 bytes tests/data/acpi/aarch64/virt/IORT.smmuv3-dev | Bin 364 -> 364 bytes .../data/acpi/aarch64/virt/IORT.smmuv3-legacy | Bin 276 -> 276 bytes 33 files changed, 1536 insertions(+), 102 deletions(-) create mode 100644 hw/arm/smmuv3-accel.c create mode 100644 hw/arm/smmuv3-accel.h
Signature · 1 line
2.43.0
PATCH v6 1/33 backends/iommufd: Introduce iommufd_backend_alloc_viommu
From: Nicolin Chen <[email protected]>
Add a helper to allocate a viommu object.
Also introduce a struct IOMMUFDViommu that can be used later by vendor IOMMU implementations.
--- backends/iommufd.c | 26 ++++++++++++++++++++++++++ backends/trace-events | 1 + include/system/iommufd.h | 14 ++++++++++++++ 3 files changed, 41 insertions(+)
backends/iommufd.c +26 -0
@@ -446,6 +446,32 @@ bool iommufd_backend_invalidate_cache(IOMMUFDBackend *be, uint32_t id,return !ret; } +bool iommufd_backend_alloc_viommu (IOMMUFDBackend *be,uint32_t dev_id, +uint32_t viommu_type,uint32_t hwpt_id, +uint32_t *out_viommu_id,Error **errp) +{ +int ret; +struct iommu_viommu_alloc alloc_viommu = { + .size =sizeof (alloc_viommu), + .type = viommu_type, + .dev_id = dev_id, + .hwpt_id = hwpt_id, + }; + + ret =ioctl (be->fd,IOMMU_VIOMMU_ALLOC , &alloc_viommu); + +trace_iommufd_backend_alloc_viommu (be->fd, dev_id, viommu_type, hwpt_id, + alloc_viommu.out_viommu_id, ret); +if (ret) { +error_setg_errno (errp, errno,"IOMMU_VIOMMU_ALLOC failed" ); +return false; + } + +g_assert (out_viommu_id); + *out_viommu_id = alloc_viommu.out_viommu_id; +return true; +} +bool host_iommu_device_iommufd_attach_hwpt (HostIOMMUDeviceIOMMUFD *idev,uint32_t hwpt_id,Error **errp) {
backends/trace-events +1 -0
@@ -21,3 +21,4 @@ iommufd_backend_free_id(int iommufd, uint32_t id, int ret) " iommufd=%d id=%d (% iommufd_backend_set_dirty(int iommufd, uint32_t hwpt_id, bool start, int ret) " iommufd=%d hwpt=%u enable=%d (%d)" iommufd_backend_get_dirty_bitmap(int iommufd, uint32_t hwpt_id, uint64_t iova, uint64_t size, uint64_t page_size, int ret) " iommufd=%d hwpt=%u iova=0x%"PRIx64" size=0x%"PRIx64" page_size=0x%"PRIx64" (%d)" iommufd_backend_invalidate_cache(int iommufd, uint32_t id, uint32_t data_type, uint32_t entry_len, uint32_t entry_num, uint32_t done_num, uint64_t data_ptr, int ret) " iommufd=%d id=%u data_type=%u entry_len=%u entry_num=%u done_num=%u data_ptr=0x%"PRIx64" (%d)" +iommufd_backend_alloc_viommu(int iommufd, uint32_t dev_id, uint32_t type, uint32_t hwpt_id, uint32_t viommu_id, int ret) " iommufd=%d type=%u dev_id=%u hwpt_id=%u viommu_id=%u (%d)"
include/system/iommufd.h +14 -0
@@ -38,6 +38,16 @@ struct IOMMUFDBackend {/*< public >*/ }; +/* +* Virtual IOMMU object that represents physical IOMMU's virtualization +* support +*/ +typedef struct IOMMUFDViommu { +IOMMUFDBackend *iommufd; +uint32_t s2_hwpt_id;/* ID of stage 2 HWPT */ +uint32_t viommu_id;/* virtual IOMMU ID of allocated object */ +}IOMMUFDViommu ; +bool iommufd_backend_connect (IOMMUFDBackend *be,Error **errp);void iommufd_backend_disconnect (IOMMUFDBackend *be);
@@ -59,6 +69,10 @@ bool iommufd_backend_alloc_hwpt(IOMMUFDBackend *be, uint32_t dev_id, uint32_t data_type, uint32_t data_len, void *data_ptr, uint32_t *out_hwpt, Error **errp); +bool iommufd_backend_alloc_viommu (IOMMUFDBackend *be,uint32_t dev_id, +uint32_t viommu_type,uint32_t hwpt_id, +uint32_t *out_hwpt,Error **errp); +bool iommufd_backend_set_dirty_tracking (IOMMUFDBackend *be,uint32_t hwpt_id,bool start,Error **errp); bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be, uint32_t hwpt_id,
Signature · 1 line
2.43.0
PATCH v6 2/33 backends/iommufd: Introduce iommufd_backend_alloc_vdev
In reply to Shameer KolothumFrom: Nicolin Chen <[email protected]>
Add a helper to allocate an iommufd device's virtual device (in the user space) per a viommu instance.
While at it, introduce a struct IOMMUFDVdev for later use by vendor IOMMU implementations.
--- backends/iommufd.c | 27 +++++++++++++++++++++++++++ backends/trace-events | 1 + include/system/iommufd.h | 12 ++++++++++++ 3 files changed, 40 insertions(+)
backends/iommufd.c +27 -0
@@ -472,6 +472,33 @@ bool iommufd_backend_alloc_viommu(IOMMUFDBackend *be, uint32_t dev_id,return true; } +bool iommufd_backend_alloc_vdev (IOMMUFDBackend *be,uint32_t dev_id, +uint32_t viommu_id,uint64_t virt_id, +uint32_t *out_vdev_id,Error **errp) +{ +int ret; +struct iommu_vdevice_alloc alloc_vdev = { + .size =sizeof (alloc_vdev), + .viommu_id = viommu_id, + .dev_id = dev_id, + .virt_id = virt_id, + }; + + ret =ioctl (be->fd,IOMMU_VDEVICE_ALLOC , &alloc_vdev); + +trace_iommufd_backend_alloc_vdev (be->fd, dev_id, viommu_id, virt_id, + alloc_vdev.out_vdevice_id, ret); + +if (ret) { +error_setg_errno (errp, errno,"IOMMU_VDEVICE_ALLOC failed" ); +return false; + } + +g_assert (out_vdev_id); + *out_vdev_id = alloc_vdev.out_vdevice_id; +return true; +} +bool host_iommu_device_iommufd_attach_hwpt (HostIOMMUDeviceIOMMUFD *idev,uint32_t hwpt_id,Error **errp) {
backends/trace-events +1 -0
@@ -22,3 +22,4 @@ iommufd_backend_set_dirty(int iommufd, uint32_t hwpt_id, bool start, int ret) " iommufd_backend_get_dirty_bitmap(int iommufd, uint32_t hwpt_id, uint64_t iova, uint64_t size, uint64_t page_size, int ret) " iommufd=%d hwpt=%u iova=0x%"PRIx64" size=0x%"PRIx64" page_size=0x%"PRIx64" (%d)" iommufd_backend_invalidate_cache(int iommufd, uint32_t id, uint32_t data_type, uint32_t entry_len, uint32_t entry_num, uint32_t done_num, uint64_t data_ptr, int ret) " iommufd=%d id=%u data_type=%u entry_len=%u entry_num=%u done_num=%u data_ptr=0x%"PRIx64" (%d)" iommufd_backend_alloc_viommu(int iommufd, uint32_t dev_id, uint32_t type, uint32_t hwpt_id, uint32_t viommu_id, int ret) " iommufd=%d type=%u dev_id=%u hwpt_id=%u viommu_id=%u (%d)" +iommufd_backend_alloc_vdev(int iommufd, uint32_t dev_id, uint32_t viommu_id, uint64_t virt_id, uint32_t vdev_id, int ret) " iommufd=%d dev_id=%u viommu_id=%u virt_id=0x%"PRIx64" vdev_id=%u (%d)"
include/system/iommufd.h +12 -0
@@ -48,6 +48,14 @@ typedef struct IOMMUFDViommu {uint32_t viommu_id;/* virtual IOMMU ID of allocated object */ } IOMMUFDViommu; +/* +* Virtual device object for a physical device bind to a vIOMMU. +*/ +typedef struct IOMMUFDVdev { +uint32_t vdevice_id;/* object handle for vDevice */ +uint32_t virt_id;/* virtual device ID */ +}IOMMUFDVdev ; +bool iommufd_backend_connect (IOMMUFDBackend *be,Error **errp);void iommufd_backend_disconnect (IOMMUFDBackend *be);
@@ -73,6 +81,10 @@ bool iommufd_backend_alloc_viommu(IOMMUFDBackend *be, uint32_t dev_id, uint32_t viommu_type, uint32_t hwpt_id, uint32_t *out_hwpt, Error **errp); +bool iommufd_backend_alloc_vdev (IOMMUFDBackend *be,uint32_t dev_id, +uint32_t viommu_id,uint64_t virt_id, +uint32_t *out_vdev_id,Error **errp); +bool iommufd_backend_set_dirty_tracking (IOMMUFDBackend *be,uint32_t hwpt_id,bool start,Error **errp); bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be, uint32_t hwpt_id,
Signature · 1 line
2.43.0
PATCH v6 3/33 hw/arm/smmu-common: Factor out common helper functions and export
In reply to Shameer KolothumFactor out common helper functions and export. Subsequent patches for smmuv3 accel support will make use of this.
--- hw/arm/smmu-common.c | 44 +++++++++++++++++++++--------------- include/hw/arm/smmu-common.h | 6 +++++ 2 files changed, 32 insertions(+), 18 deletions(-)
hw/arm/smmu-common.c +26 -18
@@ -847,12 +847,24 @@ SMMUPciBus *smmu_find_smmu_pcibus(SMMUState *s, uint8_t bus_num)return NULL ; } -static AddressSpace *smmu_find_add_as (PCIBus *bus,void *opaque,int devfn) +void smmu_init_sdev (SMMUState *s,SMMUDevice *sdev,PCIBus *bus,int devfn) { -SMMUState *s = opaque; -SMMUPciBus *sbus =g_hash_table_lookup (s->smmu_pcibus_by_busptr, bus); -SMMUDevice *sdev;static unsigned int index; + g_autofree char *name = g_strdup_printf("%s-%d-%d", s->mrtypename, devfn, + index++); + sdev->smmu = s; + sdev->bus = bus; + sdev->devfn = devfn; + +memory_region_init_iommu (&sdev->iommu,sizeof (sdev->iommu), + s->mrtypename,OBJECT (s), name,UINT64_MAX ); +address_space_init (&sdev->as,MEMORY_REGION (&sdev->iommu), name); +trace_smmu_add_mr (name); +} + +SMMUPciBus *smmu_get_sbus (SMMUState *s,PCIBus *bus) +{ +SMMUPciBus *sbus =g_hash_table_lookup (s->smmu_pcibus_by_busptr, bus);if (!sbus) { sbus = g_malloc0(sizeof(SMMUPciBus) +
@@ -861,23 +873,19 @@ static AddressSpace *smmu_find_add_as(PCIBus *bus, void *opaque, int devfn)g_hash_table_insert (s->smmu_pcibus_by_busptr, bus, sbus); } +return sbus; +} + +static AddressSpace *smmu_find_add_as (PCIBus *bus,void *opaque,int devfn) +{ +SMMUState *s = opaque; +SMMUPciBus *sbus =smmu_get_sbus (s, bus); +SMMUDevice *sdev; + sdev = sbus->pbdev[devfn];if (!sdev) { -char *name =g_strdup_printf ("%s-%d-%d" , s->mrtypename, devfn, index++); - sdev = sbus->pbdev[devfn] =g_new0 (SMMUDevice,1 ); - - sdev->smmu = s; - sdev->bus = bus; - sdev->devfn = devfn; - -memory_region_init_iommu (&sdev->iommu,sizeof (sdev->iommu), - s->mrtypename, -OBJECT (s), name,UINT64_MAX ); -address_space_init (&sdev->as, -MEMORY_REGION (&sdev->iommu), name); -trace_smmu_add_mr (name); -g_free (name); +smmu_init_sdev (s, sdev, bus, devfn); }return &sdev->as;
include/hw/arm/smmu-common.h +6 -0
@@ -180,6 +180,12 @@ OBJECT_DECLARE_TYPE(SMMUState, SMMUBaseClass, ARM_SMMU)/* Return the SMMUPciBus handle associated to a PCI bus number */ SMMUPciBus *smmu_find_smmu_pcibus (SMMUState *s,uint8_t bus_num); +/* Return the SMMUPciBus handle associated to a PCI bus */ +SMMUPciBus *smmu_get_sbus (SMMUState *s,PCIBus *bus); + +/* Initialize SMMUDevice handle associated to a SMMUPciBus */ +void smmu_init_sdev (SMMUState *s,SMMUDevice *sdev,PCIBus *bus,int devfn); +/* Return the stream ID of an SMMU device */ static inline uint16_t smmu_get_sid (SMMUDevice *sdev) {
Signature · 1 line
2.43.0
PATCH v6 4/33 hw/arm/smmu-common: Make iommu ops part of SMMUState
In reply to Shameer KolothumMake iommu ops part of SMMUState and set to the current default smmu_ops. No functional change intended. This will allow SMMUv3 accel implementation to set a different iommu ops later.
--- hw/arm/smmu-common.c | 7 +++++-- include/hw/arm/smmu-common.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-)
hw/arm/smmu-common.c +5 -2
@@ -952,6 +952,9 @@ static void smmu_base_realize(DeviceState *dev, Error **errp)return ; } +if (!s->iommu_ops) { + s->iommu_ops = &smmu_ops; + }/* * We only allow default PCIe Root Complex(pcie.0) or pxb-pcie based extra * root complexes to be associated with SMMU.
@@ -971,9 +974,9 @@ static void smmu_base_realize(DeviceState *dev, Error **errp) }if (s->smmu_per_bus) { -pci_setup_iommu_per_bus (pci_bus, &smmu_ops, s); +pci_setup_iommu_per_bus (pci_bus, s->iommu_ops, s); }else { -pci_setup_iommu (pci_bus, &smmu_ops, s); +pci_setup_iommu (pci_bus, s->iommu_ops, s); }return ; }
include/hw/arm/smmu-common.h +1 -0
@@ -162,6 +162,7 @@ struct SMMUState {uint8_t bus_num;PCIBus *primary_bus;bool smmu_per_bus;/* SMMU is specific to the primary_bus */ +const PCIIOMMUOps *iommu_ops; };struct SMMUBaseClass {
Signature · 1 line
2.43.0
Re: [PATCH v6 04/33] hw/arm/smmu-common: Make iommu ops part of SMMUState
Hello Shameer,
Quoted 3 lines · Shameer Kolothum
Make iommu ops part of SMMUState and set to the current default
smmu_ops. No functional change intended. This will allow SMMUv3 accel implementation to set a different iommu ops later.
Hmm, shouldn't this be a class attribute instead ? I will check the rest of the series.
C.
Quoted 48 lines
Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Nicolin Chen <[email protected]>Reviewed-by Eric Auger <[email protected]>Tested-by Zhangfei Gao <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmu-common.c | 7 +++++-- include/hw/arm/smmu-common.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-)hw/arm/smmu-common.c +5
-2@@ -952,6 +952,9 @@ static void smmu_base_realize(DeviceState *dev, Error **errp)return ; } +if (!s->iommu_ops) { + s->iommu_ops = &smmu_ops; + }> /** We only allow default PCIe Root Complex(pcie.0) or pxb-pcie based extra * root complexes to be associated with SMMU. @@ -971,9 +974,9 @@ static void smmu_base_realize(DeviceState *dev, Error **errp) }if (s->smmu_per_bus) { -pci_setup_iommu_per_bus (pci_bus, &smmu_ops, s); +pci_setup_iommu_per_bus (pci_bus, s->iommu_ops, s); }else { -pci_setup_iommu (pci_bus, &smmu_ops, s); +pci_setup_iommu (pci_bus, s->iommu_ops, s); }return ; }include/hw/arm/smmu-common.h +1
-0@@ -162,6 +162,7 @@ struct SMMUState {uint8_t bus_num;PCIBus *primary_bus;bool smmu_per_bus;/* SMMU is specific to the primary_bus */ +const PCIIOMMUOps *iommu_ops; };struct SMMUBaseClass {
PATCH v6 5/33 hw/arm/smmuv3-accel: Introduce smmuv3 accel device
In reply to Shameer KolothumSet up dedicated PCIIOMMUOps for the accel SMMUv3, since it will need different callback handling in upcoming patches. This also adds a CONFIG_ARM_SMMUV3_ACCEL build option so the feature can be disabled at compile time. Because we now include CONFIG_DEVICES in the header to check for ARM_SMMUV3_ACCEL, the meson file entry for smmuv3.c needs to be changed to arm_ss.add.
The “accel” property isn’t user visible yet and it will be introduced in a later patch once all the supporting pieces are ready.
--- hw/arm/Kconfig | 5 ++++ hw/arm/meson.build | 3 ++- hw/arm/smmuv3-accel.c | 59 +++++++++++++++++++++++++++++++++++++++++ hw/arm/smmuv3-accel.h | 27 +++++++++++++++++++ hw/arm/smmuv3.c | 5 ++++ include/hw/arm/smmuv3.h | 3 +++ 6 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 hw/arm/smmuv3-accel.c create mode 100644 hw/arm/smmuv3-accel.h
hw/arm/Kconfig +5 -0
@@ -12,6 +12,7 @@ config ARM_VIRT select ARM_GIC select ACPI select ARM_SMMUV3 + select ARM_SMMUV3_ACCEL select GPIO_KEY select DEVICE_TREE select FW_CFG_DMA
@@ -629,6 +630,10 @@ config FSL_IMX8MP_EVK config ARM_SMMUV3 bool +config ARM_SMMUV3_ACCEL + bool + depends on ARM_SMMUV3 && IOMMUFD + config FSL_IMX6UL bool default y
hw/arm/meson.build +2 -1
@@ -84,7 +84,8 @@ arm_common_ss.add(when: 'CONFIG_ARMSSE', if_true: files('armsse.c')) arm_common_ss.add(when: 'CONFIG_FSL_IMX7', if_true: files('fsl-imx7.c', 'mcimx7d-sabre.c')) arm_common_ss.add(when: 'CONFIG_FSL_IMX8MP', if_true: files('fsl-imx8mp.c')) arm_common_ss.add(when: 'CONFIG_FSL_IMX8MP_EVK', if_true: files('imx8mp-evk.c')) -arm_common_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmuv3.c')) +arm_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmuv3.c')) +arm_ss.add(when: 'CONFIG_ARM_SMMUV3_ACCEL', if_true: files('smmuv3-accel.c')) arm_common_ss.add(when: 'CONFIG_FSL_IMX6UL', if_true: files('fsl-imx6ul.c', 'mcimx6ul-evk.c')) arm_common_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_soc.c')) arm_common_ss.add(when: 'CONFIG_XEN', if_true: files(
hw/arm/smmuv3-accel.c new file +59 -0
59 lines not on this page · raw message
hw/arm/smmuv3-accel.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* Copyright (c) 2025 Huawei Technologies R & D (UK) Ltd +* Copyright (C) 2025 NVIDIA +* Written by Nicolin Chen, Shameer Kolothum +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_ARM_SMMUV3_ACCEL_H +#define HW_ARM_SMMUV3_ACCEL_H + +#include "hw/arm/smmu-common.h" +#include CONFIG_DEVICES + +typedef struct SMMUv3AccelDevice { +SMMUDevice sdev; +}SMMUv3AccelDevice ; + +#ifdef CONFIG_ARM_SMMUV3_ACCEL +void smmuv3_accel_init (SMMUv3State *s); +#else +static inline void smmuv3_accel_init (SMMUv3State *s) +{ +} +#endif + +#endif /* HW_ARM_SMMUV3_ACCEL_H */
hw/arm/smmuv3.c +5 -0
@@ -32,6 +32,7 @@#include "qapi/error.h" #include "hw/arm/smmuv3.h" +#include "smmuv3-accel.h" #include "smmuv3-internal.h" #include "smmu-internal.h"
@@ -1882,6 +1883,10 @@ static void smmu_realize(DeviceState *d, Error **errp)SysBusDevice *dev =SYS_BUS_DEVICE (d);Error *local_err =NULL ; +if (s->accel) { +smmuv3_accel_init (s); + } + c->parent_realize (d, &local_err);if (local_err) {error_propagate (errp, local_err);
include/hw/arm/smmuv3.h +3 -0
@@ -63,6 +63,9 @@ struct SMMUv3State {qemu_irq irq[4 ];QemuMutex mutex;char *stage; + +/* SMMU has HW accelerator support for nested S1 + s2 */ +bool accel; }; typedef enum {
Signature · 1 line
2.43.0
Re: [PATCH v6 05/33] hw/arm/smmuv3-accel: Introduce smmuv3 accel device
Quoted 84 lines · Shameer Kolothum
Set up dedicated PCIIOMMUOps for the accel SMMUv3, since it will need different callback handling in upcoming patches. This also adds a
CONFIG_ARM_SMMUV3_ACCELbuild option so the feature can be disabled at compile time. Because we now includeCONFIG_DEVICESin the header to check forARM_SMMUV3_ACCEL, the meson file entry forsmmuv3.cneeds to be changed to arm_ss.add.The “accel” property isn’t user visible yet and it will be introduced in a later patch once all the supporting pieces are ready.
Signed-off-by Shameer Kolothum <[email protected]>Reviewed-by Nicolin Chen <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Eric Auger <[email protected]>Tested-by Zhangfei Gao <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/Kconfig | 5 ++++ hw/arm/meson.build | 3 ++- hw/arm/smmuv3-accel.c | 59 +++++++++++++++++++++++++++++++++++++++++ hw/arm/smmuv3-accel.h | 27 +++++++++++++++++++ hw/arm/smmuv3.c | 5 ++++ include/hw/arm/smmuv3.h | 3 +++ 6 files changed, 101 insertions(+), 1 deletion(-)create mode 100644
hw/arm/smmuv3-accel.c
create mode 100644hw/arm/smmuv3-accel.hhw/arm/Kconfig +5
-0@@ -12,6 +12,7 @@ config ARM_VIRT select ARM_GIC select ACPI select ARM_SMMUV3 + select ARM_SMMUV3_ACCEL select GPIO_KEY select DEVICE_TREE select FW_CFG_DMA@@ -629,6 +630,10 @@ config FSL_IMX8MP_EVK config ARM_SMMUV3 bool +config ARM_SMMUV3_ACCEL + bool + depends on ARM_SMMUV3 && IOMMUFD + config FSL_IMX6UL bool default yhw/arm/meson.build +2
-1@@ -84,7 +84,8 @@ arm_common_ss.add(when: 'CONFIG_ARMSSE', if_true: files('armsse.c')) arm_common_ss.add(when: 'CONFIG_FSL_IMX7', if_true: files('fsl-imx7.c', 'mcimx7d-sabre.c')) arm_common_ss.add(when: 'CONFIG_FSL_IMX8MP', if_true: files('fsl-imx8mp.c')) arm_common_ss.add(when: 'CONFIG_FSL_IMX8MP_EVK', if_true: files('imx8mp-evk.c')) -arm_common_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmuv3.c')) +arm_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmuv3.c')) +arm_ss.add(when: 'CONFIG_ARM_SMMUV3_ACCEL', if_true: files('smmuv3-accel.c')) arm_common_ss.add(when: 'CONFIG_FSL_IMX6UL', if_true: files('fsl-imx6ul.c', 'mcimx6ul-evk.c')) arm_common_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_soc.c')) arm_common_ss.add(when: 'CONFIG_XEN', if_true: files(hw/arm/smmuv3-accel.c new file +14
-0@@ -0,0 +1,59 @@ +/* +* Copyright (c) 2025 Huawei Technologies R & D (UK) Ltd +* Copyright (C) 2025 NVIDIA +* Written by Nicolin Chen, Shameer Kolothum +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" + +#include "hw/arm/smmuv3.h" +#include "smmuv3-accel.h" + +static SMMUv3AccelDevice *smmuv3_accel_get_dev(SMMUState *bs, SMMUPciBus *sbus,
hw/arm/smmuv3-accel.c line 24
Quoted 10 lines
hw/arm/smmuv3-accel.c new file +10
-0+ PCIBus *bus, int devfn) +{ +SMMUDevice *sdev = sbus->pbdev[devfn]; +SMMUv3AccelDevice *accel_dev; + +if (sdev) { +return container_of (sdev, SMMUv3AccelDevice, sdev); + } + + accel_dev =g_new0 (SMMUv3AccelDevice,1 );
oh. This is not a QOM object :/
Quoted 24 lines
hw/arm/smmuv3-accel.c new file +24
-0+ sdev = &accel_dev->sdev; + + sbus->pbdev[devfn] = sdev; +smmu_init_sdev (bs, sdev, bus, devfn); +return accel_dev; +} + +/* +* Find or add an address space for the given PCI device. +* +* If a device matching @bus and @devfn already exists, return its +* corresponding address space. Otherwise, create a new device entry +* and initialize address space for it. +*/ +static AddressSpace *smmuv3_accel_find_add_as (PCIBus *bus,void *opaque, +int devfn) +{ +SMMUState *bs = opaque; +SMMUPciBus *sbus =smmu_get_sbus (bs, bus); +SMMUv3AccelDevice *accel_dev =smmuv3_accel_get_dev (bs, sbus, bus, devfn); +SMMUDevice *sdev = &accel_dev->sdev; + +return &sdev->as; +}
hw/arm/smmuv3-accel.c line 58
Quoted 10 lines
hw/arm/smmuv3-accel.c new file +10
-0+ +static const PCIIOMMUOps smmuv3_accel_ops = { + .get_address_space = smmuv3_accel_find_add_as, +}; + +void smmuv3_accel_init (SMMUv3State *s) +{ +SMMUState *bs =ARM_SMMU (s); + + bs->iommu_ops = &smmuv3_accel_ops;
again, I think this should be a sSMMUv3Class attribute.
Quoted 62 lines
hw/arm/smmuv3-accel.c new file +1
-0+}hw/arm/smmuv3-accel.h new file +27
-0@@ -0,0 +1,27 @@ +/* +* Copyright (c) 2025 Huawei Technologies R & D (UK) Ltd +* Copyright (C) 2025 NVIDIA +* Written by Nicolin Chen, Shameer Kolothum +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_ARM_SMMUV3_ACCEL_H +#define HW_ARM_SMMUV3_ACCEL_H + +#include "hw/arm/smmu-common.h" +#include CONFIG_DEVICES + +typedef struct SMMUv3AccelDevice { +SMMUDevice sdev; +}SMMUv3AccelDevice ; + +#ifdef CONFIG_ARM_SMMUV3_ACCEL +void smmuv3_accel_init (SMMUv3State *s); +#else +static inline void smmuv3_accel_init (SMMUv3State *s) +{ +} +#endif + +#endif /* HW_ARM_SMMUV3_ACCEL_H */ hw/arm/smmuv3.c +5
-0@@ -32,6 +32,7 @@#include "qapi/error.h" #include "hw/arm/smmuv3.h" +#include "smmuv3-accel.h" #include "smmuv3-internal.h" #include "smmu-internal.h" @@ -1882,6 +1883,10 @@ static void smmu_realize(DeviceState *d, Error **errp)SysBusDevice *dev =SYS_BUS_DEVICE (d);Error *local_err =NULL ; +if (s->accel) { +smmuv3_accel_init (s); + } + c->parent_realize (d, &local_err);if (local_err) {error_propagate (errp, local_err);include/hw/arm/smmuv3.h +0
-0
include/hw/arm/smmuv3.h struct SMMUv3State { · line 68
Quoted 6 lines
include/hw/arm/smmuv3.h +3
-0@@ -63,6 +63,9 @@ struct SMMUv3State {qemu_irq irq[4 ];QemuMutex mutex;char *stage; + +/* SMMU has HW accelerator support for nested S1 + s2 */ +bool accel;
Have you considered modeling with a QOM object instead ?
Thanks,
C.
Quoted 3 lines
include/hw/arm/smmuv3.h +0
-0}; typedef enum {
RE: [PATCH v6 05/33] hw/arm/smmuv3-accel: Introduce smmuv3 accel device
Hi Cédric,
Quoted 116 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: 11 December 2025 12:55
To: Shameer Kolothum <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 05/33] hw/arm/smmuv3-accel: Introduce smmuv3 accel deviceExternal email: Use caution opening links or attachments
Quoted 5 lines · Shameer Kolothum
Set up dedicated PCIIOMMUOps for the accel SMMUv3, since it will need different callback handling in upcoming patches. This also adds a
CONFIG_ARM_SMMUV3_ACCELbuild option so the feature can be disabled at compile time. Because we now includeCONFIG_DEVICESin the header to check forARM_SMMUV3_ACCEL, the meson file entry forsmmuv3.cneedsto
Quoted 6 lines
be changed to arm_ss.add.
The “accel” property isn’t user visible yet and it will be introduced in a later patch once all the supporting pieces are ready.
Signed-off-by Shameer KolothumQuoted 9 lines
Reviewed-by Nicolin Chen <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Eric Auger <[email protected]>Tested-by Zhangfei Gao <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/Kconfig | 5 ++++ hw/arm/meson.build | 3 ++- hw/arm/smmuv3-accel.c | 59+++++++++++++++++++++++++++++++++++++++++
hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE',
Quoted 35 lines
hw/arm/smmuv3-accel.h | 27 +++++++++++++++++++ hw/arm/smmuv3.c | 5 ++++ include/hw/arm/smmuv3.h | 3 +++ 6 files changed, 101 insertions(+), 1 deletion(-)create mode 100644
hw/arm/smmuv3-accel.c
create mode 100644hw/arm/smmuv3-accel.hhw/arm/Kconfig +5
-0@@ -12,6 +12,7 @@ config ARM_VIRT select ARM_GIC select ACPI select ARM_SMMUV3 + select ARM_SMMUV3_ACCEL select GPIO_KEY select DEVICE_TREE select FW_CFG_DMA@@ -629,6 +630,10 @@ config FSL_IMX8MP_EVK config ARM_SMMUV3 bool +config ARM_SMMUV3_ACCEL + bool + depends on ARM_SMMUV3 && IOMMUFD + config FSL_IMX6UL bool default yhw/arm/meson.build +0
-0@@ -84,7 +84,8 @@ arm_common_ss.add(when: 'CONFIG_ARMSSE',
if_true: files('armsse.c'))hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 84
Quoted 1 line
hw/arm/meson.build +0
-0arm_common_ss.add(when: 'CONFIG_FSL_IMX7', if_true: files('fsl-imx7.c','
mcimx7d-sabre.c'))hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 85
Quoted 1 line
hw/arm/meson.build +0
-0arm_common_ss.add(when: 'CONFIG_FSL_IMX8MP', if_true: files('fsl-
imx8mp.c'))hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 86
Quoted 1 line
hw/arm/meson.build +0
-0arm_common_ss.add(when: 'CONFIG_FSL_IMX8MP_EVK', if_true:files('imx8mp-evk.c'))
hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 87
Quoted 1 line
hw/arm/meson.build +0
-1-arm_common_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true:files('smmuv3.c'))
hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 88
Quoted 2 lines
hw/arm/meson.build +2
-0+arm_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmuv3.c')) +arm_ss.add(when: 'CONFIG_ARM_SMMUV3_ACCEL', if_true:files('smmuv3-accel.c'))
hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 89
Quoted 1 line
hw/arm/meson.build +0
-0arm_common_ss.add(when: 'CONFIG_FSL_IMX6UL', if_true: files('fsl-
imx6ul.c', 'mcimx6ul-evk.c'))hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 90
Quoted 1 line
hw/arm/meson.build +0
-0arm_common_ss.add(when: 'CONFIG_NRF51_SOC', if_true:
files('nrf51_soc.c'))Quoted 11 lines
hw/arm/meson.build +0
-0arm_common_ss.add(when: 'CONFIG_XEN', if_true: files(hw/arm/smmuv3-accel.c new file +4
-0@@ -0,0 +1,59 @@ +/* +* Copyright (c) 2025 Huawei Technologies R & D (UK) Ltd +* Copyright (C) 2025 NVIDIA +* Written by Nicolin Chen, Shameer Kolothum hw/arm/smmuv3-accel.c line 14
Quoted 10 lines
hw/arm/smmuv3-accel.c new file +10
-0+* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" + +#include "hw/arm/smmuv3.h" +#include "smmuv3-accel.h" + +static SMMUv3AccelDevice *smmuv3_accel_get_dev(SMMUState *bs,SMMUPciBus *sbus,
Quoted 12 lines
hw/arm/smmuv3-accel.c line 24
Quoted 10 lines
hw/arm/smmuv3-accel.c new file +10
-0+ PCIBus *bus, int devfn) +{ +SMMUDevice *sdev = sbus->pbdev[devfn]; +SMMUv3AccelDevice *accel_dev; + +if (sdev) { +return container_of (sdev, SMMUv3AccelDevice, sdev); + } + + accel_dev =g_new0 (SMMUv3AccelDevice,1 );oh. This is not a QOM object :/
Right.
Quoted 23 lines
Quoted 6 lines
hw/arm/smmuv3-accel.c new file +5
-0+ sdev = &accel_dev->sdev; + + sbus->pbdev[devfn] = sdev; +smmu_init_sdev (bs, sdev, bus, devfn); +return accel_dev;hw/arm/smmuv3-accel.c
Quoted 10 lines
hw/arm/smmuv3-accel.c new file +10
-0+} + +/* +* Find or add an address space for the given PCI device. +* +* If a device matching @bus and @devfn already exists, return its +* corresponding address space. Otherwise, create a new device entry +* and initialize address space for it. +*/ +static AddressSpace *smmuv3_accel_find_add_as(PCIBus *bus, void*opaque,
hw/arm/smmuv3-accel.c
Quoted 5 lines
hw/arm/smmuv3-accel.c new file +5
-0+ int devfn) +{ +SMMUState *bs = opaque; +SMMUPciBus *sbus =smmu_get_sbus (bs, bus); + SMMUv3AccelDevice *accel_dev = smmuv3_accel_get_dev(bs, sbus,bus, devfn);
Quoted 16 lines
Quoted 4 lines
hw/arm/smmuv3-accel.c new file +4
-0+SMMUDevice *sdev = &accel_dev->sdev; + +return &sdev->as; +}hw/arm/smmuv3-accel.c line 58
Quoted 10 lines
hw/arm/smmuv3-accel.c new file +10
-0+ +static const PCIIOMMUOps smmuv3_accel_ops = { + .get_address_space = smmuv3_accel_find_add_as, +}; + +void smmuv3_accel_init (SMMUv3State *s) +{ +SMMUState *bs =ARM_SMMU (s); + + bs->iommu_ops = &smmuv3_accel_ops;again, I think this should be a sSMMUv3Class attribute.
See below.
Quoted 64 lines
hw/arm/smmuv3.c static void smmu_realize(DeviceState *d, Error
Quoted 48 lines
hw/arm/smmuv3-accel.c new file +1
-0+}hw/arm/smmuv3-accel.h new file +27
-0@@ -0,0 +1,27 @@ +/* +* Copyright (c) 2025 Huawei Technologies R & D (UK) Ltd +* Copyright (C) 2025 NVIDIA +* Written by Nicolin Chen, Shameer Kolothum +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_ARM_SMMUV3_ACCEL_H +#define HW_ARM_SMMUV3_ACCEL_H + +#include "hw/arm/smmu-common.h" +#include CONFIG_DEVICES + +typedef struct SMMUv3AccelDevice { +SMMUDevice sdev; +}SMMUv3AccelDevice ; + +#ifdef CONFIG_ARM_SMMUV3_ACCEL +void smmuv3_accel_init (SMMUv3State *s); +#else +static inline void smmuv3_accel_init (SMMUv3State *s) +{ +} +#endif + +#endif /* HW_ARM_SMMUV3_ACCEL_H */ hw/arm/smmuv3.c +1
-0@@ -32,6 +32,7 @@#include "qapi/error.h" #include "hw/arm/smmuv3.h" +#include "smmuv3-accel.h" #include "smmuv3-internal.h" #include "smmu-internal.h" @@ -1882,6 +1883,10 @@ static void smmu_realize(DeviceState *d, Error**errp)
Quoted 15 lines
hw/arm/smmuv3.c +4
-0SysBusDevice *dev =SYS_BUS_DEVICE (d);Error *local_err =NULL ; +if (s->accel) { +smmuv3_accel_init (s); + } + c->parent_realize (d, &local_err);if (local_err) {error_propagate (errp, local_err);include/hw/arm/smmuv3.h +0
-0@@ -63,6 +63,9 @@ struct SMMUv3State {
Quoted 8 lines
include/hw/arm/smmuv3.h struct SMMUv3State { · line 68
Quoted 6 lines
include/hw/arm/smmuv3.h +3
-0qemu_irq irq[4 ];QemuMutex mutex;char *stage; + +/* SMMU has HW accelerator support for nested S1 + s2 */ +bool accel;Have you considered modeling with a QOM object instead ?
A bit of history on this:
The SMMUv3 accel support was introduced first as a separate device, -device arm-smmuv3-accel
https://lore.kernel.org/qemu-devel/[email protected]/
However, the general consensus at that time was that we should instead model it on the -device arm-smmuv3 itself, with an added "accel" property.
Eric had also suggested making use of something similar to the TYPE_VFIO_IOMMU_IOMMUFD / LEGACY classes for selecting the iommu_ops.
https://lore.kernel.org/qemu-devel/[email protected]/
In RFCv3, I did introduce a TYPE_ARM_SMMUV3_ACCEL object class, but we later found that it wasn’t doing much beyond helping to retrieve the iommu_ops based on the object type, so decided to drop it.
https://lore.kernel.org/qemu-devel/[email protected]/
From your feedback, I understand that you would like to revisit that approach again. Just to make sure I get this right, is the SMMUv3AccelClass you have in mind meant to be an abstract object, like HOST_IOMMU_DEVICE, or are you suggesting another child device object?
Please let me know if there is an example/precedent, I can look at for a similar object model in QEMU.
Thanks,
Shameer
Re: [PATCH v6 05/33] hw/arm/smmuv3-accel: Introduce smmuv3 accel device
Hello Shameer,
Quoted 266 lines · Shameer Kolothum
Hi Cédric,
Quoted 116 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: 11 December 2025 12:55
To: Shameer Kolothum <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 05/33] hw/arm/smmuv3-accel: Introduce smmuv3 accel deviceExternal email: Use caution opening links or attachments
Quoted 5 lines · Shameer Kolothum
Set up dedicated PCIIOMMUOps for the accel SMMUv3, since it will need different callback handling in upcoming patches. This also adds a
CONFIG_ARM_SMMUV3_ACCELbuild option so the feature can be disabled at compile time. Because we now includeCONFIG_DEVICESin the header to check forARM_SMMUV3_ACCEL, the meson file entry forsmmuv3.cneedsto
Quoted 6 lines
be changed to arm_ss.add.
The “accel” property isn’t user visible yet and it will be introduced in a later patch once all the supporting pieces are ready.
Signed-off-by Shameer KolothumQuoted 9 lines
Reviewed-by Nicolin Chen <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Eric Auger <[email protected]>Tested-by Zhangfei Gao <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/Kconfig | 5 ++++ hw/arm/meson.build | 3 ++- hw/arm/smmuv3-accel.c | 59+++++++++++++++++++++++++++++++++++++++++
hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE',
Quoted 35 lines
hw/arm/smmuv3-accel.h | 27 +++++++++++++++++++ hw/arm/smmuv3.c | 5 ++++ include/hw/arm/smmuv3.h | 3 +++ 6 files changed, 101 insertions(+), 1 deletion(-)create mode 100644
hw/arm/smmuv3-accel.c
create mode 100644hw/arm/smmuv3-accel.hhw/arm/Kconfig +5
-0@@ -12,6 +12,7 @@ config ARM_VIRT select ARM_GIC select ACPI select ARM_SMMUV3 + select ARM_SMMUV3_ACCEL select GPIO_KEY select DEVICE_TREE select FW_CFG_DMA@@ -629,6 +630,10 @@ config FSL_IMX8MP_EVK config ARM_SMMUV3 bool +config ARM_SMMUV3_ACCEL + bool + depends on ARM_SMMUV3 && IOMMUFD + config FSL_IMX6UL bool default yhw/arm/meson.build +0
-0@@ -84,7 +84,8 @@ arm_common_ss.add(when: 'CONFIG_ARMSSE',
if_true: files('armsse.c'))hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 84
Quoted 1 line
hw/arm/meson.build +0
-0arm_common_ss.add(when: 'CONFIG_FSL_IMX7', if_true: files('fsl-imx7.c','
mcimx7d-sabre.c'))hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 85
Quoted 1 line
hw/arm/meson.build +0
-0arm_common_ss.add(when: 'CONFIG_FSL_IMX8MP', if_true: files('fsl-
imx8mp.c'))hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 86
Quoted 1 line
hw/arm/meson.build +0
-0arm_common_ss.add(when: 'CONFIG_FSL_IMX8MP_EVK', if_true:files('imx8mp-evk.c'))
hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 87
Quoted 1 line
hw/arm/meson.build +0
-1-arm_common_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true:files('smmuv3.c'))
hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 88
Quoted 2 lines
hw/arm/meson.build +2
-0+arm_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmuv3.c')) +arm_ss.add(when: 'CONFIG_ARM_SMMUV3_ACCEL', if_true:files('smmuv3-accel.c'))
hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 89
Quoted 1 line
hw/arm/meson.build +0
-0arm_common_ss.add(when: 'CONFIG_FSL_IMX6UL', if_true: files('fsl-
imx6ul.c', 'mcimx6ul-evk.c'))hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 90
Quoted 1 line
hw/arm/meson.build +0
-0arm_common_ss.add(when: 'CONFIG_NRF51_SOC', if_true:
files('nrf51_soc.c'))Quoted 11 lines
hw/arm/meson.build +0
-0arm_common_ss.add(when: 'CONFIG_XEN', if_true: files(hw/arm/smmuv3-accel.c new file +4
-0@@ -0,0 +1,59 @@ +/* +* Copyright (c) 2025 Huawei Technologies R & D (UK) Ltd +* Copyright (C) 2025 NVIDIA +* Written by Nicolin Chen, Shameer Kolothum hw/arm/smmuv3-accel.c line 14
Quoted 10 lines
hw/arm/smmuv3-accel.c new file +10
-0+* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" + +#include "hw/arm/smmuv3.h" +#include "smmuv3-accel.h" + +static SMMUv3AccelDevice *smmuv3_accel_get_dev(SMMUState *bs,SMMUPciBus *sbus,
Quoted 12 lines
hw/arm/smmuv3-accel.c line 24
Quoted 10 lines
hw/arm/smmuv3-accel.c new file +10
-0+ PCIBus *bus, int devfn) +{ +SMMUDevice *sdev = sbus->pbdev[devfn]; +SMMUv3AccelDevice *accel_dev; + +if (sdev) { +return container_of (sdev, SMMUv3AccelDevice, sdev); + } + + accel_dev =g_new0 (SMMUv3AccelDevice,1 );oh. This is not a QOM object :/
Right.
Quoted 23 lines
Quoted 6 lines
hw/arm/smmuv3-accel.c new file +5
-0+ sdev = &accel_dev->sdev; + + sbus->pbdev[devfn] = sdev; +smmu_init_sdev (bs, sdev, bus, devfn); +return accel_dev;hw/arm/smmuv3-accel.c
Quoted 10 lines
hw/arm/smmuv3-accel.c new file +10
-0+} + +/* +* Find or add an address space for the given PCI device. +* +* If a device matching @bus and @devfn already exists, return its +* corresponding address space. Otherwise, create a new device entry +* and initialize address space for it. +*/ +static AddressSpace *smmuv3_accel_find_add_as(PCIBus *bus, void*opaque,
hw/arm/smmuv3-accel.c
Quoted 5 lines
hw/arm/smmuv3-accel.c new file +5
-0+ int devfn) +{ +SMMUState *bs = opaque; +SMMUPciBus *sbus =smmu_get_sbus (bs, bus); + SMMUv3AccelDevice *accel_dev = smmuv3_accel_get_dev(bs, sbus,bus, devfn);
Quoted 16 lines
Quoted 4 lines
hw/arm/smmuv3-accel.c new file +4
-0+SMMUDevice *sdev = &accel_dev->sdev; + +return &sdev->as; +}hw/arm/smmuv3-accel.c line 58
Quoted 10 lines
hw/arm/smmuv3-accel.c new file +10
-0+ +static const PCIIOMMUOps smmuv3_accel_ops = { + .get_address_space = smmuv3_accel_find_add_as, +}; + +void smmuv3_accel_init (SMMUv3State *s) +{ +SMMUState *bs =ARM_SMMU (s); + + bs->iommu_ops = &smmuv3_accel_ops;again, I think this should be a sSMMUv3Class attribute.
See below.
Quoted 64 lines
hw/arm/smmuv3.c static void smmu_realize(DeviceState *d, Error
Quoted 48 lines
hw/arm/smmuv3-accel.c new file +1
-0+}hw/arm/smmuv3-accel.h new file +27
-0@@ -0,0 +1,27 @@ +/* +* Copyright (c) 2025 Huawei Technologies R & D (UK) Ltd +* Copyright (C) 2025 NVIDIA +* Written by Nicolin Chen, Shameer Kolothum +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_ARM_SMMUV3_ACCEL_H +#define HW_ARM_SMMUV3_ACCEL_H + +#include "hw/arm/smmu-common.h" +#include CONFIG_DEVICES + +typedef struct SMMUv3AccelDevice { +SMMUDevice sdev; +}SMMUv3AccelDevice ; + +#ifdef CONFIG_ARM_SMMUV3_ACCEL +void smmuv3_accel_init (SMMUv3State *s); +#else +static inline void smmuv3_accel_init (SMMUv3State *s) +{ +} +#endif + +#endif /* HW_ARM_SMMUV3_ACCEL_H */ hw/arm/smmuv3.c +1
-0@@ -32,6 +32,7 @@#include "qapi/error.h" #include "hw/arm/smmuv3.h" +#include "smmuv3-accel.h" #include "smmuv3-internal.h" #include "smmu-internal.h" @@ -1882,6 +1883,10 @@ static void smmu_realize(DeviceState *d, Error**errp)
Quoted 15 lines
hw/arm/smmuv3.c +4
-0SysBusDevice *dev =SYS_BUS_DEVICE (d);Error *local_err =NULL ; +if (s->accel) { +smmuv3_accel_init (s); + } + c->parent_realize (d, &local_err);if (local_err) {error_propagate (errp, local_err);include/hw/arm/smmuv3.h +0
-0@@ -63,6 +63,9 @@ struct SMMUv3State {Quoted 8 lines
include/hw/arm/smmuv3.h struct SMMUv3State { · line 68
Quoted 6 lines
include/hw/arm/smmuv3.h +3
-0qemu_irq irq[4 ];QemuMutex mutex;char *stage; + +/* SMMU has HW accelerator support for nested S1 + s2 */ +bool accel;Have you considered modeling with a QOM object instead ?
A bit of history on this:
The SMMUv3 accel support was introduced first as a separate device, -device arm-smmuv3-accel
https://lore.kernel.org/qemu-devel/[email protected]/
However, the general consensus at that time was that we should instead model it on the -device arm-smmuv3 itself, with an added "accel" property.
Eric had also suggested making use of something similar to the
TYPE_VFIO_IOMMU_IOMMUFD/ LEGACY classes for selecting theiommu_ops.
https://lore.kernel.org/qemu-devel/[email protected]/In RFCv3, I did introduce a
TYPE_ARM_SMMUV3_ACCELobject class, but we later found that it wasn’t doing much beyond helping to retrieve theiommu_opsbased on the object type, so decided to drop it.
https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 4 lines
From your feedback, I understand that you would like to revisit that approach
again. Just to make sure I get this right, is the SMMUv3AccelClass you have in mind meant to be an abstract object, likeHOST_IOMMU_DEVICE, or are you suggesting another child device object?
HOST_IOMMU_DEVICE are for host IOMMU backends (VFIO IOMMU Type1 legacy and IOMMUFD). I was imagining an "arm-smmuv3" children class for acceleration.
I understand I am jumping a bit late in the discussion. Sorry about that and the late reply also.
I have been experimenting with your series on other systems and on an ARM system with MLX5 VFs and an L4 GPU. I had to fake CANWBS support in the host kernel to make progress. On a side note, I also pulled in a patch from Nicolin to add dmabuf support and it seemed to behave ok. This would require more in-depth P2P testing. That's another topic we should discuss in the QEMU 11.0 cycle.
Quoted 2 lines
Please let me know if there is an example/precedent, I can look at for a similar object model in QEMU.
Now regarding modeling, it is more or less a design choice. But while I scanned through the code, I felt there was some problems that could be solved in a cleaner way with a sub class. The changes are mostly about moving code in different places and changing/removing the "if (s->accel) parts". Don't change everything now, I will check RFCv3.
Nevertheless, they are several more issues, build breakages and also runtime breakage that should be addressed. Let's do that first.
Furthermore, an (idealistic) design principle of QEMU that we tend to forget is to offer acceleration when possible and else fallback to emulation, in order to guarantee parity of features between different hardware. I expected the "arm-smmuv3" device to decide to operate in accelerated mode when ever possible, i.e when the IOMMUFD backend (the SMMUV3 + the FW) offers the right level of functionality. This would allow the machine to maintain a constant view of the sMMUv3 device and facilitate its integration with management layers and ease migration too.
I understand this is complex, it has been done for some interrupt controllers, and this is not the approach of the series.
That said, what about integration with libvirt ?
Thanks,
C.
RE: [PATCH v6 05/33] hw/arm/smmuv3-accel: Introduce smmuv3 accel device
Hi Cédric,
Quoted 15 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: 17 December 2025 17:39
To: Shameer Kolothum <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 05/33] hw/arm/smmuv3-accel: Introduce smmuv3 accel device
[...]
Quoted 29 lines
Quoted 9 lines
Quoted 2 lines
Have you considered modeling with a QOM object instead ?
A bit of history on this:
The SMMUv3 accel support was introduced first as a separate device, -device arm-smmuv3-accel
Quoted 6 lines
However, the general consensus at that time was that we should instead model it on the -device arm-smmuv3 itself, with an added "accel" property.
Eric had also suggested making use of something similar to the
TYPE_VFIO_IOMMU_IOMMUFD/ LEGACY classes for selecting the
iommu_ops.Quoted 3 lines
In RFCv3, I did introduce a
TYPE_ARM_SMMUV3_ACCELobject class, but we later found that it wasn’t doing much beyond helping to retrieve the
iommu_opsQuoted 2 lines
based on the object type, so decided to drop it.
https://lore.kernel.org/qemu-devel/71ca9132-8deb-4f57-abb0-Quoted 2 lines
From your feedback, I understand that you would like to revisit that
approach
Quoted 8 lines
Quoted 1 line
again. Just to make sure I get this right, is the SMMUv3AccelClass you have
in
Quoted 2 lines
mind meant to be an abstract object, like
HOST_IOMMU_DEVICE, or are you suggesting another child device object?
HOST_IOMMU_DEVICEare for host IOMMU backends (VFIO IOMMU Type1 legacy and IOMMUFD). I was imagining an "arm-smmuv3" children class for acceleration.
Ok. As mentioned above, the accelerated SMMUv3 is currently not a separate child device of "arm-smmuv3". Instead, acceleration support is enabled via the accel property on "arm-smmuv3".
Quoted 9 lines
I understand I am jumping a bit late in the discussion. Sorry about that and the late reply also.
I have been experimenting with your series on other systems and on an ARM system with MLX5 VFs and an L4 GPU. I had to fake CANWBS support in the host kernel to make progress. On a side note, I also pulled in a patch from Nicolin to add dmabuf support and it seemed to behave ok. This would require more in-depth P2P testing. That's another topic we should discuss in the QEMU 11.0 cycle.
Thanks for giving this a spin.
Quoted 10 lines
Quoted 2 lines
Please let me know if there is an example/precedent, I can look at for a
similar
Quoted 1 line
object model in QEMU.
Now regarding modeling, it is more or less a design choice. But while I scanned through the code, I felt there was some problems that could be solved in a cleaner way with a sub class. The changes are mostly about moving code in different places and changing/removing the "if (
s->accel) parts". Don't change everything now, I will check RFCv3.
Without having a proper child device of "arm-smmuv3", it is not clear to me how we can avoid the "if (s->accel)" checks. Please let me know if you have any thoughts on this.
Quoted 2 lines
Nevertheless, they are several more issues, build breakages and also runtime breakage that should be addressed. Let's do that first.
The build breakage you pointed out is something I missed during my testing ☹. The same applies to the GPU mdev core dump. Hopefully, we can address these without requiring major rework.
Quoted 6 lines
Furthermore, an (idealistic) design principle of QEMU that we tend to forget is to offer acceleration when possible and else fallback to emulation, in order to guarantee parity of features between different hardware. I expected the "arm-smmuv3" device to decide to operate in accelerated mode when ever possible, i.e when the IOMMUFD backend (the SMMUV3 + the FW) offers the right level of functionality.
Accelerated SMMUv3 support only makes sense for vfio pci pass-through devices which require the nested stage configuration. Emulated endpoint devices are not allowed with accel SMMUv3.
This
Quoted 3 lines
would allow the machine to maintain a constant view of the sMMUv3 device and facilitate its integration with management layers and ease migration too.
The current model relies on specifying an accelerated SMMUv3 with the default features of "arm-smmuv3", along with user-specified optional features that make sense for accelerated use cases (e.g. RIL, PASID). The implementation performs a compatibility check against the host SMMUv3 to ensure the requested configuration can be safely supported (patch #20).
Quoted 4 lines
I understand this is complex, it has been done for some interrupt controllers, and this is not the approach of the series.
That said, what about integration with libvirt ?
Nathan has this "Implement support for iommufd and multiple HW-accel vSMMUs" libvirt series here:
https://lists.libvirt.org/archives/list/[email protected]/thread/F4XIUZCDNMXGW5WBJ47VLVSZMGXO5B6E/
And I believe his precursor, “Implement support for multiple device-pluggable SMMUv3s”, has already been applied.
https://lists.libvirt.org/archives/list/[email protected]/thread/WOJKDS3N23N63SMMDLLTZJRVXWPHK7EM/
Thanks,
Shameer
Re: [PATCH v6 05/33] hw/arm/smmuv3-accel: Introduce smmuv3 accel device
In reply to Cédric Le GoaterHi Cédric, Shameer,
Quoted 285 lines · Cédric Le Goater
Hello Shameer,
Quoted 275 lines · Shameer Kolothum
Hi Cédric,
Quoted 119 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: 11 December 2025 12:55
To: Shameer Kolothum <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 05/33] hw/arm/smmuv3-accel: Introduce smmuv3 accel deviceExternal email: Use caution opening links or attachments
Quoted 6 lines · Shameer Kolothum
Set up dedicated PCIIOMMUOps for the accel SMMUv3, since it will need different callback handling in upcoming patches. This also adds a
CONFIG_ARM_SMMUV3_ACCELbuild option so the feature can be disabled at compile time. Because we now includeCONFIG_DEVICESin the header to
check forARM_SMMUV3_ACCEL, the meson file entry forsmmuv3.cneedsto
Quoted 7 lines
be changed to arm_ss.add.
The “accel” property isn’t user visible yet and it will be introduced in
a later patch once all the supporting pieces are ready.Signed-off-by Shameer KolothumQuoted 9 lines
Reviewed-by Nicolin Chen <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Eric Auger <[email protected]>Tested-by Zhangfei Gao <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>---
hw/arm/Kconfig | 5 ++++
hw/arm/meson.build | 3 ++-
hw/arm/smmuv3-accel.c | 59+++++++++++++++++++++++++++++++++++++++++
hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE',
Quoted 35 lines
hw/arm/smmuv3-accel.h | 27 +++++++++++++++++++ hw/arm/smmuv3.c | 5 ++++
include/hw/arm/smmuv3.h| 3 +++6 files changed, 101 insertions(+), 1 deletion(-)create mode 100644
hw/arm/smmuv3-accel.c
create mode 100644hw/arm/smmuv3-accel.hhw/arm/Kconfig +0
-0@@ -12,6 +12,7 @@ config ARM_VIRTselect
ARM_GIC
select ACPI
selectARM_SMMUV3
+ selectARM_SMMUV3_ACCEL
selectGPIO_KEY
selectDEVICE_TREE
selectFW_CFG_DMAhw/arm/Kconfig +0
-0@@ -629,6 +630,10 @@ config FSL_IMX8MP_EVKconfig
ARM_SMMUV3
boolhw/arm/Kconfig +4
-0+config ARM_SMMUV3_ACCEL + bool + depends on ARM_SMMUV3 && IOMMUFD +config
FSL_IMX6UL
bool
default yhw/arm/meson.build +0
-0@@ -84,7 +84,8 @@ arm_common_ss.add(when: 'CONFIG_ARMSSE',
if_true: files('armsse.c'))Quoted 2 lines
arm_common_ss.add(when: '
CONFIG_FSL_IMX7',if_true:
files('fsl-imx7.c','
mcimx7d-sabre.c'))Quoted 1 line
arm_common_ss.add(when: '
CONFIG_FSL_IMX8MP',if_true: files('fsl-
imx8mp.c'))Quoted 1 line
arm_common_ss.add(when: '
CONFIG_FSL_IMX8MP_EVK',if_true:files('imx8mp-evk.c'))
Quoted 1 line
-arm_common_ss.add(when: '
CONFIG_ARM_SMMUV3',if_true:files('smmuv3.c'))
hw/arm/meson.build
Quoted 2 lines
hw/arm/meson.build +2
-0+arm_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmuv3.c')) +arm_ss.add(when: 'CONFIG_ARM_SMMUV3_ACCEL', if_true:files('smmuv3-accel.c'))
Quoted 1 line
arm_common_ss.add(when: '
CONFIG_FSL_IMX6UL',if_true: files('fsl-
imx6ul.c', 'mcimx6ul-evk.c'))Quoted 1 line
arm_common_ss.add(when: '
CONFIG_NRF51_SOC',if_true:
files('nrf51_soc.c'))Quoted 11 lines
arm_common_ss.add(when: '
CONFIG_XEN',if_true: files(hw/arm/smmuv3-accel.c new file +4
-0@@ -0,0 +1,59 @@ +/* +* Copyright (c) 2025 Huawei Technologies R & D (UK) Ltd +* Copyright (C) 2025 NVIDIA +* Written by Nicolin Chen, Shameer Kolothum hw/arm/smmuv3-accel.c line 14
Quoted 10 lines
hw/arm/smmuv3-accel.c new file +10
-0+* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" + +#include "hw/arm/smmuv3.h" +#include "smmuv3-accel.h" + +static SMMUv3AccelDevice *smmuv3_accel_get_dev(SMMUState *bs,SMMUPciBus *sbus,
Quoted 13 lines
hw/arm/smmuv3-accel.c line 24
Quoted 11 lines
hw/arm/smmuv3-accel.c new file +1
-0+ PCIBus *bus, intdevfn)
hw/arm/smmuv3-accel.c new file +9
-0+{ + SMMUDevice *sdev = sbus->pbdev[devfn]; + SMMUv3AccelDevice *accel_dev; + + if (sdev) { + return container_of(sdev, SMMUv3AccelDevice, sdev); + } + + accel_dev = g_new0(SMMUv3AccelDevice, 1);oh. This is not a QOM object :/
Right.
Quoted 23 lines
Quoted 6 lines
+ sdev =
&accel_dev->sdev;hw/arm/smmuv3-accel.c new file +4
-0+ + sbus->pbdev[devfn] = sdev; + smmu_init_sdev(bs, sdev, bus, devfn); + return accel_dev;hw/arm/smmuv3-accel.c
Quoted 10 lines
hw/arm/smmuv3-accel.c new file +10
-0+} + +/* +* Find or add an address space for the given PCI device. +* +* If a device matching @bus and @devfn already exists, return its +* corresponding address space. Otherwise, create a new device entry +* and initialize address space for it. +*/ +static AddressSpace *smmuv3_accel_find_add_as(PCIBus *bus, void*opaque,
Quoted 5 lines
+ int devfn) +{
+ SMMUState *bs = opaque;
+ SMMUPciBus *sbus =smmu_get_sbus(bs, bus);
+ SMMUv3AccelDevice*accel_dev= smmuv3_accel_get_dev(bs, sbus,bus, devfn);
Quoted 16 lines
Quoted 4 lines
+ SMMUDevice *sdev =
&accel_dev->sdev;hw/arm/smmuv3-accel.c new file +3
-0+ + return &sdev->as; +}hw/arm/smmuv3-accel.c line 58
Quoted 10 lines
hw/arm/smmuv3-accel.c new file +10
-0+ +static const PCIIOMMUOps smmuv3_accel_ops = { + .get_address_space = smmuv3_accel_find_add_as, +}; + +void smmuv3_accel_init (SMMUv3State *s) +{ + SMMUState *bs = ARM_SMMU(s); + + bs->iommu_ops = &smmuv3_accel_ops;again, I think this should be a sSMMUv3Class attribute.
See below.
Quoted 64 lines
hw/arm/smmuv3.c static void smmu_realize(DeviceState *d, Error
Quoted 48 lines
hw/arm/smmuv3-accel.c new file +1
-0+}hw/arm/smmuv3-accel.h new file +27
-0@@ -0,0 +1,27 @@ +/* +* Copyright (c) 2025 Huawei Technologies R & D (UK) Ltd +* Copyright (C) 2025 NVIDIA +* Written by Nicolin Chen, Shameer Kolothum +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_ARM_SMMUV3_ACCEL_H +#define HW_ARM_SMMUV3_ACCEL_H + +#include "hw/arm/smmu-common.h" +#include CONFIG_DEVICES + +typedef struct SMMUv3AccelDevice { + SMMUDevice sdev; +}SMMUv3AccelDevice ; + +#ifdef CONFIG_ARM_SMMUV3_ACCEL +void smmuv3_accel_init (SMMUv3State *s); +#else +static inline void smmuv3_accel_init (SMMUv3State *s) +{ +} +#endif + +#endif /* HW_ARM_SMMUV3_ACCEL_H */ hw/arm/smmuv3.c +1
-0@@ -32,6 +32,7 @@ #include "qapi/error.h" #include "hw/arm/smmuv3.h" +#include "smmuv3-accel.h" #include "smmuv3-internal.h" #include "smmu-internal.h"@@ -1882,6 +1883,10 @@ static void smmu_realize(DeviceState *d, Error**errp)
Quoted 15 lines
hw/arm/smmuv3.c +4
-0SysBusDevice *dev = SYS_BUS_DEVICE(d); Error *local_err = NULL; + if (s->accel) { + smmuv3_accel_init(s); + } + c->parent_realize(d, &local_err); if (local_err) { error_propagate(errp, local_err);include/hw/arm/smmuv3.h +0
-0@@ -63,6 +63,9 @@ struct SMMUv3State {Quoted 8 lines
include/hw/arm/smmuv3.h struct SMMUv3State { · line 68
Quoted 6 lines
include/hw/arm/smmuv3.h +3
-0qemu_irq irq[4]; QemuMutex mutex; char *stage; + + /* SMMU has HW accelerator support for nested S1 + s2 */ + bool accel;Have you considered modeling with a QOM object instead ?
A bit of history on this:
The SMMUv3 accel support was introduced first as a separate device, -device arm-smmuv3-accel
https://lore.kernel.org/qemu-devel/[email protected]/
However, the general consensus at that time was that we should instead model it on the -device arm-smmuv3 itself, with an added "accel" property.
Eric had also suggested making use of something similar to the
TYPE_VFIO_IOMMU_IOMMUFD/ LEGACY classes for selecting theiommu_ops.
https://lore.kernel.org/qemu-devel/[email protected]/In RFCv3, I did introduce a
TYPE_ARM_SMMUV3_ACCELobject class, but we later found that it wasn’t doing much beyond helping to retrieve theiommu_ops
based on the object type, so decided to drop it.
https://lore.kernel.org/qemu-devel/[email protected]/Quoted 6 lines
From your feedback, I understand that you would like to revisit that approach
again. Just to make sure I get this right, is the SMMUv3AccelClass you have in
mind meant to be an abstract object, likeHOST_IOMMU_DEVICE, or are you suggesting another child device object?
Quoted 3 lines
HOST_IOMMU_DEVICEare for host IOMMU backends (VFIO IOMMU Type1 legacy and IOMMUFD). I was imagining an "arm-smmuv3" children class for acceleration.
We were trying to find similar examples of inheritance in the qemu tree. I also inspected hw/intc, for instance the GICv3 but it is not really similar as the choice between the kvm and tcg one is not made by an option.
As Shameer explained, we attempted to use a class and eventually we noticed it did not bring any real benefit besides complexifying the code.
Note that on intel_iommu, the "vfio" integration is opted-in with the caching-mode option. so using an accel option sounds a similar knob.
Quoted 7 lines
I understand I am jumping a bit late in the discussion. Sorry about that and the late reply also.
I have been experimenting with your series on other systems and on an ARM system with MLX5 VFs and an L4 GPU. I had to fake CANWBS support in the host kernel to make progress. On a side note, I also
I also encountered this issue but as my HW does support CANWBS, this is a FW issue. So this does not relate to that series.
Quoted 3 lines
pulled in a patch from Nicolin to add dmabuf support and it seemed to behave ok. This would require more in-depth P2P testing. That's another topic we should discuss in the QEMU 11.0 cycle.
I tested the functionality with P2P. I am waiting for the respin before sending my T-b.
Quoted 6 lines
Quoted 5 lines
Please let me know if there is an example/precedent, I can look at for a similar
object model in QEMU.
Quoted 8 lines
Now regarding modeling, it is more or less a design choice. But while I scanned through the code, I felt there was some problems that could be solved in a cleaner way with a sub class. The changes are mostly about moving code in different places and changing/removing the "if (
s->accel) parts". Don't change everything now, I will check RFCv3.Nevertheless, they are several more issues, build breakages and also runtime breakage that should be addressed. Let's do that first.
I don't know where we stand with that respect. Shameer, were you able to address those breakages?
Quoted 10 lines
Furthermore, an (idealistic) design principle of QEMU that we tend to forget is to offer acceleration when possible and else fallback to emulation, in order to guarantee parity of features between different hardware. I expected the "arm-smmuv3" device to decide to operate in accelerated mode when ever possible, i.e when the IOMMUFD backend (the SMMUV3 + the FW) offers the right level of functionality. This would allow the machine to maintain a constant view of the sMMUv3 device and facilitate its integration with management layers and ease migration too.
I don't think it makes sense to fall back to a non accel mode anyway because the protected end point device wouldn't work. SMMU has no cachine mode as Intel. So either it works in accelerated mode along with VFIO devices or it is not able to protected host assigned devices.
Thanks
Eric
Quoted 11 lines
I understand this is complex, it has been done for some interrupt controllers, and this is not the approach of the series.
That said, what about integration with libvirt ?
Thanks,
C.
RE: [PATCH v6 05/33] hw/arm/smmuv3-accel: Introduce smmuv3 accel device
Hi Eric,
Quoted 357 lines
-----Original Message-----
From: Eric Auger <[email protected]>
Sent: 06 January 2026 10:23
To: Cédric Le Goater <[email protected]>; Shameer Kolothum <[email protected]>; [email protected]; qemu- [email protected]
Cc: [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 05/33] hw/arm/smmuv3-accel: Introduce smmuv3 accel deviceExternal email: Use caution opening links or attachments
Hi Cédric, Shameer,
Quoted 19 lines · Cédric Le Goater
Hello Shameer,
Quoted 16 lines · Shameer Kolothum
Hi Cédric,
Quoted 14 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: 11 December 2025 12:55
To: Shameer Kolothum <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 05/33] hw/arm/smmuv3-accel: Introducesmmuv3
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
accel device
External email: Use caution opening links or attachments
Quoted 3 lines · Shameer Kolothum
Set up dedicated PCIIOMMUOps for the accel SMMUv3, since it will need different callback handling in upcoming patches. This also adds a
CONFIG_ARM_SMMUV3_ACCELbuild option so the feature can bedisabled
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
at compile time. Because we now include
CONFIG_DEVICESin the header to
check forARM_SMMUV3_ACCEL, the meson file entry forsmmuv3.cneeds
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
to
Quoted 7 lines
be changed to arm_ss.add.
The “accel” property isn’t user visible yet and it will be introduced in
a later patch once all the supporting pieces are ready.Signed-off-by Shameer KolothumQuoted 9 lines
Reviewed-by Nicolin Chen <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Eric Auger <[email protected]>Tested-by Zhangfei Gao <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/Kconfig | 5 ++++ hw/arm/meson.build | 3 ++- hw/arm/smmuv3-accel.c | 59+++++++++++++++++++++++++++++++++++++++++
hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE',
Quoted 35 lines
hw/arm/smmuv3-accel.h | 27 +++++++++++++++++++ hw/arm/smmuv3.c | 5 ++++ include/hw/arm/smmuv3.h | 3 +++ 6 files changed, 101 insertions(+), 1 deletion(-)create mode 100644
hw/arm/smmuv3-accel.c
create mode 100644hw/arm/smmuv3-accel.hhw/arm/Kconfig +5
-0@@ -12,6 +12,7 @@ config ARM_VIRT select ARM_GIC select ACPI select ARM_SMMUV3 + select ARM_SMMUV3_ACCEL select GPIO_KEY select DEVICE_TREE select FW_CFG_DMA@@ -629,6 +630,10 @@ config FSL_IMX8MP_EVK config ARM_SMMUV3 bool +config ARM_SMMUV3_ACCEL + bool + depends on ARM_SMMUV3 && IOMMUFD + config FSL_IMX6UL bool default yhw/arm/meson.build +0
-0@@ -84,7 +84,8 @@ arm_common_ss.add(when: 'CONFIG_ARMSSE',
if_true: files('armsse.c'))Quoted 2 lines
hw/arm/meson.build +0
-0arm_common_ss.add(when: 'CONFIG_FSL_IMX7', if_true: files('fsl-imx7.c',Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
'
mcimx7d-sabre.c'))hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 86
Quoted 1 line
hw/arm/meson.build +0
-0arm_common_ss.add(when: 'CONFIG_FSL_IMX8MP', if_true: files('fsl-
imx8mp.c'))hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 87
Quoted 1 line
hw/arm/meson.build +0
-0arm_common_ss.add(when: 'CONFIG_FSL_IMX8MP_EVK', if_true:files('imx8mp-evk.c'))
hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 88
Quoted 1 line
hw/arm/meson.build +0
-1-arm_common_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true:files('smmuv3.c'))
Quoted 1 line
hw/arm/meson.build +1
-0+arm_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true:files('smmuv3.c'))
Quoted 127 lines
Quoted 127 lines
Quoted 28 lines
hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 89
Quoted 1 line
hw/arm/meson.build +1
-0+arm_ss.add(when: 'CONFIG_ARM_SMMUV3_ACCEL', if_true:files('smmuv3-accel.c'))
hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 90
Quoted 1 line
hw/arm/meson.build +0
-0arm_common_ss.add(when: 'CONFIG_FSL_IMX6UL', if_true: files('fsl-
imx6ul.c', 'mcimx6ul-evk.c'))hw/arm/meson.build arm_common_ss.add(when: 'CONFIG_ARMSSE', · line 91
Quoted 1 line
hw/arm/meson.build +0
-0arm_common_ss.add(when: 'CONFIG_NRF51_SOC', if_true:
files('nrf51_soc.c'))Quoted 11 lines
arm_common_ss.add(when: 'CONFIG_XEN', if_true: files(hw/arm/smmuv3-accel.c new file +4
-0@@ -0,0 +1,59 @@ +/* +* Copyright (c) 2025 Huawei Technologies R & D (UK) Ltd +* Copyright (C) 2025 NVIDIA +* Written by Nicolin Chen, Shameer Kolothum hw/arm/smmuv3-accel.c line 14
Quoted 10 lines
hw/arm/smmuv3-accel.c new file +10
-0+* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" + +#include "hw/arm/smmuv3.h" +#include "smmuv3-accel.h" + +static SMMUv3AccelDevice *smmuv3_accel_get_dev(SMMUState *bs,SMMUPciBus *sbus,
Quoted 13 lines
hw/arm/smmuv3-accel.c line 24
Quoted 11 lines
hw/arm/smmuv3-accel.c new file +1
-0+PCIBus *bus, intdevfn)
hw/arm/smmuv3-accel.c new file +9
-0+{ +SMMUDevice *sdev = sbus->pbdev[devfn]; +SMMUv3AccelDevice *accel_dev; + +if (sdev) { +return container_of (sdev, SMMUv3AccelDevice, sdev); + } + + accel_dev =g_new0 (SMMUv3AccelDevice,1 );oh. This is not a QOM object :/
Right.
Quoted 23 lines
Quoted 6 lines
hw/arm/smmuv3-accel.c new file +5
-0+ sdev = &accel_dev->sdev; + + sbus->pbdev[devfn] = sdev; +smmu_init_sdev (bs, sdev, bus, devfn); +return accel_dev;hw/arm/smmuv3-accel.c
Quoted 10 lines
hw/arm/smmuv3-accel.c new file +10
-0+} + +/* +* Find or add an address space for the given PCI device. +* +* If a device matching @bus and @devfn already exists, return its +* corresponding address space. Otherwise, create a new device entry +* and initialize address space for it. +*/ +static AddressSpace *smmuv3_accel_find_add_as(PCIBus *bus, void*opaque,
hw/arm/smmuv3-accel.c
Quoted 5 lines
hw/arm/smmuv3-accel.c new file +5
-0+ int devfn) +{ +SMMUState *bs = opaque; +SMMUPciBus *sbus =smmu_get_sbus (bs, bus); + SMMUv3AccelDevice *accel_dev = smmuv3_accel_get_dev(bs, sbus,bus, devfn);
Quoted 16 lines
Quoted 4 lines
hw/arm/smmuv3-accel.c new file +4
-0+SMMUDevice *sdev = &accel_dev->sdev; + +return &sdev->as; +}hw/arm/smmuv3-accel.c line 58
Quoted 10 lines
hw/arm/smmuv3-accel.c new file +10
-0+ +static const PCIIOMMUOps smmuv3_accel_ops = { + .get_address_space = smmuv3_accel_find_add_as, +}; + +void smmuv3_accel_init (SMMUv3State *s) +{ +SMMUState *bs =ARM_SMMU (s); + + bs->iommu_ops = &smmuv3_accel_ops;again, I think this should be a sSMMUv3Class attribute.
See below.
Quoted 42 lines
Quoted 42 lines
hw/arm/smmuv3-accel.c new file +1
-0+}hw/arm/smmuv3-accel.h new file +27
-0@@ -0,0 +1,27 @@ +/* +* Copyright (c) 2025 Huawei Technologies R & D (UK) Ltd +* Copyright (C) 2025 NVIDIA +* Written by Nicolin Chen, Shameer Kolothum +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_ARM_SMMUV3_ACCEL_H +#define HW_ARM_SMMUV3_ACCEL_H + +#include "hw/arm/smmu-common.h" +#include CONFIG_DEVICES + +typedef struct SMMUv3AccelDevice { +SMMUDevice sdev; +}SMMUv3AccelDevice ; + +#ifdef CONFIG_ARM_SMMUV3_ACCEL +void smmuv3_accel_init (SMMUv3State *s); +#else +static inline void smmuv3_accel_init (SMMUv3State *s) +{ +} +#endif + +#endif /* HW_ARM_SMMUV3_ACCEL_H */ hw/arm/smmuv3.c +0
-0@@ -32,6 +32,7 @@#include "qapi/error.h" Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/arm/smmuv3.c static void smmu_realize(DeviceState *d,
Quoted 6 lines
hw/arm/smmuv3.c +1
-0#include "hw/arm/smmuv3.h" +#include "smmuv3-accel.h" #include "smmuv3-internal.h" #include "smmu-internal.h" @@ -1882,6 +1883,10 @@ static void smmu_realize(DeviceState *d,Error
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
**errp)
Quoted 15 lines
hw/arm/smmuv3.c +4
-0SysBusDevice *dev =SYS_BUS_DEVICE (d);Error *local_err =NULL ; +if (s->accel) { +smmuv3_accel_init (s); + } + c->parent_realize (d, &local_err);if (local_err) {error_propagate (errp, local_err);include/hw/arm/smmuv3.h +0
-0include/hw/arm/smmuv3.h struct SMMUv3State { · line 68
Quoted 6 lines
include/hw/arm/smmuv3.h +3
-0@@ -63,6 +63,9 @@ struct SMMUv3State {qemu_irq irq[4 ];QemuMutex mutex;char *stage; + +/* SMMU has HW accelerator support for nested S1 + s2 */ +bool accel;Have you considered modeling with a QOM object instead ?
Quoted 6 lines
Quoted 6 lines
A bit of history on this:
The SMMUv3 accel support was introduced first as a separate device, -device arm-smmuv3-accel
Quoted 8 lines
Quoted 8 lines
However, the general consensus at that time was that we should instead model it on the -device arm-smmuv3 itself, with an added "accel" property.
Eric had also suggested making use of something similar to the
TYPE_VFIO_IOMMU_IOMMUFD/ LEGACY classes for selecting the
iommu_ops.Quoted 1 line
Quoted 3 lines
Quoted 3 lines
In RFCv3, I did introduce a
TYPE_ARM_SMMUV3_ACCELobject class, butwe
Quoted 4 lines
Quoted 4 lines
later found that it wasn’t doing much beyond helping to retrieve the
iommu_ops
based on the object type, so decided to drop it.
https://lore.kernel.org/qemu-devel/71ca9132-8deb-4f57-abb0-Quoted 9 lines
Quoted 8 lines
From your feedback, I understand that you would like to revisit that
approach
again. Just to make sure I get this right, is the SMMUv3AccelClass you have in
mind meant to be an abstract object, likeHOST_IOMMU_DEVICE, or are you suggesting another child device object?Quoted 3 lines
HOST_IOMMU_DEVICEare for host IOMMU backends (VFIO IOMMU Type1 legacy and IOMMUFD). I was imagining an "arm-smmuv3" children class for acceleration.We were trying to find similar examples of inheritance in the qemu tree. I also inspected hw/intc, for instance the GICv3 but it is not really similar as the choice between the kvm and tcg one is not made by an option.
As Shameer explained, we attempted to use a class and eventually we noticed it did not bring any real benefit besides complexifying the code.
Note that on
intel_iommu, the "vfio" integration is opted-in with the caching-mode option. so using an accel option sounds a similar knob.Quoted 7 lines
I understand I am jumping a bit late in the discussion. Sorry about that and the late reply also.
I have been experimenting with your series on other systems and on an ARM system with MLX5 VFs and an L4 GPU. I had to fake CANWBS support in the host kernel to make progress. On a side note, I also
I also encountered this issue but as my HW does support CANWBS, this is a FW issue. So this does not relate to that series.
Quoted 3 lines
pulled in a patch from Nicolin to add dmabuf support and it seemed to behave ok. This would require more in-depth P2P testing. That's another topic we should discuss in the QEMU 11.0 cycle.
I tested the functionality with P2P. I am waiting for the respin before sending my T-b.
Quoted 12 lines
Quoted 5 lines
Please let me know if there is an example/precedent, I can look at for a similar
object model in QEMU.Now regarding modeling, it is more or less a design choice. But while I scanned through the code, I felt there was some problems that could be solved in a cleaner way with a sub class. The changes are mostly about moving code in different places and changing/removing the "if (
s->accel) parts". Don't change everything now, I will check RFCv3.
Quoted 5 lines
Quoted 2 lines
Nevertheless, they are several more issues, build breakages and also runtime breakage that should be addressed. Let's do that first.
I don't know where we stand with that respect. Shameer, were you able to address those breakages?
Missed this. Yes, I am working on v7 addressing the build issues. For the HostIOMMUDevice related build and runtime issues, I have sent out a proposal here,
https://lore.kernel.org/qemu-devel/CH3PR12MB75482AA6E44111F51B5F8E47ABBBA@CH3PR12MB7548.namprd12.prod.outlook.com/
Thanks,
Shameer
PATCH v6 6/33 hw/arm/smmuv3-accel: Initialize shared system address space
In reply to Shameer KolothumTo support accelerated SMMUv3 instances, introduce a shared system-wide AddressSpace (shared_as_sysmem) that aliases the global system memory. This shared AddressSpace will be used in a subsequent patch for all vfio-pci devices behind all accelerated SMMUv3 instances within a VM.
Sharing a single system AddressSpace ensures that all devices behind accelerated SMMUv3s use the same system address space pointer. This allows VFIO/iommufd to reuse a single IOAS ID in iommufd_cdev_attach(), enabling the Stage-2 page tables to be shared within the VM rather than duplicated for each SMMUv3 instance.
--- hw/arm/smmuv3-accel.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
hw/arm/smmuv3-accel.c +26 -0
@@ -11,6 +11,14 @@#include "hw/arm/smmuv3.h" #include "smmuv3-accel.h" +/* +* The root region aliases the global system memory, and shared_as_sysmem +* provides a shared Address Space referencing it. This Address Space is used +* by all vfio-pci devices behind all accelerated SMMUv3 instances within a VM. +*/ +static MemoryRegion root, sysmem; +static AddressSpace *shared_as_sysmem; +static SMMUv3AccelDevice *smmuv3_accel_get_dev (SMMUState *bs,SMMUPciBus *sbus,PCIBus *bus,int devfn) {
@@ -51,9 +59,27 @@ static const PCIIOMMUOps smmuv3_accel_ops = { .get_address_space = smmuv3_accel_find_add_as, }; +static void smmuv3_accel_as_init (SMMUv3State *s) +{ + +if (shared_as_sysmem) { +return ; + } + +memory_region_init (&root,OBJECT (s),"root" ,UINT64_MAX ); +memory_region_init_alias (&sysmem,OBJECT (s),"smmuv3-accel-sysmem" , +get_system_memory (),0 , +memory_region_size (get_system_memory ())); +memory_region_add_subregion (&root,0 , &sysmem); + + shared_as_sysmem =g_new0 (AddressSpace,1 ); +address_space_init (shared_as_sysmem, &root,"smmuv3-accel-as-sysmem" ); +} +void smmuv3_accel_init (SMMUv3State *s) {SMMUState *bs =ARM_SMMU (s); bs->iommu_ops = &smmuv3_accel_ops; +smmuv3_accel_as_init (s); }
Signature · 1 line
2.43.0
Re: [PATCH v6 06/33] hw/arm/smmuv3-accel: Initialize shared system address space
Quoted 11 lines · Shameer Kolothum
To support accelerated SMMUv3 instances, introduce a shared system-wide AddressSpace (
shared_as_sysmem) that aliases the global system memory. This shared AddressSpace will be used in a subsequent patch for all vfio-pci devices behind all accelerated SMMUv3 instances within a VM.Sharing a single system AddressSpace ensures that all devices behind accelerated SMMUv3s use the same system address space pointer. This allows VFIO/iommufd to reuse a single IOAS ID in
iommufd_cdev_attach(), enabling the Stage-2 page tables to be shared within the VM rather than duplicated for each SMMUv3 instance.
Quoted 3 lines
Reviewed-by Nicolin Chen <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>
Eric
Quoted 51 lines
--- hw/arm/smmuv3-accel.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)hw/arm/smmuv3-accel.c +26
-0@@ -11,6 +11,14 @@#include "hw/arm/smmuv3.h" #include "smmuv3-accel.h" +/* +* The root region aliases the global system memory, and shared_as_sysmem +* provides a shared Address Space referencing it. This Address Space is used +* by all vfio-pci devices behind all accelerated SMMUv3 instances within a VM. +*/ +static MemoryRegion root, sysmem; +static AddressSpace *shared_as_sysmem; +static SMMUv3AccelDevice *smmuv3_accel_get_dev (SMMUState *bs,SMMUPciBus *sbus,PCIBus *bus,int devfn) {@@ -51,9 +59,27 @@ static const PCIIOMMUOps smmuv3_accel_ops = { .get_address_space = smmuv3_accel_find_add_as, }; +static void smmuv3_accel_as_init (SMMUv3State *s) +{ + +if (shared_as_sysmem) { +return ; + } + +memory_region_init (&root,OBJECT (s),"root" ,UINT64_MAX ); +memory_region_init_alias (&sysmem,OBJECT (s),"smmuv3-accel-sysmem" , +get_system_memory (),0 , +memory_region_size (get_system_memory ())); +memory_region_add_subregion (&root,0 , &sysmem); + + shared_as_sysmem =g_new0 (AddressSpace,1 ); +address_space_init (shared_as_sysmem, &root,"smmuv3-accel-as-sysmem" ); +} +void smmuv3_accel_init (SMMUv3State *s) {SMMUState *bs =ARM_SMMU (s); bs->iommu_ops = &smmuv3_accel_ops; +smmuv3_accel_as_init (s); }
PATCH v6 7/33 hw/pci/pci: Move pci_init_bus_master() after adding device to bus
In reply to Shameer KolothumDuring PCI hotplug, in do_pci_register_device(), pci_init_bus_master() is called before storing the pci_dev pointer in bus->devices[devfn].
This causes a problem if pci_init_bus_master() (via its get_address_space() callback) attempts to retrieve the device using pci_find_device(), since the PCI device is not yet visible on the bus.
Fix this by moving the pci_init_bus_master() call to after the device has been added to bus->devices[devfn].
This prepares for a subsequent patch where the accel SMMUv3 get_address_space() callback retrieves the pci_dev to identify the attached device type.
No functional change intended.
--- hw/pci/pci.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/pci/pci.c +3 -3
@@ -1381,9 +1381,6 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, pci_dev->bus_master_as.max_bounce_buffer_size = pci_dev->max_bounce_buffer_size; -if (phase_check (PHASE_MACHINE_READY )) { -pci_init_bus_master (pci_dev); - } pci_dev->irq_state =0 ;pci_config_alloc (pci_dev);
@@ -1427,6 +1424,9 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, pci_dev->config_write = config_write; bus->devices[devfn] = pci_dev; pci_dev->version_id =2 ;/* Current pci device vmstate version */ +if (phase_check (PHASE_MACHINE_READY )) { +pci_init_bus_master (pci_dev); + }return pci_dev; }
Signature · 1 line
2.43.0
Re: [PATCH v6 07/33] hw/pci/pci: Move pci_init_bus_master() after adding device to bus
Quoted 14 lines · Shameer Kolothum
During PCI hotplug, in
do_pci_register_device(),pci_init_bus_master()is called before storing thepci_devpointer in bus->devices[devfn].This causes a problem if
pci_init_bus_master()(via itsget_address_space()callback) attempts to retrieve the device usingpci_find_device(), since the PCI device is not yet visible on the bus.Fix this by moving the
pci_init_bus_master()call to after the device has been added to bus->devices[devfn].This prepares for a subsequent patch where the accel SMMUv3
get_address_space()callback retrieves thepci_devto identify the attached device type.
Quoted 6 lines
No functional change intended.
Cc Michael S. Tsirkin <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Eric Auger <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>
PATCH v6 8/33 hw/pci/pci: Add optional supports_address_space() callback
In reply to Shameer KolothumIntroduce an optional supports_address_space() callback in PCIIOMMUOps to allow a vIOMMU implementation to reject devices that should not be attached to it.
Currently, get_address_space() is the first and mandatory callback into the vIOMMU layer, which always returns an address space. For certain setups, such as hardware accelerated vIOMMUs (e.g. ARM SMMUv3 with accel=on), attaching emulated endpoint devices is undesirable as it may impact the behavior or performance of VFIO passthrough devices, for example, by triggering unnecessary invalidations on the host IOMMU.
The new callback allows a vIOMMU to check and reject unsupported devices early during PCI device registration.
--- hw/pci/pci.c | 20 ++++++++++++++++++++ include/hw/pci/pci.h | 17 +++++++++++++++++ 2 files changed, 37 insertions(+)
hw/pci/pci.c +20 -0
@@ -135,6 +135,21 @@ static void pci_set_master(PCIDevice *d, bool enable) d->is_master = enable;/* cache the status */ } +static bool +pci_device_supports_iommu_address_space (PCIDevice *dev,Error **errp) +{ +PCIBus *bus; +PCIBus *iommu_bus; +int devfn; + +pci_device_get_iommu_bus_devfn (dev, &iommu_bus, &bus, &devfn); +if (iommu_bus && iommu_bus->iommu_ops->supports_address_space) { +return iommu_bus->iommu_ops->supports_address_space (bus, + iommu_bus->iommu_opaque, devfn, errp); + } +return true; +} +static void pci_init_bus_master (PCIDevice *pci_dev) {AddressSpace *dma_as =pci_device_iommu_address_space (pci_dev);
@@ -1424,6 +1439,11 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, pci_dev->config_write = config_write; bus->devices[devfn] = pci_dev; pci_dev->version_id =2 ;/* Current pci device vmstate version */ +if (!pci_device_supports_iommu_address_space (pci_dev, errp)) { +do_pci_unregister_device (pci_dev); + bus->devices[devfn] =NULL ; +return NULL ; + }if (phase_check (PHASE_MACHINE_READY )) {pci_init_bus_master (pci_dev); }
include/hw/pci/pci.h +17 -0
@@ -417,6 +417,23 @@ typedef struct IOMMUPRINotifier {* framework for a set of devices on a PCI bus. */ typedef struct PCIIOMMUOps { + /** + * @supports_address_space: Optional pre-check to determine if a PCI + * device can have an IOMMU address space. + * + * @bus: the #PCIBus being accessed. + * + * @opaque: the data passed to pci_setup_iommu(). + * + * @devfn: device and function number. + * + * @errp: pass an Error out only when return false + * + * Returns: true if the device can be associated with an IOMMU address + * space, false otherwise with errp set. + */ + bool (*supports_address_space)(PCIBus *bus, void *opaque, int devfn, + Error **errp); /** * @get_address_space: get the address space for a set of devices * on a PCI bus.
Signature · 1 line
2.43.0
Re: [PATCH v6 08/33] hw/pci/pci: Add optional supports_address_space() callback
Quoted 1 line · Shameer Kolothum
Introduce an optional
supports_address_space()callback in PCIIOMMUOps to
"supports_address_space" sounds a bit to wide to me than its indication to supporting an IOMMU address space specifically, since the "system address space" being used in this series is a legit address space as well.
With that being said, I think we are fine for now, given the API docs has clarified it. If someone shares the same concern, we can rename it later.
Quoted 10 lines
allow a vIOMMU implementation to reject devices that should not be attached to it.
Currently,
get_address_space()is the first and mandatory callback into the vIOMMU layer, which always returns an address space. For certain setups, such as hardware accelerated vIOMMUs (e.g. ARM SMMUv3 with accel=on), attaching emulated endpoint devices is undesirable as it may impact the behavior or performance of VFIO passthrough devices, for example, by triggering unnecessary invalidations on the host IOMMU.
Quoted 7 lines
The new callback allows a vIOMMU to check and reject unsupported devices early during PCI device registration.
Cc Michael S. Tsirkin <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Eric Auger <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>
RE: [PATCH v6 08/33] hw/pci/pci: Add optional supports_address_space() callback
Quoted 21 lines
-----Original Message-----
From: Nicolin Chen <[email protected]>
Sent: 20 November 2025 20:51
To: Shameer Kolothum <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>; Michael S . Tsirkin <[email protected]>
Subject: Re: [PATCH v6 08/33] hw/pci/pci: Add optionalsupports_address_space()callbackQuoted 1 line · Shameer Kolothum
Introduce an optional
supports_address_space()callback in PCIIOMMUOpsto
Quoted 8 lines
"
supports_address_space" sounds a bit to wide to me than its indication to supporting an IOMMU address space specifically, since the "system address space" being used in this series is a legit address space as well.With that being said, I think we are fine for now, given the API docs has clarified it. If someone shares the same concern, we can rename it later.
The intent here is just to let the vIOMMU decide whether a device should be associated with its address_space before we call get_address_space(). If the check passes, the vIOMMU must provide the actual address_space through get_address_space() callback.
Sure. Open to suggestion here.
Thanks,
Shameer
Re: [PATCH v6 08/33] hw/pci/pci: Add optional supports_address_space() callback
Quoted 24 lines · Shameer Kolothum
Quoted 24 lines
-----Original Message-----
From: Nicolin Chen <[email protected]>
Sent: 20 November 2025 20:51
To: Shameer Kolothum <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>; Michael S . Tsirkin <[email protected]>
Subject: Re: [PATCH v6 08/33] hw/pci/pci: Add optionalsupports_address_space()callbackQuoted 1 line · Shameer Kolothum
Introduce an optional
supports_address_space()callback in PCIIOMMUOpsto
"
supports_address_space" sounds a bit to wide to me than its indication to supporting an IOMMU address space specifically, since the "system address space" being used in this series is a legit address space as well.
Quoted 8 lines
Quoted 3 lines
With that being said, I think we are fine for now, given the API docs has clarified it. If someone shares the same concern, we can rename it later.
The intent here is just to let the vIOMMU decide whether a device should be associated with its
address_spacebefore we callget_address_space(). If the check passes, the vIOMMU must provide the actualaddress_spacethroughget_address_space()callback.
The naming makes sense now. Yet, the API doc is a bit confusing..
Why it says "device can have an IOMMU address space"? If a device only has a system address space (i.e. it doesn't support an IOMMU address space), it still returns true, right?
Nicolin
RE: [PATCH v6 08/33] hw/pci/pci: Add optional supports_address_space() callback
Quoted 53 lines
-----Original Message-----
From: Nicolin Chen <[email protected]>
Sent: 21 November 2025 17:28
To: Shameer Kolothum <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>; Michael S . Tsirkin <[email protected]>
Subject: Re: [PATCH v6 08/33] hw/pci/pci: Add optionalsupports_address_space()callbackQuoted 4 lines · Shameer Kolothum
Quoted 4 lines
-----Original Message-----
From: Nicolin Chen <[email protected]>
Sent: 20 November 2025 20:51
To: Shameer Kolothum <[email protected]>Quoted 8 lines
Quoted 8 lines
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>; Michael S . Tsirkin
Quoted 5 lines
Quoted 5 lines
Subject: Re: [PATCH v6 08/33] hw/pci/pci: Add optional
supports_address_space()callbackQuoted 1 line · Shameer Kolothum
Introduce an optional
supports_address_space()callback inPCIIOMMUOps
Quoted 7 lines
Quoted 7 lines
to
"
supports_address_space" sounds a bit to wide to me than its indication to supporting an IOMMU address space specifically, since the "system address space" being used in this series is a legit address space as well.Quoted 8 lines
Quoted 3 lines
With that being said, I think we are fine for now, given the API docs has clarified it. If someone shares the same concern, we can rename it later.
The intent here is just to let the vIOMMU decide whether a device should be associated with its
address_spacebefore we callget_address_space(). If the check passes, the vIOMMU must provide the actualaddress_spacethroughget_address_space()callback.
Quoted 5 lines
The naming makes sense now. Yet, the API doc is a bit confusing..
Why it says "device can have an IOMMU address space"? If a device only has a system address space (i.e. it doesn't support an IOMMU address space), it still returns true, right?
Yes. I think the API doc wording requires tightening. Will do.
Thanks,
Shameer
Re: [PATCH v6 08/33] hw/pci/pci: Add optional supports_address_space() callback
In reply to Shameer KolothumHello,
Quoted 3 lines · Shameer Kolothum
Introduce an optional
supports_address_space()callback in PCIIOMMUOps to allow a vIOMMU implementation to reject devices that should not be attached to it.
Why can't we use the existing .set_iommu_device() op instead ?
C.
Quoted 86 lines
Currently,
get_address_space()is the first and mandatory callback into the vIOMMU layer, which always returns an address space. For certain setups, such as hardware accelerated vIOMMUs (e.g. ARM SMMUv3 with accel=on), attaching emulated endpoint devices is undesirable as it may impact the behavior or performance of VFIO passthrough devices, for example, by triggering unnecessary invalidations on the host IOMMU.The new callback allows a vIOMMU to check and reject unsupported devices early during PCI device registration.
Cc Michael S. Tsirkin <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Eric Auger <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/pci/pci.c | 20 ++++++++++++++++++++ include/hw/pci/pci.h | 17 +++++++++++++++++ 2 files changed, 37 insertions(+)hw/pci/pci.c +20
-0@@ -135,6 +135,21 @@ static void pci_set_master(PCIDevice *d, bool enable) d->is_master = enable;/* cache the status */ } +static bool +pci_device_supports_iommu_address_space (PCIDevice *dev,Error **errp) +{ +PCIBus *bus; +PCIBus *iommu_bus; +int devfn; + +pci_device_get_iommu_bus_devfn (dev, &iommu_bus, &bus, &devfn); +if (iommu_bus && iommu_bus->iommu_ops->supports_address_space) { +return iommu_bus->iommu_ops->supports_address_space (bus, + iommu_bus->iommu_opaque, devfn, errp); + } +return true; +} +static void pci_init_bus_master (PCIDevice *pci_dev) {AddressSpace *dma_as =pci_device_iommu_address_space (pci_dev);@@ -1424,6 +1439,11 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, pci_dev->config_write = config_write; bus->devices[devfn] = pci_dev; pci_dev->version_id =2 ;/* Current pci device vmstate version */ +if (!pci_device_supports_iommu_address_space (pci_dev, errp)) { +do_pci_unregister_device (pci_dev); + bus->devices[devfn] =NULL ; +return NULL ; + }if (phase_check (PHASE_MACHINE_READY )) {pci_init_bus_master (pci_dev); }include/hw/pci/pci.h +17
-0@@ -417,6 +417,23 @@ typedef struct IOMMUPRINotifier {* framework for a set of devices on a PCI bus. */ typedef struct PCIIOMMUOps { + /** + * @supports_address_space: Optional pre-check to determine if a PCI + * device can have an IOMMU address space. + * + * @bus: the #PCIBus being accessed. + * + * @opaque: the data passed to pci_setup_iommu(). + * + * @devfn: device and function number. + * + * @errp: pass an Error out only when return false + * + * Returns: true if the device can be associated with an IOMMU address + * space, false otherwise with errp set. + */ + bool (*supports_address_space)(PCIBus *bus, void *opaque, int devfn, + Error **errp); /** * @get_address_space: get the address space for a set of devices * on a PCI bus.
RE: [PATCH v6 08/33] hw/pci/pci: Add optional supports_address_space() callback
Quoted 21 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: 11 December 2025 14:40
To: Shameer Kolothum <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>; Michael S . Tsirkin <[email protected]>
Subject: Re: [PATCH v6 08/33] hw/pci/pci: Add optionalsupports_address_space()callbackExternal email: Use caution opening links or attachments
Quoted 8 lines
Hello,
Quoted 3 lines · Shameer Kolothum
Introduce an optional
supports_address_space()callback in PCIIOMMUOps to allow a vIOMMU implementation to reject devices that should not be attached to it.Why can't we use the existing .set_iommu_device() op instead ?
Because it is called a bit later after the mandatory get_address_space() callback during pci dev registration. And would like to fail the dev registration before that.
Thanks,
Shameer
PATCH v6 9/33 hw/pci-bridge/pci_expander_bridge: Move TYPE_PXB_PCIE_DEV to header
In reply to Shameer KolothumMove the TYPE_PXB_PCIE_DEV definition to header so that it can be referenced by other code in subsequent patch.
--- hw/pci-bridge/pci_expander_bridge.c | 1 - include/hw/pci/pci_bridge.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)
hw/pci-bridge/pci_expander_bridge.c +0 -1
@@ -48,7 +48,6 @@ struct PXBBus {char bus_path[8 ]; }; -#define TYPE_PXB_PCIE_DEV "pxb-pcie" OBJECT_DECLARE_SIMPLE_TYPE(PXBPCIEDev, PXB_PCIE_DEV)static GList *pxb_dev_list;
include/hw/pci/pci_bridge.h +1 -0
@@ -106,6 +106,7 @@ typedef struct PXBPCIEDev {#define TYPE_PXB_PCIE_BUS "pxb-pcie-bus"#define TYPE_PXB_CXL_BUS "pxb-cxl-bus" +#define TYPE_PXB_PCIE_DEV "pxb-pcie"#define TYPE_PXB_DEV "pxb"OBJECT_DECLARE_SIMPLE_TYPE (PXBDev,PXB_DEV )
Signature · 1 line
2.43.0
Re: [PATCH v6 09/33] hw/pci-bridge/pci_expander_bridge: Move TYPE_PXB_PCIE_DEV to header
Quoted 6 lines · Shameer Kolothum
Move the
TYPE_PXB_PCIE_DEVdefinition to header so that it can be referenced by other code in subsequent patch.Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Eric Auger <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>
PATCH v6 10/33 hw/arm/smmuv3-accel: Restrict accelerated SMMUv3 to vfio-pci endpoints with iommufd
In reply to Shameer KolothumAccelerated SMMUv3 is only meaningful when a device can leverage the host SMMUv3 in nested mode (S1+S2 translation). To keep the model consistent and correct, this mode is restricted to vfio-pci endpoint devices using the iommufd backend.
Non-endpoint emulated devices such as PCIe root ports and bridges are also permitted so that vfio-pci devices can be attached downstream. All other device types are unsupported in accelerated mode.
Implement supports_address_space() callback to reject all such unsupported devices.
This restriction also avoids complications with IOTLB invalidations. Some TLBI commands (e.g. CMD_TLBI_NH_ASID) lack an associated SID, making it difficult to trace the originating device. Allowing emulated endpoints would require invalidating both QEMU’s software IOTLB and the host’s hardware IOTLB, which can significantly degrade performance.
A key design choice is the address space returned for accelerated vfio-pci endpoints. VFIO core has a container that manages an HWPT. By default, it allocates a stage-1 normal HWPT, unless vIOMMU requests for a nesting parent HWPT for accelerated cases.
VFIO core adds a listener for that HWPT and sets up a handler vfio_container_region_add() where it checks the memory region.
-If the region is a non-IOMMU translated one (system address space), VFIO
treats it as RAM and handles all stage-2 mappings for the core allocated nesting parent HWPT.
-If the region is an IOMMU address space, VFIO instead enables IOTLB
notifier handling and translation replay, skipping the RAM listener and therefore not installing stage-2 mappings.
For accelerated SMMUv3, correct operation requires the S1+S2 nesting model, and therefore VFIO must take the "system address space" path so that stage-2 mappings are properly built. Returning an alias of the system address space ensures this happens. Returning the IOMMU address space would omit stage-2 mapping and break nested translation.
Another option considered was forcing a pre-registration path using vfio_prereg_listener() to set up stage-2 mappings, but this requires changes in VFIO core and was not adopted. Returning an alias of the system address space keeps the design aligned with existing VFIO/iommufd nesting flows and avoids the need for cross-subsystem changes.
In summary:
- vfio-pci devices(with iommufd as backend) return an address space aliased to system address space.
- bridges and root ports return the IOMMU address space.
--- hw/arm/smmuv3-accel.c | 77 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-)
hw/arm/smmuv3-accel.c +76 -1
@@ -7,8 +7,13 @@*/ #include "qemu/osdep.h" +#include "qemu/error-report.h" #include "hw/arm/smmuv3.h" +#include "hw/pci/pci_bridge.h" +#include "hw/pci-host/gpex.h" +#include "hw/vfio/pci.h" +#include "smmuv3-accel.h" /*
@@ -37,6 +42,48 @@ static SMMUv3AccelDevice *smmuv3_accel_get_dev(SMMUState *bs, SMMUPciBus *sbus,return accel_dev; } +/* +* Only allow PCIe bridges, pxb-pcie roots, and GPEX roots so vfio-pci +* endpoints can sit downstream. Accelerated SMMUv3 requires a vfio-pci +* endpoint using the iommufd backend; all other device types are rejected. +* This avoids supporting emulated endpoints, which would complicate IOTLB +* invalidation and hurt performance. +*/ +static bool smmuv3_accel_pdev_allowed (PCIDevice *pdev,bool *vfio_pci) +{ + +if (object_dynamic_cast (OBJECT (pdev),TYPE_PCI_BRIDGE ) || +object_dynamic_cast (OBJECT (pdev),TYPE_PXB_PCIE_DEV ) || +object_dynamic_cast (OBJECT (pdev),TYPE_GPEX_ROOT_DEVICE )) { +return true; + }else if ((object_dynamic_cast (OBJECT (pdev),TYPE_VFIO_PCI ))) { + *vfio_pci = true; +if (object_property_get_link (OBJECT (pdev),"iommufd" ,NULL )) { +return true; + } + } +return false; +} + +static bool smmuv3_accel_supports_as (PCIBus *bus,void *opaque,int devfn, +Error **errp) +{ +PCIDevice *pdev =pci_find_device (bus,pci_bus_num (bus), devfn); +bool vfio_pci = false; + +if (pdev && !smmuv3_accel_pdev_allowed (pdev, &vfio_pci)) { +if (vfio_pci) { +error_setg (errp,"vfio-pci endpoint devices without an iommufd " +"backend not allowed when using arm-smmuv3,accel=on" ); + + }else { +error_setg (errp,"Emulated endpoint devices are not allowed when " +"using arm-smmuv3,accel=on" ); + } +return false; + } +return true; +}/* * Find or add an address space for the given PCI device. *
@@ -47,15 +94,43 @@ static SMMUv3AccelDevice *smmuv3_accel_get_dev(SMMUState *bs, SMMUPciBus *sbus,static AddressSpace *smmuv3_accel_find_add_as (PCIBus *bus,void *opaque,int devfn) { +PCIDevice *pdev =pci_find_device (bus,pci_bus_num (bus), devfn);SMMUState *bs = opaque;SMMUPciBus *sbus =smmu_get_sbus (bs, bus);SMMUv3AccelDevice *accel_dev =smmuv3_accel_get_dev (bs, sbus, bus, devfn);SMMUDevice *sdev = &accel_dev->sdev; +bool vfio_pci = false; -return &sdev->as; +if (pdev && !smmuv3_accel_pdev_allowed (pdev, &vfio_pci)) { +/* Should never be here: supports_address_space() filters these out */ +g_assert_not_reached (); + } + +/* +* In the accelerated mode, a vfio-pci device attached via the iommufd +* backend must remain in the system address space. Such a device is +* always translated by its physical SMMU (using either a stage-2-only +* STE or a nested STE), where the parent stage-2 page table is allocated +* by the VFIO core to back the system address space. +* +* Return the shared_as_sysmem aliased to the global system memory in this +* case. Sharing address_space_memory also allows devices under different +* vSMMU instances in the same VM to reuse a single nesting parent HWPT in +* the VFIO core. +* +* For non-endpoint emulated devices such as PCIe root ports and bridges, +* which may use the normal emulated translation path and software IOTLBs, +* return the SMMU's IOMMU address space. +*/ +if (vfio_pci) { +return shared_as_sysmem; + }else { +return &sdev->as; + } }static const PCIIOMMUOps smmuv3_accel_ops = { + .supports_address_space = smmuv3_accel_supports_as, .get_address_space = smmuv3_accel_find_add_as, };
Signature · 1 line
2.43.0
PATCH v6 11/33 hw/arm/smmuv3: Implement get_viommu_cap() callback
In reply to Shameer KolothumFor accelerated SMMUv3, we need nested parent domain creation. Add the callback support so that VFIO can create a nested parent.
--- hw/arm/smmuv3-accel.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
hw/arm/smmuv3-accel.c +13 -0
@@ -10,6 +10,7 @@#include "qemu/error-report.h" #include "hw/arm/smmuv3.h" +#include "hw/iommu.h" #include "hw/pci/pci_bridge.h" #include "hw/pci-host/gpex.h" #include "hw/vfio/pci.h"
@@ -129,9 +130,21 @@ static AddressSpace *smmuv3_accel_find_add_as(PCIBus *bus, void *opaque, } } +static uint64_t smmuv3_accel_get_viommu_flags (void *opaque) +{ +/* +* We return VIOMMU_FLAG_WANT_NESTING_PARENT to inform VFIO core to create a +* nesting parent which is required for accelerated SMMUv3 support. +* The real HW nested support should be reported from host SMMUv3 and if +* it doesn't, the nesting parent allocation will fail anyway in VFIO core. +*/ +return VIOMMU_FLAG_WANT_NESTING_PARENT ; +} +static const PCIIOMMUOps smmuv3_accel_ops = { .supports_address_space = smmuv3_accel_supports_as, .get_address_space = smmuv3_accel_find_add_as, + .get_viommu_flags = smmuv3_accel_get_viommu_flags, };static void smmuv3_accel_as_init (SMMUv3State *s)
Signature · 1 line
2.43.0
PATCH v6 12/33 hw/arm/smmuv3-accel: Add set/unset_iommu_device callback
In reply to Shameer KolothumFrom: Nicolin Chen <[email protected]>
Implement the VFIO/PCI callbacks to attach and detach a HostIOMMUDevice to a vSMMUv3 when accel=on,
- set_iommu_device(): attach a HostIOMMUDevice to a vIOMMU
- unset_iommu_device(): detach and release associated resources
In SMMUv3 accel=on mode, the guest SMMUv3 is backed by the host SMMUv3 via IOMMUFD. A vIOMMU object (created via IOMMU_VIOMMU_ALLOC) provides a per-VM, security-isolated handle to the physical SMMUv3. Without a vIOMMU, the vSMMUv3 cannot relay guest operations to the host hardware nor maintain isolation across VMs or devices. Therefore, set_iommu_device() allocates a vIOMMU object if one does not already exist.
There are two main points to consider in this implementation:
1) VFIO core allocates and attaches a S2 HWPT that acts as the nesting parent for nested HWPTs(IOMMU_DOMAIN_NESTED). This parent HWPT will be shared across multiple vSMMU instances within a VM.
2) A device cannot attach directly to a vIOMMU. Instead, it attaches through a proxy nested HWPT (IOMMU_DOMAIN_NESTED). Based on the STE configuration,there are three types of nested HWPTs: bypass, abort, and translate.
-The bypass and abort proxy HWPTs are pre-allocated. When SMMUv3
operates in global abort or bypass modes, as controlled by the GBPA register, or issues a vSTE for bypass or abort we attach these pre-allocated nested HWPTs.
-The translate HWPT requires a vDEVICE to be allocated first, since
invalidations and events depend on a valid vSID.
-The vDEVICE allocation and attach operations for vSTE based HWPTs
are implemented in subsequent patches.
In summary, a device placed behind a vSMMU instance must have a vSID for translate vSTE. The bypass and abort vSTEs are pre-allocated as proxy nested HWPTs and is attached based on GBPA register. The core-managed nesting parent S2 HWPT is used as parent S2 HWPT for all the nested HWPTs and is intended to be shared across vSMMU instances within the same VM.
set_iommu_device():
- Reuse an existing vIOMMU for the same physical SMMU if available. If not, allocate a new one using the nesting parent S2 HWPT.
- Pre-allocate two proxy nested HWPTs (bypass and abort) under the vIOMMU and install one based on GBPA.ABORT value.
- Add the device to the vIOMMU’s device list.
unset_iommu_device():
- Re-attach device to the nesting parent S2 HWPT.
- Remove the device from the vIOMMU’s device list.
- If the list is empty, free the proxy HWPTs (bypass and abort) and release the vIOMMU object.
Introduce struct SMMUv3AccelState, representing an accelerated SMMUv3 instance backed by an iommufd vIOMMU object, and storing the bypass and abort proxy HWPT IDs.
--- hw/arm/smmuv3-accel.c | 154 +++++++++++++++++++++++++++++++++++++++ hw/arm/smmuv3-accel.h | 16 ++++ hw/arm/smmuv3-internal.h | 3 + hw/arm/trace-events | 4 + include/hw/arm/smmuv3.h | 1 + 5 files changed, 178 insertions(+)
hw/arm/smmuv3-accel.c +154 -0
@@ -8,6 +8,7 @@#include "qemu/osdep.h" #include "qemu/error-report.h" +#include "trace.h" #include "hw/arm/smmuv3.h" #include "hw/iommu.h"
@@ -15,6 +16,7 @@#include "hw/pci-host/gpex.h" #include "hw/vfio/pci.h" +#include "smmuv3-internal.h" #include "smmuv3-accel.h" /*
@@ -43,6 +45,156 @@ static SMMUv3AccelDevice *smmuv3_accel_get_dev(SMMUState *bs, SMMUPciBus *sbus,return accel_dev; } +static uint32_t smmuv3_accel_gbpa_hwpt (SMMUv3State *s,SMMUv3AccelState *accel) +{ +return FIELD_EX32 (s->gbpa,GBPA ,ABORT ) ? + accel->abort_hwpt_id : accel->bypass_hwpt_id; +} + +static bool +smmuv3_accel_alloc_viommu (SMMUv3State *s,HostIOMMUDeviceIOMMUFD *idev, +Error **errp) +{ +struct iommu_hwpt_arm_smmuv3 bypass_data = { + .ste = {SMMU_STE_CFG_BYPASS |SMMU_STE_VALID ,0x0ULL }, + }; +struct iommu_hwpt_arm_smmuv3 abort_data = { + .ste = {SMMU_STE_VALID ,0x0ULL }, + }; +uint32_t s2_hwpt_id = idev->hwpt_id; +uint32_t viommu_id, hwpt_id; +SMMUv3AccelState *accel; + +if (!iommufd_backend_alloc_viommu (idev->iommufd, idev->devid, +IOMMU_VIOMMU_TYPE_ARM_SMMUV3 , + s2_hwpt_id, &viommu_id, errp)) { +return false; + } + + accel =g_new0 (SMMUv3AccelState,1 ); + accel->viommu.viommu_id = viommu_id; + accel->viommu.s2_hwpt_id = s2_hwpt_id; + accel->viommu.iommufd = idev->iommufd; + +/* +* Pre-allocate HWPTs for S1 bypass and abort cases. These will be attached +* later for guest STEs or GBPAs that require bypass or abort configuration. +*/ +if (!iommufd_backend_alloc_hwpt (idev->iommufd, idev->devid, viommu_id, +0 ,IOMMU_HWPT_DATA_ARM_SMMUV3 , +sizeof (abort_data), &abort_data, + &accel->abort_hwpt_id, errp)) { + goto free_viommu; + } + +if (!iommufd_backend_alloc_hwpt (idev->iommufd, idev->devid, viommu_id, +0 ,IOMMU_HWPT_DATA_ARM_SMMUV3 , +sizeof (bypass_data), &bypass_data, + &accel->bypass_hwpt_id, errp)) { + goto free_abort_hwpt; + } + +/* Attach a HWPT based on SMMUv3 GBPA.ABORT value */ + hwpt_id =smmuv3_accel_gbpa_hwpt (s, accel); +if (!host_iommu_device_iommufd_attach_hwpt (idev, hwpt_id, errp)) { + goto free_bypass_hwpt; + } + s->s_accel = accel; +return true; + +free_bypass_hwpt: +iommufd_backend_free_id (idev->iommufd, accel->bypass_hwpt_id); +free_abort_hwpt: +iommufd_backend_free_id (idev->iommufd, accel->abort_hwpt_id); +free_viommu: +iommufd_backend_free_id (idev->iommufd, accel->viommu.viommu_id); +g_free (accel); +return false; +} + +static bool smmuv3_accel_set_iommu_device (PCIBus *bus,void *opaque,int devfn, +HostIOMMUDevice *hiod,Error **errp) +{ +HostIOMMUDeviceIOMMUFD *idev =HOST_IOMMU_DEVICE_IOMMUFD (hiod); +SMMUState *bs = opaque; +SMMUv3State *s =ARM_SMMUV3 (bs); +SMMUPciBus *sbus =smmu_get_sbus (bs, bus); +SMMUv3AccelDevice *accel_dev =smmuv3_accel_get_dev (bs, sbus, bus, devfn); + +if (!idev) { +return true; + } + +if (accel_dev->idev) { +if (accel_dev->idev != idev) { +error_setg (errp,"Device already has an associated idev 0x%x" , + idev->devid); +return false; + } +return true; + } + +if (s->s_accel) { + goto done; + } + +if (!smmuv3_accel_alloc_viommu (s, idev, errp)) { +error_append_hint (errp,"Unable to alloc vIOMMU: idev devid 0x%x: " , + idev->devid); +return false; + } + +done: + accel_dev->idev = idev; + accel_dev->s_accel = s->s_accel; +QLIST_INSERT_HEAD (&s->s_accel->device_list, accel_dev, next); +trace_smmuv3_accel_set_iommu_device (devfn, idev->devid); +return true; +} + +static void smmuv3_accel_unset_iommu_device (PCIBus *bus,void *opaque, +int devfn) +{ +SMMUState *bs = opaque; +SMMUv3State *s =ARM_SMMUV3 (bs); +SMMUPciBus *sbus =g_hash_table_lookup (bs->smmu_pcibus_by_busptr, bus); +HostIOMMUDeviceIOMMUFD *idev; +SMMUv3AccelDevice *accel_dev; +SMMUv3AccelState *accel; +SMMUDevice *sdev; + +if (!sbus) { +return ; + } + + sdev = sbus->pbdev[devfn]; +if (!sdev) { +return ; + } + + accel_dev =container_of (sdev, SMMUv3AccelDevice, sdev); + idev = accel_dev->idev; + accel = accel_dev->s_accel; +/* Re-attach the default s2 hwpt id */ +if (!host_iommu_device_iommufd_attach_hwpt (idev, idev->hwpt_id,NULL )) { +error_report ("Unable to attach the default HW pagetable: idev devid " +"0x%x" , idev->devid); + } + + accel_dev->idev =NULL ; + accel_dev->s_accel =NULL ; +QLIST_REMOVE (accel_dev, next); +trace_smmuv3_accel_unset_iommu_device (devfn, idev->devid); + +if (QLIST_EMPTY (&accel->device_list)) { +iommufd_backend_free_id (accel->viommu.iommufd, accel->bypass_hwpt_id); +iommufd_backend_free_id (accel->viommu.iommufd, accel->abort_hwpt_id); +iommufd_backend_free_id (accel->viommu.iommufd, accel->viommu.viommu_id); +g_free (accel); + s->s_accel =NULL ; + } +} +/* * Only allow PCIe bridges, pxb-pcie roots, and GPEX roots so vfio-pci * endpoints can sit downstream. Accelerated SMMUv3 requires a vfio-pci
@@ -145,6 +297,8 @@ static const PCIIOMMUOps smmuv3_accel_ops = { .supports_address_space = smmuv3_accel_supports_as, .get_address_space = smmuv3_accel_find_add_as, .get_viommu_flags = smmuv3_accel_get_viommu_flags, + .set_iommu_device = smmuv3_accel_set_iommu_device, + .unset_iommu_device = smmuv3_accel_unset_iommu_device, };static void smmuv3_accel_as_init (SMMUv3State *s)
hw/arm/smmuv3-accel.h +16 -0
@@ -10,10 +10,26 @@#define HW_ARM_SMMUV3_ACCEL_H #include "hw/arm/smmu-common.h" +#include "system/iommufd.h" +#include <linux/iommufd.h> #include CONFIG_DEVICES +/* +* Represents an accelerated SMMU instance backed by an iommufd vIOMMU object. +* Holds bypass and abort proxy HWPT IDs used for device attachment. +*/ +typedef struct SMMUv3AccelState { +IOMMUFDViommu viommu; +uint32_t bypass_hwpt_id; +uint32_t abort_hwpt_id; + QLIST_HEAD(, SMMUv3AccelDevice) device_list; +}SMMUv3AccelState ; +typedef struct SMMUv3AccelDevice {SMMUDevice sdev; +HostIOMMUDeviceIOMMUFD *idev; +QLIST_ENTRY (SMMUv3AccelDevice) next; +SMMUv3AccelState *s_accel; }SMMUv3AccelDevice ;#ifdef CONFIG_ARM_SMMUV3_ACCEL
hw/arm/smmuv3-internal.h +3 -0
@@ -583,6 +583,9 @@ typedef struct CD { ((extract64 ((x)->word[7 ],0 ,16 ) <<32 ) | \ ((x)->word[6] & 0xfffffff0)) +#define SMMU_STE_VALID (1ULL << 0) +#define SMMU_STE_CFG_BYPASS (1ULL << 3) +static inline int oas2bits (int oas_field) {switch (oas_field) {
hw/arm/trace-events +4 -0
@@ -66,6 +66,10 @@ smmuv3_notify_flag_del(const char *iommu) "DEL SMMUNotifier node for iommu mr=%s smmuv3_inv_notifiers_iova(const char *name, int asid, int vmid, uint64_t iova, uint8_t tg, uint64_t num_pages, int stage) "iommu mr=%s asid=%d vmid=%d iova=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64" stage=%d" smmu_reset_exit(void) "" +#smmuv3-accel.c +smmuv3_accel_set_iommu_device(int devfn, uint32_t devid) "devfn=0x%x (idev devid=0x%x)" +smmuv3_accel_unset_iommu_device(int devfn, uint32_t devid) "devfn=0x%x (idev devid=0x%x)" + # strongarm.c strongarm_uart_update_parameters(const char *label, int speed, char parity, int data_bits, int stop_bits) "%s speed=%d parity=%c data=%d stop=%d" strongarm_ssp_read_underrun(void) "SSP rx underrun"
include/hw/arm/smmuv3.h +1 -0
@@ -66,6 +66,7 @@ struct SMMUv3State {/* SMMU has HW accelerator support for nested S1 + s2 */ bool accel; +struct SMMUv3AccelState *s_accel; }; typedef enum {
Signature · 1 line
2.43.0
Re: [PATCH v6 12/33] hw/arm/smmuv3-accel: Add set/unset_iommu_device callback
Hi Shameer,
Quoted 322 lines · Shameer Kolothum
From: Nicolin Chen <[email protected]>
Implement the VFIO/PCI callbacks to attach and detach a HostIOMMUDevice to a vSMMUv3 when accel=on,
-
set_iommu_device(): attach a HostIOMMUDevice to a vIOMMU
-unset_iommu_device(): detach and release associated resourcesIn SMMUv3 accel=on mode, the guest SMMUv3 is backed by the host SMMUv3 via IOMMUFD. A vIOMMU object (created via
IOMMU_VIOMMU_ALLOC) provides a per-VM, security-isolated handle to the physical SMMUv3. Without a vIOMMU, the vSMMUv3 cannot relay guest operations to the host hardware nor maintain isolation across VMs or devices. Therefore,set_iommu_device()allocates a vIOMMU object if one does not already exist.There are two main points to consider in this implementation:
1) VFIO core allocates and attaches a S2 HWPT that acts as the nesting parent for nested
HWPTs(IOMMU_DOMAIN_NESTED). This parent HWPT will be shared across multiple vSMMU instances within a VM.2) A device cannot attach directly to a vIOMMU. Instead, it attaches through a proxy nested HWPT (
IOMMU_DOMAIN_NESTED). Based on the STE configuration,there are three types of nested HWPTs: bypass, abort, and translate.
-The bypass and abort proxy HWPTs are pre-allocated. When SMMUv3
operates in global abort or bypass modes, as controlled by the GBPA register, or issues a vSTE for bypass or abort we attach these pre-allocated nested HWPTs.
-The translate HWPT requires a vDEVICE to be allocated first, since
invalidations and events depend on a valid vSID.
-The vDEVICE allocation and attach operations for vSTE based HWPTs
are implemented in subsequent patches.In summary, a device placed behind a vSMMU instance must have a vSID for translate vSTE. The bypass and abort vSTEs are pre-allocated as proxy nested HWPTs and is attached based on GBPA register. The core-managed nesting parent S2 HWPT is used as parent S2 HWPT for all the nested HWPTs and is intended to be shared across vSMMU instances within the same VM.
set_iommu_device():
- Reuse an existing vIOMMU for the same physical SMMU if available. If not, allocate a new one using the nesting parent S2 HWPT.
- Pre-allocate two proxy nested HWPTs (bypass and abort) under the vIOMMU and install one based on GBPA.ABORT value.
- Add the device to the vIOMMU’s device list.
unset_iommu_device():
- Re-attach device to the nesting parent S2 HWPT.
- Remove the device from the vIOMMU’s device list.
- If the list is empty, free the proxy HWPTs (bypass and abort) and release the vIOMMU object.Introduce struct SMMUv3AccelState, representing an accelerated SMMUv3 instance backed by an iommufd vIOMMU object, and storing the bypass and abort proxy HWPT IDs.
Signed-off-by Nicolin Chen <[email protected]>Signed-off-by Shameer Kolothum <[email protected]Reviewed-by Jonathan Cameron <[email protected]>Tested-by Zhangfei Gao <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.c | 154 +++++++++++++++++++++++++++++++++++++++ hw/arm/smmuv3-accel.h | 16 ++++ hw/arm/smmuv3-internal.h | 3 + hw/arm/trace-events | 4 + include/hw/arm/smmuv3.h | 1 + 5 files changed, 178 insertions(+)hw/arm/smmuv3-accel.c +154
-0@@ -8,6 +8,7 @@#include "qemu/osdep.h" #include "qemu/error-report.h" +#include "trace.h" #include "hw/arm/smmuv3.h" #include "hw/iommu.h" @@ -15,6 +16,7 @@#include "hw/pci-host/gpex.h" #include "hw/vfio/pci.h" +#include "smmuv3-internal.h" #include "smmuv3-accel.h" /* @@ -43,6 +45,156 @@ static SMMUv3AccelDevice *smmuv3_accel_get_dev(SMMUState *bs, SMMUPciBus *sbus,return accel_dev; } +static uint32_t smmuv3_accel_gbpa_hwpt (SMMUv3State *s,SMMUv3AccelState *accel) +{ +return FIELD_EX32 (s->gbpa,GBPA ,ABORT ) ? + accel->abort_hwpt_id : accel->bypass_hwpt_id; +} + +static bool +smmuv3_accel_alloc_viommu (SMMUv3State *s,HostIOMMUDeviceIOMMUFD *idev, +Error **errp) +{ +struct iommu_hwpt_arm_smmuv3 bypass_data = { + .ste = {SMMU_STE_CFG_BYPASS |SMMU_STE_VALID ,0x0ULL }, + }; +struct iommu_hwpt_arm_smmuv3 abort_data = { + .ste = {SMMU_STE_VALID ,0x0ULL }, + }; +uint32_t s2_hwpt_id = idev->hwpt_id; +uint32_t viommu_id, hwpt_id; +SMMUv3AccelState *accel; + +if (!iommufd_backend_alloc_viommu (idev->iommufd, idev->devid, +IOMMU_VIOMMU_TYPE_ARM_SMMUV3 , + s2_hwpt_id, &viommu_id, errp)) { +return false; + } + + accel =g_new0 (SMMUv3AccelState,1 ); + accel->viommu.viommu_id = viommu_id; + accel->viommu.s2_hwpt_id = s2_hwpt_id; + accel->viommu.iommufd = idev->iommufd; + +/* +* Pre-allocate HWPTs for S1 bypass and abort cases. These will be attached +* later for guest STEs or GBPAs that require bypass or abort configuration. +*/ +if (!iommufd_backend_alloc_hwpt (idev->iommufd, idev->devid, viommu_id, +0 ,IOMMU_HWPT_DATA_ARM_SMMUV3 , +sizeof (abort_data), &abort_data, + &accel->abort_hwpt_id, errp)) { + goto free_viommu; + } + +if (!iommufd_backend_alloc_hwpt (idev->iommufd, idev->devid, viommu_id, +0 ,IOMMU_HWPT_DATA_ARM_SMMUV3 , +sizeof (bypass_data), &bypass_data, + &accel->bypass_hwpt_id, errp)) { + goto free_abort_hwpt; + } + +/* Attach a HWPT based on SMMUv3 GBPA.ABORT value */ + hwpt_id =smmuv3_accel_gbpa_hwpt (s, accel); +if (!host_iommu_device_iommufd_attach_hwpt (idev, hwpt_id, errp)) { + goto free_bypass_hwpt; + } + s->s_accel = accel; +return true; + +free_bypass_hwpt: +iommufd_backend_free_id (idev->iommufd, accel->bypass_hwpt_id); +free_abort_hwpt: +iommufd_backend_free_id (idev->iommufd, accel->abort_hwpt_id); +free_viommu: +iommufd_backend_free_id (idev->iommufd, accel->viommu.viommu_id); +g_free (accel); +return false; +} + +static bool smmuv3_accel_set_iommu_device (PCIBus *bus,void *opaque,int devfn, +HostIOMMUDevice *hiod,Error **errp) +{ +HostIOMMUDeviceIOMMUFD *idev =HOST_IOMMU_DEVICE_IOMMUFD (hiod); +SMMUState *bs = opaque; +SMMUv3State *s =ARM_SMMUV3 (bs); +SMMUPciBus *sbus =smmu_get_sbus (bs, bus); +SMMUv3AccelDevice *accel_dev =smmuv3_accel_get_dev (bs, sbus, bus, devfn); + +if (!idev) { +return true; + } + +if (accel_dev->idev) { +if (accel_dev->idev != idev) { +error_setg (errp,"Device already has an associated idev 0x%x" , + idev->devid); +return false; + } +return true; + } + +if (s->s_accel) { + goto done; + } + +if (!smmuv3_accel_alloc_viommu (s, idev, errp)) { +error_append_hint (errp,"Unable to alloc vIOMMU: idev devid 0x%x: " , + idev->devid); +return false; + } + +done: + accel_dev->idev = idev; + accel_dev->s_accel = s->s_accel; +QLIST_INSERT_HEAD (&s->s_accel->device_list, accel_dev, next); +trace_smmuv3_accel_set_iommu_device (devfn, idev->devid); +return true; +} + +static void smmuv3_accel_unset_iommu_device (PCIBus *bus,void *opaque, +int devfn) +{ +SMMUState *bs = opaque; +SMMUv3State *s =ARM_SMMUV3 (bs); +SMMUPciBus *sbus =g_hash_table_lookup (bs->smmu_pcibus_by_busptr, bus); +HostIOMMUDeviceIOMMUFD *idev; +SMMUv3AccelDevice *accel_dev; +SMMUv3AccelState *accel; +SMMUDevice *sdev; + +if (!sbus) { +return ; + } + + sdev = sbus->pbdev[devfn]; +if (!sdev) { +return ; + } + + accel_dev =container_of (sdev, SMMUv3AccelDevice, sdev); + idev = accel_dev->idev; + accel = accel_dev->s_accel; +/* Re-attach the default s2 hwpt id */ +if (!host_iommu_device_iommufd_attach_hwpt (idev, idev->hwpt_id,NULL )) { +error_report ("Unable to attach the default HW pagetable: idev devid " +"0x%x" , idev->devid); + } + + accel_dev->idev =NULL ; + accel_dev->s_accel =NULL ; +QLIST_REMOVE (accel_dev, next); +trace_smmuv3_accel_unset_iommu_device (devfn, idev->devid); + +if (QLIST_EMPTY (&accel->device_list)) { +iommufd_backend_free_id (accel->viommu.iommufd, accel->bypass_hwpt_id); +iommufd_backend_free_id (accel->viommu.iommufd, accel->abort_hwpt_id); +iommufd_backend_free_id (accel->viommu.iommufd, accel->viommu.viommu_id); +g_free (accel); + s->s_accel =NULL ; + } +} +/* * Only allow PCIe bridges, pxb-pcie roots, and GPEX roots so vfio-pci * endpoints can sit downstream. Accelerated SMMUv3 requires a vfio-pci @@ -145,6 +297,8 @@ static const PCIIOMMUOps smmuv3_accel_ops = { .supports_address_space = smmuv3_accel_supports_as, .get_address_space = smmuv3_accel_find_add_as, .get_viommu_flags = smmuv3_accel_get_viommu_flags, + .set_iommu_device = smmuv3_accel_set_iommu_device, + .unset_iommu_device = smmuv3_accel_unset_iommu_device, };static void smmuv3_accel_as_init (SMMUv3State *s)hw/arm/smmuv3-accel.h +16
-0@@ -10,10 +10,26 @@#define HW_ARM_SMMUV3_ACCEL_H #include "hw/arm/smmu-common.h" +#include "system/iommufd.h" +#include <linux/iommufd.h> #include CONFIG_DEVICES +/* +* Represents an accelerated SMMU instance backed by an iommufd vIOMMU object. +* Holds bypass and abort proxy HWPT IDs used for device attachment. +*/ +typedef struct SMMUv3AccelState { +IOMMUFDViommu viommu; +uint32_t bypass_hwpt_id; +uint32_t abort_hwpt_id; + QLIST_HEAD(, SMMUv3AccelDevice) device_list; +}SMMUv3AccelState ; +typedef struct SMMUv3AccelDevice {SMMUDevice sdev; +HostIOMMUDeviceIOMMUFD *idev; +QLIST_ENTRY (SMMUv3AccelDevice) next; +SMMUv3AccelState *s_accel; }SMMUv3AccelDevice ;#ifdef CONFIG_ARM_SMMUV3_ACCEL hw/arm/smmuv3-internal.h +3
-0@@ -583,6 +583,9 @@ typedef struct CD { ((extract64 ((x)->word[7 ],0 ,16 ) <<32 ) | \ ((x)->word[6] & 0xfffffff0)) +#define SMMU_STE_VALID (1ULL << 0) +#define SMMU_STE_CFG_BYPASS (1ULL << 3) +static inline int oas2bits (int oas_field) {switch (oas_field) {hw/arm/trace-events +4
-0@@ -66,6 +66,10 @@ smmuv3_notify_flag_del(const char *iommu) "DEL SMMUNotifier node for iommu mr=%s smmuv3_inv_notifiers_iova(const char *name, int asid, int vmid, uint64_t iova, uint8_t tg, uint64_t num_pages, int stage) "iommu mr=%s asid=%d vmid=%d iova=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64" stage=%d" smmu_reset_exit(void) "" +#smmuv3-accel.c +smmuv3_accel_set_iommu_device(int devfn, uint32_t devid) "devfn=0x%x (idev devid=0x%x)" +smmuv3_accel_unset_iommu_device(int devfn, uint32_t devid) "devfn=0x%x (idev devid=0x%x)" + # strongarm.c strongarm_uart_update_parameters(const char *label, int speed, char parity, int data_bits, int stop_bits) "%s speed=%d parity=%c data=%d stop=%d" strongarm_ssp_read_underrun(void) "SSP rx underrun"include/hw/arm/smmuv3.h +0
-0
include/hw/arm/smmuv3.h struct SMMUv3State { · line 72
Quoted 7 lines
include/hw/arm/smmuv3.h +1
-0@@ -66,6 +66,7 @@ struct SMMUv3State {/* SMMU has HW accelerator support for nested S1 + s2 */ bool accel; +struct SMMUv3AccelState *s_accel; }; typedef enum {
Looks good to me
Eric
Re: [PATCH v6 12/33] hw/arm/smmuv3-accel: Add set/unset_iommu_device callback
In reply to Shameer KolothumQuoted 322 lines · Shameer Kolothum
From: Nicolin Chen <[email protected]>
Implement the VFIO/PCI callbacks to attach and detach a HostIOMMUDevice to a vSMMUv3 when accel=on,
-
set_iommu_device(): attach a HostIOMMUDevice to a vIOMMU
-unset_iommu_device(): detach and release associated resourcesIn SMMUv3 accel=on mode, the guest SMMUv3 is backed by the host SMMUv3 via IOMMUFD. A vIOMMU object (created via
IOMMU_VIOMMU_ALLOC) provides a per-VM, security-isolated handle to the physical SMMUv3. Without a vIOMMU, the vSMMUv3 cannot relay guest operations to the host hardware nor maintain isolation across VMs or devices. Therefore,set_iommu_device()allocates a vIOMMU object if one does not already exist.There are two main points to consider in this implementation:
1) VFIO core allocates and attaches a S2 HWPT that acts as the nesting parent for nested
HWPTs(IOMMU_DOMAIN_NESTED). This parent HWPT will be shared across multiple vSMMU instances within a VM.2) A device cannot attach directly to a vIOMMU. Instead, it attaches through a proxy nested HWPT (
IOMMU_DOMAIN_NESTED). Based on the STE configuration,there are three types of nested HWPTs: bypass, abort, and translate.
-The bypass and abort proxy HWPTs are pre-allocated. When SMMUv3
operates in global abort or bypass modes, as controlled by the GBPA register, or issues a vSTE for bypass or abort we attach these pre-allocated nested HWPTs.
-The translate HWPT requires a vDEVICE to be allocated first, since
invalidations and events depend on a valid vSID.
-The vDEVICE allocation and attach operations for vSTE based HWPTs
are implemented in subsequent patches.In summary, a device placed behind a vSMMU instance must have a vSID for translate vSTE. The bypass and abort vSTEs are pre-allocated as proxy nested HWPTs and is attached based on GBPA register. The core-managed nesting parent S2 HWPT is used as parent S2 HWPT for all the nested HWPTs and is intended to be shared across vSMMU instances within the same VM.
set_iommu_device():
- Reuse an existing vIOMMU for the same physical SMMU if available. If not, allocate a new one using the nesting parent S2 HWPT.
- Pre-allocate two proxy nested HWPTs (bypass and abort) under the vIOMMU and install one based on GBPA.ABORT value.
- Add the device to the vIOMMU’s device list.
unset_iommu_device():
- Re-attach device to the nesting parent S2 HWPT.
- Remove the device from the vIOMMU’s device list.
- If the list is empty, free the proxy HWPTs (bypass and abort) and release the vIOMMU object.Introduce struct SMMUv3AccelState, representing an accelerated SMMUv3 instance backed by an iommufd vIOMMU object, and storing the bypass and abort proxy HWPT IDs.
Signed-off-by Nicolin Chen <[email protected]>Signed-off-by Shameer Kolothum <[email protected]Reviewed-by Jonathan Cameron <[email protected]>Tested-by Zhangfei Gao <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.c | 154 +++++++++++++++++++++++++++++++++++++++ hw/arm/smmuv3-accel.h | 16 ++++ hw/arm/smmuv3-internal.h | 3 + hw/arm/trace-events | 4 + include/hw/arm/smmuv3.h | 1 + 5 files changed, 178 insertions(+)hw/arm/smmuv3-accel.c +154
-0@@ -8,6 +8,7 @@#include "qemu/osdep.h" #include "qemu/error-report.h" +#include "trace.h" #include "hw/arm/smmuv3.h" #include "hw/iommu.h" @@ -15,6 +16,7 @@#include "hw/pci-host/gpex.h" #include "hw/vfio/pci.h" +#include "smmuv3-internal.h" #include "smmuv3-accel.h" /* @@ -43,6 +45,156 @@ static SMMUv3AccelDevice *smmuv3_accel_get_dev(SMMUState *bs, SMMUPciBus *sbus,return accel_dev; } +static uint32_t smmuv3_accel_gbpa_hwpt (SMMUv3State *s,SMMUv3AccelState *accel) +{ +return FIELD_EX32 (s->gbpa,GBPA ,ABORT ) ? + accel->abort_hwpt_id : accel->bypass_hwpt_id; +} + +static bool +smmuv3_accel_alloc_viommu (SMMUv3State *s,HostIOMMUDeviceIOMMUFD *idev, +Error **errp) +{ +struct iommu_hwpt_arm_smmuv3 bypass_data = { + .ste = {SMMU_STE_CFG_BYPASS |SMMU_STE_VALID ,0x0ULL }, + }; +struct iommu_hwpt_arm_smmuv3 abort_data = { + .ste = {SMMU_STE_VALID ,0x0ULL }, + }; +uint32_t s2_hwpt_id = idev->hwpt_id; +uint32_t viommu_id, hwpt_id; +SMMUv3AccelState *accel; + +if (!iommufd_backend_alloc_viommu (idev->iommufd, idev->devid, +IOMMU_VIOMMU_TYPE_ARM_SMMUV3 , + s2_hwpt_id, &viommu_id, errp)) { +return false; + } + + accel =g_new0 (SMMUv3AccelState,1 ); + accel->viommu.viommu_id = viommu_id; + accel->viommu.s2_hwpt_id = s2_hwpt_id; + accel->viommu.iommufd = idev->iommufd; + +/* +* Pre-allocate HWPTs for S1 bypass and abort cases. These will be attached +* later for guest STEs or GBPAs that require bypass or abort configuration. +*/ +if (!iommufd_backend_alloc_hwpt (idev->iommufd, idev->devid, viommu_id, +0 ,IOMMU_HWPT_DATA_ARM_SMMUV3 , +sizeof (abort_data), &abort_data, + &accel->abort_hwpt_id, errp)) { + goto free_viommu; + } + +if (!iommufd_backend_alloc_hwpt (idev->iommufd, idev->devid, viommu_id, +0 ,IOMMU_HWPT_DATA_ARM_SMMUV3 , +sizeof (bypass_data), &bypass_data, + &accel->bypass_hwpt_id, errp)) { + goto free_abort_hwpt; + } + +/* Attach a HWPT based on SMMUv3 GBPA.ABORT value */ + hwpt_id =smmuv3_accel_gbpa_hwpt (s, accel); +if (!host_iommu_device_iommufd_attach_hwpt (idev, hwpt_id, errp)) { + goto free_bypass_hwpt; + } + s->s_accel = accel; +return true; + +free_bypass_hwpt: +iommufd_backend_free_id (idev->iommufd, accel->bypass_hwpt_id); +free_abort_hwpt: +iommufd_backend_free_id (idev->iommufd, accel->abort_hwpt_id); +free_viommu: +iommufd_backend_free_id (idev->iommufd, accel->viommu.viommu_id); +g_free (accel); +return false; +} + +static bool smmuv3_accel_set_iommu_device (PCIBus *bus,void *opaque,int devfn, +HostIOMMUDevice *hiod,Error **errp) +{ +HostIOMMUDeviceIOMMUFD *idev =HOST_IOMMU_DEVICE_IOMMUFD (hiod); +SMMUState *bs = opaque; +SMMUv3State *s =ARM_SMMUV3 (bs); +SMMUPciBus *sbus =smmu_get_sbus (bs, bus); +SMMUv3AccelDevice *accel_dev =smmuv3_accel_get_dev (bs, sbus, bus, devfn); + +if (!idev) { +return true; + } + +if (accel_dev->idev) { +if (accel_dev->idev != idev) { +error_setg (errp,"Device already has an associated idev 0x%x" , + idev->devid); +return false; + } +return true; + } + +if (s->s_accel) { + goto done; + } + +if (!smmuv3_accel_alloc_viommu (s, idev, errp)) { +error_append_hint (errp,"Unable to alloc vIOMMU: idev devid 0x%x: " , + idev->devid); +return false; + } + +done: + accel_dev->idev = idev; + accel_dev->s_accel = s->s_accel; +QLIST_INSERT_HEAD (&s->s_accel->device_list, accel_dev, next); +trace_smmuv3_accel_set_iommu_device (devfn, idev->devid); +return true; +} + +static void smmuv3_accel_unset_iommu_device (PCIBus *bus,void *opaque, +int devfn) +{ +SMMUState *bs = opaque; +SMMUv3State *s =ARM_SMMUV3 (bs); +SMMUPciBus *sbus =g_hash_table_lookup (bs->smmu_pcibus_by_busptr, bus); +HostIOMMUDeviceIOMMUFD *idev; +SMMUv3AccelDevice *accel_dev; +SMMUv3AccelState *accel; +SMMUDevice *sdev; + +if (!sbus) { +return ; + } + + sdev = sbus->pbdev[devfn]; +if (!sdev) { +return ; + } + + accel_dev =container_of (sdev, SMMUv3AccelDevice, sdev); + idev = accel_dev->idev; + accel = accel_dev->s_accel; +/* Re-attach the default s2 hwpt id */ +if (!host_iommu_device_iommufd_attach_hwpt (idev, idev->hwpt_id,NULL )) { +error_report ("Unable to attach the default HW pagetable: idev devid " +"0x%x" , idev->devid); + } + + accel_dev->idev =NULL ; + accel_dev->s_accel =NULL ; +QLIST_REMOVE (accel_dev, next); +trace_smmuv3_accel_unset_iommu_device (devfn, idev->devid); + +if (QLIST_EMPTY (&accel->device_list)) { +iommufd_backend_free_id (accel->viommu.iommufd, accel->bypass_hwpt_id); +iommufd_backend_free_id (accel->viommu.iommufd, accel->abort_hwpt_id); +iommufd_backend_free_id (accel->viommu.iommufd, accel->viommu.viommu_id); +g_free (accel); + s->s_accel =NULL ; + } +} +/* * Only allow PCIe bridges, pxb-pcie roots, and GPEX roots so vfio-pci * endpoints can sit downstream. Accelerated SMMUv3 requires a vfio-pci @@ -145,6 +297,8 @@ static const PCIIOMMUOps smmuv3_accel_ops = { .supports_address_space = smmuv3_accel_supports_as, .get_address_space = smmuv3_accel_find_add_as, .get_viommu_flags = smmuv3_accel_get_viommu_flags, + .set_iommu_device = smmuv3_accel_set_iommu_device, + .unset_iommu_device = smmuv3_accel_unset_iommu_device, };static void smmuv3_accel_as_init (SMMUv3State *s)hw/arm/smmuv3-accel.h +16
-0@@ -10,10 +10,26 @@#define HW_ARM_SMMUV3_ACCEL_H #include "hw/arm/smmu-common.h" +#include "system/iommufd.h" +#include <linux/iommufd.h> #include CONFIG_DEVICES +/* +* Represents an accelerated SMMU instance backed by an iommufd vIOMMU object. +* Holds bypass and abort proxy HWPT IDs used for device attachment. +*/ +typedef struct SMMUv3AccelState { +IOMMUFDViommu viommu; +uint32_t bypass_hwpt_id; +uint32_t abort_hwpt_id; + QLIST_HEAD(, SMMUv3AccelDevice) device_list; +}SMMUv3AccelState ; +typedef struct SMMUv3AccelDevice {SMMUDevice sdev; +HostIOMMUDeviceIOMMUFD *idev; +QLIST_ENTRY (SMMUv3AccelDevice) next; +SMMUv3AccelState *s_accel; }SMMUv3AccelDevice ;#ifdef CONFIG_ARM_SMMUV3_ACCEL hw/arm/smmuv3-internal.h +3
-0@@ -583,6 +583,9 @@ typedef struct CD { ((extract64 ((x)->word[7 ],0 ,16 ) <<32 ) | \ ((x)->word[6] & 0xfffffff0)) +#define SMMU_STE_VALID (1ULL << 0) +#define SMMU_STE_CFG_BYPASS (1ULL << 3) +static inline int oas2bits (int oas_field) {switch (oas_field) {hw/arm/trace-events +4
-0@@ -66,6 +66,10 @@ smmuv3_notify_flag_del(const char *iommu) "DEL SMMUNotifier node for iommu mr=%s smmuv3_inv_notifiers_iova(const char *name, int asid, int vmid, uint64_t iova, uint8_t tg, uint64_t num_pages, int stage) "iommu mr=%s asid=%d vmid=%d iova=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64" stage=%d" smmu_reset_exit(void) "" +#smmuv3-accel.c +smmuv3_accel_set_iommu_device(int devfn, uint32_t devid) "devfn=0x%x (idev devid=0x%x)" +smmuv3_accel_unset_iommu_device(int devfn, uint32_t devid) "devfn=0x%x (idev devid=0x%x)" + # strongarm.c strongarm_uart_update_parameters(const char *label, int speed, char parity, int data_bits, int stop_bits) "%s speed=%d parity=%c data=%d stop=%d" strongarm_ssp_read_underrun(void) "SSP rx underrun"include/hw/arm/smmuv3.h +0
-0
include/hw/arm/smmuv3.h struct SMMUv3State { · line 69
Quoted 4 lines
include/hw/arm/smmuv3.h +1
-0@@ -66,6 +66,7 @@ struct SMMUv3State {/* SMMU has HW accelerator support for nested S1 + s2 */ bool accel; +struct SMMUv3AccelState *s_accel;
This is a sign that SMMUv3AccelState should a QOM object.
C.
Quoted 3 lines
include/hw/arm/smmuv3.h +0
-0}; typedef enum {
PATCH v6 13/33 hw/arm/smmuv3: propagate smmuv3_cmdq_consume() errors to caller
In reply to Shameer Kolothumsmmuv3_cmdq_consume() is updated to return detailed errors via errp.
Although this is currently a no-op, it prepares the ground for accel SMMUv3 specific command handling where proper error reporting will be useful.
--- hw/arm/smmuv3.c | 67 +++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 30 deletions(-)
hw/arm/smmuv3.c +37 -30
@@ -1279,7 +1279,7 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd, SMMUStage stage) } } -static int smmuv3_cmdq_consume (SMMUv3State *s) +static int smmuv3_cmdq_consume (SMMUv3State *s,Error **errp) {SMMUState *bs =ARM_SMMU (s);SMMUCmdError cmd_error =SMMU_CERROR_NONE ;
@@ -1547,42 +1547,44 @@ static MemTxResult smmu_writell(SMMUv3State *s, hwaddr offset,static MemTxResult smmu_writel (SMMUv3State *s,hwaddr offset,uint64_t data,MemTxAttrs attrs) { +Error *local_err =NULL ; +switch (offset) {case A_CR0 : s->cr[0 ] = data; s->cr0ack = data & ~SMMU_CR0_RESERVED ;/* in case the command queue has been enabled */ -smmuv3_cmdq_consume (s); -return MEMTX_OK ; +smmuv3_cmdq_consume (s, &local_err); +break ;case A_CR1 : s->cr[1 ] = data; -return MEMTX_OK ; +break ;case A_CR2 : s->cr[2 ] = data; -return MEMTX_OK ; +break ;case A_IRQ_CTRL : s->irq_ctrl = data; -return MEMTX_OK ; +break ;case A_GERRORN :smmuv3_write_gerrorn (s, data);/* * By acknowledging the CMDQ_ERR, SW may notify cmds can * be processed again */ -smmuv3_cmdq_consume (s); -return MEMTX_OK ; +smmuv3_cmdq_consume (s, &local_err); +break ;case A_GERROR_IRQ_CFG0 :/* 64b */ s->gerror_irq_cfg0 =deposit64 (s->gerror_irq_cfg0,0 ,32 , data); -return MEMTX_OK ; +break ;case A_GERROR_IRQ_CFG0 +4 : s->gerror_irq_cfg0 =deposit64 (s->gerror_irq_cfg0,32 ,32 , data); -return MEMTX_OK ; +break ;case A_GERROR_IRQ_CFG1 : s->gerror_irq_cfg1 = data; -return MEMTX_OK ; +break ;case A_GERROR_IRQ_CFG2 : s->gerror_irq_cfg2 = data; -return MEMTX_OK ; +break ;case A_GBPA :/* * If UPDATE is not set, the write is ignored. This is the only
@@ -1592,71 +1594,76 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwaddr offset,/* Ignore update bit as write is synchronous. */ s->gbpa = data & ~R_GBPA_UPDATE_MASK ; } -return MEMTX_OK ; +break ;case A_STRTAB_BASE :/* 64b */ s->strtab_base =deposit64 (s->strtab_base,0 ,32 , data); -return MEMTX_OK ; +break ;case A_STRTAB_BASE +4 : s->strtab_base =deposit64 (s->strtab_base,32 ,32 , data); -return MEMTX_OK ; +break ;case A_STRTAB_BASE_CFG : s->strtab_base_cfg = data;if (FIELD_EX32 (data,STRTAB_BASE_CFG ,FMT ) ==1 ) { s->sid_split =FIELD_EX32 (data,STRTAB_BASE_CFG ,SPLIT ); s->features |=SMMU_FEATURE_2LVL_STE ; } -return MEMTX_OK ; +break ;case A_CMDQ_BASE :/* 64b */ s->cmdq.base =deposit64 (s->cmdq.base,0 ,32 , data); s->cmdq.log2size =extract64 (s->cmdq.base,0 ,5 );if (s->cmdq.log2size >SMMU_CMDQS ) { s->cmdq.log2size =SMMU_CMDQS ; } -return MEMTX_OK ; +break ;case A_CMDQ_BASE +4 :/* 64b */ s->cmdq.base =deposit64 (s->cmdq.base,32 ,32 , data); -return MEMTX_OK ; +break ;case A_CMDQ_PROD : s->cmdq.prod = data; -smmuv3_cmdq_consume (s); -return MEMTX_OK ; +smmuv3_cmdq_consume (s, &local_err); +break ;case A_CMDQ_CONS : s->cmdq.cons = data; -return MEMTX_OK ; +break ;case A_EVENTQ_BASE :/* 64b */ s->eventq.base =deposit64 (s->eventq.base,0 ,32 , data); s->eventq.log2size =extract64 (s->eventq.base,0 ,5 );if (s->eventq.log2size >SMMU_EVENTQS ) { s->eventq.log2size =SMMU_EVENTQS ; } -return MEMTX_OK ; +break ;case A_EVENTQ_BASE +4 : s->eventq.base =deposit64 (s->eventq.base,32 ,32 , data); -return MEMTX_OK ; +break ;case A_EVENTQ_PROD : s->eventq.prod = data; -return MEMTX_OK ; +break ;case A_EVENTQ_CONS : s->eventq.cons = data; -return MEMTX_OK ; +break ;case A_EVENTQ_IRQ_CFG0 :/* 64b */ s->eventq_irq_cfg0 =deposit64 (s->eventq_irq_cfg0,0 ,32 , data); -return MEMTX_OK ; +break ;case A_EVENTQ_IRQ_CFG0 +4 : s->eventq_irq_cfg0 =deposit64 (s->eventq_irq_cfg0,32 ,32 , data); -return MEMTX_OK ; +break ;case A_EVENTQ_IRQ_CFG1 : s->eventq_irq_cfg1 = data; -return MEMTX_OK ; +break ;case A_EVENTQ_IRQ_CFG2 : s->eventq_irq_cfg2 = data; -return MEMTX_OK ; +break ;default :qemu_log_mask (LOG_UNIMP ,"%s Unexpected 32-bit access to 0x%" PRIx64" (WI)\n" , __func__, offset); -return MEMTX_OK ; +break ; } + +if (local_err) { +error_report_err (local_err); + } +return MEMTX_OK ; } static MemTxResult smmu_write_mmio(void *opaque, hwaddr offset, uint64_t data,
Signature · 1 line
2.43.0
Re: [PATCH v6 13/33] hw/arm/smmuv3: propagate smmuv3_cmdq_consume() errors to caller
Quoted 7 lines · Shameer Kolothum
smmuv3_cmdq_consume()is updated to return detailed errors via errp.Although this is currently a no-op, it prepares the ground for accel SMMUv3 specific command handling where proper error reporting will be useful.
Signed-off-by Shameer Kolothum <[email protected]>
Re: [PATCH v6 13/33] hw/arm/smmuv3: propagate smmuv3_cmdq_consume() errors to caller
In reply to Shameer KolothumQuoted 7 lines · Shameer Kolothum
smmuv3_cmdq_consume()is updated to return detailed errors via errp.Although this is currently a no-op, it prepares the ground for accel SMMUv3 specific command handling where proper error reporting will be useful.
Signed-off-by Shameer Kolothum <[email protected]>
Eric
Quoted 168 lines
--- hw/arm/smmuv3.c | 67 +++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 30 deletions(-)hw/arm/smmuv3.c +37
-30@@ -1279,7 +1279,7 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd, SMMUStage stage) } } -static int smmuv3_cmdq_consume (SMMUv3State *s) +static int smmuv3_cmdq_consume (SMMUv3State *s,Error **errp) {SMMUState *bs =ARM_SMMU (s);SMMUCmdError cmd_error =SMMU_CERROR_NONE ;@@ -1547,42 +1547,44 @@ static MemTxResult smmu_writell(SMMUv3State *s, hwaddr offset,static MemTxResult smmu_writel (SMMUv3State *s,hwaddr offset,uint64_t data,MemTxAttrs attrs) { +Error *local_err =NULL ; +switch (offset) {case A_CR0 : s->cr[0 ] = data; s->cr0ack = data & ~SMMU_CR0_RESERVED ;/* in case the command queue has been enabled */ -smmuv3_cmdq_consume (s); -return MEMTX_OK ; +smmuv3_cmdq_consume (s, &local_err); +break ;case A_CR1 : s->cr[1 ] = data; -return MEMTX_OK ; +break ;case A_CR2 : s->cr[2 ] = data; -return MEMTX_OK ; +break ;case A_IRQ_CTRL : s->irq_ctrl = data; -return MEMTX_OK ; +break ;case A_GERRORN :smmuv3_write_gerrorn (s, data);/* * By acknowledging the CMDQ_ERR, SW may notify cmds can * be processed again */ -smmuv3_cmdq_consume (s); -return MEMTX_OK ; +smmuv3_cmdq_consume (s, &local_err); +break ;case A_GERROR_IRQ_CFG0 :/* 64b */ s->gerror_irq_cfg0 =deposit64 (s->gerror_irq_cfg0,0 ,32 , data); -return MEMTX_OK ; +break ;case A_GERROR_IRQ_CFG0 +4 : s->gerror_irq_cfg0 =deposit64 (s->gerror_irq_cfg0,32 ,32 , data); -return MEMTX_OK ; +break ;case A_GERROR_IRQ_CFG1 : s->gerror_irq_cfg1 = data; -return MEMTX_OK ; +break ;case A_GERROR_IRQ_CFG2 : s->gerror_irq_cfg2 = data; -return MEMTX_OK ; +break ;case A_GBPA :/* * If UPDATE is not set, the write is ignored. This is the only @@ -1592,71 +1594,76 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwaddr offset,/* Ignore update bit as write is synchronous. */ s->gbpa = data & ~R_GBPA_UPDATE_MASK ; } -return MEMTX_OK ; +break ;case A_STRTAB_BASE :/* 64b */ s->strtab_base =deposit64 (s->strtab_base,0 ,32 , data); -return MEMTX_OK ; +break ;case A_STRTAB_BASE +4 : s->strtab_base =deposit64 (s->strtab_base,32 ,32 , data); -return MEMTX_OK ; +break ;case A_STRTAB_BASE_CFG : s->strtab_base_cfg = data;if (FIELD_EX32 (data,STRTAB_BASE_CFG ,FMT ) ==1 ) { s->sid_split =FIELD_EX32 (data,STRTAB_BASE_CFG ,SPLIT ); s->features |=SMMU_FEATURE_2LVL_STE ; } -return MEMTX_OK ; +break ;case A_CMDQ_BASE :/* 64b */ s->cmdq.base =deposit64 (s->cmdq.base,0 ,32 , data); s->cmdq.log2size =extract64 (s->cmdq.base,0 ,5 );if (s->cmdq.log2size >SMMU_CMDQS ) { s->cmdq.log2size =SMMU_CMDQS ; } -return MEMTX_OK ; +break ;case A_CMDQ_BASE +4 :/* 64b */ s->cmdq.base =deposit64 (s->cmdq.base,32 ,32 , data); -return MEMTX_OK ; +break ;case A_CMDQ_PROD : s->cmdq.prod = data; -smmuv3_cmdq_consume (s); -return MEMTX_OK ; +smmuv3_cmdq_consume (s, &local_err); +break ;case A_CMDQ_CONS : s->cmdq.cons = data; -return MEMTX_OK ; +break ;case A_EVENTQ_BASE :/* 64b */ s->eventq.base =deposit64 (s->eventq.base,0 ,32 , data); s->eventq.log2size =extract64 (s->eventq.base,0 ,5 );if (s->eventq.log2size >SMMU_EVENTQS ) { s->eventq.log2size =SMMU_EVENTQS ; } -return MEMTX_OK ; +break ;case A_EVENTQ_BASE +4 : s->eventq.base =deposit64 (s->eventq.base,32 ,32 , data); -return MEMTX_OK ; +break ;case A_EVENTQ_PROD : s->eventq.prod = data; -return MEMTX_OK ; +break ;case A_EVENTQ_CONS : s->eventq.cons = data; -return MEMTX_OK ; +break ;case A_EVENTQ_IRQ_CFG0 :/* 64b */ s->eventq_irq_cfg0 =deposit64 (s->eventq_irq_cfg0,0 ,32 , data); -return MEMTX_OK ; +break ;case A_EVENTQ_IRQ_CFG0 +4 : s->eventq_irq_cfg0 =deposit64 (s->eventq_irq_cfg0,32 ,32 , data); -return MEMTX_OK ; +break ;case A_EVENTQ_IRQ_CFG1 : s->eventq_irq_cfg1 = data; -return MEMTX_OK ; +break ;case A_EVENTQ_IRQ_CFG2 : s->eventq_irq_cfg2 = data; -return MEMTX_OK ; +break ;default :qemu_log_mask (LOG_UNIMP ,"%s Unexpected 32-bit access to 0x%" PRIx64" (WI)\n" , __func__, offset); -return MEMTX_OK ; +break ; } + +if (local_err) { +error_report_err (local_err); + } +return MEMTX_OK ; } static MemTxResult smmu_write_mmio(void *opaque, hwaddr offset, uint64_t data,
PATCH v6 14/33 hw/arm/smmuv3-accel: Add nested vSTE install/uninstall support
In reply to Shameer KolothumFrom: Nicolin Chen <[email protected]>
A device placed behind a vSMMU instance must have corresponding vSTEs (bypass, abort, or translate) installed. The bypass and abort proxy nested HWPTs are pre-allocated.
For translate HWPT, a vDEVICE object is allocated and associated with the vIOMMU for each guest device. This allows the host kernel to establish a virtual SID to physical SID mapping, which is required for handling invalidations and event reporting.
The translate HWPT is allocated based on the guest STE configuration and attached to the device when the guest issues SMMU_CMD_CFGI_STE or SMMU_CMD_CFGI_STE_RANGE, provided the STE enables S1 translation.
If the guest STE is invalid or S1 translation is disabled, the device is attached to one of the pre-allocated ABORT or BYPASS HWPTs instead.
While at it, export smmu_find_ste() for use here.
--- hw/arm/smmuv3-accel.c | 197 +++++++++++++++++++++++++++++++++++++++ hw/arm/smmuv3-accel.h | 22 +++++ hw/arm/smmuv3-internal.h | 20 ++++ hw/arm/smmuv3.c | 11 ++- hw/arm/trace-events | 2 + 5 files changed, 250 insertions(+), 2 deletions(-)
hw/arm/smmuv3-accel.c +197 -0
@@ -51,6 +51,188 @@ static uint32_t smmuv3_accel_gbpa_hwpt(SMMUv3State *s, SMMUv3AccelState *accel) accel->abort_hwpt_id : accel->bypass_hwpt_id; } +static bool +smmuv3_accel_alloc_vdev (SMMUv3AccelDevice *accel_dev,int sid,Error **errp) +{ +SMMUv3AccelState *accel = accel_dev->s_accel; +HostIOMMUDeviceIOMMUFD *idev = accel_dev->idev; +IOMMUFDVdev *vdev = accel_dev->vdev; +uint32_t vdevice_id; + +if (!idev || vdev) { +return true; + } + +if (!iommufd_backend_alloc_vdev (idev->iommufd, idev->devid, + accel->viommu.viommu_id, sid, + &vdevice_id, errp)) { +return false; + } + + vdev =g_new (IOMMUFDVdev,1 ); + vdev->vdevice_id = vdevice_id; + vdev->virt_id = sid; + accel_dev->vdev = vdev; +return true; +} + +static SMMUS1Hwpt * +smmuv3_accel_dev_alloc_translate (SMMUv3AccelDevice *accel_dev,STE *ste, +Error **errp) +{ +uint64_t ste_0 = (uint64_t )ste->word[0 ] | (uint64_t )ste->word[1 ] <<32 ; +uint64_t ste_1 = (uint64_t )ste->word[2 ] | (uint64_t )ste->word[3 ] <<32 ; +HostIOMMUDeviceIOMMUFD *idev = accel_dev->idev; +SMMUv3AccelState *accel = accel_dev->s_accel; +struct iommu_hwpt_arm_smmuv3 nested_data = { + .ste = { +cpu_to_le64 (ste_0 &STE0_MASK ), +cpu_to_le64 (ste_1 &STE1_MASK ), + }, + }; +uint32_t hwpt_id =0 , flags =0 ; +SMMUS1Hwpt *s1_hwpt; + +if (!iommufd_backend_alloc_hwpt (idev->iommufd, idev->devid, + accel->viommu.viommu_id, flags, +IOMMU_HWPT_DATA_ARM_SMMUV3 , +sizeof (nested_data), &nested_data, + &hwpt_id, errp)) { +return NULL ; + } + + s1_hwpt =g_new0 (SMMUS1Hwpt,1 ); + s1_hwpt->hwpt_id = hwpt_id; +trace_smmuv3_accel_translate_ste (accel_dev->vdev->virt_id, hwpt_id, + nested_data.ste[1 ], nested_data.ste[0 ]); +return s1_hwpt; +} + +bool smmuv3_accel_install_ste (SMMUv3State *s,SMMUDevice *sdev,int sid, +Error **errp) +{ +SMMUEventInfo event = {.type =SMMU_EVT_NONE , .sid = sid, + .inval_ste_allowed = true}; +SMMUv3AccelState *accel = s->s_accel; +SMMUv3AccelDevice *accel_dev; +HostIOMMUDeviceIOMMUFD *idev; +uint32_t config, hwpt_id =0 ; +SMMUS1Hwpt *s1_hwpt =NULL ; +const char *type; +STE ste; + +if (!accel) { +return true; + } + + accel_dev =container_of (sdev, SMMUv3AccelDevice, sdev); +if (!accel_dev->s_accel) { +return true; + } + + idev = accel_dev->idev; +if (!smmuv3_accel_alloc_vdev (accel_dev, sid, errp)) { +return false; + } + +if (smmu_find_ste (sdev->smmu, sid, &ste, &event)) { +/* No STE found, nothing to install */ +return true; + } + +/* +* Install the STE based on SMMU enabled/config: +* - attach a pre-allocated HWPT for abort/bypass +* - or a new HWPT for translate STE +* +* Note: The vdev remains associated with accel_dev even if HWPT +* attach/alloc fails, since the Guest-Host SID mapping stays +* valid as long as the device is behind the accelerated SMMUv3. +*/ +if (!smmu_enabled (s)) { + hwpt_id =smmuv3_accel_gbpa_hwpt (s, accel); + }else { + config =STE_CONFIG (&ste); + +if (!STE_VALID (&ste) ||STE_CFG_ABORT (config)) { + hwpt_id = accel->abort_hwpt_id; + }else if (STE_CFG_BYPASS (config)) { + hwpt_id = accel->bypass_hwpt_id; + }else if (STE_CFG_S1_TRANSLATE (config)) { + s1_hwpt =smmuv3_accel_dev_alloc_translate (accel_dev, &ste, errp); +if (!s1_hwpt) { +return false; + } + hwpt_id = s1_hwpt->hwpt_id; + } + } + +if (!hwpt_id) { +error_setg (errp,"Invalid STE config for sid 0x%x" , +smmu_get_sid (&accel_dev->sdev)); +return false; + } + +if (!host_iommu_device_iommufd_attach_hwpt (idev, hwpt_id, errp)) { +if (s1_hwpt) { +iommufd_backend_free_id (idev->iommufd, s1_hwpt->hwpt_id); +g_free (s1_hwpt); + } +return false; + } + +/* Free the previous s1_hwpt */ +if (accel_dev->s1_hwpt) { +iommufd_backend_free_id (idev->iommufd, accel_dev->s1_hwpt->hwpt_id); +g_free (accel_dev->s1_hwpt); + } + + accel_dev->s1_hwpt = s1_hwpt; +if (hwpt_id == accel->abort_hwpt_id) { + type ="abort" ; + }else if (hwpt_id == accel->bypass_hwpt_id) { + type ="bypass" ; + }else { + type ="translate" ; + } + +trace_smmuv3_accel_install_ste (sid, type, hwpt_id); +return true; +} + +bool smmuv3_accel_install_ste_range (SMMUv3State *s,SMMUSIDRange *range, +Error **errp) +{ +SMMUv3AccelState *accel = s->s_accel; +SMMUv3AccelDevice *accel_dev; +Error *local_err =NULL ; +bool all_ok = true; + +if (!accel) { +return true; + } + + QLIST_FOREACH(accel_dev, &accel->device_list, next) { +uint32_t sid =smmu_get_sid (&accel_dev->sdev); + +if (sid >= range->start && sid <= range->end) { +if (!smmuv3_accel_install_ste (s, &accel_dev->sdev, + sid, &local_err)) { +error_append_hint (&local_err,"Device 0x%x: Failed to install " +"STE\n" , sid); +error_report_err (local_err); + local_err =NULL ; + all_ok = false; + } + } + } + +if (!all_ok) { +error_setg (errp,"Failed to install all STEs properly" ); + } +return all_ok; +} +static bool smmuv3_accel_alloc_viommu (SMMUv3State *s,HostIOMMUDeviceIOMMUFD *idev,Error **errp)
@@ -161,6 +343,7 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bus, void *opaque,HostIOMMUDeviceIOMMUFD *idev;SMMUv3AccelDevice *accel_dev;SMMUv3AccelState *accel; +IOMMUFDVdev *vdev;SMMUDevice *sdev;if (!sbus) {
@@ -181,6 +364,20 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bus, void *opaque, "0x%x", idev->devid); } +if (accel_dev->s1_hwpt) { +iommufd_backend_free_id (accel_dev->idev->iommufd, + accel_dev->s1_hwpt->hwpt_id); +g_free (accel_dev->s1_hwpt); + accel_dev->s1_hwpt =NULL ; + } + + vdev = accel_dev->vdev; +if (vdev) { +iommufd_backend_free_id (accel->viommu.iommufd, vdev->vdevice_id); +g_free (vdev); + accel_dev->vdev =NULL ; + } + accel_dev->idev =NULL ; accel_dev->s_accel =NULL ;QLIST_REMOVE (accel_dev, next);
hw/arm/smmuv3-accel.h +22 -0
@@ -25,19 +25,41 @@ typedef struct SMMUv3AccelState { QLIST_HEAD(, SMMUv3AccelDevice) device_list; } SMMUv3AccelState; +typedef struct SMMUS1Hwpt { +uint32_t hwpt_id; +}SMMUS1Hwpt ; +typedef struct SMMUv3AccelDevice {SMMUDevice sdev;HostIOMMUDeviceIOMMUFD *idev; +SMMUS1Hwpt *s1_hwpt; +IOMMUFDVdev *vdev;QLIST_ENTRY (SMMUv3AccelDevice) next;SMMUv3AccelState *s_accel; }SMMUv3AccelDevice ;#ifdef CONFIG_ARM_SMMUV3_ACCEL void smmuv3_accel_init (SMMUv3State *s); +bool smmuv3_accel_install_ste (SMMUv3State *s,SMMUDevice *sdev,int sid, +Error **errp); +bool smmuv3_accel_install_ste_range (SMMUv3State *s,SMMUSIDRange *range, +Error **errp);#else static inline void smmuv3_accel_init (SMMUv3State *s) { } +static inline bool +smmuv3_accel_install_ste (SMMUv3State *s,SMMUDevice *sdev,int sid, +Error **errp) +{ +return true; +} +static inline bool +smmuv3_accel_install_ste_range (SMMUv3State *s,SMMUSIDRange *range, +Error **errp) +{ +return true; +}#endif #endif /* HW_ARM_SMMUV3_ACCEL_H */
hw/arm/smmuv3-internal.h +20 -0
@@ -547,6 +547,8 @@ typedef struct CD {uint32_t word[16 ]; }CD ; +int smmu_find_ste (SMMUv3State *s,uint32_t sid,STE *ste,SMMUEventInfo *event); +/* STE fields */ #define STE_VALID (x) extract32((x)->word[0], 0, 1)
@@ -556,6 +558,7 @@ typedef struct CD {#define STE_CFG_S2_ENABLED (config) (config & 0x2)#define STE_CFG_ABORT (config) (!(config & 0x4))#define STE_CFG_BYPASS (config) (config == 0x4) +#define STE_CFG_S1_TRANSLATE (config) (config == 0x5)#define STE_S1FMT (x) extract32((x)->word[0], 4 , 2)#define STE_S1CDMAX (x) extract32((x)->word[1], 27, 5)
@@ -586,6 +589,23 @@ typedef struct CD {#define SMMU_STE_VALID (1ULL << 0)#define SMMU_STE_CFG_BYPASS (1ULL << 3) +#define STE0_V MAKE_64BIT_MASK(0, 1) +#define STE0_CONFIG MAKE_64BIT_MASK(1, 3) +#define STE0_S1FMT MAKE_64BIT_MASK(4, 2) +#define STE0_CTXPTR MAKE_64BIT_MASK(6, 50) +#define STE0_S1CDMAX MAKE_64BIT_MASK(59, 5) +#define STE0_MASK (STE0_S1CDMAX | STE0_CTXPTR | STE0_S1FMT | STE0_CONFIG | \ + STE0_V) + +#define STE1_S1DSS MAKE_64BIT_MASK(0, 2) +#define STE1_S1CIR MAKE_64BIT_MASK(2, 2) +#define STE1_S1COR MAKE_64BIT_MASK(4, 2) +#define STE1_S1CSH MAKE_64BIT_MASK(6, 2) +#define STE1_S1STALLD MAKE_64BIT_MASK(27, 1) +#define STE1_EATS MAKE_64BIT_MASK(28, 2) +#define STE1_MASK (STE1_EATS | STE1_S1STALLD | STE1_S1CSH | STE1_S1COR | \ + STE1_S1CIR | STE1_S1DSS) +static inline int oas2bits (int oas_field) {switch (oas_field) {
hw/arm/smmuv3.c +9 -2
@@ -630,8 +630,7 @@ bad_ste:* Supports linear and 2-level stream table * Return 0 on success, -EINVAL otherwise */ -static int smmu_find_ste (SMMUv3State *s,uint32_t sid,STE *ste, -SMMUEventInfo *event) +int smmu_find_ste (SMMUv3State *s,uint32_t sid,STE *ste,SMMUEventInfo *event) {dma_addr_t addr, strtab_base;uint32_t log2size;
@@ -1341,6 +1340,10 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp) }trace_smmuv3_cmdq_cfgi_ste (sid); +if (!smmuv3_accel_install_ste (s, sdev, sid, errp)) { + cmd_error =SMMU_CERROR_ILL ; +break ; + }smmuv3_flush_config (sdev);break ;
@@ -1361,6 +1364,10 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp) sid_range.end = sid_range.start + mask;trace_smmuv3_cmdq_cfgi_ste_range (sid_range.start, sid_range.end); +if (!smmuv3_accel_install_ste_range (s, &sid_range, errp)) { + cmd_error =SMMU_CERROR_ILL ; +break ; + }smmu_configs_inv_sid_range (bs, sid_range);break ; }
hw/arm/trace-events +2 -0
@@ -69,6 +69,8 @@ smmu_reset_exit(void) "" #smmuv3-accel.c smmuv3_accel_set_iommu_device(int devfn, uint32_t devid) "devfn=0x%x (idev devid=0x%x)" smmuv3_accel_unset_iommu_device(int devfn, uint32_t devid) "devfn=0x%x (idev devid=0x%x)" +smmuv3_accel_translate_ste(uint32_t vsid, uint32_t hwpt_id, uint64_t ste_1, uint64_t ste_0) "vSID=0x%x hwpt_id=0x%x ste=%"PRIx64":%"PRIx64 +smmuv3_accel_install_ste(uint32_t vsid, const char * type, uint32_t hwpt_id) "vSID=0x%x ste type=%s hwpt_id=0x%x" # strongarm.c strongarm_uart_update_parameters(const char *label, int speed, char parity, int data_bits, int stop_bits) "%s speed=%d parity=%c data=%d stop=%d"
Signature · 1 line
2.43.0
Re: [PATCH v6 14/33] hw/arm/smmuv3-accel: Add nested vSTE install/uninstall support
Quoted 386 lines · Shameer Kolothum
From: Nicolin Chen <[email protected]>
A device placed behind a vSMMU instance must have corresponding vSTEs (bypass, abort, or translate) installed. The bypass and abort proxy nested HWPTs are pre-allocated.
For translate HWPT, a vDEVICE object is allocated and associated with the vIOMMU for each guest device. This allows the host kernel to establish a virtual SID to physical SID mapping, which is required for handling invalidations and event reporting.
The translate HWPT is allocated based on the guest STE configuration and attached to the device when the guest issues
SMMU_CMD_CFGI_STEorSMMU_CMD_CFGI_STE_RANGE, provided the STE enables S1 translation.If the guest STE is invalid or S1 translation is disabled, the device is attached to one of the pre-allocated ABORT or BYPASS HWPTs instead.
While at it, export
smmu_find_ste()for use here.Signed-off-by Nicolin Chen <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.c | 197 +++++++++++++++++++++++++++++++++++++++ hw/arm/smmuv3-accel.h | 22 +++++ hw/arm/smmuv3-internal.h | 20 ++++ hw/arm/smmuv3.c | 11 ++- hw/arm/trace-events | 2 + 5 files changed, 250 insertions(+), 2 deletions(-)hw/arm/smmuv3-accel.c +197
-0@@ -51,6 +51,188 @@ static uint32_t smmuv3_accel_gbpa_hwpt(SMMUv3State *s, SMMUv3AccelState *accel) accel->abort_hwpt_id : accel->bypass_hwpt_id; } +static bool +smmuv3_accel_alloc_vdev (SMMUv3AccelDevice *accel_dev,int sid,Error **errp) +{ +SMMUv3AccelState *accel = accel_dev->s_accel; +HostIOMMUDeviceIOMMUFD *idev = accel_dev->idev; +IOMMUFDVdev *vdev = accel_dev->vdev; +uint32_t vdevice_id; + +if (!idev || vdev) { +return true; + } + +if (!iommufd_backend_alloc_vdev (idev->iommufd, idev->devid, + accel->viommu.viommu_id, sid, + &vdevice_id, errp)) { +return false; + } + + vdev =g_new (IOMMUFDVdev,1 ); + vdev->vdevice_id = vdevice_id; + vdev->virt_id = sid; + accel_dev->vdev = vdev; +return true; +} + +static SMMUS1Hwpt * +smmuv3_accel_dev_alloc_translate (SMMUv3AccelDevice *accel_dev,STE *ste, +Error **errp) +{ +uint64_t ste_0 = (uint64_t )ste->word[0 ] | (uint64_t )ste->word[1 ] <<32 ; +uint64_t ste_1 = (uint64_t )ste->word[2 ] | (uint64_t )ste->word[3 ] <<32 ; +HostIOMMUDeviceIOMMUFD *idev = accel_dev->idev; +SMMUv3AccelState *accel = accel_dev->s_accel; +struct iommu_hwpt_arm_smmuv3 nested_data = { + .ste = { +cpu_to_le64 (ste_0 &STE0_MASK ), +cpu_to_le64 (ste_1 &STE1_MASK ), + }, + }; +uint32_t hwpt_id =0 , flags =0 ; +SMMUS1Hwpt *s1_hwpt; + +if (!iommufd_backend_alloc_hwpt (idev->iommufd, idev->devid, + accel->viommu.viommu_id, flags, +IOMMU_HWPT_DATA_ARM_SMMUV3 , +sizeof (nested_data), &nested_data, + &hwpt_id, errp)) { +return NULL ; + } + + s1_hwpt =g_new0 (SMMUS1Hwpt,1 ); + s1_hwpt->hwpt_id = hwpt_id; +trace_smmuv3_accel_translate_ste (accel_dev->vdev->virt_id, hwpt_id, + nested_data.ste[1 ], nested_data.ste[0 ]); +return s1_hwpt; +} + +bool smmuv3_accel_install_ste (SMMUv3State *s,SMMUDevice *sdev,int sid, +Error **errp) +{ +SMMUEventInfo event = {.type =SMMU_EVT_NONE , .sid = sid, + .inval_ste_allowed = true}; +SMMUv3AccelState *accel = s->s_accel; +SMMUv3AccelDevice *accel_dev; +HostIOMMUDeviceIOMMUFD *idev; +uint32_t config, hwpt_id =0 ; +SMMUS1Hwpt *s1_hwpt =NULL ; +const char *type; +STE ste; + +if (!accel) { +return true; + } + + accel_dev =container_of (sdev, SMMUv3AccelDevice, sdev); +if (!accel_dev->s_accel) { +return true; + } + + idev = accel_dev->idev; +if (!smmuv3_accel_alloc_vdev (accel_dev, sid, errp)) { +return false; + } + +if (smmu_find_ste (sdev->smmu, sid, &ste, &event)) { +/* No STE found, nothing to install */ +return true; + } + +/* +* Install the STE based on SMMU enabled/config: +* - attach a pre-allocated HWPT for abort/bypass +* - or a new HWPT for translate STE +* +* Note: The vdev remains associated with accel_dev even if HWPT +* attach/alloc fails, since the Guest-Host SID mapping stays +* valid as long as the device is behind the accelerated SMMUv3. +*/ +if (!smmu_enabled (s)) { + hwpt_id =smmuv3_accel_gbpa_hwpt (s, accel); + }else { + config =STE_CONFIG (&ste); + +if (!STE_VALID (&ste) ||STE_CFG_ABORT (config)) { + hwpt_id = accel->abort_hwpt_id; + }else if (STE_CFG_BYPASS (config)) { + hwpt_id = accel->bypass_hwpt_id; + }else if (STE_CFG_S1_TRANSLATE (config)) { + s1_hwpt =smmuv3_accel_dev_alloc_translate (accel_dev, &ste, errp); +if (!s1_hwpt) { +return false; + } + hwpt_id = s1_hwpt->hwpt_id; + } + } + +if (!hwpt_id) { +error_setg (errp,"Invalid STE config for sid 0x%x" , +smmu_get_sid (&accel_dev->sdev)); +return false; + } + +if (!host_iommu_device_iommufd_attach_hwpt (idev, hwpt_id, errp)) { +if (s1_hwpt) { +iommufd_backend_free_id (idev->iommufd, s1_hwpt->hwpt_id); +g_free (s1_hwpt); + } +return false; + } + +/* Free the previous s1_hwpt */ +if (accel_dev->s1_hwpt) { +iommufd_backend_free_id (idev->iommufd, accel_dev->s1_hwpt->hwpt_id); +g_free (accel_dev->s1_hwpt); + } + + accel_dev->s1_hwpt = s1_hwpt; +if (hwpt_id == accel->abort_hwpt_id) { + type ="abort" ; + }else if (hwpt_id == accel->bypass_hwpt_id) { + type ="bypass" ; + }else { + type ="translate" ; + } + +trace_smmuv3_accel_install_ste (sid, type, hwpt_id); +return true; +} + +bool smmuv3_accel_install_ste_range (SMMUv3State *s,SMMUSIDRange *range, +Error **errp) +{ +SMMUv3AccelState *accel = s->s_accel; +SMMUv3AccelDevice *accel_dev; +Error *local_err =NULL ; +bool all_ok = true; + +if (!accel) { +return true; + } + + QLIST_FOREACH(accel_dev, &accel->device_list, next) { +uint32_t sid =smmu_get_sid (&accel_dev->sdev); + +if (sid >= range->start && sid <= range->end) { +if (!smmuv3_accel_install_ste (s, &accel_dev->sdev, + sid, &local_err)) { +error_append_hint (&local_err,"Device 0x%x: Failed to install " +"STE\n" , sid); +error_report_err (local_err); + local_err =NULL ; + all_ok = false; + } + } + } + +if (!all_ok) { +error_setg (errp,"Failed to install all STEs properly" ); + } +return all_ok; +} +static bool smmuv3_accel_alloc_viommu (SMMUv3State *s,HostIOMMUDeviceIOMMUFD *idev,Error **errp)@@ -161,6 +343,7 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bus, void *opaque,HostIOMMUDeviceIOMMUFD *idev;SMMUv3AccelDevice *accel_dev;SMMUv3AccelState *accel; +IOMMUFDVdev *vdev;SMMUDevice *sdev;if (!sbus) {@@ -181,6 +364,20 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bus, void *opaque, "0x%x", idev->devid); } +if (accel_dev->s1_hwpt) { +iommufd_backend_free_id (accel_dev->idev->iommufd, + accel_dev->s1_hwpt->hwpt_id); +g_free (accel_dev->s1_hwpt); + accel_dev->s1_hwpt =NULL ; + } + + vdev = accel_dev->vdev; +if (vdev) { +iommufd_backend_free_id (accel->viommu.iommufd, vdev->vdevice_id); +g_free (vdev); + accel_dev->vdev =NULL ; + } + accel_dev->idev =NULL ; accel_dev->s_accel =NULL ;QLIST_REMOVE (accel_dev, next);hw/arm/smmuv3-accel.h +22
-0@@ -25,19 +25,41 @@ typedef struct SMMUv3AccelState { QLIST_HEAD(, SMMUv3AccelDevice) device_list; } SMMUv3AccelState; +typedef struct SMMUS1Hwpt { +uint32_t hwpt_id; +}SMMUS1Hwpt ; +typedef struct SMMUv3AccelDevice {SMMUDevice sdev;HostIOMMUDeviceIOMMUFD *idev; +SMMUS1Hwpt *s1_hwpt; +IOMMUFDVdev *vdev;QLIST_ENTRY (SMMUv3AccelDevice) next;SMMUv3AccelState *s_accel; }SMMUv3AccelDevice ;#ifdef CONFIG_ARM_SMMUV3_ACCEL void smmuv3_accel_init (SMMUv3State *s); +bool smmuv3_accel_install_ste (SMMUv3State *s,SMMUDevice *sdev,int sid, +Error **errp); +bool smmuv3_accel_install_ste_range (SMMUv3State *s,SMMUSIDRange *range, +Error **errp);#else static inline void smmuv3_accel_init (SMMUv3State *s) { } +static inline bool +smmuv3_accel_install_ste (SMMUv3State *s,SMMUDevice *sdev,int sid, +Error **errp) +{ +return true; +} +static inline bool +smmuv3_accel_install_ste_range (SMMUv3State *s,SMMUSIDRange *range, +Error **errp) +{ +return true; +}#endif #endif /* HW_ARM_SMMUV3_ACCEL_H */ hw/arm/smmuv3-internal.h +20
-0@@ -547,6 +547,8 @@ typedef struct CD {uint32_t word[16 ]; }CD ; +int smmu_find_ste (SMMUv3State *s,uint32_t sid,STE *ste,SMMUEventInfo *event); +/* STE fields */ #define STE_VALID (x) extract32((x)->word[0], 0, 1)@@ -556,6 +558,7 @@ typedef struct CD {#define STE_CFG_S2_ENABLED (config) (config & 0x2)#define STE_CFG_ABORT (config) (!(config & 0x4))#define STE_CFG_BYPASS (config) (config == 0x4) +#define STE_CFG_S1_TRANSLATE (config) (config == 0x5)#define STE_S1FMT (x) extract32((x)->word[0], 4 , 2)#define STE_S1CDMAX (x) extract32((x)->word[1], 27, 5)@@ -586,6 +589,23 @@ typedef struct CD {#define SMMU_STE_VALID (1ULL << 0)#define SMMU_STE_CFG_BYPASS (1ULL << 3) +#define STE0_V MAKE_64BIT_MASK(0, 1) +#define STE0_CONFIG MAKE_64BIT_MASK(1, 3) +#define STE0_S1FMT MAKE_64BIT_MASK(4, 2) +#define STE0_CTXPTR MAKE_64BIT_MASK(6, 50) +#define STE0_S1CDMAX MAKE_64BIT_MASK(59, 5) +#define STE0_MASK (STE0_S1CDMAX | STE0_CTXPTR | STE0_S1FMT | STE0_CONFIG | \ + STE0_V) + +#define STE1_S1DSS MAKE_64BIT_MASK(0, 2) +#define STE1_S1CIR MAKE_64BIT_MASK(2, 2) +#define STE1_S1COR MAKE_64BIT_MASK(4, 2) +#define STE1_S1CSH MAKE_64BIT_MASK(6, 2) +#define STE1_S1STALLD MAKE_64BIT_MASK(27, 1) +#define STE1_EATS MAKE_64BIT_MASK(28, 2) +#define STE1_MASK (STE1_EATS | STE1_S1STALLD | STE1_S1CSH | STE1_S1COR | \ + STE1_S1CIR | STE1_S1DSS) +static inline int oas2bits (int oas_field) {switch (oas_field) {hw/arm/smmuv3.c +9
-2@@ -630,8 +630,7 @@ bad_ste:* Supports linear and 2-level stream table * Return 0 on success, -EINVAL otherwise */ -static int smmu_find_ste (SMMUv3State *s,uint32_t sid,STE *ste, -SMMUEventInfo *event) +int smmu_find_ste (SMMUv3State *s,uint32_t sid,STE *ste,SMMUEventInfo *event) {dma_addr_t addr, strtab_base;uint32_t log2size;@@ -1341,6 +1340,10 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp) }trace_smmuv3_cmdq_cfgi_ste (sid); +if (!smmuv3_accel_install_ste (s, sdev, sid, errp)) { + cmd_error =SMMU_CERROR_ILL ; +break ; + }smmuv3_flush_config (sdev);break ;@@ -1361,6 +1364,10 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp) sid_range.end = sid_range.start + mask;trace_smmuv3_cmdq_cfgi_ste_range (sid_range.start, sid_range.end); +if (!smmuv3_accel_install_ste_range (s, &sid_range, errp)) { + cmd_error =SMMU_CERROR_ILL ; +break ; + }smmu_configs_inv_sid_range (bs, sid_range);break ; }hw/arm/trace-events +0
-0
hw/arm/trace-events smmu_reset_exit(void) "" · line 76
Quoted 8 lines
hw/arm/trace-events +2
-0@@ -69,6 +69,8 @@ smmu_reset_exit(void) "" #smmuv3-accel.c smmuv3_accel_set_iommu_device(int devfn, uint32_t devid) "devfn=0x%x (idev devid=0x%x)" smmuv3_accel_unset_iommu_device(int devfn, uint32_t devid) "devfn=0x%x (idev devid=0x%x)" +smmuv3_accel_translate_ste(uint32_t vsid, uint32_t hwpt_id, uint64_t ste_1, uint64_t ste_0) "vSID=0x%x hwpt_id=0x%x ste=%"PRIx64":%"PRIx64 +smmuv3_accel_install_ste(uint32_t vsid, const char * type, uint32_t hwpt_id) "vSID=0x%x ste type=%s hwpt_id=0x%x" # strongarm.c strongarm_uart_update_parameters(const char *label, int speed, char parity, int data_bits, int stop_bits) "%s speed=%d parity=%c data=%d stop=%d"
Eric
PATCH v6 15/33 hw/arm/smmuv3-accel: Install SMMUv3 GBPA based hwpt
In reply to Shameer KolothumOn guest reboot or on GBPA update, attach a nested HWPT based on the GPBA.ABORT bit which either aborts all incoming transactions or bypasses them.
--- hw/arm/smmuv3-accel.c | 36 ++++++++++++++++++++++++++++++++++++ hw/arm/smmuv3-accel.h | 9 +++++++++ hw/arm/smmuv3.c | 2 ++ 3 files changed, 47 insertions(+)
hw/arm/smmuv3-accel.c +36 -0
@@ -498,6 +498,42 @@ static const PCIIOMMUOps smmuv3_accel_ops = { .unset_iommu_device = smmuv3_accel_unset_iommu_device, }; +/* Based on SMUUv3 GPBA.ABORT configuration, attach a corresponding HWPT */ +bool smmuv3_accel_attach_gbpa_hwpt (SMMUv3State *s,Error **errp) +{ +SMMUv3AccelState *accel = s->s_accel; +SMMUv3AccelDevice *accel_dev; +Error *local_err =NULL ; +bool all_ok = true; +uint32_t hwpt_id; + +if (!accel) { +return true; + } + + hwpt_id =smmuv3_accel_gbpa_hwpt (s, accel); + QLIST_FOREACH(accel_dev, &accel->device_list, next) { +if (!host_iommu_device_iommufd_attach_hwpt (accel_dev->idev, hwpt_id, + &local_err)) { +error_append_hint (&local_err,"Failed to attach GBPA hwpt %u for " +"idev devid %u" , hwpt_id, accel_dev->idev->devid); +error_report_err (local_err); + local_err =NULL ; + all_ok = false; + } + } +if (!all_ok) { +error_setg (errp,"Failed to attach all GBPA based HWPTs properly" ); + } +return all_ok; +} + +void smmuv3_accel_reset (SMMUv3State *s) +{ +/* Attach a HWPT based on GBPA reset value */ +smmuv3_accel_attach_gbpa_hwpt (s,NULL ); +} +static void smmuv3_accel_as_init (SMMUv3State *s) {
hw/arm/smmuv3-accel.h +9 -0
@@ -44,6 +44,8 @@ bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevice *sdev, int sid, Error **errp);bool smmuv3_accel_install_ste_range (SMMUv3State *s,SMMUSIDRange *range,Error **errp); +bool smmuv3_accel_attach_gbpa_hwpt (SMMUv3State *s,Error **errp); +void smmuv3_accel_reset (SMMUv3State *s);#else static inline void smmuv3_accel_init (SMMUv3State *s) {
@@ -60,6 +62,13 @@ smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange *range, {return true; } +static inline bool smmuv3_accel_attach_gbpa_hwpt (SMMUv3State *s,Error **errp) +{ +return true; +} +static inline void smmuv3_accel_reset (SMMUv3State *s) +{ +}#endif #endif /* HW_ARM_SMMUV3_ACCEL_H */
hw/arm/smmuv3.c +2 -0
@@ -1600,6 +1600,7 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwaddr offset,if (data &R_GBPA_UPDATE_MASK ) {/* Ignore update bit as write is synchronous. */ s->gbpa = data & ~R_GBPA_UPDATE_MASK ; +smmuv3_accel_attach_gbpa_hwpt (s, &local_err); }break ;case A_STRTAB_BASE :/* 64b */
@@ -1887,6 +1888,7 @@ static void smmu_reset_exit(Object *obj, ResetType type) }smmuv3_init_regs (s); +smmuv3_accel_reset (s); }static void smmu_realize (DeviceState *d,Error **errp)
Signature · 1 line
2.43.0
Re: [PATCH v6 15/33] hw/arm/smmuv3-accel: Install SMMUv3 GBPA based hwpt
Quoted 6 lines · Shameer Kolothum
On guest reboot or on GBPA update, attach a nested HWPT based on the GPBA.ABORT bit which either aborts all incoming transactions or bypasses them.
Reviewed-by Eric Auger <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>
PATCH v6 16/33 hw/pci/pci: Introduce a callback to retrieve the MSI doorbell GPA directly
In reply to Shameer KolothumFor certain vIOMMU implementations, such as SMMUv3 in accelerated mode, the translation tables are programmed directly into the physical SMMUv3 in a nested configuration. While QEMU knows where the guest tables live, safely walking them in software would require trapping and ordering all guest invalidations on every command queue. Without this, QEMU could race with guest updates and walk stale or freed page tables.
This constraint is fundamental to the design of HW-accelerated vSMMU when used with downstream vfio-pci endpoint devices, where QEMU must never walk guest translation tables and must rely on the physical SMMU for translation. Future accelerated vSMMU features, such as virtual CMDQ, will also prevent trapping invalidations, reinforcing this restriction.
For vfio-pci endpoints behind such a vSMMU, the only translation QEMU needs is for the MSI doorbell used when setting up KVM MSI route tables. Instead of attempting a software walk, introduce an optional vIOMMU callback that returns the MSI doorbell GPA directly.
kvm_arch_fixup_msi_route() uses this callback when available and ignores the guest provided IOVA in that case.
If the vIOMMU does not implement the callback, we fall back to the existing IOMMU based address space translation path.
This ensures correct MSI routing for accelerated SMMUv3 + VFIO passthrough while avoiding unsafe software walks of guest translation tables.
--- hw/pci/pci.c | 17 +++++++++++++++++ include/hw/pci/pci.h | 17 +++++++++++++++++ target/arm/kvm.c | 18 +++++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-)
hw/pci/pci.c +17 -0
@@ -2979,6 +2979,23 @@ bool pci_device_get_iommu_bus_devfn(PCIDevice *dev, PCIBus **piommu_bus,return aliased; } +bool pci_device_iommu_msi_direct_gpa (PCIDevice *dev,hwaddr *out_doorbell) +{ +PCIBus *bus; +PCIBus *iommu_bus; +int devfn; + +pci_device_get_iommu_bus_devfn (dev, &iommu_bus, &bus, &devfn); +if (iommu_bus) { +if (iommu_bus->iommu_ops->get_msi_direct_gpa) { + *out_doorbell = iommu_bus->iommu_ops->get_msi_direct_gpa (bus, + iommu_bus->iommu_opaque, devfn); +return true; + } + } +return false; +} +AddressSpace *pci_device_iommu_address_space (PCIDevice *dev) {PCIBus *bus;
include/hw/pci/pci.h +17 -0
@@ -664,6 +664,22 @@ typedef struct PCIIOMMUOps { uint32_t pasid, bool priv_req, bool exec_req, hwaddr addr, bool lpig, uint16_t prgi, bool is_read, bool is_write); +/** +* @get_msi_direct_gpa: get the guest physical address of MSI doorbell +* for the device on a PCI bus. +* +* Optional callback. If implemented, it must return a valid guest +* physical address for the MSI doorbell +* +* @bus: the #PCIBus being accessed. +* +* @opaque: the data passed to pci_setup_iommu(). +* +* @devfn: device and function number +* +* Returns: the guest physical address of the MSI doorbell. +*/ +uint64_t (*get_msi_direct_gpa)(PCIBus *bus,void *opaque,int devfn); } PCIIOMMUOps; bool pci_device_get_iommu_bus_devfn(PCIDevice *dev, PCIBus **piommu_bus,
@@ -672,6 +688,7 @@ AddressSpace *pci_device_iommu_address_space(PCIDevice *dev);bool pci_device_set_iommu_device (PCIDevice *dev,HostIOMMUDevice *hiod,Error **errp);void pci_device_unset_iommu_device (PCIDevice *dev); +bool pci_device_iommu_msi_direct_gpa (PCIDevice *dev,hwaddr *out_doorbell);/** * pci_device_get_viommu_flags: get vIOMMU flags.
target/arm/kvm.c +17 -1
@@ -1620,26 +1620,42 @@ int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route,return 0 ; } +/* +* We do have an IOMMU address space, but for some vIOMMU implementations +* (e.g. accelerated SMMUv3) the translation tables are programmed into +* the physical SMMUv3 in the host (nested S1=guest, S2=host). QEMU cannot +* walk these tables in a safe way, so in that case we obtain the MSI +* doorbell GPA directly from the vIOMMU backend and ignore the gIOVA +* @address. +*/ +if (pci_device_iommu_msi_direct_gpa (dev, &doorbell_gpa)) { + goto set_doorbell; + } +/* MSI doorbell address is translated by an IOMMU */ -RCU_READ_LOCK_GUARD (); +rcu_read_lock (); mr =address_space_translate (as, address, &xlat, &len, true,MEMTXATTRS_UNSPECIFIED );if (!mr) { +rcu_read_unlock ();return 1 ; } mrs =memory_region_find (mr, xlat,1 );if (!mrs.mr) { +rcu_read_unlock ();return 1 ; } doorbell_gpa = mrs.offset_within_address_space;memory_region_unref (mrs.mr); +rcu_read_unlock (); +set_doorbell: route->u.msi.address_lo = doorbell_gpa; route->u.msi.address_hi = doorbell_gpa >>32 ;
Signature · 1 line
2.43.0
Re: [PATCH v6 16/33] hw/pci/pci: Introduce a callback to retrieve the MSI doorbell GPA directly
Quoted 21 lines · Shameer Kolothum
For certain vIOMMU implementations, such as SMMUv3 in accelerated mode, the translation tables are programmed directly into the physical SMMUv3 in a nested configuration. While QEMU knows where the guest tables live, safely walking them in software would require trapping and ordering all guest invalidations on every command queue. Without this, QEMU could race with guest updates and walk stale or freed page tables.
This constraint is fundamental to the design of HW-accelerated vSMMU when used with downstream vfio-pci endpoint devices, where QEMU must never walk guest translation tables and must rely on the physical SMMU for translation. Future accelerated vSMMU features, such as virtual CMDQ, will also prevent trapping invalidations, reinforcing this restriction.
For vfio-pci endpoints behind such a vSMMU, the only translation QEMU needs is for the MSI doorbell used when setting up KVM MSI route tables. Instead of attempting a software walk, introduce an optional vIOMMU callback that returns the MSI doorbell GPA directly.
kvm_arch_fixup_msi_route()uses this callback when available and ignores the guest provided IOVA in that case.
Quoted 8 lines
If the vIOMMU does not implement the callback, we fall back to the existing IOMMU based address space translation path.
This ensures correct MSI routing for accelerated SMMUv3 + VFIO passthrough while avoiding unsafe software walks of guest translation tables.
Cc Michael S. Tsirkin <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>
Re: [PATCH v6 16/33] hw/pci/pci: Introduce a callback to retrieve the MSI doorbell GPA directly
In reply to Shameer KolothumHi Shameer,
Quoted 112 lines · Shameer Kolothum
For certain vIOMMU implementations, such as SMMUv3 in accelerated mode, the translation tables are programmed directly into the physical SMMUv3 in a nested configuration. While QEMU knows where the guest tables live, safely walking them in software would require trapping and ordering all guest invalidations on every command queue. Without this, QEMU could race with guest updates and walk stale or freed page tables.
This constraint is fundamental to the design of HW-accelerated vSMMU when used with downstream vfio-pci endpoint devices, where QEMU must never walk guest translation tables and must rely on the physical SMMU for translation. Future accelerated vSMMU features, such as virtual CMDQ, will also prevent trapping invalidations, reinforcing this restriction.
For vfio-pci endpoints behind such a vSMMU, the only translation QEMU needs is for the MSI doorbell used when setting up KVM MSI route tables. Instead of attempting a software walk, introduce an optional vIOMMU callback that returns the MSI doorbell GPA directly.
kvm_arch_fixup_msi_route()uses this callback when available and ignores the guest provided IOVA in that case.If the vIOMMU does not implement the callback, we fall back to the existing IOMMU based address space translation path.
This ensures correct MSI routing for accelerated SMMUv3 + VFIO passthrough while avoiding unsafe software walks of guest translation tables.
Cc Michael S. Tsirkin <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/pci/pci.c | 17 +++++++++++++++++ include/hw/pci/pci.h | 17 +++++++++++++++++ target/arm/kvm.c | 18 +++++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-)hw/pci/pci.c +17
-0@@ -2979,6 +2979,23 @@ bool pci_device_get_iommu_bus_devfn(PCIDevice *dev, PCIBus **piommu_bus,return aliased; } +bool pci_device_iommu_msi_direct_gpa (PCIDevice *dev,hwaddr *out_doorbell) +{ +PCIBus *bus; +PCIBus *iommu_bus; +int devfn; + +pci_device_get_iommu_bus_devfn (dev, &iommu_bus, &bus, &devfn); +if (iommu_bus) { +if (iommu_bus->iommu_ops->get_msi_direct_gpa) { + *out_doorbell = iommu_bus->iommu_ops->get_msi_direct_gpa (bus, + iommu_bus->iommu_opaque, devfn); +return true; + } + } +return false; +} +AddressSpace *pci_device_iommu_address_space (PCIDevice *dev) {PCIBus *bus;include/hw/pci/pci.h +17
-0@@ -664,6 +664,22 @@ typedef struct PCIIOMMUOps { uint32_t pasid, bool priv_req, bool exec_req, hwaddr addr, bool lpig, uint16_t prgi, bool is_read, bool is_write); +/** +* @get_msi_direct_gpa: get the guest physical address of MSI doorbell +* for the device on a PCI bus. +* +* Optional callback. If implemented, it must return a valid guest +* physical address for the MSI doorbell +* +* @bus: the #PCIBus being accessed. +* +* @opaque: the data passed to pci_setup_iommu(). +* +* @devfn: device and function number +* +* Returns: the guest physical address of the MSI doorbell. +*/ +uint64_t (*get_msi_direct_gpa)(PCIBus *bus,void *opaque,int devfn); } PCIIOMMUOps; bool pci_device_get_iommu_bus_devfn(PCIDevice *dev, PCIBus **piommu_bus,@@ -672,6 +688,7 @@ AddressSpace *pci_device_iommu_address_space(PCIDevice *dev);bool pci_device_set_iommu_device (PCIDevice *dev,HostIOMMUDevice *hiod,Error **errp);void pci_device_unset_iommu_device (PCIDevice *dev); +bool pci_device_iommu_msi_direct_gpa (PCIDevice *dev,hwaddr *out_doorbell);/** * pci_device_get_viommu_flags: get vIOMMU flags. target/arm/kvm.c +6
-0@@ -1620,26 +1620,42 @@ int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route,return 0 ; } +/* +* We do have an IOMMU address space, but for some vIOMMU implementations +* (e.g. accelerated SMMUv3) the translation tables are programmed into +* the physical SMMUv3 in the host (nested S1=guest, S2=host). QEMU cannot +* walk these tables in a safe way, so in that case we obtain the MSI +* doorbell GPA directly from the vIOMMU backend and ignore the gIOVA
target/arm/kvm.c int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, · line 1637
Quoted 10 lines
target/arm/kvm.c +7
-1+* @address. +*/ +if (pci_device_iommu_msi_direct_gpa (dev, &doorbell_gpa)) { + goto set_doorbell; + } +/* MSI doorbell address is translated by an IOMMU */ -RCU_READ_LOCK_GUARD (); +rcu_read_lock ();
what is the rationale behind the RCU changes?
Eric
Quoted 24 lines
target/arm/kvm.c +4
-0mr =address_space_translate (as, address, &xlat, &len, true,MEMTXATTRS_UNSPECIFIED );if (!mr) { +rcu_read_unlock ();return 1 ; } mrs =memory_region_find (mr, xlat,1 );if (!mrs.mr) { +rcu_read_unlock ();return 1 ; } doorbell_gpa = mrs.offset_within_address_space;memory_region_unref (mrs.mr); +rcu_read_unlock (); +set_doorbell: route->u.msi.address_lo = doorbell_gpa; route->u.msi.address_hi = doorbell_gpa >>32 ;
RE: [PATCH v6 16/33] hw/pci/pci: Introduce a callback to retrieve the MSI doorbell GPA directly
Hi Eric,
Quoted 16 lines
-----Original Message-----
From: Eric Auger <[email protected]>
Sent: 04 December 2025 16:39
To: Shameer Kolothum <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>; Michael S . Tsirkin <[email protected]>
Subject: Re: [PATCH v6 16/33] hw/pci/pci: Introduce a callback to retrieve the MSI doorbell GPA directlyExternal email: Use caution opening links or attachments
...
Quoted 24 lines
target/arm/kvm.c int kvm_arch_fixup_msi_route(struct
Quoted 3 lines
target/arm/kvm.c +0
-0@@ -1620,26 +1620,42 @@ int kvm_arch_fixup_msi_route(struct
kvm_irq_routing_entry*route,target/arm/kvm.c int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route,
Quoted 5 lines
target/arm/kvm.c +2
-0return 0 ; } +/* +* We do have an IOMMU address space, but for some vIOMMU implementations
target/arm/kvm.c int kvm_arch_fixup_msi_route(struct · line 1626
Quoted 2 lines
target/arm/kvm.c +2
-0+* (e.g. accelerated SMMUv3) the translation tables are programmed into +* the physical SMMUv3 in the host (nested S1=guest, S2=host). QEMU cannot
target/arm/kvm.c int kvm_arch_fixup_msi_route(struct · line 1628
Quoted 2 lines
target/arm/kvm.c +2
-0+* walk these tables in a safe way, so in that case we obtain the MSI +* doorbell GPA directly from the vIOMMU backend and ignore the gIOVA
Quoted 8 lines
target/arm/kvm.c +6
-0+* @address. +*/ +if (pci_device_iommu_msi_direct_gpa (dev, &doorbell_gpa)) { + goto set_doorbell; + } +/* MSI doorbell address is translated by an IOMMU */
Quoted 4 lines
target/arm/kvm.c int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, · line 1637
Quoted 2 lines
target/arm/kvm.c +1
-1-RCU_READ_LOCK_GUARD (); +rcu_read_lock ();what is the rationale behind the RCU changes?
Otherwise, it will crash if this fn returns via the goto set_doorbell path with,
include/qemu/rcu.h:101: rcu_read_unlock: Assertion `p_rcu_reader->depth != 0' failed
goto set_doorbell path skips over the scope where RCU_READ_LOCK_GUARD() is active. When the function later reaches rcu_read_unlock() implicitly via destructor, the guard was never entered, so we hit above.
An alternative would be to wrap the translation logic in its own block, like
if (pci_device_iommu_msi_direct_gpa(dev, &doorbell_gpa)) {
goto set_doorbell;
}
{
RCU_READ_LOCK_GUARD();
/* MSI translation logic */
}set_doorbell:
route->u.msi.address_lo = doorbell_gpa;
route->u.msi.address_hi = doorbell_gpa >> 32;
return 0;Or could do:
if (!pci_device_iommu_msi_direct_gpa(dev, &doorbell_gpa)) {
RCU_READ_LOCK_GUARD();
/* translation logic */
}route->u.msi.address_lo = doorbell_gpa;route->u.msi.address_hi = doorbell_gpa >> 32;
return 0;
Both approaches work, but I find the explicit lock/unlock variant easier to follow. Please let me know if there is a better way.
Thanks,
Shameer
Eric Auger
Reviewed-byRe: [PATCH v6 16/33] hw/pci/pci: Introduce a callback to retrieve the MSI doorbell GPA directly
Hi Shameer,
Quoted 79 lines · Shameer Kolothum
Hi Eric,
Quoted 16 lines
-----Original Message-----
From: Eric Auger <[email protected]>
Sent: 04 December 2025 16:39
To: Shameer Kolothum <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>; Michael S . Tsirkin <[email protected]>
Subject: Re: [PATCH v6 16/33] hw/pci/pci: Introduce a callback to retrieve the MSI doorbell GPA directlyExternal email: Use caution opening links or attachments
...
Quoted 24 lines
target/arm/kvm.c int kvm_arch_fixup_msi_route(struct
Quoted 3 lines
target/arm/kvm.c +0
-0@@ -1620,26 +1620,42 @@ int kvm_arch_fixup_msi_route(struct
kvm_irq_routing_entry*route,target/arm/kvm.c int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route,
Quoted 5 lines
target/arm/kvm.c +2
-0return 0 ; } +/* +* We do have an IOMMU address space, but for some vIOMMU implementations
target/arm/kvm.c int kvm_arch_fixup_msi_route(struct · line 1626
Quoted 2 lines
target/arm/kvm.c +2
-0+* (e.g. accelerated SMMUv3) the translation tables are programmed into +* the physical SMMUv3 in the host (nested S1=guest, S2=host). QEMU cannot
target/arm/kvm.c int kvm_arch_fixup_msi_route(struct · line 1628
Quoted 2 lines
target/arm/kvm.c +2
-0+* walk these tables in a safe way, so in that case we obtain the MSI +* doorbell GPA directly from the vIOMMU backend and ignore the gIOVA
Quoted 8 lines
target/arm/kvm.c +6
-0+* @address. +*/ +if (pci_device_iommu_msi_direct_gpa (dev, &doorbell_gpa)) { + goto set_doorbell; + } +/* MSI doorbell address is translated by an IOMMU */ Quoted 4 lines
target/arm/kvm.c int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, · line 1637
Quoted 2 lines
target/arm/kvm.c +1
-1-RCU_READ_LOCK_GUARD (); +rcu_read_lock ();what is the rationale behind the RCU changes?
Otherwise, it will crash if this fn returns via the goto
set_doorbellpath with,
include/qemu/rcu.h:101:rcu_read_unlock: Assertion `p_rcu_reader->depth != 0' failedgoto
set_doorbellpath skips over the scope whereRCU_READ_LOCK_GUARD()is active. When the function later reachesrcu_read_unlock()implicitly via destructor, the guard was never entered, so we hit above.An alternative would be to wrap the translation logic in its own block, like
if (pci_device_iommu_msi_direct_gpa(dev, &doorbell_gpa)) { goto set_doorbell; } { RCU_READ_LOCK_GUARD(); /* MSI translation logic */ }
set_doorbell:route->u.msi.address_lo = doorbell_gpa; route->u.msi.address_hi = doorbell_gpa >> 32; return 0;Or could do:
if (!pci_device_iommu_msi_direct_gpa(dev, &doorbell_gpa)) { RCU_READ_LOCK_GUARD(); /* translation logic */ }
Quoted 6 lines
route->u.msi.address_lo=doorbell_gpa;route->u.msi.address_hi=doorbell_gpa>> 32;
return 0;Both approaches work, but I find the explicit lock/unlock variant easier to follow. Please let me know if there is a better way.
thank you for the explanation. It was not obvious to me. Maybe document that in the commit msg and keep the current version.
Eric
Quoted 4 lines
Thanks,
Shameer
PATCH v6 17/33 hw/arm/smmuv3: Add support for providing a direct MSI doorbell GPA
In reply to Shameer KolothumAccelerated SMMUv3 instances rely on the physical SMMUv3 for nested translation (Guest Stage-1, Host Stage-2). In this mode the guest’s Stage-1 tables are programmed directly into hardware, and QEMU should not attempt to walk them for translation since doing so is not reliably safe. For vfio-pci endpoints behind such a vSMMU, the only translation QEMU is responsible for is the MSI doorbell used during KVM MSI setup.
Add a device property to carry the MSI doorbell GPA from the virt machine, and expose it through a new get_msi_direct_gpa PCIIOMMUOp. kvm_arch_fixup_msi_route() can then use this GPA directly instead of attempting a software walk of guest translation tables.
This enables correct MSI routing with accelerated SMMUv3 while avoiding unsafe accesses to page tables.
For meaningful use of vfio-pci devices with accelerated SMMUv3, both KVM and a kernel irqchip are required. Enforce this requirement when accel=on is selected.
--- hw/arm/smmuv3-accel.c | 10 ++++++++++ hw/arm/smmuv3.c | 2 ++ hw/arm/virt.c | 22 ++++++++++++++++++++++ include/hw/arm/smmuv3.h | 1 + 4 files changed, 35 insertions(+)
hw/arm/smmuv3-accel.c +10 -0
@@ -392,6 +392,15 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bus, void *opaque, } } +static uint64_t smmuv3_accel_get_msi_gpa (PCIBus *bus,void *opaque,int devfn) +{ +SMMUState *bs = opaque; +SMMUv3State *s =ARM_SMMUV3 (bs); + +g_assert (s->msi_gpa); +return s->msi_gpa; +} +/* * Only allow PCIe bridges, pxb-pcie roots, and GPEX roots so vfio-pci * endpoints can sit downstream. Accelerated SMMUv3 requires a vfio-pci
@@ -496,6 +505,7 @@ static const PCIIOMMUOps smmuv3_accel_ops = { .get_viommu_flags = smmuv3_accel_get_viommu_flags, .set_iommu_device = smmuv3_accel_set_iommu_device, .unset_iommu_device = smmuv3_accel_unset_iommu_device, + .get_msi_direct_gpa = smmuv3_accel_get_msi_gpa, };/* Based on SMUUv3 GPBA.ABORT configuration, attach a corresponding HWPT */
hw/arm/smmuv3.c +2 -0
@@ -1998,6 +1998,8 @@ static const Property smmuv3_properties[] = {* Defaults to stage 1 */ DEFINE_PROP_STRING ("stage" , SMMUv3State, stage), +/* GPA of MSI doorbell, for SMMUv3 accel use. */ + DEFINE_PROP_UINT64("msi-gpa", SMMUv3State, msi_gpa, 0), };static void smmuv3_instance_init (Object *obj)
hw/arm/virt.c +22 -0
@@ -3052,6 +3052,14 @@ static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,/* The new SMMUv3 device is specific to the PCI bus */ object_property_set_bool (OBJECT (dev),"smmu_per_bus" , true,NULL ); } +if (object_property_find (OBJECT (dev),"accel" ) && +object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) { +if (!kvm_enabled () || !kvm_irqchip_in_kernel ()) { +error_setg (errp,"SMMUv3 accel=on requires KVM with " +"kernel-irqchip=on support" ); +return ; + } + } } }
@@ -3088,6 +3096,20 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, }create_smmuv3_dev_dtb (vms, dev, bus); +if (object_property_find (OBJECT (dev),"accel" ) && +object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) { +hwaddr db_start; + +if (vms->msi_controller ==VIRT_MSI_CTRL_ITS ) { +/* GITS_TRANSLATER page + offset */ + db_start = base_memmap[VIRT_GIC_ITS ].base +0x10000 +0x40 ; + }else { +/* MSI_SETSPI_NS page + offset */ + db_start = base_memmap[VIRT_GIC_V2M ].base +0x40 ; + } +object_property_set_uint (OBJECT (dev),"msi-gpa" , db_start, + &error_abort); + } } }
include/hw/arm/smmuv3.h +1 -0
@@ -67,6 +67,7 @@ struct SMMUv3State {/* SMMU has HW accelerator support for nested S1 + s2 */ bool accel;struct SMMUv3AccelState *s_accel; +uint64_t msi_gpa; }; typedef enum {
Signature · 1 line
2.43.0
Re: [PATCH v6 17/33] hw/arm/smmuv3: Add support for providing a direct MSI doorbell GPA
Quoted 12 lines · Shameer Kolothum
Accelerated SMMUv3 instances rely on the physical SMMUv3 for nested translation (Guest Stage-1, Host Stage-2). In this mode the guest’s Stage-1 tables are programmed directly into hardware, and QEMU should not attempt to walk them for translation since doing so is not reliably safe. For vfio-pci endpoints behind such a vSMMU, the only translation QEMU is responsible for is the MSI doorbell used during KVM MSI setup.
Add a device property to carry the MSI doorbell GPA from the virt machine, and expose it through a new
get_msi_direct_gpaPCIIOMMUOp.kvm_arch_fixup_msi_route()can then use this GPA directly instead of attempting a software walk of guest translation tables.
Quoted 8 lines
This enables correct MSI routing with accelerated SMMUv3 while avoiding unsafe accesses to page tables.
For meaningful use of vfio-pci devices with accelerated SMMUv3, both KVM and a kernel irqchip are required. Enforce this requirement when accel=on is selected.
Signed-off-by Shameer Kolothum <[email protected]>
Nits:
hw/arm/virt.c static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, · line 3056
Quoted 7 lines
+++
b/hw/arm/virt.chw/arm/virt.c +2
-0@@ -3052,6 +3052,14 @@ static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,/* The new SMMUv3 device is specific to the PCI bus */ object_property_set_bool (OBJECT (dev),"smmu_per_bus" , true,NULL ); } +if (object_property_find (OBJECT (dev),"accel" ) && +object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) {
Do we need object_property_find()? A later patch seems to drop it. Perhaps we shouldn't add it in the first place?
hw/arm/virt.c static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, · line 3100
Quoted 6 lines
hw/arm/virt.c +2
-0@@ -3088,6 +3096,20 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, }create_smmuv3_dev_dtb (vms, dev, bus); +if (object_property_find (OBJECT (dev),"accel" ) && +object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) {
Ditto
RE: [PATCH v6 17/33] hw/arm/smmuv3: Add support for providing a direct MSI doorbell GPA
Quoted 48 lines
-----Original Message-----
From: Nicolin Chen <[email protected]>
Sent: 20 November 2025 21:22
To: Shameer Kolothum <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 17/33] hw/arm/smmuv3: Add support for providing a direct MSI doorbell GPAQuoted 12 lines · Shameer Kolothum
Accelerated SMMUv3 instances rely on the physical SMMUv3 for nested translation (Guest Stage-1, Host Stage-2). In this mode the guest’s Stage-1 tables are programmed directly into hardware, and QEMU should not attempt to walk them for translation since doing so is not reliably safe. For vfio-pci endpoints behind such a vSMMU, the only translation QEMU is responsible for is the MSI doorbell used during KVM MSI setup.
Add a device property to carry the MSI doorbell GPA from the virt machine, and expose it through a new
get_msi_direct_gpaPCIIOMMUOp.kvm_arch_fixup_msi_route()can then use this GPA directly instead of attempting a software walk of guest translation tables.Quoted 8 lines
This enables correct MSI routing with accelerated SMMUv3 while avoiding unsafe accesses to page tables.
For meaningful use of vfio-pci devices with accelerated SMMUv3, both KVM and a kernel irqchip are required. Enforce this requirement when accel=on is selected.
Signed-off-by Shameer Kolothum <[email protected]>Reviewed-by Nicolin Chen <[email protected]>Nits:
Review static void
Quoted 2 lines
+++
b/hw/arm/virt.c(quoted diff) +0
-0@@ -3052,6 +3052,14 @@ static voidvirt_machine_device_pre_plug_cb(HotplugHandler
*hotplug_dev,Review static void · line 3053
Quoted 2 lines
(quoted diff) +0
-0/* The new SMMUv3 device is specific to the PCI bus */ object_property_set_bool(OBJECT(dev), "smmu_per_bus", true,
Quoted 7 lines
NULL);
hw/arm/virt.c static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, · line 3056
Quoted 3 lines
hw/arm/virt.c +2
-0} +if (object_property_find (OBJECT (dev),"accel" ) && +object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) {Do we need
object_property_find()? A later patch seems to drop it. Perhaps we shouldn't add it in the first place?
We need that at this stage as we haven't added the "accel" property yet and that will cause "make check" tests to fail without that.
We remove it once we introduce "accel" property later.
Thanks,
Shameer
Re: [PATCH v6 17/33] hw/arm/smmuv3: Add support for providing a direct MSI doorbell GPA
Quoted 36 lines · Shameer Kolothum
Quoted 36 lines · Shameer Kolothum
Quoted 12 lines
Accelerated SMMUv3 instances rely on the physical SMMUv3 for nested translation (Guest Stage-1, Host Stage-2). In this mode the guest’s Stage-1 tables are programmed directly into hardware, and QEMU should not attempt to walk them for translation since doing so is not reliably safe. For vfio-pci endpoints behind such a vSMMU, the only translation QEMU is responsible for is the MSI doorbell used during KVM MSI setup.
Add a device property to carry the MSI doorbell GPA from the virt machine, and expose it through a new
get_msi_direct_gpaPCIIOMMUOp.kvm_arch_fixup_msi_route()can then use this GPA directly instead of attempting a software walk of guest translation tables.Quoted 8 lines
This enables correct MSI routing with accelerated SMMUv3 while avoiding unsafe accesses to page tables.
For meaningful use of vfio-pci devices with accelerated SMMUv3, both KVM and a kernel irqchip are required. Enforce this requirement when accel=on is selected.
Signed-off-by Shameer Kolothum <[email protected]>Reviewed-by Nicolin Chen <[email protected]>Nits:
Review static void
Quoted 2 lines
+++
b/hw/arm/virt.c(quoted diff) +0
-0@@ -3052,6 +3052,14 @@ static voidvirt_machine_device_pre_plug_cb(HotplugHandler
*hotplug_dev,Review static void · line 3053
Quoted 2 lines
(quoted diff) +0
-0/* The new SMMUv3 device is specific to the PCI bus */ object_property_set_bool(OBJECT(dev), "smmu_per_bus", true,NULL);
Quoted 3 lines
hw/arm/virt.c +2
-0} +if (object_property_find (OBJECT (dev),"accel" ) && +object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) {
Quoted 7 lines
Quoted 2 lines
Do we need
object_property_find()? A later patch seems to drop it. Perhaps we shouldn't add it in the first place?We need that at this stage as we haven't added the "accel" property yet and that will cause "make check" tests to fail without that.
We remove it once we introduce "accel" property later.
Hmm, I assume object_property_get_bool() would return false when "accel" is not available yet? No?
Nicolin
RE: [PATCH v6 17/33] hw/arm/smmuv3: Add support for providing a direct MSI doorbell GPA
Quoted 25 lines
-----Original Message-----
From: Nicolin Chen <[email protected]>
Sent: 21 November 2025 17:56
To: Shameer Kolothum <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 17/33] hw/arm/smmuv3: Add support for providing a direct MSI doorbell GPAQuoted 6 lines
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (object_property_find(OBJECT(dev), "accel") && + object_property_get_bool(OBJECT(dev), "accel", &error_abort)) {Do we need
object_property_find()? A later patch seems to drop it. Perhaps we shouldn't add it in the first place?
Quoted 7 lines
Quoted 4 lines
We need that at this stage as we haven't added the "accel" property yet and that will cause "make check" tests to fail without that.
We remove it once we introduce "accel" property later.
Hmm, I assume
object_property_get_bool()would return false when "accel" is not available yet? No?
It is the errp that will be set if there is no "accel" is available that will fail the tests. Another way to avoid object_property_find() is to pass NULL for errp in object_property_get_bool(), but I think again when we introduce "accel" we have change that into either errp/error_abort here.
I am not sure there is any other way to handle this.
Thanks,
Shameer
Re: [PATCH v6 17/33] hw/arm/smmuv3: Add support for providing a direct MSI doorbell GPA
Quoted 14 lines · Shameer Kolothum
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (object_property_find(OBJECT(dev), "accel") && + object_property_get_bool(OBJECT(dev), "accel", &error_abort)) {Do we need
object_property_find()? A later patch seems to drop it. Perhaps we shouldn't add it in the first place?Quoted 7 lines
Quoted 4 lines
We need that at this stage as we haven't added the "accel" property yet and that will cause "make check" tests to fail without that.
We remove it once we introduce "accel" property later.
Hmm, I assume
object_property_get_bool()would return false when "accel" is not available yet? No?
Quoted 6 lines
It is the errp that will be set if there is no "accel" is available that will fail the tests. Another way to avoid
object_property_find()is to pass NULL for errp inobject_property_get_bool(), but I think again when we introduce "accel" we have change that into either errp/error_abort here.I am not sure there is any other way to handle this.
This path is to set MSI GPA, which could be optional, right? So, we don't really need to exit when accel is not found or accel is set to "n".
In that case, could we just use NULL even when "accel" is added? Why do we use error_abort or errp?
Nicolin
RE: [PATCH v6 17/33] hw/arm/smmuv3: Add support for providing a direct MSI doorbell GPA
Quoted 40 lines
-----Original Message-----
From: Nicolin Chen <[email protected]>
Sent: 24 November 2025 18:34
To: Shameer Kolothum <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 17/33] hw/arm/smmuv3: Add support for providing a direct MSI doorbell GPAQuoted 2 lines · Shameer Kolothum
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (object_property_find(OBJECT(dev), "accel") && + object_property_get_bool(OBJECT(dev), "accel",
&error_abort)) {Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Do we need
object_property_find()? A later patch seems to drop it. Perhaps we shouldn't add it in the first place?We need that at this stage as we haven't added the "accel" property yet and that will cause "make check" tests to fail without that.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
We remove it once we introduce "accel" property later.
Hmm, I assume
object_property_get_bool()would return false when "accel" is not available yet? No?It is the errp that will be set if there is no "accel" is available that will fail the tests. Another way to avoid
object_property_find()is to pass NULL for errpin
Quoted 1 line
object_property_get_bool(), but I think again when we introduce "accel" wehave
Quoted 2 lines
change that into either errp/error_abort here.
Quoted 8 lines
Quoted 1 line
I am not sure there is any other way to handle this.
This path is to set MSI GPA, which could be optional, right? So, we don't really need to exit when accel is not found or accel is set to "n".
In that case, could we just use NULL even when "accel" is added? Why do we use
error_abortor errp?
I cant recollect why I used error_abort here in the first place. May be since we used that for the "primary-bus" above. But as you said, we could argue "accel" is optional property. However, if we pass NULL and then for some other reason it fails(even if accel=on), we will end up ignoring the error completely and silently boot without "accel" ?
The object_property_get_bool(..., &error_abort) is used in virt-acpi-build.c as well.
Still not sure "NULL" is a good idea or not.
Thanks,
Shameer
Re: [PATCH v6 17/33] hw/arm/smmuv3: Add support for providing a direct MSI doorbell GPA
Quoted 32 lines · Shameer Kolothum
Quoted 23 lines · Shameer Kolothum
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (object_property_find(OBJECT(dev), "accel") && + object_property_get_bool(OBJECT(dev), "accel",
&error_abort)) {Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Do we need
object_property_find()? A later patch seems to drop it. Perhaps we shouldn't add it in the first place?We need that at this stage as we haven't added the "accel" property yet and that will cause "make check" tests to fail without that.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
We remove it once we introduce "accel" property later.
Hmm, I assume
object_property_get_bool()would return false when "accel" is not available yet? No?It is the errp that will be set if there is no "accel" is available that will fail the tests. Another way to avoid
object_property_find()is to pass NULL for errpin
Quoted 1 line
object_property_get_bool(), but I think again when we introduce "accel" wehave
Quoted 2 lines
change that into either errp/error_abort here.
Quoted 8 lines
Quoted 1 line
I am not sure there is any other way to handle this.
This path is to set MSI GPA, which could be optional, right? So, we don't really need to exit when accel is not found or accel is set to "n".
In that case, could we just use NULL even when "accel" is added? Why do we use
error_abortor errp?
Quoted 6 lines
I cant recollect why I used
error_aborthere in the first place. May be since we used that for the "primary-bus" above. But as you said, we could argue "accel" is optional property. However, if we pass NULL and then for some other reason it fails(even if accel=on), we will end up ignoring the error completely and silently boot without "accel" ?
OK. I see now..
What we want are:
1) When "accel" isn't defined, don't abort it by calling that object_property_find() to make msi-gpa optional.
2) When "accel" is defined, remove the object_property_find() because object_property_get_bool() will never abort. And it will make the msi-gpa optional depending on accel=on/off.
Perhaps we should re-organize the patch sequence, putting the MSI one later. Checking the "accel" before we introduce it is a bit odd. But any way, I think we are fine here, if you don't want to change.
Thanks
Nicolin
Re: [PATCH v6 17/33] hw/arm/smmuv3: Add support for providing a direct MSI doorbell GPA
In reply to Shameer KolothumQuoted 12 lines · Shameer Kolothum
Accelerated SMMUv3 instances rely on the physical SMMUv3 for nested translation (Guest Stage-1, Host Stage-2). In this mode the guest’s Stage-1 tables are programmed directly into hardware, and QEMU should not attempt to walk them for translation since doing so is not reliably safe. For vfio-pci endpoints behind such a vSMMU, the only translation QEMU is responsible for is the MSI doorbell used during KVM MSI setup.
Add a device property to carry the MSI doorbell GPA from the virt machine, and expose it through a new
get_msi_direct_gpaPCIIOMMUOp.kvm_arch_fixup_msi_route()can then use this GPA directly instead of attempting a software walk of guest translation tables.
Quoted 6 lines
This enables correct MSI routing with accelerated SMMUv3 while avoiding unsafe accesses to page tables.
For meaningful use of vfio-pci devices with accelerated SMMUv3, both KVM and a kernel irqchip are required. Enforce this requirement when accel=on is selected.
There are multiple changes in one patch. I suggest splitting.
Quoted 55 lines
Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.c | 10 ++++++++++ hw/arm/smmuv3.c | 2 ++ hw/arm/virt.c | 22 ++++++++++++++++++++++ include/hw/arm/smmuv3.h | 1 + 4 files changed, 35 insertions(+)hw/arm/smmuv3-accel.c +10
-0@@ -392,6 +392,15 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bus, void *opaque, } } +static uint64_t smmuv3_accel_get_msi_gpa (PCIBus *bus,void *opaque,int devfn) +{ +SMMUState *bs = opaque; +SMMUv3State *s =ARM_SMMUV3 (bs); + +g_assert (s->msi_gpa); +return s->msi_gpa; +} +/* * Only allow PCIe bridges, pxb-pcie roots, and GPEX roots so vfio-pci * endpoints can sit downstream. Accelerated SMMUv3 requires a vfio-pci @@ -496,6 +505,7 @@ static const PCIIOMMUOps smmuv3_accel_ops = { .get_viommu_flags = smmuv3_accel_get_viommu_flags, .set_iommu_device = smmuv3_accel_set_iommu_device, .unset_iommu_device = smmuv3_accel_unset_iommu_device, + .get_msi_direct_gpa = smmuv3_accel_get_msi_gpa, };/* Based on SMUUv3 GPBA.ABORT configuration, attach a corresponding HWPT */ hw/arm/smmuv3.c +2
-0@@ -1998,6 +1998,8 @@ static const Property smmuv3_properties[] = {* Defaults to stage 1 */ DEFINE_PROP_STRING ("stage" , SMMUv3State, stage), +/* GPA of MSI doorbell, for SMMUv3 accel use. */ + DEFINE_PROP_UINT64("msi-gpa", SMMUv3State, msi_gpa, 0), };static void smmuv3_instance_init (Object *obj)hw/arm/virt.c +0
-0
hw/arm/virt.c static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, · line 3060
Quoted 9 lines
hw/arm/virt.c +6
-0@@ -3052,6 +3052,14 @@ static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,/* The new SMMUv3 device is specific to the PCI bus */ object_property_set_bool (OBJECT (dev),"smmu_per_bus" , true,NULL ); } +if (object_property_find (OBJECT (dev),"accel" ) && +object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) { +if (!kvm_enabled () || !kvm_irqchip_in_kernel ()) { +error_setg (errp,"SMMUv3 accel=on requires KVM with " +"kernel-irqchip=on support" ); +return ;
Couldn't these checks be done in the "smmuv3-accel" model realize handler instead ?
Quoted 12 lines
hw/arm/virt.c +5
-0+ } + } } }@@ -3088,6 +3096,20 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, }create_smmuv3_dev_dtb (vms, dev, bus); +if (object_property_find (OBJECT (dev),"accel" ) && +object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) { +hwaddr db_start;
hw/arm/virt.c static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, · line 3111
Quoted 10 lines
hw/arm/virt.c +10
-0+ +if (vms->msi_controller ==VIRT_MSI_CTRL_ITS ) { +/* GITS_TRANSLATER page + offset */ + db_start = base_memmap[VIRT_GIC_ITS ].base +0x10000 +0x40 ; + }else { +/* MSI_SETSPI_NS page + offset */ + db_start = base_memmap[VIRT_GIC_V2M ].base +0x40 ; + } +object_property_set_uint (OBJECT (dev),"msi-gpa" , db_start, + &error_abort);
IIRC, this plug handler is called after the device realize handler and setting properties after realize is strongly discouraged.
C.
Quoted 16 lines
hw/arm/virt.c +1
-0+ } } }include/hw/arm/smmuv3.h +1
-0@@ -67,6 +67,7 @@ struct SMMUv3State {/* SMMU has HW accelerator support for nested S1 + s2 */ bool accel;struct SMMUv3AccelState *s_accel; +uint64_t msi_gpa; }; typedef enum {
RE: [PATCH v6 17/33] hw/arm/smmuv3: Add support for providing a direct MSI doorbell GPA
Quoted 33 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: 11 December 2025 14:04
To: Shameer Kolothum <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 17/33] hw/arm/smmuv3: Add support for providing a direct MSI doorbell GPAExternal email: Use caution opening links or attachments
Quoted 12 lines · Shameer Kolothum
Accelerated SMMUv3 instances rely on the physical SMMUv3 for nested translation (Guest Stage-1, Host Stage-2). In this mode the guest’s Stage-1 tables are programmed directly into hardware, and QEMU should not attempt to walk them for translation since doing so is not reliably safe. For vfio-pci endpoints behind such a vSMMU, the only translation QEMU is responsible for is the MSI doorbell used during KVM MSI setup.
Add a device property to carry the MSI doorbell GPA from the virt machine, and expose it through a new
get_msi_direct_gpaPCIIOMMUOp.kvm_arch_fixup_msi_route()can then use this GPA directly instead of attempting a software walk of guest translation tables.
Quoted 8 lines
Quoted 6 lines
This enables correct MSI routing with accelerated SMMUv3 while avoiding unsafe accesses to page tables.
For meaningful use of vfio-pci devices with accelerated SMMUv3, both KVM and a kernel irqchip are required. Enforce this requirement when accel=on is selected.
There are multiple changes in one patch. I suggest splitting.
Ok.
Quoted 70 lines
hw/arm/smmuv3-accel.c static void
Quoted 14 lines
Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.c | 10 ++++++++++ hw/arm/smmuv3.c | 2 ++ hw/arm/virt.c | 22 ++++++++++++++++++++++ include/hw/arm/smmuv3.h | 1 + 4 files changed, 35 insertions(+)hw/arm/smmuv3-accel.c +0
-0@@ -392,6 +392,15 @@ static voidsmmuv3_accel_unset_iommu_device(PCIBus *bus, void *opaque,
hw/arm/smmuv3-accel.c static void · line 395
Quoted 4 lines
hw/arm/smmuv3-accel.c +1
-0} } +static uint64_t smmuv3_accel_get_msi_gpa(PCIBus *bus, void *opaque, intdevfn)
Quoted 12 lines
hw/arm/smmuv3-accel.c +8
-0+{ +SMMUState *bs = opaque; +SMMUv3State *s =ARM_SMMUV3 (bs); + +g_assert (s->msi_gpa); +return s->msi_gpa; +} +/* * Only allow PCIe bridges, pxb-pcie roots, and GPEX roots so vfio-pci * endpoints can sit downstream. Accelerated SMMUv3 requires a vfio-pci hw/arm/smmuv3-accel.c static const PCIIOMMUOps smmuv3_accel_ops = { · line 511
Quoted 7 lines
hw/arm/smmuv3-accel.c +1
-0@@ -496,6 +505,7 @@ static const PCIIOMMUOps smmuv3_accel_ops = { .get_viommu_flags = smmuv3_accel_get_viommu_flags, .set_iommu_device = smmuv3_accel_set_iommu_device, .unset_iommu_device = smmuv3_accel_unset_iommu_device, + .get_msi_direct_gpa = smmuv3_accel_get_msi_gpa, };/* Based on SMUUv3 GPBA.ABORT configuration, attach a corresponding HWPT */
hw/arm/virt.c static void
Quoted 18 lines
hw/arm/smmuv3.c +2
-0@@ -1998,6 +1998,8 @@ static const Property smmuv3_properties[] = {* Defaults to stage 1 */ DEFINE_PROP_STRING ("stage" , SMMUv3State, stage), +/* GPA of MSI doorbell, for SMMUv3 accel use. */ + DEFINE_PROP_UINT64("msi-gpa", SMMUv3State, msi_gpa, 0), };static void smmuv3_instance_init (Object *obj)hw/arm/virt.c +0
-0@@ -3052,6 +3052,14 @@ static voidvirt_machine_device_pre_plug_cb(HotplugHandler
*hotplug_dev,hw/arm/virt.c static void · line 3053
Quoted 2 lines
hw/arm/virt.c +0
-0/* The new SMMUv3 device is specific to the PCI bus */ object_property_set_bool(OBJECT(dev), "smmu_per_bus", true,NULL);
hw/arm/virt.c static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, · line 3060
Quoted 7 lines
hw/arm/virt.c +6
-0} +if (object_property_find (OBJECT (dev),"accel" ) && +object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) { +if (!kvm_enabled () || !kvm_irqchip_in_kernel ()) { +error_setg (errp,"SMMUv3 accel=on requires KVM with " +"kernel-irqchip=on support" ); +return ;
Quoted 2 lines
Couldn't these checks be done in the "smmuv3-accel" model realize handler instead ?
Could do I guess. I placed it here thinking pre_plug is before realize(), allowing an early exit. But probably realize is better as that will cover all future machine types as well(if any).
Quoted 26 lines
hw/arm/virt.c static void
Quoted 7 lines
hw/arm/virt.c +2
-0+ } + } } }@@ -3088,6 +3096,20 @@ static voidvirt_machine_device_plug_cb(HotplugHandler
*hotplug_dev,hw/arm/virt.c static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev,
Quoted 10 lines
hw/arm/virt.c +7
-0}create_smmuv3_dev_dtb (vms, dev, bus); +if (object_property_find (OBJECT (dev),"accel" ) && +object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) { +hwaddr db_start; + +if (vms->msi_controller ==VIRT_MSI_CTRL_ITS ) { +/* GITS_TRANSLATER page + offset */ + db_start = base_memmap[VIRT_GIC_ITS].base + 0x10000 +
0x40;hw/arm/virt.c static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, · line 3111
Quoted 6 lines
hw/arm/virt.c +6
-0+ }else { +/* MSI_SETSPI_NS page + offset */ + db_start = base_memmap[VIRT_GIC_V2M ].base +0x40 ; + } +object_property_set_uint (OBJECT (dev),"msi-gpa" , db_start, + &error_abort);
Quoted 2 lines
IIRC, this plug handler is called after the device realize handler and setting properties after realize is strongly discouraged.
Looking at this again, I think this can be moved to pre_plug handler.
Thanks,
Shameer
Re: [PATCH v6 17/33] hw/arm/smmuv3: Add support for providing a direct MSI doorbell GPA
In reply to Cédric Le Goater viaQuoted 86 lines · Cédric Le Goater
Quoted 12 lines · Shameer Kolothum
Accelerated SMMUv3 instances rely on the physical SMMUv3 for nested translation (Guest Stage-1, Host Stage-2). In this mode the guest’s Stage-1 tables are programmed directly into hardware, and QEMU should not attempt to walk them for translation since doing so is not reliably safe. For vfio-pci endpoints behind such a vSMMU, the only translation QEMU is responsible for is the MSI doorbell used during KVM MSI setup.
Add a device property to carry the MSI doorbell GPA from the virt machine, and expose it through a new
get_msi_direct_gpaPCIIOMMUOp.kvm_arch_fixup_msi_route()can then use this GPA directly instead of attempting a software walk of guest translation tables.Quoted 7 lines
This enables correct MSI routing with accelerated SMMUv3 while avoiding unsafe accesses to page tables.
For meaningful use of vfio-pci devices with accelerated SMMUv3, both KVM and a kernel irqchip are required. Enforce this requirement when accel=on
is selected.There are multiple changes in one patch. I suggest splitting.
Quoted 63 lines
Signed-off-by Shameer Kolothum <[email protected]>---
hw/arm/smmuv3-accel.c | 10 ++++++++++ hw/arm/smmuv3.c | 2 ++ hw/arm/virt.c | 22 ++++++++++++++++++++++include/hw/arm/smmuv3.h| 1 +4 files changed, 35 insertions(+)hw/arm/smmuv3-accel.c +0
-0@@ -392,6 +392,15 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bus, void *opaque, } }+static
uint64_tsmmuv3_accel_get_msi_gpa(PCIBus *bus, void *opaque, int devfn)hw/arm/smmuv3-accel.c +8
-0+{ + SMMUState *bs = opaque; + SMMUv3State *s = ARM_SMMUV3(bs); + + g_assert(s->msi_gpa); + return s->msi_gpa; +} +/*
* Only allow PCIe bridges, pxb-pcie roots, and GPEX roots so vfio-pci
* endpoints can sit downstream. Accelerated SMMUv3 requires a vfio-pcihw/arm/smmuv3-accel.c +1
-0@@ -496,6 +505,7 @@ static const PCIIOMMUOps smmuv3_accel_ops = { .get_viommu_flags = smmuv3_accel_get_viommu_flags, .set_iommu_device = smmuv3_accel_set_iommu_device, .unset_iommu_device = smmuv3_accel_unset_iommu_device, + .get_msi_direct_gpa = smmuv3_accel_get_msi_gpa, }; /* Based on SMUUv3 GPBA.ABORT configuration, attach acorresponding HWPT */
hw/arm/smmuv3.c +2
-0@@ -1998,6 +1998,8 @@ static const Property smmuv3_properties[] = {* Defaults to stage 1 */ DEFINE_PROP_STRING("stage", SMMUv3State, stage), + /* GPA of MSI doorbell, for SMMUv3 accel use. */ + DEFINE_PROP_UINT64("msi-gpa", SMMUv3State, msi_gpa, 0), }; static void smmuv3_instance_init(Object *obj)hw/arm/virt.c +2
-0@@ -3052,6 +3052,14 @@ static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, /* The new SMMUv3 device is specific to the PCI bus */ object_property_set_bool(OBJECT(dev), "smmu_per_bus", true, NULL); } + if (object_property_find(OBJECT(dev), "accel") && + object_property_get_bool(OBJECT(dev), "accel",
Quoted 8 lines
hw/arm/virt.c static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, · line 3060
Quoted 5 lines
hw/arm/virt.c +4
-0&error_abort)) { + if (!kvm_enabled() || !kvm_irqchip_in_kernel()) { + error_setg(errp, "SMMUv3 accel=on requires KVM with " + "kernel-irqchip=on support"); + return;Couldn't these checks be done in the "smmuv3-accel" model realize handler instead ?
currently smmuv3-accel has no kvm adherence. If you look at virt machine code, there are quite a lot of similar checks for various other devices so it does not strongly shock me. Nevertheless I have no strong opinion.
Thanks
Eric
Quoted 47 lines
Quoted 16 lines
hw/arm/virt.c +2
-0+ } + }}
}
@@ -3088,6 +3096,20 @@ static void virt_machine_device_plug_cb(HotplugHandler*hotplug_dev, }
create_smmuv3_dev_dtb(vms, dev, bus); + if (object_property_find(OBJECT(dev), "accel")&& +object_property_get_bool(OBJECT(dev), "accel", &error_abort)) {
+ hwaddrdb_start;
+
+ if (vms->msi_controller==VIRT_MSI_CTRL_ITS) { + /*GITS_TRANSLATERpage + offset */ +db_start= base_memmap[VIRT_GIC_ITS].base +Quoted 8 lines
0x10000+0x40;
+ } else {
+ /*MSI_SETSPI_NSpage + offset */
+db_start= base_memmap[VIRT_GIC_V2M].base +0x40; + }
+ object_property_set_uint(OBJECT(dev), "msi-gpa",db_start,
+&error_abort);IIRC, this plug handler is called after the device realize handler and setting properties after realize is strongly discouraged.
C.
Quoted 14 lines
+ }
}
}
diff --gita/include/hw/arm/smmuv3.hb/include/hw/arm/smmuv3.hindexe54ece2d38..5616a8a2be100644include/hw/arm/smmuv3.h +1
-0@@ -67,6 +67,7 @@ struct SMMUv3State { /* SMMU has HW accelerator support for nested S1 + s2 */ bool accel; struct SMMUv3AccelState *s_accel; + uint64_t msi_gpa; }; typedef enum {
PATCH v6 18/33 hw/arm/smmuv3-accel: Add support to issue invalidation cmd to host
In reply to Shameer KolothumProvide a helper and use that to issue the invalidation cmd to host SMMUv3. We only issue one cmd at a time for now.
Support for batching of commands will be added later after analysing the impact.
--- hw/arm/smmuv3-accel.c | 36 ++++++++++++++++++++++++++++++++++++ hw/arm/smmuv3-accel.h | 8 ++++++++ hw/arm/smmuv3.c | 16 ++++++++++++++++ 3 files changed, 60 insertions(+)
hw/arm/smmuv3-accel.c +36 -0
@@ -233,6 +233,42 @@ bool smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange *range,return all_ok; } +/* +* This issues the invalidation cmd to the host SMMUv3. +* +* sdev is non-NULL for SID based invalidations (e.g. CFGI_CD), and NULL for +* non SID invalidations such as SMMU_CMD_TLBI_NH_ASID and SMMU_CMD_TLBI_NH_VA. +*/ +bool smmuv3_accel_issue_inv_cmd (SMMUv3State *bs,void *cmd,SMMUDevice *sdev, +Error **errp) +{ +SMMUv3State *s =ARM_SMMUV3 (bs); +SMMUv3AccelState *accel = s->s_accel; +uint32_t entry_num =1 ; + +/* +* No SMMUv3AccelState means no VFIO/IOMMUFD devices, nothing to +* invalidate. +*/ +if (!accel) { +return true; + } + +/* +* SID based invalidations (e.g. CFGI_CD) apply only to vfio-pci endpoints +* with a valid vIOMMU vdev. +*/ +if (sdev && !container_of (sdev, SMMUv3AccelDevice, sdev)->vdev) { +return true; + } + +/* Single command (entry_num = 1); no need to check returned entry_num */ +return iommufd_backend_invalidate_cache ( + accel->viommu.iommufd, accel->viommu.viommu_id, +IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3 , +sizeof (Cmd), &entry_num, cmd, errp); +} +static bool smmuv3_accel_alloc_viommu (SMMUv3State *s,HostIOMMUDeviceIOMMUFD *idev,Error **errp)
hw/arm/smmuv3-accel.h +8 -0
@@ -45,6 +45,8 @@ bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevice *sdev, int sid,bool smmuv3_accel_install_ste_range (SMMUv3State *s,SMMUSIDRange *range,Error **errp);bool smmuv3_accel_attach_gbpa_hwpt (SMMUv3State *s,Error **errp); +bool smmuv3_accel_issue_inv_cmd (SMMUv3State *s,void *cmd,SMMUDevice *sdev, +Error **errp);void smmuv3_accel_reset (SMMUv3State *s);#else static inline void smmuv3_accel_init (SMMUv3State *s)
@@ -66,6 +68,12 @@ static inline bool smmuv3_accel_attach_gbpa_hwpt(SMMUv3State *s, Error **errp) {return true; } +static inline bool +smmuv3_accel_issue_inv_cmd (SMMUv3State *s,void *cmd,SMMUDevice *sdev, +Error **errp) +{ +return true; +}static inline void smmuv3_accel_reset (SMMUv3State *s) { }
hw/arm/smmuv3.c +16 -0
@@ -1388,6 +1388,10 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp)trace_smmuv3_cmdq_cfgi_cd (sid);smmuv3_flush_config (sdev); +if (!smmuv3_accel_issue_inv_cmd (s, &cmd, sdev, errp)) { + cmd_error =SMMU_CERROR_ILL ; +break ; + }break ; }case SMMU_CMD_TLBI_NH_ASID :
@@ -1411,6 +1415,10 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp)trace_smmuv3_cmdq_tlbi_nh_asid (asid);smmu_inv_notifiers_all (&s->smmu_state);smmu_iotlb_inv_asid_vmid (bs, asid, vmid); +if (!smmuv3_accel_issue_inv_cmd (s, &cmd,NULL , errp)) { + cmd_error =SMMU_CERROR_ILL ; +break ; + }break ; }case SMMU_CMD_TLBI_NH_ALL :
@@ -1438,6 +1446,10 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp)trace_smmuv3_cmdq_tlbi_nsnh ();smmu_inv_notifiers_all (&s->smmu_state);smmu_iotlb_inv_all (bs); +if (!smmuv3_accel_issue_inv_cmd (s, &cmd,NULL , errp)) { + cmd_error =SMMU_CERROR_ILL ; +break ; + }break ;case SMMU_CMD_TLBI_NH_VAA :case SMMU_CMD_TLBI_NH_VA :
@@ -1446,6 +1458,10 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp)break ; }smmuv3_range_inval (bs, &cmd,SMMU_STAGE_1 ); +if (!smmuv3_accel_issue_inv_cmd (s, &cmd,NULL , errp)) { + cmd_error =SMMU_CERROR_ILL ; +break ; + }break ;case SMMU_CMD_TLBI_S12_VMALL : {
Signature · 1 line
2.43.0
PATCH v6 19/33 hw/arm/smmuv3: Initialize ID registers early during realize()
In reply to Shameer KolothumFactor out ID register init into smmuv3_init_id_regs() and call it from realize(). This ensures ID registers are initialized early for use in the accelerated SMMUv3 path and will be utilized in subsequent patch.
Other registers remain initialized in smmuv3_reset().
--- hw/arm/smmuv3.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
hw/arm/smmuv3.c +12 -3
@@ -258,7 +258,12 @@ void smmuv3_record_event(SMMUv3State *s, SMMUEventInfo *info) info->recorded = true; } -static void smmuv3_init_regs (SMMUv3State *s) +/* +* Called during realize(), as the ID registers will be accessed early in the +* SMMUv3 accel path for feature compatibility checks. The remaining registers +* are initialized later in smmuv3_reset(). +*/ +static void smmuv3_init_id_regs (SMMUv3State *s) {/* Based on sys property, the stages supported in smmu will be advertised.*/ if (s->stage && !strcmp ("2" , s->stage)) {
@@ -298,7 +303,11 @@ static void smmuv3_init_regs(SMMUv3State *s) s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN4K ,1 ); s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN16K ,1 ); s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN64K ,1 ); + s->aidr =0x1 ; +} +static void smmuv3_reset (SMMUv3State *s) +{ s->cmdq.base =deposit64 (s->cmdq.base,0 ,5 ,SMMU_CMDQS ); s->cmdq.prod =0 ; s->cmdq.cons =0 ;
@@ -310,7 +319,6 @@ static void smmuv3_init_regs(SMMUv3State *s) s->features =0 ; s->sid_split =0 ; - s->aidr =0x1 ; s->cr[0 ] =0 ; s->cr0ack =0 ; s->irq_ctrl =0 ;
@@ -1903,7 +1911,7 @@ static void smmu_reset_exit(Object *obj, ResetType type) c->parent_phases.exit (obj, type); } -smmuv3_init_regs (s); +smmuv3_reset (s);smmuv3_accel_reset (s); }
@@ -1935,6 +1943,7 @@ static void smmu_realize(DeviceState *d, Error **errp)sysbus_init_mmio (dev, &sys->iomem);smmu_init_irq (s, dev); +smmuv3_init_id_regs (s); }static const VMStateDescription vmstate_smmuv3_queue = {
Signature · 1 line
2.43.0
PATCH v6 20/33 hw/arm/smmuv3-accel: Get host SMMUv3 hw info and validate
In reply to Shameer KolothumJust before the device gets attached to the SMMUv3, make sure QEMU SMMUv3 features are compatible with the host SMMUv3.
Not all fields in the host SMMUv3 IDR registers are meaningful for userspace. Only the following fields can be used:
- IDR0: ST_LEVEL, TERM_MODEL, STALL_MODEL, TTENDIAN, CD2L, ASID16, TTF
- IDR1: SIDSIZE, SSIDSIZE
- IDR3: BBML, RIL
- IDR5: VAX, GRAN64K, GRAN16K, GRAN4K
For now, the check is to make sure the features are in sync to enable basic accelerated SMMUv3 support. AIDR is not checked, as hardware implementations often provide a mix of architecture features regardless of the revision reported in AIDR.
Note that SSIDSIZE check will be added later when support for PASID is introduced.
--- hw/arm/smmuv3-accel.c | 95 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+)
hw/arm/smmuv3-accel.c +95 -0
@@ -27,6 +27,93 @@static MemoryRegion root, sysmem;static AddressSpace *shared_as_sysmem; +static bool +smmuv3_accel_check_hw_compatible (SMMUv3State *s, +struct iommu_hw_info_arm_smmuv3 *info, +Error **errp) +{ +/* QEMU SMMUv3 supports both linear and 2-level stream tables */ +if (FIELD_EX32 (info->idr[0 ],IDR0 ,STLEVEL ) != +FIELD_EX32 (s->idr[0 ],IDR0 ,STLEVEL )) { +error_setg (errp,"Host SMMUv3 differs in Stream Table format" ); +return false; + } + +/* QEMU SMMUv3 supports only little-endian translation table walks */ +if (FIELD_EX32 (info->idr[0 ],IDR0 ,TTENDIAN ) > +FIELD_EX32 (s->idr[0 ],IDR0 ,TTENDIAN )) { +error_setg (errp,"Host SMMUv3 doesn't support Little-endian " +"translation table" ); +return false; + } + +/* QEMU SMMUv3 supports only AArch64 translation table format */ +if (FIELD_EX32 (info->idr[0 ],IDR0 ,TTF ) < +FIELD_EX32 (s->idr[0 ],IDR0 ,TTF )) { +error_setg (errp,"Host SMMUv3 doesn't support AArch64 translation " +"table format" ); +return false; + } + +/* QEMU SMMUv3 supports SIDSIZE 16 */ +if (FIELD_EX32 (info->idr[1 ],IDR1 ,SIDSIZE ) < +FIELD_EX32 (s->idr[1 ],IDR1 ,SIDSIZE )) { +error_setg (errp,"Host SMMUv3 SIDSIZE not compatible" ); +return false; + } + +/* QEMU SMMUv3 supports Range Invalidation by default */ +if (FIELD_EX32 (info->idr[3 ],IDR3 ,RIL ) != +FIELD_EX32 (s->idr[3 ],IDR3 ,RIL )) { +error_setg (errp,"Host SMMUv3 doesn't support Range Invalidation" ); +return false; + } + +/* QEMU SMMUv3 supports GRAN4K/GRAN16K/GRAN64K translation granules */ +if (FIELD_EX32 (info->idr[5 ],IDR5 ,GRAN4K ) != +FIELD_EX32 (s->idr[5 ],IDR5 ,GRAN4K )) { +error_setg (errp,"Host SMMUv3 doesn't support 4K translation granule" ); +return false; + } +if (FIELD_EX32 (info->idr[5 ],IDR5 ,GRAN16K ) != +FIELD_EX32 (s->idr[5 ],IDR5 ,GRAN16K )) { +error_setg (errp,"Host SMMUv3 doesn't support 16K translation granule" ); +return false; + } +if (FIELD_EX32 (info->idr[5 ],IDR5 ,GRAN64K ) != +FIELD_EX32 (s->idr[5 ],IDR5 ,GRAN64K )) { +error_setg (errp,"Host SMMUv3 doesn't support 64K translation granule" ); +return false; + } + +return true; +} + +static bool +smmuv3_accel_hw_compatible (SMMUv3State *s,HostIOMMUDeviceIOMMUFD *idev, +Error **errp) +{ +struct iommu_hw_info_arm_smmuv3 info; +uint32_t data_type; +uint64_t caps; + +if (!iommufd_backend_get_device_info (idev->iommufd, idev->devid, &data_type, + &info,sizeof (info), &caps, errp)) { +return false; + } + +if (data_type !=IOMMU_HW_INFO_TYPE_ARM_SMMUV3 ) { +error_setg (errp,"Wrong data type (%d) for Host SMMUv3 device info" , + data_type); +return false; + } + +if (!smmuv3_accel_check_hw_compatible (s, &info, errp)) { +return false; + } +return true; +} +static SMMUv3AccelDevice *smmuv3_accel_get_dev (SMMUState *bs,SMMUPciBus *sbus,PCIBus *bus,int devfn) {
@@ -352,6 +439,14 @@ static bool smmuv3_accel_set_iommu_device(PCIBus *bus, void *opaque, int devfn,return true; } +/* +* Check the host SMMUv3 associated with the dev is compatible with the +* QEMU SMMUv3 accel. +*/ +if (!smmuv3_accel_hw_compatible (s, idev, errp)) { +return false; + } +if (s->s_accel) { goto done; }
Signature · 1 line
2.43.0
Re: [PATCH v6 20/33] hw/arm/smmuv3-accel: Get host SMMUv3 hw info and validate
hw/arm/smmuv3-accel.c line 69
Quoted 5 lines · Shameer Kolothum
hw/arm/smmuv3-accel.c +5
-0+/* QEMU SMMUv3 supports Range Invalidation by default */ +if (FIELD_EX32 (info->idr[3 ],IDR3 ,RIL ) != +FIELD_EX32 (s->idr[3 ],IDR3 ,RIL )) { +error_setg (errp,"Host SMMUv3 doesn't support Range Invalidation" ); +return false;
If host reports info->ril=1 while VM sets s->ril=0, it could have worked. But this would reject the case.
I think it should be:
if (FIELD_EX32(info->idr[3], IDR3, RIL) <
FIELD_EX32(s->idr[3], IDR3, RIL)) {?
Nicolin
Re: [PATCH v6 20/33] hw/arm/smmuv3-accel: Get host SMMUv3 hw info and validate
Quoted 7 lines · Nicolin Chen
hw/arm/smmuv3-accel.c line 69
Quoted 5 lines · Shameer Kolothum
hw/arm/smmuv3-accel.c +5
-0+/* QEMU SMMUv3 supports Range Invalidation by default */ +if (FIELD_EX32 (info->idr[3 ],IDR3 ,RIL ) != +FIELD_EX32 (s->idr[3 ],IDR3 ,RIL )) { +error_setg (errp,"Host SMMUv3 doesn't support Range Invalidation" ); +return false;
Quoted 7 lines
If host reports info->ril=1 while VM sets s->ril=0, it could have worked. But this would reject the case.
I think it should be:
if (FIELD_EX32(info->idr[3], IDR3, RIL) < FIELD_EX32(s->idr[3], IDR3, RIL)) {?
Never mind. I realized that you are doing in a followup patch :)
Nicolin
PATCH v6 21/33 hw/pci-host/gpex: Allow to generate preserve boot config DSM #5
In reply to Shameer KolothumFrom: Eric Auger <[email protected]>
Add a 'preserve_config' field in struct GPEXConfig and, if set, generate the _DSM function #5 for preserving PCI boot configurations.
This will be used for SMMUv3 accel=on support in subsequent patch. When SMMUv3 acceleration (accel=on) is enabled, QEMU exposes IORT Reserved Memory Region (RMR) nodes to support MSI doorbell translations. As per the Arm IORT specification, using IORT RMRs mandates the presence of _DSM function #5 so that the OS retains the firmware-assigned PCI configuration. Hence, this patch adds conditional support for generating _DSM #5.
According to the ACPI Specification, Revision 6.6, Section 9.1.1 - “_DSM (Device Specific Method)”,
"
If Function Index is zero, the return is a buffer containing one bit for each function index, starting with zero. Bit 0 indicates whether there is support for any functions other than function 0 for the specified UUID and Revision ID. If set to zero, no functions are supported (other than function zero) for the specified UUID and Revision ID. If set to one, at least one additional function is supported. For all other bits in the buffer, a bit is set to zero to indicate if that function index is not supported for the specific UUID and Revision ID. (For example, bit 1 set to 0 indicates that function index 1 is not supported for the specific UUID and Revision ID.)
"
Please refer PCI Firmware Specification, Revision 3.3, Section 4.6.5 — "_DSM for Preserving PCI Boot Configurations" for Function 5 of _DSM method.
Also, while at it, move the byte_list declaration to the top of the function for clarity.
At the moment, DSM generation is not yet enabled.
The resulting AML when preserve_config=true is:
Method (_DSM, 4, NotSerialized)
{
If ((Arg0 == ToUUID ("e5c937d0-3553-4d7a-9117-ea4d19c3434d")))
{
If ((Arg2 == Zero))
{
Return (Buffer (One)
{
0x21
})
}
If ((Arg2 == 0x05))
{
Return (Zero)
}
}
...
}---
Previously, QEMU reverted an attempt to enable DSM #5 because it caused a regression,
https://lore.kernel.org/all/[email protected]/.
However, in this series, we enable it selectively, only when SMMUv3 is in accelerator mode. The devices involved in the earlier regression are not expected in accelerated SMMUv3 use cases.
--- hw/pci-host/gpex-acpi.c | 29 +++++++++++++++++++++++------ include/hw/pci-host/gpex.h | 1 + 2 files changed, 24 insertions(+), 6 deletions(-)
hw/pci-host/gpex-acpi.c +23 -6
@@ -51,10 +51,11 @@ static void acpi_dsdt_add_pci_route_table(Aml *dev, uint32_t irq, } } -static Aml *build_pci_host_bridge_dsm_method (void ) +static Aml *build_pci_host_bridge_dsm_method (bool preserve_config) {Aml *method =aml_method ("_DSM" ,4 ,AML_NOTSERIALIZED );Aml *UUID , *ifctx, *ifctx1, *buf; +uint8_t byte_list[1 ] = {0 };/* PCI Firmware Specification 3.0 * 4.6.1. _DSM for PCI Express Slot Information
@@ -64,10 +65,23 @@ static Aml *build_pci_host_bridge_dsm_method(void)UUID =aml_touuid ("E5C937D0-3553-4D7A-9117-EA4D19C3434D" ); ifctx =aml_if (aml_equal (aml_arg (0 ),UUID )); ifctx1 =aml_if (aml_equal (aml_arg (2 ),aml_int (0 ))); -uint8_t byte_list[1 ] = {0 }; +if (preserve_config) { +/* support functions other than 0, specifically function 5 */ + byte_list[0 ] =0x21 ; + } buf =aml_buffer (1 , byte_list);aml_append (ifctx1,aml_return (buf));aml_append (ifctx, ifctx1); +if (preserve_config) { +Aml *ifctx2 =aml_if (aml_equal (aml_arg (2 ),aml_int (5 ))); +/* +* 0 - The operating system must not ignore the PCI configuration that +* firmware has done at boot time. +*/ +aml_append (ifctx2,aml_return (aml_int (0 ))); +aml_append (ifctx, ifctx2); + } +aml_append (method, ifctx); byte_list[0 ] =0 ;
@@ -77,12 +91,13 @@ static Aml *build_pci_host_bridge_dsm_method(void) }static void acpi_dsdt_add_host_bridge_methods (Aml *dev, -bool enable_native_pcie_hotplug) +bool enable_native_pcie_hotplug, +bool preserve_config) {/* Declare an _OSC (OS Control Handoff) method */ aml_append (dev,build_pci_host_bridge_osc_method (enable_native_pcie_hotplug)); -aml_append (dev,build_pci_host_bridge_dsm_method ()); +aml_append (dev,build_pci_host_bridge_dsm_method (preserve_config)); }void acpi_dsdt_add_gpex (Aml *scope,struct GPEXConfig *cfg)
@@ -152,7 +167,8 @@ void acpi_dsdt_add_gpex(Aml *scope, struct GPEXConfig *cfg)build_cxl_osc_method (dev); }else {/* pxb bridges do not have ACPI PCI Hot-plug enabled */ -acpi_dsdt_add_host_bridge_methods (dev, true); +acpi_dsdt_add_host_bridge_methods (dev, true, + cfg->preserve_config); }aml_append (scope, dev);
@@ -227,7 +243,8 @@ void acpi_dsdt_add_gpex(Aml *scope, struct GPEXConfig *cfg) }aml_append (dev,aml_name_decl ("_CRS" , rbuf)); -acpi_dsdt_add_host_bridge_methods (dev, cfg->pci_native_hotplug); +acpi_dsdt_add_host_bridge_methods (dev, cfg->pci_native_hotplug, + cfg->preserve_config);Aml *dev_res0 =aml_device ("%s" ,"RES0" );aml_append (dev_res0,aml_name_decl ("_HID" ,aml_string ("PNP0C02" )));
include/hw/pci-host/gpex.h +1 -0
@@ -46,6 +46,7 @@ struct GPEXConfig {int irq;PCIBus *bus;bool pci_native_hotplug; +bool preserve_config; };typedef struct GPEXIrq GPEXIrq ;
Signature · 1 line
2.43.0
PATCH v6 22/33 hw/arm/virt: Set PCI preserve_config for accel SMMUv3
In reply to Shameer KolothumIntroduce a new pci_preserve_config field in virt machine state which allows the generation of DSM #5. This field is only set if accel SMMU is instantiated.
In a subsequent patch, SMMUv3 accel mode will make use of IORT RMR nodes to enable nested translation of MSI doorbell addresses. IORT RMR requires _DSM #5 to be set for the PCI host bridge so that the Guest kernel preserves the PCI boot configuration.
--- hw/arm/virt-acpi-build.c | 8 ++++++++ hw/arm/virt.c | 1 + include/hw/arm/virt.h | 1 + 3 files changed, 10 insertions(+)
hw/arm/virt-acpi-build.c +8 -0
@@ -164,6 +164,14 @@ static void acpi_dsdt_add_pci(Aml *scope, const MemMapEntry *memmap, .pci_native_hotplug = !acpi_pcihp, }; +/* +* Accel SMMU requires RMRs for MSI 1-1 mapping, which require _DSM +* function 5 (_DSM for Preserving PCI Boot Configurations). +*/ +if (vms->pci_preserve_config) { + cfg.preserve_config = true; + } +if (vms->highmem_mmio) { cfg.mmio64 = memmap[VIRT_HIGH_PCIE_MMIO ]; }
hw/arm/virt.c +1 -0
@@ -3109,6 +3109,7 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, }object_property_set_uint (OBJECT (dev),"msi-gpa" , db_start, &error_abort); + vms->pci_preserve_config = true; } } }
include/hw/arm/virt.h +1 -0
@@ -180,6 +180,7 @@ struct VirtMachineState {bool ns_el2_virt_timer_irq;CXLState cxl_devices_state;bool legacy_smmuv3_present; +bool pci_preserve_config; };#define VIRT_ECAM_ID (high) (high ? VIRT_HIGH_PCIE_ECAM : VIRT_PCIE_ECAM)
Signature · 1 line
2.43.0
PATCH v6 23/33 tests/qtest/bios-tables-test: Prepare for IORT revison upgrade
In reply to Shameer KolothumSubsequent patch will upgrade IORT revision to 5 to add support for IORT RMR nodes.
Add the affected IORT blobs to allowed-diff list for bios-table tests.
--- tests/qtest/bios-tables-test-allowed-diff.h | 4 ++++ 1 file changed, 4 insertions(+)
tests/qtest/bios-tables-test-allowed-diff.h +4 -0
@@ -1 +1,5 @@/* List of comma-separated changed AML files to ignore */ +"tests/data/acpi/aarch64/virt/IORT" , +"tests/data/acpi/aarch64/virt/IORT.its_off" , +"tests/data/acpi/aarch64/virt/IORT.smmuv3-legacy" , +"tests/data/acpi/aarch64/virt/IORT.smmuv3-dev",
Signature · 1 line
2.43.0
PATCH v6 24/33 hw/arm/virt-acpi-build: Add IORT RMR regions to handle MSI nested binding
In reply to Shameer KolothumFrom: Eric Auger <[email protected]>
To handle SMMUv3 accel=on mode(which configures the host SMMUv3 in nested mode), it is practical to expose the guest with reserved memory regions (RMRs) covering the IOVAs used by the host kernel to map physical MSI doorbells.
Those IOVAs belong to [0x8000000, 0x8100000] matching MSI_IOVA_BASE and MSI_IOVA_LENGTH definitions in kernel arm-smmu-v3 driver. This is the window used to allocate IOVAs matching physical MSI doorbells.
With those RMRs, the guest is forced to use a flat mapping for this range. Hence the assigned device is programmed with one IOVA from this range. Stage 1, owned by the guest has a flat mapping for this IOVA. Stage2, owned by the VMM then enforces a mapping from this IOVA to the physical MSI doorbell.
The creation of those RMR nodes is only relevant if nested stage SMMU is in use, along with VFIO. As VFIO devices can be hotplugged, all RMRs need to be created in advance.
--- hw/arm/virt-acpi-build.c | 111 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 103 insertions(+), 8 deletions(-)
hw/arm/virt-acpi-build.c +103 -8
@@ -257,6 +257,29 @@ static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms)#define ROOT_COMPLEX_ENTRY_SIZE 36#define IORT_NODE_OFFSET 48 +#define IORT_RMR_NUM_ID_MAPPINGS 1 +#define IORT_RMR_NUM_MEM_RANGE_DESC 1 +#define IORT_RMR_COMMON_HEADER_SIZE 28 +#define IORT_RMR_MEM_RANGE_DESC_SIZE 20 + +/* +* IORT RMR flags: +* Bit[0] = 0 Disallow remapping of reserved ranges +* Bit[1] = 0 Unprivileged access +* Bits[9:2] = 0x00 Device nGnRnE memory +*/ +#define IORT_RMR_FLAGS 0 + +/* +* MSI doorbell IOVA window used by the host kernel SMMUv3 driver. +* Described in IORT RMR nodes to reserve the IOVA range where the host +* kernel maps physical MSI doorbells for devices. This ensures guests +* preserve a flat mapping for MSI doorbell in nested SMMUv3(accel=on) +* configurations. +*/ +#define MSI_IOVA_BASE 0x8000000 +#define MSI_IOVA_LENGTH 0x100000 +/* * Append an ID mapping entry as described by "Table 4 ID mapping format" in * "IO Remapping Table System Software on ARM Platforms", Chapter 3.
@@ -265,7 +288,8 @@ static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms)* Note that @id_count gets internally subtracted by one, following the spec. */ static void build_iort_id_mapping (GArray *table_data,uint32_t input_base, -uint32_t id_count,uint32_t out_ref) +uint32_t id_count,uint32_t out_ref, +uint32_t flags) {build_append_int_noprefix (table_data, input_base,4 );/* Input base */ /* Number of IDs - The number of IDs in the range minus one */
@@ -273,7 +297,7 @@ static void build_iort_id_mapping(GArray *table_data, uint32_t input_base,build_append_int_noprefix (table_data, input_base,4 );/* Output base */ build_append_int_noprefix (table_data, out_ref,4 );/* Output Reference */ /* Flags */ -build_append_int_noprefix (table_data,0 /* Single mapping (disabled) */ ,4 ); +build_append_int_noprefix (table_data, flags,4 ); }struct AcpiIortIdMapping {
@@ -321,6 +345,7 @@ typedef struct AcpiIortSMMUv3Dev {GArray *rc_smmu_idmaps;/* Offset of the SMMUv3 IORT Node relative to the start of the IORT */ size_t offset; +bool accel; } AcpiIortSMMUv3Dev;/*
@@ -375,6 +400,9 @@ static int iort_smmuv3_devices(Object *obj, void *opaque) } bus =PCI_BUS (object_property_get_link (obj,"primary-bus" , &error_abort)); +if (object_property_find (obj,"accel" )) { + sdev.accel =object_property_get_bool (obj,"accel" , &error_abort); + } pbus =PLATFORM_BUS_DEVICE (vms->platform_bus_dev); sbdev =SYS_BUS_DEVICE (obj); sdev.base =platform_bus_get_mmio_addr (pbus, sbdev,0 );
@@ -448,10 +476,69 @@ static void create_rc_its_idmaps(GArray *its_idmaps, GArray *smmuv3_devs) } } +static void +build_iort_rmr_nodes (GArray *table_data,GArray *smmuv3_devices,uint32_t *id) +{ +AcpiIortSMMUv3Dev *sdev; +AcpiIortIdMapping *idmap; +int i; + +for (i =0 ; i < smmuv3_devices->len; i++) { +uint16_t rmr_len; +int bdf; + + sdev = &g_array_index (smmuv3_devices, AcpiIortSMMUv3Dev, i); +if (!sdev->accel) { +continue ; + } + +/* +* Spec reference:Arm IO Remapping Table(IORT), ARM DEN 0049E.d, +* Section 3.1.1.5 "Reserved Memory Range node" +*/ + idmap = &g_array_index (sdev->rc_smmu_idmaps, AcpiIortIdMapping,0 ); + bdf = idmap->input_base; + rmr_len =IORT_RMR_COMMON_HEADER_SIZE + + (IORT_RMR_NUM_ID_MAPPINGS *ID_MAPPING_ENTRY_SIZE ) + + (IORT_RMR_NUM_MEM_RANGE_DESC *IORT_RMR_MEM_RANGE_DESC_SIZE ); + +/* Table 18 Reserved Memory Range Node */ +build_append_int_noprefix (table_data,6 /* RMR */ ,1 );/* Type */ +/* Length */ +build_append_int_noprefix (table_data, rmr_len,2 ); +build_append_int_noprefix (table_data,3 ,1 );/* Revision */ +build_append_int_noprefix (table_data, (*id)++,4 );/* Identifier */ +/* Number of ID mappings */ +build_append_int_noprefix (table_data,IORT_RMR_NUM_ID_MAPPINGS ,4 ); +/* Reference to ID Array */ +build_append_int_noprefix (table_data,IORT_RMR_COMMON_HEADER_SIZE ,4 ); + +/* RMR specific data */ + +/* Flags */ +build_append_int_noprefix (table_data,IORT_RMR_FLAGS ,4 ); +/* Number of Memory Range Descriptors */ +build_append_int_noprefix (table_data,IORT_RMR_NUM_MEM_RANGE_DESC ,4 ); +/* Reference to Memory Range Descriptors */ +build_append_int_noprefix (table_data,IORT_RMR_COMMON_HEADER_SIZE + + (IORT_RMR_NUM_ID_MAPPINGS *ID_MAPPING_ENTRY_SIZE ),4 ); +build_iort_id_mapping (table_data, bdf, idmap->id_count, sdev->offset, +1 ); + +/* Table 19 Memory Range Descriptor */ + +/* Physical Range offset */ +build_append_int_noprefix (table_data,MSI_IOVA_BASE ,8 ); +/* Physical Range length */ +build_append_int_noprefix (table_data,MSI_IOVA_LENGTH ,8 ); +build_append_int_noprefix (table_data,0 ,4 );/* Reserved */ + } +} +/* * Input Output Remapping Table (IORT) * Conforms to "IO Remapping Table System Software on ARM Platforms", -* Document number: ARM DEN 0049E.b, Feb 2021 +* Document number: ARM DEN 0049E.d, Feb 2022 */ static void build_iort (GArray *table_data,BIOSLinker *linker,VirtMachineState *vms)
@@ -465,7 +552,7 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)GArray *smmuv3_devs =g_array_new (false, true,sizeof (AcpiIortSMMUv3Dev));GArray *rc_its_idmaps =g_array_new (false, true,sizeof (AcpiIortIdMapping)); -AcpiTable table = { .sig ="IORT" , .rev =3 , .oem_id = vms->oem_id, +AcpiTable table = { .sig ="IORT" , .rev =5 , .oem_id = vms->oem_id, .oem_table_id = vms->oem_table_id };/* Table 2 The IORT */ acpi_table_begin (&table, table_data);
@@ -491,6 +578,13 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) nb_nodes++;/* ITS */ rc_mapping_count += rc_its_idmaps->len; } +/* Calculate RMR nodes required. One per SMMUv3 with accelerated mode */ +for (i =0 ; i < num_smmus; i++) { + sdev = &g_array_index (smmuv3_devs, AcpiIortSMMUv3Dev, i); +if (sdev->accel) { + nb_nodes++; + } + } }else {if (vms->its) { nb_nodes =2 ;/* RC and ITS */
@@ -563,7 +657,7 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)/* Array of ID mappings */ if (smmu_mapping_count) {/* Output IORT node is the ITS Group node (the first node). */ -build_iort_id_mapping (table_data,0 ,0x10000 ,IORT_NODE_OFFSET ); +build_iort_id_mapping (table_data,0 ,0x10000 ,IORT_NODE_OFFSET ,0 ); } }
@@ -615,7 +709,7 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) AcpiIortIdMapping, j);/* Output IORT node is the SMMUv3 node. */ build_iort_id_mapping (table_data, range->input_base, - range->id_count, sdev->offset); + range->id_count, sdev->offset,0 ); } }
@@ -628,7 +722,7 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) range = &g_array_index (rc_its_idmaps, AcpiIortIdMapping, i);/* Output IORT node is the ITS Group node (the first node). */ build_iort_id_mapping (table_data, range->input_base, - range->id_count,IORT_NODE_OFFSET ); + range->id_count,IORT_NODE_OFFSET ,0 ); } } }else {
@@ -637,9 +731,10 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)* SMMU: RC -> ITS. * Output IORT node is the ITS Group node (the first node). */ -build_iort_id_mapping (table_data,0 ,0x10000 ,IORT_NODE_OFFSET ); +build_iort_id_mapping (table_data,0 ,0x10000 ,IORT_NODE_OFFSET ,0 ); } +build_iort_rmr_nodes (table_data, smmuv3_devs, &id);acpi_table_end (linker, &table);g_array_free (rc_its_idmaps, true);for (i =0 ; i < num_smmus; i++) {
Signature · 1 line
2.43.0
PATCH v6 25/33 tests/qtest/bios-tables-test: Update IORT blobs after revision upgrade
In reply to Shameer KolothumUpdate the reference IORT blobs after revision upgrade for RMR node support. This affects the aarch64 'virt' IORT tests.
IORT diff is the same for all the tests:
/*
* Intel ACPI Component Architecture
* AML/ASL+ Disassembler version 20230628 (64-bit version)
* Copyright (c) 2000 - 2023 Intel Corporation
*
- * Disassembly of tests/data/acpi/aarch64/virt/IORT, Mon Oct 20 14:42:41 2025
+ * Disassembly of /tmp/aml-B4ZRE3, Mon Oct 20 14:42:41 2025
*
* ACPI Data Table [IORT]
*
* Format: [HexOffset DecimalOffset ByteLength] FieldName : FieldValue (in hex) */
[000h 0000 004h] Signature : "IORT" [IO Remapping Table]
[004h 0004 004h] Table Length : 00000080
-[008h 0008 001h] Revision : 03 -[009h 0009 001h] Checksum : B3 +[008h 0008 001h] Revision : 05 +[009h 0009 001h] Checksum : B1
[00Ah 0010 006h] Oem ID : "BOCHS "
[010h 0016 008h] Oem Table ID : "BXPC "
[018h 0024 004h] Oem Revision : 00000001
[01Ch 0028 004h] Asl Compiler ID : "BXPC"
[020h 0032 004h] Asl Compiler Revision : 00000001
...
--- tests/data/acpi/aarch64/virt/IORT | Bin 128 -> 128 bytes tests/data/acpi/aarch64/virt/IORT.its_off | Bin 172 -> 172 bytes tests/data/acpi/aarch64/virt/IORT.smmuv3-dev | Bin 364 -> 364 bytes tests/data/acpi/aarch64/virt/IORT.smmuv3-legacy | Bin 276 -> 276 bytes tests/qtest/bios-tables-test-allowed-diff.h | 4 ---- 5 files changed, 4 deletions(-)
tests/data/acpi/aarch64/virt/IORT binary +0 -0
tests/data/acpi/aarch64/virt/IORT.its_off binary +0 -0
tests/data/acpi/aarch64/virt/IORT.smmuv3-dev binary +0 -0
tests/data/acpi/aarch64/virt/IORT.smmuv3-legacy binary +0 -0
tests/qtest/bios-tables-test-allowed-diff.h +0 -4
@@ -1,5 +1 @@/* List of comma-separated changed AML files to ignore */ -"tests/data/acpi/aarch64/virt/IORT" , -"tests/data/acpi/aarch64/virt/IORT.its_off" , -"tests/data/acpi/aarch64/virt/IORT.smmuv3-legacy" , -"tests/data/acpi/aarch64/virt/IORT.smmuv3-dev",
Signature · 1 line
2.43.0
PATCH v6 26/33 hw/arm/smmuv3: Add accel property for SMMUv3 device
In reply to Shameer KolothumIntroduce an “accel” property to enable accelerator mode.
Live migration is currently unsupported when accelerator mode is enabled, so a migration blocker is added.
Because this mode relies on IORT RMR for MSI support, accelerator mode is not supported for device tree boot.
Also, in the accelerated SMMUv3 case, the host SMMUv3 is configured in nested mode (S1 + S2), and the guest owns the Stage-1 page table. Therefore, we expose only Stage-1 to the guest to ensure it uses the correct page table format.
--- hw/arm/smmuv3.c | 26 ++++++++++++++++++++++++++ hw/arm/virt-acpi-build.c | 4 +--- hw/arm/virt.c | 15 +++++++++++---- include/hw/arm/smmuv3.h | 1 + 4 files changed, 39 insertions(+), 7 deletions(-)
hw/arm/smmuv3.c +26 -0
@@ -20,6 +20,7 @@#include "qemu/bitops.h" #include "hw/irq.h" #include "hw/sysbus.h" +#include "migration/blocker.h" #include "migration/vmstate.h" #include "hw/qdev-properties.h" #include "hw/qdev-core.h"
@@ -1915,6 +1916,17 @@ static void smmu_reset_exit(Object *obj, ResetType type)smmuv3_accel_reset (s); } +static bool smmu_validate_property (SMMUv3State *s,Error **errp) +{ +#ifndef CONFIG_ARM_SMMUV3_ACCEL +if (s->accel) { +error_setg (errp,"accel=on support not compiled in" ); +return false; + } +#endif +return true; +} +static void smmu_realize (DeviceState *d,Error **errp) {SMMUState *sys =ARM_SMMU (d);
@@ -1923,8 +1935,17 @@ static void smmu_realize(DeviceState *d, Error **errp)SysBusDevice *dev =SYS_BUS_DEVICE (d);Error *local_err =NULL ; +if (!smmu_validate_property (s, errp)) { +return ; + } +if (s->accel) {smmuv3_accel_init (s); +error_setg (&s->migration_blocker,"Migration not supported with SMMUv3 " +"accelerator mode enabled" ); +if (migrate_add_blocker (&s->migration_blocker, errp) <0 ) { +return ; + } } c->parent_realize (d, &local_err);
@@ -2023,6 +2044,7 @@ static const Property smmuv3_properties[] = {* Defaults to stage 1 */ DEFINE_PROP_STRING ("stage" , SMMUv3State, stage), +DEFINE_PROP_BOOL ("accel" , SMMUv3State, accel, false),/* GPA of MSI doorbell, for SMMUv3 accel use. */ DEFINE_PROP_UINT64("msi-gpa", SMMUv3State, msi_gpa, 0), };
@@ -2046,6 +2068,10 @@ static void smmuv3_class_init(ObjectClass *klass, const void *data)device_class_set_props (dc, smmuv3_properties); dc->hotpluggable = false; dc->user_creatable = true; + +object_class_property_set_description (klass,"accel" , +"Enable SMMUv3 accelerator support. Allows host SMMUv3 to be " +"configured in nested mode for vfio-pci dev assignment" ); } static int smmuv3_notify_flag_changed(IOMMUMemoryRegion *iommu,
hw/arm/virt-acpi-build.c +1 -3
@@ -400,9 +400,7 @@ static int iort_smmuv3_devices(Object *obj, void *opaque) } bus =PCI_BUS (object_property_get_link (obj,"primary-bus" , &error_abort)); -if (object_property_find (obj,"accel" )) { - sdev.accel =object_property_get_bool (obj,"accel" , &error_abort); - } + sdev.accel =object_property_get_bool (obj,"accel" , &error_abort); pbus =PLATFORM_BUS_DEVICE (vms->platform_bus_dev); sbdev =SYS_BUS_DEVICE (obj); sdev.base =platform_bus_get_mmio_addr (pbus, sbdev,0 );
hw/arm/virt.c +11 -4
@@ -3052,13 +3052,21 @@ static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,/* The new SMMUv3 device is specific to the PCI bus */ object_property_set_bool (OBJECT (dev),"smmu_per_bus" , true,NULL ); } -if (object_property_find (OBJECT (dev),"accel" ) && -object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) { +if (object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) { +char *stage; +if (!kvm_enabled () || !kvm_irqchip_in_kernel ()) {error_setg (errp,"SMMUv3 accel=on requires KVM with " "kernel-irqchip=on support" );return ; } + stage =object_property_get_str (OBJECT (dev),"stage" , &error_fatal); +/* If no stage specified, SMMUv3 will default to stage 1 */ +if (*stage &&strcmp ("1" , stage)) { +error_setg (errp,"Only stage1 is supported for SMMUV3 with " +"accel=on" ); +return ; + } } } }
@@ -3096,8 +3104,7 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, }create_smmuv3_dev_dtb (vms, dev, bus); -if (object_property_find (OBJECT (dev),"accel" ) && -object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) { +if (object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) {hwaddr db_start;if (vms->msi_controller ==VIRT_MSI_CTRL_ITS ) {
include/hw/arm/smmuv3.h +1 -0
@@ -68,6 +68,7 @@ struct SMMUv3State {bool accel;struct SMMUv3AccelState *s_accel;uint64_t msi_gpa; +Error *migration_blocker; }; typedef enum {
Signature · 1 line
2.43.0
Re: [PATCH v6 26/33] hw/arm/smmuv3: Add accel property for SMMUv3 device
Quoted 56 lines · Shameer Kolothum
Introduce an “accel” property to enable accelerator mode.
Live migration is currently unsupported when accelerator mode is enabled, so a migration blocker is added.
Because this mode relies on IORT RMR for MSI support, accelerator mode is not supported for device tree boot.
Also, in the accelerated SMMUv3 case, the host SMMUv3 is configured in nested mode (S1 + S2), and the guest owns the Stage-1 page table. Therefore, we expose only Stage-1 to the guest to ensure it uses the correct page table format.
Reviewed-by Nicolin Chen <[email protected]>Reviewed-by Eric Auger <[email protected]>Tested-by Zhangfei Gao <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3.c | 26 ++++++++++++++++++++++++++ hw/arm/virt-acpi-build.c | 4 +--- hw/arm/virt.c | 15 +++++++++++---- include/hw/arm/smmuv3.h | 1 + 4 files changed, 39 insertions(+), 7 deletions(-)hw/arm/smmuv3.c +12
-0@@ -20,6 +20,7 @@#include "qemu/bitops.h" #include "hw/irq.h" #include "hw/sysbus.h" +#include "migration/blocker.h" #include "migration/vmstate.h" #include "hw/qdev-properties.h" #include "hw/qdev-core.h" @@ -1915,6 +1916,17 @@ static void smmu_reset_exit(Object *obj, ResetType type)smmuv3_accel_reset (s); } +static bool smmu_validate_property (SMMUv3State *s,Error **errp) +{ +#ifndef CONFIG_ARM_SMMUV3_ACCEL +if (s->accel) { +error_setg (errp,"accel=on support not compiled in" ); +return false; + } +#endif +return true; +} +static void smmu_realize (DeviceState *d,Error **errp) {SMMUState *sys =ARM_SMMU (d);
hw/arm/smmuv3.c static void smmu_realize(DeviceState *d, Error **errp) · line 1940
Quoted 6 lines
hw/arm/smmuv3.c +3
-0@@ -1923,8 +1935,17 @@ static void smmu_realize(DeviceState *d, Error **errp)SysBusDevice *dev =SYS_BUS_DEVICE (d);Error *local_err =NULL ; +if (!smmu_validate_property (s, errp)) { +return ; + }
You should really consider adding a new QOM model for the "accel" mode.
hw/arm/smmuv3.c static void smmu_realize(DeviceState *d, Error **errp) · line 1948
Quoted 7 lines
hw/arm/smmuv3.c +5
-0if (s->accel) {smmuv3_accel_init (s); +error_setg (&s->migration_blocker,"Migration not supported with SMMUv3 " +"accelerator mode enabled" ); +if (migrate_add_blocker (&s->migration_blocker, errp) <0 ) { +return ; + }
I would add the migration blocker in a separate patch.
Quoted 48 lines
hw/arm/smmuv3.c +5
-0} c->parent_realize (d, &local_err);@@ -2023,6 +2044,7 @@ static const Property smmuv3_properties[] = {* Defaults to stage 1 */ DEFINE_PROP_STRING ("stage" , SMMUv3State, stage), +DEFINE_PROP_BOOL ("accel" , SMMUv3State, accel, false),/* GPA of MSI doorbell, for SMMUv3 accel use. */ DEFINE_PROP_UINT64("msi-gpa", SMMUv3State, msi_gpa, 0), };@@ -2046,6 +2068,10 @@ static void smmuv3_class_init(ObjectClass *klass, const void *data)device_class_set_props (dc, smmuv3_properties); dc->hotpluggable = false; dc->user_creatable = true; + +object_class_property_set_description (klass,"accel" , +"Enable SMMUv3 accelerator support. Allows host SMMUv3 to be " +"configured in nested mode for vfio-pci dev assignment" ); } static int smmuv3_notify_flag_changed(IOMMUMemoryRegion *iommu,hw/arm/virt-acpi-build.c +1
-3@@ -400,9 +400,7 @@ static int iort_smmuv3_devices(Object *obj, void *opaque) } bus =PCI_BUS (object_property_get_link (obj,"primary-bus" , &error_abort)); -if (object_property_find (obj,"accel" )) { - sdev.accel =object_property_get_bool (obj,"accel" , &error_abort); - } + sdev.accel =object_property_get_bool (obj,"accel" , &error_abort); pbus =PLATFORM_BUS_DEVICE (vms->platform_bus_dev); sbdev =SYS_BUS_DEVICE (obj); sdev.base =platform_bus_get_mmio_addr (pbus, sbdev,0 );hw/arm/virt.c +1
-2@@ -3052,13 +3052,21 @@ static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,/* The new SMMUv3 device is specific to the PCI bus */ object_property_set_bool (OBJECT (dev),"smmu_per_bus" , true,NULL ); } -if (object_property_find (OBJECT (dev),"accel" ) && -object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) { +if (object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) {
hw/arm/virt.c static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, · line 3065
Quoted 10 lines
hw/arm/virt.c +5
-0+char *stage; +if (!kvm_enabled () || !kvm_irqchip_in_kernel ()) {error_setg (errp,"SMMUv3 accel=on requires KVM with " "kernel-irqchip=on support" );return ; } + stage =object_property_get_str (OBJECT (dev),"stage" , &error_fatal); +/* If no stage specified, SMMUv3 will default to stage 1 */ +if (*stage &&strcmp ("1" , stage)) {
It would be less "ugly" to check SMMUStage enum values instead of using string compare :/
hw/arm/virt.c static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, · line 3067
Quoted 2 lines
hw/arm/virt.c +2
-0+error_setg (errp,"Only stage1 is supported for SMMUV3 with " +"accel=on" );
Can't this condition be checked in the realize handler instead ?
C.
Quoted 27 lines
hw/arm/virt.c +3
-2+return ; + } } } }@@ -3096,8 +3104,7 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, }create_smmuv3_dev_dtb (vms, dev, bus); -if (object_property_find (OBJECT (dev),"accel" ) && -object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) { +if (object_property_get_bool (OBJECT (dev),"accel" , &error_abort)) {hwaddr db_start;if (vms->msi_controller ==VIRT_MSI_CTRL_ITS ) {include/hw/arm/smmuv3.h +1
-0@@ -68,6 +68,7 @@ struct SMMUv3State {bool accel;struct SMMUv3AccelState *s_accel;uint64_t msi_gpa; +Error *migration_blocker; }; typedef enum {
PATCH v6 27/33 hw/arm/smmuv3-accel: Add a property to specify RIL support
In reply to Shameer KolothumCurrently QEMU SMMUv3 has RIL support by default. But if accelerated mode is enabled, RIL has to be compatible with host SMMUv3 support.
Add a property so that the user can specify this.
--- hw/arm/smmuv3-accel.c | 14 ++++++++++++-- hw/arm/smmuv3-accel.h | 4 ++++ hw/arm/smmuv3.c | 12 ++++++++++++ include/hw/arm/smmuv3.h | 1 + 4 files changed, 29 insertions(+), 2 deletions(-)
hw/arm/smmuv3-accel.c +12 -2
@@ -62,8 +62,8 @@ smmuv3_accel_check_hw_compatible(SMMUv3State *s,return false; } -/* QEMU SMMUv3 supports Range Invalidation by default */ -if (FIELD_EX32 (info->idr[3 ],IDR3 ,RIL ) != +/* User can disable QEMU SMMUv3 Range Invalidation support */ +if (FIELD_EX32 (info->idr[3 ],IDR3 ,RIL ) >FIELD_EX32 (s->idr[3 ],IDR3 ,RIL )) {error_setg (errp,"Host SMMUv3 doesn't support Range Invalidation" );return false;
@@ -639,6 +639,16 @@ static const PCIIOMMUOps smmuv3_accel_ops = { .get_msi_direct_gpa = smmuv3_accel_get_msi_gpa, }; +void smmuv3_accel_idr_override (SMMUv3State *s) +{ +if (!s->accel) { +return ; + } + +/* By default QEMU SMMUv3 has RIL. Update IDR3 if user has disabled it */ + s->idr[3 ] =FIELD_DP32 (s->idr[3 ],IDR3 ,RIL , s->ril); +} +/* Based on SMUUv3 GPBA.ABORT configuration, attach a corresponding HWPT */ bool smmuv3_accel_attach_gbpa_hwpt (SMMUv3State *s,Error **errp) {
hw/arm/smmuv3-accel.h +4 -0
@@ -47,6 +47,7 @@ bool smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange *range,bool smmuv3_accel_attach_gbpa_hwpt (SMMUv3State *s,Error **errp);bool smmuv3_accel_issue_inv_cmd (SMMUv3State *s,void *cmd,SMMUDevice *sdev,Error **errp); +void smmuv3_accel_idr_override (SMMUv3State *s);void smmuv3_accel_reset (SMMUv3State *s);#else static inline void smmuv3_accel_init (SMMUv3State *s)
@@ -74,6 +75,9 @@ smmuv3_accel_issue_inv_cmd(SMMUv3State *s, void *cmd, SMMUDevice *sdev, {return true; } +static inline void smmuv3_accel_idr_override (SMMUv3State *s) +{ +}static inline void smmuv3_accel_reset (SMMUv3State *s) { }
hw/arm/smmuv3.c +12 -0
@@ -305,6 +305,7 @@ static void smmuv3_init_id_regs(SMMUv3State *s) s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN16K ,1 ); s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN64K ,1 ); s->aidr =0x1 ; +smmuv3_accel_idr_override (s); }static void smmuv3_reset (SMMUv3State *s)
@@ -1924,6 +1925,13 @@ static bool smmu_validate_property(SMMUv3State *s, Error **errp) return false; }#endif +if (!s->accel) { +if (!s->ril) { +error_setg (errp,"ril can only be disabled if accel=on" ); +return false; + } +return true; + }return true; }
@@ -2047,6 +2055,8 @@ static const Property smmuv3_properties[] = {DEFINE_PROP_BOOL ("accel" , SMMUv3State, accel, false),/* GPA of MSI doorbell, for SMMUv3 accel use. */ DEFINE_PROP_UINT64 ("msi-gpa" , SMMUv3State, msi_gpa,0 ), +/* RIL can be turned off for accel cases */ + DEFINE_PROP_BOOL("ril", SMMUv3State, ril, true), };static void smmuv3_instance_init (Object *obj)
@@ -2072,6 +2082,8 @@ static void smmuv3_class_init(ObjectClass *klass, const void *data)object_class_property_set_description (klass,"accel" ,"Enable SMMUv3 accelerator support. Allows host SMMUv3 to be " "configured in nested mode for vfio-pci dev assignment" ); +object_class_property_set_description (klass,"ril" , +"Disable range invalidation support (for accel=on)" ); } static int smmuv3_notify_flag_changed(IOMMUMemoryRegion *iommu,
include/hw/arm/smmuv3.h +1 -0
@@ -69,6 +69,7 @@ struct SMMUv3State {struct SMMUv3AccelState *s_accel;uint64_t msi_gpa;Error *migration_blocker; +bool ril; }; typedef enum {
Signature · 1 line
2.43.0
Re: [PATCH v6 27/33] hw/arm/smmuv3-accel: Add a property to specify RIL support
Quoted 21 lines · Shameer Kolothum
Currently QEMU SMMUv3 has RIL support by default. But if accelerated mode is enabled, RIL has to be compatible with host SMMUv3 support.
Add a property so that the user can specify this.
Reviewed-by Jonathan Cameron <[email protected]>Tested-by Zhangfei Gao <[email protected]>Reviewed-by Eric Auger <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.c | 14 ++++++++++++-- hw/arm/smmuv3-accel.h | 4 ++++ hw/arm/smmuv3.c | 12 ++++++++++++ include/hw/arm/smmuv3.h | 1 + 4 files changed, 29 insertions(+), 2 deletions(-)hw/arm/smmuv3-accel.c +0
-0
hw/arm/smmuv3-accel.c smmuv3_accel_check_hw_compatible(SMMUv3State *s, · line 67
Quoted 8 lines
hw/arm/smmuv3-accel.c +2
-2@@ -62,8 +62,8 @@ smmuv3_accel_check_hw_compatible(SMMUv3State *s,return false; } -/* QEMU SMMUv3 supports Range Invalidation by default */ -if (FIELD_EX32 (info->idr[3 ],IDR3 ,RIL ) != +/* User can disable QEMU SMMUv3 Range Invalidation support */ +if (FIELD_EX32 (info->idr[3 ],IDR3 ,RIL ) >FIELD_EX32 (s->idr[3 ],IDR3 ,RIL )) {
When (host) info->idr = 1 > (VM) s->idr = 0, it should work?
So, should it be "<" instead?
Otherwise,
RE: [PATCH v6 27/33] hw/arm/smmuv3-accel: Add a property to specify RIL support
Quoted 43 lines
-----Original Message-----
From: Nicolin Chen <[email protected]>
Sent: 20 November 2025 21:35
To: Shameer Kolothum <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 27/33] hw/arm/smmuv3-accel: Add a property to specify RIL supporthw/arm/smmuv3-accel.c smmuv3_accel_check_hw_compatible(SMMUv3State
Quoted 21 lines · Shameer Kolothum
Currently QEMU SMMUv3 has RIL support by default. But if accelerated mode is enabled, RIL has to be compatible with host SMMUv3 support.
Add a property so that the user can specify this.
Reviewed-by Jonathan Cameron <[email protected]>Tested-by Zhangfei Gao <[email protected]>Reviewed-by Eric Auger <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.c | 14 ++++++++++++-- hw/arm/smmuv3-accel.h | 4 ++++ hw/arm/smmuv3.c | 12 ++++++++++++ include/hw/arm/smmuv3.h | 1 + 4 files changed, 29 insertions(+), 2 deletions(-)hw/arm/smmuv3-accel.c index renamed from hw/arm/smmuv3-accel.c +0
-0
aae7840c40..b6429c8b42100644hw/arm/smmuv3-accel.c +0
-0@@ -62,8 +62,8 @@ smmuv3_accel_check_hw_compatible(SMMUv3State*s,
Quoted 3 lines
hw/arm/smmuv3-accel.c +0
-0return false; }
Quoted 7 lines
hw/arm/smmuv3-accel.c smmuv3_accel_check_hw_compatible(SMMUv3State *s, · line 67
Quoted 5 lines
hw/arm/smmuv3-accel.c +2
-2-/* QEMU SMMUv3 supports Range Invalidation by default */ -if (FIELD_EX32 (info->idr[3 ],IDR3 ,RIL ) != +/* User can disable QEMU SMMUv3 Range Invalidation support */ +if (FIELD_EX32 (info->idr[3 ],IDR3 ,RIL ) >FIELD_EX32 (s->idr[3 ],IDR3 ,RIL )) {When (host)
info->idr= 1 > (VM)s->idr= 0, it should work?
Yes, that was my intention.
Quoted 1 line
So, should it be "<" instead?
And got it wrong 😊. Will correct.
Thanks,
Shameer
Re: [PATCH v6 27/33] hw/arm/smmuv3-accel: Add a property to specify RIL support
In reply to Shameer KolothumQuoted 32 lines · Shameer Kolothum
Currently QEMU SMMUv3 has RIL support by default. But if accelerated mode is enabled, RIL has to be compatible with host SMMUv3 support.
Add a property so that the user can specify this.
Reviewed-by Jonathan Cameron <[email protected]>Tested-by Zhangfei Gao <[email protected]>Reviewed-by Eric Auger <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.c | 14 ++++++++++++-- hw/arm/smmuv3-accel.h | 4 ++++ hw/arm/smmuv3.c | 12 ++++++++++++ include/hw/arm/smmuv3.h | 1 + 4 files changed, 29 insertions(+), 2 deletions(-)hw/arm/smmuv3-accel.c +2
-2@@ -62,8 +62,8 @@ smmuv3_accel_check_hw_compatible(SMMUv3State *s,return false; } -/* QEMU SMMUv3 supports Range Invalidation by default */ -if (FIELD_EX32 (info->idr[3 ],IDR3 ,RIL ) != +/* User can disable QEMU SMMUv3 Range Invalidation support */ +if (FIELD_EX32 (info->idr[3 ],IDR3 ,RIL ) >FIELD_EX32 (s->idr[3 ],IDR3 ,RIL )) {error_setg (errp,"Host SMMUv3 doesn't support Range Invalidation" );return false;
hw/arm/smmuv3-accel.c static const PCIIOMMUOps smmuv3_accel_ops = { · line 646
Quoted 8 lines
hw/arm/smmuv3-accel.c +5
-0@@ -639,6 +639,16 @@ static const PCIIOMMUOps smmuv3_accel_ops = { .get_msi_direct_gpa = smmuv3_accel_get_msi_gpa, }; +void smmuv3_accel_idr_override (SMMUv3State *s) +{ +if (!s->accel) { +return ; + }
Those :
if (s->accel)
in the code reveal a modeling issue.
Quoted 57 lines
hw/arm/smmuv3-accel.c +5
-0+ +/* By default QEMU SMMUv3 has RIL. Update IDR3 if user has disabled it */ + s->idr[3 ] =FIELD_DP32 (s->idr[3 ],IDR3 ,RIL , s->ril); +} +/* Based on SMUUv3 GPBA.ABORT configuration, attach a corresponding HWPT */ bool smmuv3_accel_attach_gbpa_hwpt (SMMUv3State *s,Error **errp) {hw/arm/smmuv3-accel.h +4
-0@@ -47,6 +47,7 @@ bool smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange *range,bool smmuv3_accel_attach_gbpa_hwpt (SMMUv3State *s,Error **errp);bool smmuv3_accel_issue_inv_cmd (SMMUv3State *s,void *cmd,SMMUDevice *sdev,Error **errp); +void smmuv3_accel_idr_override (SMMUv3State *s);void smmuv3_accel_reset (SMMUv3State *s);#else static inline void smmuv3_accel_init (SMMUv3State *s)@@ -74,6 +75,9 @@ smmuv3_accel_issue_inv_cmd(SMMUv3State *s, void *cmd, SMMUDevice *sdev, {return true; } +static inline void smmuv3_accel_idr_override (SMMUv3State *s) +{ +}static inline void smmuv3_accel_reset (SMMUv3State *s) { }hw/arm/smmuv3.c +8
-0@@ -305,6 +305,7 @@ static void smmuv3_init_id_regs(SMMUv3State *s) s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN16K ,1 ); s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN64K ,1 ); s->aidr =0x1 ; +smmuv3_accel_idr_override (s); }static void smmuv3_reset (SMMUv3State *s)@@ -1924,6 +1925,13 @@ static bool smmu_validate_property(SMMUv3State *s, Error **errp) return false; }#endif +if (!s->accel) { +if (!s->ril) { +error_setg (errp,"ril can only be disabled if accel=on" ); +return false; + } +return true; + }return true; }
hw/arm/smmuv3.c static const Property smmuv3_properties[] = { · line 2059
Quoted 5 lines
hw/arm/smmuv3.c +2
-0@@ -2047,6 +2055,8 @@ static const Property smmuv3_properties[] = {DEFINE_PROP_BOOL ("accel" , SMMUv3State, accel, false),/* GPA of MSI doorbell, for SMMUv3 accel use. */ DEFINE_PROP_UINT64 ("msi-gpa" , SMMUv3State, msi_gpa,0 ), +/* RIL can be turned off for accel cases */ + DEFINE_PROP_BOOL("ril", SMMUv3State, ril, true),
yep. Adding a QOM model would clarify a lot of things.
C.
Quoted 24 lines
hw/arm/smmuv3.c +2
-0};static void smmuv3_instance_init (Object *obj)@@ -2072,6 +2082,8 @@ static void smmuv3_class_init(ObjectClass *klass, const void *data)object_class_property_set_description (klass,"accel" ,"Enable SMMUv3 accelerator support. Allows host SMMUv3 to be " "configured in nested mode for vfio-pci dev assignment" ); +object_class_property_set_description (klass,"ril" , +"Disable range invalidation support (for accel=on)" ); } static int smmuv3_notify_flag_changed(IOMMUMemoryRegion *iommu,include/hw/arm/smmuv3.h +1
-0@@ -69,6 +69,7 @@ struct SMMUv3State {struct SMMUv3AccelState *s_accel;uint64_t msi_gpa;Error *migration_blocker; +bool ril; }; typedef enum {
PATCH v6 28/33 hw/arm/smmuv3-accel: Add support for ATS
In reply to Shameer KolothumQEMU SMMUv3 does not enable ATS (Address Translation Services) by default. When accelerated mode is enabled and the host SMMUv3 supports ATS, it can be useful to report ATS capability to the guest so it can take advantage of it if the device also supports ATS.
Note: ATS support cannot be reliably detected from the host SMMUv3 IDR registers alone, as firmware ACPI IORT tables may override them. The user must therefore ensure the support before enabling it.
The ATS support enabled here is only relevant for vfio-pci endpoints, as SMMUv3 accelerated mode does not support emulated endpoint devices. QEMU’s SMMUv3 implementation still lacks support for handling ATS translation requests, which would be required for emulated endpoints.
--- hw/arm/smmuv3-accel.c | 3 +++ hw/arm/smmuv3.c | 21 ++++++++++++++++++++- hw/arm/virt-acpi-build.c | 10 ++++++++-- include/hw/arm/smmuv3.h | 1 + 4 files changed, 32 insertions(+), 3 deletions(-)
hw/arm/smmuv3-accel.c +3 -0
@@ -647,6 +647,9 @@ void smmuv3_accel_idr_override(SMMUv3State *s)/* By default QEMU SMMUv3 has RIL. Update IDR3 if user has disabled it */ s->idr[3 ] =FIELD_DP32 (s->idr[3 ],IDR3 ,RIL , s->ril); + +/* QEMU SMMUv3 has no ATS. Advertise ATS if opt-on by property */ + s->idr[0 ] =FIELD_DP32 (s->idr[0 ],IDR0 ,ATS , s->ats); }/* Based on SMUUv3 GPBA.ABORT configuration, attach a corresponding HWPT */
hw/arm/smmuv3.c +20 -1
@@ -1498,13 +1498,24 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp)*/ smmuv3_range_inval (bs, &cmd,SMMU_STAGE_2 );break ; +case SMMU_CMD_ATC_INV : +SMMUDevice *sdev =smmu_find_sdev (bs,CMD_SID (&cmd)); + +if (!sdev) { +break ; + } + +if (!smmuv3_accel_issue_inv_cmd (s, &cmd, sdev, errp)) { + cmd_error =SMMU_CERROR_ILL ; +break ; + } +break ;case SMMU_CMD_TLBI_EL3_ALL :case SMMU_CMD_TLBI_EL3_VA :case SMMU_CMD_TLBI_EL2_ALL :case SMMU_CMD_TLBI_EL2_ASID :case SMMU_CMD_TLBI_EL2_VA :case SMMU_CMD_TLBI_EL2_VAA : -case SMMU_CMD_ATC_INV :case SMMU_CMD_PRI_RESP :case SMMU_CMD_RESUME :case SMMU_CMD_STALL_TERM :
@@ -1930,6 +1941,10 @@ static bool smmu_validate_property(SMMUv3State *s, Error **errp)error_setg (errp,"ril can only be disabled if accel=on" );return false; } +if (s->ats) { +error_setg (errp,"ats can only be enabled if accel=on" ); +return false; + }return true; }return true;
@@ -2057,6 +2072,7 @@ static const Property smmuv3_properties[] = {DEFINE_PROP_UINT64 ("msi-gpa" , SMMUv3State, msi_gpa,0 ),/* RIL can be turned off for accel cases */ DEFINE_PROP_BOOL ("ril" , SMMUv3State, ril, true), + DEFINE_PROP_BOOL("ats", SMMUv3State, ats, false), };static void smmuv3_instance_init (Object *obj)
@@ -2084,6 +2100,9 @@ static void smmuv3_class_init(ObjectClass *klass, const void *data) "configured in nested mode for vfio-pci dev assignment");object_class_property_set_description (klass,"ril" ,"Disable range invalidation support (for accel=on)" ); +object_class_property_set_description (klass,"ats" , +"Enable/disable ATS support (for accel=on). Please ensure host " +"platform has ATS support before enabling this" ); } static int smmuv3_notify_flag_changed(IOMMUMemoryRegion *iommu,
hw/arm/virt-acpi-build.c +8 -2
@@ -346,6 +346,7 @@ typedef struct AcpiIortSMMUv3Dev {/* Offset of the SMMUv3 IORT Node relative to the start of the IORT */ size_t offset;bool accel; +bool ats; } AcpiIortSMMUv3Dev;/*
@@ -401,6 +402,7 @@ static int iort_smmuv3_devices(Object *obj, void *opaque) bus =PCI_BUS (object_property_get_link (obj,"primary-bus" , &error_abort)); sdev.accel =object_property_get_bool (obj,"accel" , &error_abort); + sdev.ats =object_property_get_bool (obj,"ats" , &error_abort); pbus =PLATFORM_BUS_DEVICE (vms->platform_bus_dev); sbdev =SYS_BUS_DEVICE (obj); sdev.base =platform_bus_get_mmio_addr (pbus, sbdev,0 );
@@ -544,6 +546,7 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)int i, nb_nodes, rc_mapping_count;AcpiIortSMMUv3Dev *sdev;size_t node_size; +bool ats_needed = false;int num_smmus =0 ;uint32_t id =0 ;int rc_smmu_idmaps_len =0 ;
@@ -579,6 +582,9 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)/* Calculate RMR nodes required. One per SMMUv3 with accelerated mode */ for (i =0 ; i < num_smmus; i++) { sdev = &g_array_index (smmuv3_devs, AcpiIortSMMUv3Dev, i); +if (sdev->ats) { + ats_needed = true; + }if (sdev->accel) { nb_nodes++; }
@@ -678,8 +684,8 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)build_append_int_noprefix (table_data,0 ,2 );/* Reserved */ /* Table 15 Memory Access Flags */ build_append_int_noprefix (table_data,0x3 /* CCA = CPM = DACS = 1 */ ,1 ); - -build_append_int_noprefix (table_data,0 ,4 );/* ATS Attribute */ +/* ATS Attribute */ +build_append_int_noprefix (table_data, ats_needed,4 );/* MCFG pci_segment */ build_append_int_noprefix (table_data,0 ,4 );/* PCI Segment number */
include/hw/arm/smmuv3.h +1 -0
@@ -70,6 +70,7 @@ struct SMMUv3State {uint64_t msi_gpa;Error *migration_blocker;bool ril; +bool ats; }; typedef enum {
Signature · 1 line
2.43.0
Re: [PATCH v6 28/33] hw/arm/smmuv3-accel: Add support for ATS
Quoted 5 lines · Shameer Kolothum
hw/arm/smmuv3.c +0
-0
hw/arm/smmuv3.c static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp) · line 1506
Quoted 9 lines
hw/arm/smmuv3.c +6
-0@@ -1498,13 +1498,24 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp)*/ smmuv3_range_inval (bs, &cmd,SMMU_STAGE_2 );break ; +case SMMU_CMD_ATC_INV : +SMMUDevice *sdev =smmu_find_sdev (bs,CMD_SID (&cmd)); + +if (!sdev) { +break ; + }
Should we do:
if (!sdev || !s->ats) {
trace_smmuv3_unhandled_cmd(type);
break;
}?
Otherwise,
Re: [PATCH v6 28/33] hw/arm/smmuv3-accel: Add support for ATS
In reply to Shameer KolothumQuoted 49 lines · Shameer Kolothum
QEMU SMMUv3 does not enable ATS (Address Translation Services) by default. When accelerated mode is enabled and the host SMMUv3 supports ATS, it can be useful to report ATS capability to the guest so it can take advantage of it if the device also supports ATS.
Note: ATS support cannot be reliably detected from the host SMMUv3 IDR registers alone, as firmware ACPI IORT tables may override them. The user must therefore ensure the support before enabling it.
The ATS support enabled here is only relevant for vfio-pci endpoints, as SMMUv3 accelerated mode does not support emulated endpoint devices. QEMU’s SMMUv3 implementation still lacks support for handling ATS translation requests, which would be required for emulated endpoints.
Reviewed-by Jonathan Cameron <[email protected]>Tested-by Zhangfei Gao <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.c | 3 +++ hw/arm/smmuv3.c | 21 ++++++++++++++++++++- hw/arm/virt-acpi-build.c | 10 ++++++++-- include/hw/arm/smmuv3.h | 1 + 4 files changed, 32 insertions(+), 3 deletions(-)hw/arm/smmuv3-accel.c +3
-0@@ -647,6 +647,9 @@ void smmuv3_accel_idr_override(SMMUv3State *s)/* By default QEMU SMMUv3 has RIL. Update IDR3 if user has disabled it */ s->idr[3 ] =FIELD_DP32 (s->idr[3 ],IDR3 ,RIL , s->ril); + +/* QEMU SMMUv3 has no ATS. Advertise ATS if opt-on by property */ + s->idr[0 ] =FIELD_DP32 (s->idr[0 ],IDR0 ,ATS , s->ats); }/* Based on SMUUv3 GPBA.ABORT configuration, attach a corresponding HWPT */ hw/arm/smmuv3.c +2
-0@@ -1498,13 +1498,24 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp)*/ smmuv3_range_inval (bs, &cmd,SMMU_STAGE_2 );break ; +case SMMU_CMD_ATC_INV : +SMMUDevice *sdev =smmu_find_sdev (bs,CMD_SID (&cmd));
hw/arm/smmuv3.c static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp) · line 1512
Quoted 10 lines
hw/arm/smmuv3.c +10
-0+ +if (!sdev) { +break ; + } + +if (!smmuv3_accel_issue_inv_cmd (s, &cmd, sdev, errp)) { + cmd_error =SMMU_CERROR_ILL ; +break ; + } +break ;
got build error here, need { }
../hw/arm/smmuv3.c: In function ‘smmuv3_cmdq_consume’:../hw/arm/smmuv3.c:1505:13: error: a label can only be part of a statement and a declaration is not a statement
1505 | SMMUDevice *sdev = smmu_find_sdev(bs, CMD_SID(&cmd));
| ^~~~~~~~~~Thanks
RE: [PATCH v6 28/33] hw/arm/smmuv3-accel: Add support for ATS
Quoted 17 lines
-----Original Message-----
From: Zhangfei Gao <[email protected]>
Sent: 24 November 2025 12:01
To: Shameer Kolothum <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 28/33] hw/arm/smmuv3-accel: Add support for ATS
Quoted 16 lines
Quoted 4 lines
smmuv3_range_inval(bs, &cmd, SMMU_STAGE_2); break;hw/arm/smmuv3.c +2
-0+case SMMU_CMD_ATC_INV : +SMMUDevice *sdev =smmu_find_sdev (bs,CMD_SID (&cmd));hw/arm/smmuv3.c static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp) · line 1512
Quoted 10 lines
hw/arm/smmuv3.c +10
-0+ +if (!sdev) { +break ; + } + +if (!smmuv3_accel_issue_inv_cmd (s, &cmd, sdev, errp)) { + cmd_error =SMMU_CERROR_ILL ; +break ; + } +break ;got build error here, need { }
Yes, need the braces. Will fix.
Thanks,
Shameer
Re: [PATCH v6 28/33] hw/arm/smmuv3-accel: Add support for ATS
In reply to Shameer KolothumHi Shameer,
Quoted 4 lines · Shameer Kolothum
QEMU SMMUv3 does not enable ATS (Address Translation Services) by default. When accelerated mode is enabled and the host SMMUv3 supports ATS, it can be useful to report ATS capability to the guest so it can take advantage of it if the device also supports ATS.
device = assigned device
Quoted 25 lines
Note: ATS support cannot be reliably detected from the host SMMUv3 IDR registers alone, as firmware ACPI IORT tables may override them. The user must therefore ensure the support before enabling it.
The ATS support enabled here is only relevant for vfio-pci endpoints, as SMMUv3 accelerated mode does not support emulated endpoint devices. QEMU’s SMMUv3 implementation still lacks support for handling ATS translation requests, which would be required for emulated endpoints.
Reviewed-by Jonathan Cameron <[email protected]>Tested-by Zhangfei Gao <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.c | 3 +++ hw/arm/smmuv3.c | 21 ++++++++++++++++++++- hw/arm/virt-acpi-build.c | 10 ++++++++-- include/hw/arm/smmuv3.h | 1 + 4 files changed, 32 insertions(+), 3 deletions(-)hw/arm/smmuv3-accel.c +0
-0
hw/arm/smmuv3-accel.c void smmuv3_accel_idr_override(SMMUv3State *s) · line 651
Quoted 5 lines
hw/arm/smmuv3-accel.c +2
-0@@ -647,6 +647,9 @@ void smmuv3_accel_idr_override(SMMUv3State *s)/* By default QEMU SMMUv3 has RIL. Update IDR3 if user has disabled it */ s->idr[3 ] =FIELD_DP32 (s->idr[3 ],IDR3 ,RIL , s->ril); + +/* QEMU SMMUv3 has no ATS. Advertise ATS if opt-on by property */
opt-in?
Quoted 14 lines
hw/arm/smmuv3-accel.c +1
-0+ s->idr[0 ] =FIELD_DP32 (s->idr[0 ],IDR0 ,ATS , s->ats); }/* Based on SMUUv3 GPBA.ABORT configuration, attach a corresponding HWPT */ hw/arm/smmuv3.c +2
-0@@ -1498,13 +1498,24 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp)*/ smmuv3_range_inval (bs, &cmd,SMMU_STAGE_2 );break ; +case SMMU_CMD_ATC_INV : +SMMUDevice *sdev =smmu_find_sdev (bs,CMD_SID (&cmd));
hw/arm/smmuv3.c static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp) · line 1512
Quoted 10 lines
hw/arm/smmuv3.c +10
-0+ +if (!sdev) { +break ; + } + +if (!smmuv3_accel_issue_inv_cmd (s, &cmd, sdev, errp)) { + cmd_error =SMMU_CERROR_ILL ; +break ; + } +break ;
with the compilation issue fixed,
Eric
Quoted 100 lines
hw/arm/smmuv3.c +8
-1case SMMU_CMD_TLBI_EL3_ALL :case SMMU_CMD_TLBI_EL3_VA :case SMMU_CMD_TLBI_EL2_ALL :case SMMU_CMD_TLBI_EL2_ASID :case SMMU_CMD_TLBI_EL2_VA :case SMMU_CMD_TLBI_EL2_VAA : -case SMMU_CMD_ATC_INV :case SMMU_CMD_PRI_RESP :case SMMU_CMD_RESUME :case SMMU_CMD_STALL_TERM :@@ -1930,6 +1941,10 @@ static bool smmu_validate_property(SMMUv3State *s, Error **errp)error_setg (errp,"ril can only be disabled if accel=on" );return false; } +if (s->ats) { +error_setg (errp,"ats can only be enabled if accel=on" ); +return false; + }return true; }return true;@@ -2057,6 +2072,7 @@ static const Property smmuv3_properties[] = {DEFINE_PROP_UINT64 ("msi-gpa" , SMMUv3State, msi_gpa,0 ),/* RIL can be turned off for accel cases */ DEFINE_PROP_BOOL ("ril" , SMMUv3State, ril, true), + DEFINE_PROP_BOOL("ats", SMMUv3State, ats, false), };static void smmuv3_instance_init (Object *obj)@@ -2084,6 +2100,9 @@ static void smmuv3_class_init(ObjectClass *klass, const void *data) "configured in nested mode for vfio-pci dev assignment");object_class_property_set_description (klass,"ril" ,"Disable range invalidation support (for accel=on)" ); +object_class_property_set_description (klass,"ats" , +"Enable/disable ATS support (for accel=on). Please ensure host " +"platform has ATS support before enabling this" ); } static int smmuv3_notify_flag_changed(IOMMUMemoryRegion *iommu,hw/arm/virt-acpi-build.c +8
-2@@ -346,6 +346,7 @@ typedef struct AcpiIortSMMUv3Dev {/* Offset of the SMMUv3 IORT Node relative to the start of the IORT */ size_t offset;bool accel; +bool ats; } AcpiIortSMMUv3Dev;/* @@ -401,6 +402,7 @@ static int iort_smmuv3_devices(Object *obj, void *opaque) bus =PCI_BUS (object_property_get_link (obj,"primary-bus" , &error_abort)); sdev.accel =object_property_get_bool (obj,"accel" , &error_abort); + sdev.ats =object_property_get_bool (obj,"ats" , &error_abort); pbus =PLATFORM_BUS_DEVICE (vms->platform_bus_dev); sbdev =SYS_BUS_DEVICE (obj); sdev.base =platform_bus_get_mmio_addr (pbus, sbdev,0 );@@ -544,6 +546,7 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)int i, nb_nodes, rc_mapping_count;AcpiIortSMMUv3Dev *sdev;size_t node_size; +bool ats_needed = false;int num_smmus =0 ;uint32_t id =0 ;int rc_smmu_idmaps_len =0 ;@@ -579,6 +582,9 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)/* Calculate RMR nodes required. One per SMMUv3 with accelerated mode */ for (i =0 ; i < num_smmus; i++) { sdev = &g_array_index (smmuv3_devs, AcpiIortSMMUv3Dev, i); +if (sdev->ats) { + ats_needed = true; + }if (sdev->accel) { nb_nodes++; }@@ -678,8 +684,8 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)build_append_int_noprefix (table_data,0 ,2 );/* Reserved */ /* Table 15 Memory Access Flags */ build_append_int_noprefix (table_data,0x3 /* CCA = CPM = DACS = 1 */ ,1 ); - -build_append_int_noprefix (table_data,0 ,4 );/* ATS Attribute */ +/* ATS Attribute */ +build_append_int_noprefix (table_data, ats_needed,4 );/* MCFG pci_segment */ build_append_int_noprefix (table_data,0 ,4 );/* PCI Segment number */ include/hw/arm/smmuv3.h +1
-0@@ -70,6 +70,7 @@ struct SMMUv3State {uint64_t msi_gpa;Error *migration_blocker;bool ril; +bool ats; }; typedef enum {
PATCH v6 29/33 hw/arm/smmuv3-accel: Add property to specify OAS bits
In reply to Shameer KolothumQEMU SMMUv3 currently sets the output address size (OAS) to 44 bits. With accelerator mode enabled, a device may use SVA, where CPU page tables are shared with the SMMU, requiring an OAS at least as large as the CPU’s output address size. A user option is added to configure this.
However, the OAS value advertised by the virtual SMMU must remain compatible with the capabilities of the host SMMUv3. In accelerated mode, the host SMMU performs stage-2 translation and must be able to consume the intermediate physical addresses (IPA) produced by stage-1.
The OAS exposed by the virtual SMMU defines the maximum IPA width that stage-1 translations may generate. For AArch64 implementations, the maximum usable IPA size on the host SMMU is determined by its own OAS. Check that the configured OAS does not exceed what the host SMMU can safely support.
--- hw/arm/smmuv3-accel.c | 20 ++++++++++++++++++++ hw/arm/smmuv3-internal.h | 3 ++- hw/arm/smmuv3.c | 16 +++++++++++++++- include/hw/arm/smmuv3.h | 1 + 4 files changed, 38 insertions(+), 2 deletions(-)
hw/arm/smmuv3-accel.c +20 -0
@@ -27,6 +27,12 @@static MemoryRegion root, sysmem;static AddressSpace *shared_as_sysmem; +static int smmuv3_oas_bits (uint32_t oas) +{ +static const int map[] = {32 ,36 ,40 ,42 ,44 ,48 ,52 ,56 }; +return (oas <ARRAY_SIZE (map)) ? map[oas] : -EINVAL ; +} + static bool smmuv3_accel_check_hw_compatible(SMMUv3State *s, struct iommu_hw_info_arm_smmuv3 *info,
@@ -68,6 +74,15 @@ smmuv3_accel_check_hw_compatible(SMMUv3State *s,error_setg (errp,"Host SMMUv3 doesn't support Range Invalidation" );return false; } +/* Check OAS value opted is compatible with Host SMMUv3 IPA */ +if (FIELD_EX32 (info->idr[5 ],IDR5 ,OAS ) < +FIELD_EX32 (s->idr[5 ],IDR5 ,OAS )) { +error_setg (errp,"Host SMMUv3 supports only %d-bit IPA, but the vSMMU " +"OAS implies %d-bit IPA" , +smmuv3_oas_bits (FIELD_EX32 (info->idr[5 ],IDR5 ,OAS )), +smmuv3_oas_bits (FIELD_EX32 (info->idr[5 ],IDR5 ,OAS ))); +return false; + }/* QEMU SMMUv3 supports GRAN4K/GRAN16K/GRAN64K translation granules */ if (FIELD_EX32(info->idr[5], IDR5, GRAN4K) !=
@@ -650,6 +665,11 @@ void smmuv3_accel_idr_override(SMMUv3State *s)/* QEMU SMMUv3 has no ATS. Advertise ATS if opt-on by property */ s->idr[0 ] =FIELD_DP32 (s->idr[0 ],IDR0 ,ATS , s->ats); + +/* Advertise 48-bit OAS in IDR5 when requested (default is 44 bits). */ +if (s->oas ==48 ) { + s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS ,SMMU_IDR5_OAS_48 ); + } }/* Based on SMUUv3 GPBA.ABORT configuration, attach a corresponding HWPT */
hw/arm/smmuv3-internal.h +2 -1
@@ -111,7 +111,8 @@ REG32(IDR5, 0x14)FIELD (IDR5 ,VAX ,10 ,2 );FIELD (IDR5 ,STALL_MAX ,16 ,16 ); -#define SMMU_IDR5_OAS 4 +#define SMMU_IDR5_OAS_44 4 +#define SMMU_IDR5_OAS_48 5 REG32(IIDR, 0x18)REG32 (AIDR ,0x1c )
hw/arm/smmuv3.c +15 -1
@@ -299,7 +299,8 @@ static void smmuv3_init_id_regs(SMMUv3State *s) s->idr[3 ] =FIELD_DP32 (s->idr[3 ],IDR3 ,RIL ,1 ); s->idr[3 ] =FIELD_DP32 (s->idr[3 ],IDR3 ,BBML ,2 ); - s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS ,SMMU_IDR5_OAS );/* 44 bits */ +/* OAS: 44 bits */ + s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS ,SMMU_IDR5_OAS_44 );/* 4K, 16K and 64K granule support */ s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN4K ,1 ); s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN16K ,1 );
@@ -1945,8 +1946,17 @@ static bool smmu_validate_property(SMMUv3State *s, Error **errp)error_setg (errp,"ats can only be enabled if accel=on" );return false; } +if (s->oas !=44 ) { +error_setg (errp,"OAS can only be set to 44 bits if accel=off" ); +return false; + }return true; } + +if (s->oas !=44 && s->oas !=48 ) { +error_setg (errp,"OAS can only be set to 44 or 48 bits" ); +return false; + }return true; }
@@ -2073,6 +2083,7 @@ static const Property smmuv3_properties[] = {/* RIL can be turned off for accel cases */ DEFINE_PROP_BOOL ("ril" , SMMUv3State, ril, true),DEFINE_PROP_BOOL ("ats" , SMMUv3State, ats, false), + DEFINE_PROP_UINT8("oas", SMMUv3State, oas, 44), };static void smmuv3_instance_init (Object *obj)
@@ -2103,6 +2114,9 @@ static void smmuv3_class_init(ObjectClass *klass, const void *data)object_class_property_set_description (klass,"ats" ,"Enable/disable ATS support (for accel=on). Please ensure host " "platform has ATS support before enabling this" ); +object_class_property_set_description (klass,"oas" , +"Specify Output Address Size (for accel =on). Supported values " +"are 44 or 48 bits. Defaults to 44 bits" ); } static int smmuv3_notify_flag_changed(IOMMUMemoryRegion *iommu,
include/hw/arm/smmuv3.h +1 -0
@@ -71,6 +71,7 @@ struct SMMUv3State {Error *migration_blocker;bool ril;bool ats; +uint8_t oas; }; typedef enum {
Signature · 1 line
2.43.0
Re: [PATCH v6 29/33] hw/arm/smmuv3-accel: Add property to specify OAS bits
Quoted 30 lines · Shameer Kolothum
QEMU SMMUv3 currently sets the output address size (OAS) to 44 bits. With accelerator mode enabled, a device may use SVA, where CPU page tables are shared with the SMMU, requiring an OAS at least as large as the CPU’s output address size. A user option is added to configure this.
However, the OAS value advertised by the virtual SMMU must remain compatible with the capabilities of the host SMMUv3. In accelerated mode, the host SMMU performs stage-2 translation and must be able to consume the intermediate physical addresses (IPA) produced by stage-1.
The OAS exposed by the virtual SMMU defines the maximum IPA width that stage-1 translations may generate. For AArch64 implementations, the maximum usable IPA size on the host SMMU is determined by its own OAS. Check that the configured OAS does not exceed what the host SMMU can safely support.
Tested-by Zhangfei Gao <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.c | 20 ++++++++++++++++++++ hw/arm/smmuv3-internal.h | 3 ++- hw/arm/smmuv3.c | 16 +++++++++++++++- include/hw/arm/smmuv3.h | 1 + 4 files changed, 38 insertions(+), 2 deletions(-)hw/arm/smmuv3-accel.c +0
-0
hw/arm/smmuv3-accel.c line 33
Quoted 7 lines
hw/arm/smmuv3-accel.c +4
-0@@ -27,6 +27,12 @@static MemoryRegion root, sysmem;static AddressSpace *shared_as_sysmem; +static int smmuv3_oas_bits (uint32_t oas) +{ +static const int map[] = {32 ,36 ,40 ,42 ,44 ,48 ,52 ,56 }; + return () ? map[oas] : -EINVAL;
We should probably just:
g_assert(oas < ARRAY_SIZE(map));
-EINVAL is useless anyway in the caller that prints it.
Otherwise,
Eric Auger
Reviewed-byRe: [PATCH v6 29/33] hw/arm/smmuv3-accel: Add property to specify OAS bits
Quoted 39 lines · Nicolin Chen
Quoted 30 lines · Shameer Kolothum
QEMU SMMUv3 currently sets the output address size (OAS) to 44 bits. With accelerator mode enabled, a device may use SVA, where CPU page tables are shared with the SMMU, requiring an OAS at least as large as the CPU’s output address size. A user option is added to configure this.
However, the OAS value advertised by the virtual SMMU must remain compatible with the capabilities of the host SMMUv3. In accelerated mode, the host SMMU performs stage-2 translation and must be able to consume the intermediate physical addresses (IPA) produced by stage-1.
The OAS exposed by the virtual SMMU defines the maximum IPA width that stage-1 translations may generate. For AArch64 implementations, the maximum usable IPA size on the host SMMU is determined by its own OAS. Check that the configured OAS does not exceed what the host SMMU can safely support.
Tested-by Zhangfei Gao <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.c | 20 ++++++++++++++++++++ hw/arm/smmuv3-internal.h | 3 ++- hw/arm/smmuv3.c | 16 +++++++++++++++- include/hw/arm/smmuv3.h | 1 + 4 files changed, 38 insertions(+), 2 deletions(-)hw/arm/smmuv3-accel.c +0
-0hw/arm/smmuv3-accel.c line 33
Quoted 7 lines
hw/arm/smmuv3-accel.c +4
-0@@ -27,6 +27,12 @@static MemoryRegion root, sysmem;static AddressSpace *shared_as_sysmem; +static int smmuv3_oas_bits (uint32_t oas) +{ +static const int map[] = {32 ,36 ,40 ,42 ,44 ,48 ,52 ,56 }; + return () ? map[oas] : -EINVAL;We should probably just:
Quoted 7 lines
g_assert(oas < ARRAY_SIZE(map));
-EINVALis useless anyway in the caller that prints it.Otherwise,
Reviewed-by Nicolin Chen <[email protected]>
With Nicolin's suggestion
Eric
Quoted 1 line
Re: [PATCH v6 29/33] hw/arm/smmuv3-accel: Add property to specify OAS bits
In reply to Shameer KolothumQuoted 59 lines · Shameer Kolothum
QEMU SMMUv3 currently sets the output address size (OAS) to 44 bits. With accelerator mode enabled, a device may use SVA, where CPU page tables are shared with the SMMU, requiring an OAS at least as large as the CPU’s output address size. A user option is added to configure this.
However, the OAS value advertised by the virtual SMMU must remain compatible with the capabilities of the host SMMUv3. In accelerated mode, the host SMMU performs stage-2 translation and must be able to consume the intermediate physical addresses (IPA) produced by stage-1.
The OAS exposed by the virtual SMMU defines the maximum IPA width that stage-1 translations may generate. For AArch64 implementations, the maximum usable IPA size on the host SMMU is determined by its own OAS. Check that the configured OAS does not exceed what the host SMMU can safely support.
Tested-by Zhangfei Gao <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.c | 20 ++++++++++++++++++++ hw/arm/smmuv3-internal.h | 3 ++- hw/arm/smmuv3.c | 16 +++++++++++++++- include/hw/arm/smmuv3.h | 1 + 4 files changed, 38 insertions(+), 2 deletions(-)hw/arm/smmuv3-accel.c +15
-0@@ -27,6 +27,12 @@static MemoryRegion root, sysmem;static AddressSpace *shared_as_sysmem; +static int smmuv3_oas_bits (uint32_t oas) +{ +static const int map[] = {32 ,36 ,40 ,42 ,44 ,48 ,52 ,56 }; +return (oas <ARRAY_SIZE (map)) ? map[oas] : -EINVAL ; +} + static bool smmuv3_accel_check_hw_compatible(SMMUv3State *s, struct iommu_hw_info_arm_smmuv3 *info,@@ -68,6 +74,15 @@ smmuv3_accel_check_hw_compatible(SMMUv3State *s,error_setg (errp,"Host SMMUv3 doesn't support Range Invalidation" );return false; } +/* Check OAS value opted is compatible with Host SMMUv3 IPA */ +if (FIELD_EX32 (info->idr[5 ],IDR5 ,OAS ) < +FIELD_EX32 (s->idr[5 ],IDR5 ,OAS )) { +error_setg (errp,"Host SMMUv3 supports only %d-bit IPA, but the vSMMU " +"OAS implies %d-bit IPA" , +smmuv3_oas_bits (FIELD_EX32 (info->idr[5 ],IDR5 ,OAS )), +smmuv3_oas_bits (FIELD_EX32 (info->idr[5 ],IDR5 ,OAS ))); +return false; + }/* QEMU SMMUv3 supports GRAN4K/GRAN16K/GRAN64K translation granules */ if (FIELD_EX32(info->idr[5], IDR5, GRAN4K) !=
hw/arm/smmuv3-accel.c void smmuv3_accel_idr_override(SMMUv3State *s) · line 670
Quoted 6 lines
hw/arm/smmuv3-accel.c +3
-0@@ -650,6 +665,11 @@ void smmuv3_accel_idr_override(SMMUv3State *s)/* QEMU SMMUv3 has no ATS. Advertise ATS if opt-on by property */ s->idr[0 ] =FIELD_DP32 (s->idr[0 ],IDR0 ,ATS , s->ats); + +/* Advertise 48-bit OAS in IDR5 when requested (default is 44 bits). */ +if (s->oas ==48 ) {
Intel has defines for AS width :
VTD_HOST_AW_48BIT
VTD_HOST_AW_39BIT
I suggest doing the same for SMMUv3 to avoid using directly numerical values like here and below.
Thanks,
C.
Quoted 81 lines
hw/arm/smmuv3-accel.c +2
-0+ s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS ,SMMU_IDR5_OAS_48 ); + } }/* Based on SMUUv3 GPBA.ABORT configuration, attach a corresponding HWPT */ hw/arm/smmuv3-internal.h +2
-1@@ -111,7 +111,8 @@ REG32(IDR5, 0x14)FIELD (IDR5 ,VAX ,10 ,2 );FIELD (IDR5 ,STALL_MAX ,16 ,16 ); -#define SMMU_IDR5_OAS 4 +#define SMMU_IDR5_OAS_44 4 +#define SMMU_IDR5_OAS_48 5 REG32(IIDR, 0x18)REG32 (AIDR ,0x1c )hw/arm/smmuv3.c +15
-1@@ -299,7 +299,8 @@ static void smmuv3_init_id_regs(SMMUv3State *s) s->idr[3 ] =FIELD_DP32 (s->idr[3 ],IDR3 ,RIL ,1 ); s->idr[3 ] =FIELD_DP32 (s->idr[3 ],IDR3 ,BBML ,2 ); - s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS ,SMMU_IDR5_OAS );/* 44 bits */ +/* OAS: 44 bits */ + s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS ,SMMU_IDR5_OAS_44 );/* 4K, 16K and 64K granule support */ s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN4K ,1 ); s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN16K ,1 );@@ -1945,8 +1946,17 @@ static bool smmu_validate_property(SMMUv3State *s, Error **errp)error_setg (errp,"ats can only be enabled if accel=on" );return false; } +if (s->oas !=44 ) { +error_setg (errp,"OAS can only be set to 44 bits if accel=off" ); +return false; + }return true; } + +if (s->oas !=44 && s->oas !=48 ) { +error_setg (errp,"OAS can only be set to 44 or 48 bits" ); +return false; + }return true; }@@ -2073,6 +2083,7 @@ static const Property smmuv3_properties[] = {/* RIL can be turned off for accel cases */ DEFINE_PROP_BOOL ("ril" , SMMUv3State, ril, true),DEFINE_PROP_BOOL ("ats" , SMMUv3State, ats, false), + DEFINE_PROP_UINT8("oas", SMMUv3State, oas, 44), };static void smmuv3_instance_init (Object *obj)@@ -2103,6 +2114,9 @@ static void smmuv3_class_init(ObjectClass *klass, const void *data)object_class_property_set_description (klass,"ats" ,"Enable/disable ATS support (for accel=on). Please ensure host " "platform has ATS support before enabling this" ); +object_class_property_set_description (klass,"oas" , +"Specify Output Address Size (for accel =on). Supported values " +"are 44 or 48 bits. Defaults to 44 bits" ); } static int smmuv3_notify_flag_changed(IOMMUMemoryRegion *iommu,include/hw/arm/smmuv3.h +1
-0@@ -71,6 +71,7 @@ struct SMMUv3State {Error *migration_blocker;bool ril;bool ats; +uint8_t oas; }; typedef enum {
PATCH v6 30/33 backends/iommufd: Retrieve PASID width from iommufd_backend_get_device_info()
In reply to Shameer KolothumRetrieve PASID width from iommufd_backend_get_device_info() and store it in HostIOMMUDeviceCaps for later use.
--- backends/iommufd.c | 6 +++++- hw/arm/smmuv3-accel.c | 3 ++- hw/vfio/iommufd.c | 7 +++++-- include/system/host_iommu_device.h | 3 +++ include/system/iommufd.h | 3 ++- 5 files changed, 17 insertions(+), 5 deletions(-)
backends/iommufd.c +5 -1
@@ -388,7 +388,8 @@ bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be,bool iommufd_backend_get_device_info (IOMMUFDBackend *be,uint32_t devid,uint32_t *type,void *data,uint32_t len, -uint64_t *caps,Error **errp) +uint64_t *caps,uint8_t *max_pasid_log2, +Error **errp) {struct iommu_hw_info info = { .size =sizeof (info),
@@ -407,6 +408,9 @@ bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid,g_assert (caps); *caps = info.out_capabilities; +if (max_pasid_log2) { + *max_pasid_log2 = info.out_max_pasid_log2; + }return true; }
hw/arm/smmuv3-accel.c +2 -1
@@ -113,7 +113,8 @@ smmuv3_accel_hw_compatible(SMMUv3State *s, HostIOMMUDeviceIOMMUFD *idev,uint64_t caps;if (!iommufd_backend_get_device_info (idev->iommufd, idev->devid, &data_type, - &info,sizeof (info), &caps, errp)) { + &info,sizeof (info), &caps,NULL , + errp)) {return false; }
hw/vfio/iommufd.c +5 -2
@@ -353,7 +353,8 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vbasedev,* instead. */ if (!iommufd_backend_get_device_info (vbasedev->iommufd, vbasedev->devid, - &type,NULL ,0 , &hw_caps, errp)) { + &type,NULL ,0 , &hw_caps,NULL , + errp)) {return false; }
@@ -889,19 +890,21 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque,HostIOMMUDeviceCaps *caps = &hiod->caps;VendorCaps *vendor_caps = &caps->vendor_caps;enum iommu_hw_info_type type; +uint8_t max_pasid_log2;uint64_t hw_caps; hiod->agent = opaque;if (!iommufd_backend_get_device_info (vdev->iommufd, vdev->devid, &type, vendor_caps,sizeof (*vendor_caps), - &hw_caps, errp)) { + &hw_caps, &max_pasid_log2, errp)) {return false; } hiod->name =g_strdup (vdev->name); caps->type = type; caps->hw_caps = hw_caps; + caps->max_pasid_log2 = max_pasid_log2; idev =HOST_IOMMU_DEVICE_IOMMUFD (hiod); idev->iommufd = vdev->iommufd;
include/system/host_iommu_device.h +3 -0
@@ -30,6 +30,8 @@ typedef union VendorCaps {* @hw_caps: host platform IOMMU capabilities (e.g. on IOMMUFD this represents * the @out_capabilities value returned from IOMMU_GET_HW_INFO ioctl) * +* @max_pasid_log2: width of PASIDs supported by host IOMMU device +* * @vendor_caps: host platform IOMMU vendor specific capabilities (e.g. on * IOMMUFD this represents a user-space buffer filled by kernel * with host IOMMU @type specific hardware information data)
@@ -37,6 +39,7 @@ typedef union VendorCaps {typedef struct HostIOMMUDeviceCaps {uint32_t type;uint64_t hw_caps; +uint8_t max_pasid_log2;VendorCaps vendor_caps; }HostIOMMUDeviceCaps ;#endif
include/system/iommufd.h +2 -1
@@ -71,7 +71,8 @@ int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_t ioas_id, hwaddr iova, uint64_t size);bool iommufd_backend_get_device_info (IOMMUFDBackend *be,uint32_t devid,uint32_t *type,void *data,uint32_t len, -uint64_t *caps,Error **errp); +uint64_t *caps,uint8_t *max_pasid_log2, +Error **errp); bool iommufd_backend_alloc_hwpt(IOMMUFDBackend *be, uint32_t dev_id, uint32_t pt_id, uint32_t flags, uint32_t data_type, uint32_t data_len,
Signature · 1 line
2.43.0
Re: [PATCH v6 30/33] backends/iommufd: Retrieve PASID width from iommufd_backend_get_device_info()
Quoted 7 lines · Shameer Kolothum
Retrieve PASID width from
iommufd_backend_get_device_info()and store it in HostIOMMUDeviceCaps for later use.Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Eric Auger <[email protected]>Tested-by Zhangfei Gao <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>
Re: [PATCH v6 30/33] backends/iommufd: Retrieve PASID width from iommufd_backend_get_device_info()
In reply to Shameer KolothumQuoted 7 lines · Shameer Kolothum
Retrieve PASID width from
iommufd_backend_get_device_info()and store it in HostIOMMUDeviceCaps for later use.Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Eric Auger <[email protected]>Tested-by Zhangfei Gao <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>
Thanks,
C.
Quoted 118 lines
--- backends/iommufd.c | 6 +++++- hw/arm/smmuv3-accel.c | 3 ++- hw/vfio/iommufd.c | 7 +++++-- include/system/host_iommu_device.h | 3 +++ include/system/iommufd.h | 3 ++- 5 files changed, 17 insertions(+), 5 deletions(-)backends/iommufd.c +5
-1@@ -388,7 +388,8 @@ bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be,bool iommufd_backend_get_device_info (IOMMUFDBackend *be,uint32_t devid,uint32_t *type,void *data,uint32_t len, -uint64_t *caps,Error **errp) +uint64_t *caps,uint8_t *max_pasid_log2, +Error **errp) {struct iommu_hw_info info = { .size =sizeof (info),@@ -407,6 +408,9 @@ bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid,g_assert (caps); *caps = info.out_capabilities; +if (max_pasid_log2) { + *max_pasid_log2 = info.out_max_pasid_log2; + }return true; }hw/arm/smmuv3-accel.c +2
-1@@ -113,7 +113,8 @@ smmuv3_accel_hw_compatible(SMMUv3State *s, HostIOMMUDeviceIOMMUFD *idev,uint64_t caps;if (!iommufd_backend_get_device_info (idev->iommufd, idev->devid, &data_type, - &info,sizeof (info), &caps, errp)) { + &info,sizeof (info), &caps,NULL , + errp)) {return false; }hw/vfio/iommufd.c +5
-2@@ -353,7 +353,8 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vbasedev,* instead. */ if (!iommufd_backend_get_device_info (vbasedev->iommufd, vbasedev->devid, - &type,NULL ,0 , &hw_caps, errp)) { + &type,NULL ,0 , &hw_caps,NULL , + errp)) {return false; }@@ -889,19 +890,21 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque,HostIOMMUDeviceCaps *caps = &hiod->caps;VendorCaps *vendor_caps = &caps->vendor_caps;enum iommu_hw_info_type type; +uint8_t max_pasid_log2;uint64_t hw_caps; hiod->agent = opaque;if (!iommufd_backend_get_device_info (vdev->iommufd, vdev->devid, &type, vendor_caps,sizeof (*vendor_caps), - &hw_caps, errp)) { + &hw_caps, &max_pasid_log2, errp)) {return false; } hiod->name =g_strdup (vdev->name); caps->type = type; caps->hw_caps = hw_caps; + caps->max_pasid_log2 = max_pasid_log2; idev =HOST_IOMMU_DEVICE_IOMMUFD (hiod); idev->iommufd = vdev->iommufd;include/system/host_iommu_device.h +3
-0@@ -30,6 +30,8 @@ typedef union VendorCaps {* @hw_caps: host platform IOMMU capabilities (e.g. on IOMMUFD this represents * the @out_capabilities value returned from IOMMU_GET_HW_INFO ioctl) * +* @max_pasid_log2: width of PASIDs supported by host IOMMU device +* * @vendor_caps: host platform IOMMU vendor specific capabilities (e.g. on * IOMMUFD this represents a user-space buffer filled by kernel * with host IOMMU @type specific hardware information data) @@ -37,6 +39,7 @@ typedef union VendorCaps {typedef struct HostIOMMUDeviceCaps {uint32_t type;uint64_t hw_caps; +uint8_t max_pasid_log2;VendorCaps vendor_caps; }HostIOMMUDeviceCaps ;#endif include/system/iommufd.h +2
-1@@ -71,7 +71,8 @@ int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_t ioas_id, hwaddr iova, uint64_t size);bool iommufd_backend_get_device_info (IOMMUFDBackend *be,uint32_t devid,uint32_t *type,void *data,uint32_t len, -uint64_t *caps,Error **errp); +uint64_t *caps,uint8_t *max_pasid_log2, +Error **errp); bool iommufd_backend_alloc_hwpt(IOMMUFDBackend *be, uint32_t dev_id, uint32_t pt_id, uint32_t flags, uint32_t data_type, uint32_t data_len,
PATCH v6 31/33 Extend get_cap() callback to support PASID
In reply to Shameer KolothumModify get_cap() callback so that it can return cap via an output uint64_t param. And add support for generic iommu hw capability info and max_pasid_log2(pasid width).
--- backends/iommufd.c | 23 ++++++++++++++++++----- hw/i386/intel_iommu.c | 8 +++++--- hw/vfio/container-legacy.c | 8 ++++++-- include/system/host_iommu_device.h | 18 ++++++++++++------ 4 files changed, 41 insertions(+), 16 deletions(-)
backends/iommufd.c +18 -5
@@ -523,19 +523,32 @@ bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *idev,return idevc->detach_hwpt (idev, errp); } -static int hiod_iommufd_get_cap (HostIOMMUDevice *hiod,int cap,Error **errp) +static int hiod_iommufd_get_cap (HostIOMMUDevice *hiod,int cap_id, +uint64_t *out_cap,Error **errp) {HostIOMMUDeviceCaps *caps = &hiod->caps; -switch (cap) { +g_assert (out_cap); + +switch (cap_id) {case HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE : -return caps->type; + *out_cap = caps->type; +break ;case HOST_IOMMU_DEVICE_CAP_AW_BITS : -return vfio_device_get_aw_bits (hiod->agent); + *out_cap =vfio_device_get_aw_bits (hiod->agent); +break ; +case HOST_IOMMU_DEVICE_CAP_GENERIC_HW : + *out_cap = caps->hw_caps; +break ; +case HOST_IOMMU_DEVICE_CAP_MAX_PASID_LOG2 : + *out_cap = caps->max_pasid_log2; +break ;default : -error_setg (errp,"%s: unsupported capability %x" , hiod->name, cap); + *out_cap =0 ; +error_setg (errp,"%s: unsupported capability %x" , hiod->name, cap_id);return -EINVAL ; } +return 0 ; }static void hiod_iommufd_class_init (ObjectClass *oc,const void *data)
hw/i386/intel_iommu.c +5 -3
@@ -4605,6 +4605,7 @@ static bool vtd_check_hiod(IntelIOMMUState *s, HostIOMMUDevice *hiod, Error **errp) {HostIOMMUDeviceClass *hiodc =HOST_IOMMU_DEVICE_GET_CLASS (hiod); +uint64_t out_cap;int ret;if (!hiodc->get_cap) {
@@ -4613,12 +4614,13 @@ static bool vtd_check_hiod(IntelIOMMUState *s, HostIOMMUDevice *hiod, }/* Common checks */ - ret = hiodc->get_cap (hiod,HOST_IOMMU_DEVICE_CAP_AW_BITS , errp); + ret = hiodc->get_cap (hiod,HOST_IOMMU_DEVICE_CAP_AW_BITS , &out_cap, errp);if (ret <0 ) {return false; } -if (s->aw_bits > ret) { -error_setg (errp,"aw-bits %d > host aw-bits %d" , s->aw_bits, ret); +if (s->aw_bits > out_cap) { +error_setg (errp,"aw-bits %d > host aw-bits 0x%" PRIx64, s->aw_bits, + out_cap);return false; }
hw/vfio/container-legacy.c +6 -2
@@ -1203,15 +1203,19 @@ static bool hiod_legacy_vfio_realize(HostIOMMUDevice *hiod, void *opaque, }static int hiod_legacy_vfio_get_cap (HostIOMMUDevice *hiod,int cap, -Error **errp) +uint64_t *out_cap,Error **errp) { +g_assert (out_cap); +switch (cap) {case HOST_IOMMU_DEVICE_CAP_AW_BITS : -return vfio_device_get_aw_bits (hiod->agent); + *out_cap =vfio_device_get_aw_bits (hiod->agent); +break ;default :error_setg (errp,"%s: unsupported capability %x" , hiod->name, cap);return -EINVAL ; } +return 0 ; } static GList *
include/system/host_iommu_device.h +12 -6
@@ -88,19 +88,21 @@ struct HostIOMMUDeviceClass {* @get_cap: check if a host IOMMU device capability is supported. * * Optional callback, if not implemented, hint not supporting query -* of @cap. +* of @cap_id. * * @hiod: pointer to a host IOMMU device instance. * -* @cap: capability to check. +* @cap_id: capability to check. +* +* @out_cap: 0 if a @cap_id is unsupported or else the capability +* value for @cap_id. * * @errp: pass an Error out when fails to query capability. * -* Returns: <0 on failure, 0 if a @cap is unsupported, or else -* 1 or some positive value for some special @cap, -* i.e., HOST_IOMMU_DEVICE_CAP_AW_BITS. +* Returns: <0 if @cap_id is not supported, 0 on success. */ -int (*get_cap)(HostIOMMUDevice *hiod,int cap,Error **errp); +int (*get_cap)(HostIOMMUDevice *hiod,int cap_id,uint64_t *out_cap, +Error **errp);/** * @get_iova_ranges: Return the list of usable iova_ranges along with * @hiod Host IOMMU device
@@ -123,6 +125,10 @@ struct HostIOMMUDeviceClass {*/ #define HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE 0#define HOST_IOMMU_DEVICE_CAP_AW_BITS 1 +/* Generic IOMMU HW capability info */ +#define HOST_IOMMU_DEVICE_CAP_GENERIC_HW 2 +/* PASID width */ +#define HOST_IOMMU_DEVICE_CAP_MAX_PASID_LOG2 3#define HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX 64#endif
Signature · 1 line
2.43.0
Re: [PATCH v6 31/33] Extend get_cap() callback to support PASID
Quoted 6 lines · Shameer Kolothum
Modify
get_cap()callback so that it can return cap via an outputuint64_tparam. And add support for generic iommu hw capability info andmax_pasid_log2(pasid width).Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>
Re: [PATCH v6 31/33] Extend get_cap() callback to support PASID
In reply to Shameer KolothumHi Shameer,
Quoted 38 lines · Shameer Kolothum
Modify
get_cap()callback so that it can return cap via an outputuint64_tparam. And add support for generic iommu hw capability info andmax_pasid_log2(pasid width).Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- backends/iommufd.c | 23 ++++++++++++++++++----- hw/i386/intel_iommu.c | 8 +++++--- hw/vfio/container-legacy.c | 8 ++++++-- include/system/host_iommu_device.h | 18 ++++++++++++------ 4 files changed, 41 insertions(+), 16 deletions(-)backends/iommufd.c +8
-4@@ -523,19 +523,32 @@ bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *idev,return idevc->detach_hwpt (idev, errp); } -static int hiod_iommufd_get_cap (HostIOMMUDevice *hiod,int cap,Error **errp) +static int hiod_iommufd_get_cap (HostIOMMUDevice *hiod,int cap_id, +uint64_t *out_cap,Error **errp) {HostIOMMUDeviceCaps *caps = &hiod->caps; -switch (cap) { +g_assert (out_cap); + +switch (cap_id) {case HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE : -return caps->type; + *out_cap = caps->type; +break ;case HOST_IOMMU_DEVICE_CAP_AW_BITS : -return vfio_device_get_aw_bits (hiod->agent); + *out_cap =vfio_device_get_aw_bits (hiod->agent);
backends/iommufd.c bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *idev, · line 547
Quoted 10 lines
backends/iommufd.c +8
-1+break ; +case HOST_IOMMU_DEVICE_CAP_GENERIC_HW : + *out_cap = caps->hw_caps; +break ; +case HOST_IOMMU_DEVICE_CAP_MAX_PASID_LOG2 : + *out_cap = caps->max_pasid_log2; +break ;default : -error_setg (errp,"%s: unsupported capability %x" , hiod->name, cap); + *out_cap =0 ;
not sure it is needed.
besides
Eric
Quoted 105 lines
backends/iommufd.c +2
-0+error_setg (errp,"%s: unsupported capability %x" , hiod->name, cap_id);return -EINVAL ; } +return 0 ; }static void hiod_iommufd_class_init (ObjectClass *oc,const void *data)hw/i386/intel_iommu.c +5
-3@@ -4605,6 +4605,7 @@ static bool vtd_check_hiod(IntelIOMMUState *s, HostIOMMUDevice *hiod, Error **errp) {HostIOMMUDeviceClass *hiodc =HOST_IOMMU_DEVICE_GET_CLASS (hiod); +uint64_t out_cap;int ret;if (!hiodc->get_cap) {@@ -4613,12 +4614,13 @@ static bool vtd_check_hiod(IntelIOMMUState *s, HostIOMMUDevice *hiod, }/* Common checks */ - ret = hiodc->get_cap (hiod,HOST_IOMMU_DEVICE_CAP_AW_BITS , errp); + ret = hiodc->get_cap (hiod,HOST_IOMMU_DEVICE_CAP_AW_BITS , &out_cap, errp);if (ret <0 ) {return false; } -if (s->aw_bits > ret) { -error_setg (errp,"aw-bits %d > host aw-bits %d" , s->aw_bits, ret); +if (s->aw_bits > out_cap) { +error_setg (errp,"aw-bits %d > host aw-bits 0x%" PRIx64, s->aw_bits, + out_cap);return false; }hw/vfio/container-legacy.c +6
-2@@ -1203,15 +1203,19 @@ static bool hiod_legacy_vfio_realize(HostIOMMUDevice *hiod, void *opaque, }static int hiod_legacy_vfio_get_cap (HostIOMMUDevice *hiod,int cap, -Error **errp) +uint64_t *out_cap,Error **errp) { +g_assert (out_cap); +switch (cap) {case HOST_IOMMU_DEVICE_CAP_AW_BITS : -return vfio_device_get_aw_bits (hiod->agent); + *out_cap =vfio_device_get_aw_bits (hiod->agent); +break ;default :error_setg (errp,"%s: unsupported capability %x" , hiod->name, cap);return -EINVAL ; } +return 0 ; } static GList *include/system/host_iommu_device.h +12
-6@@ -88,19 +88,21 @@ struct HostIOMMUDeviceClass {* @get_cap: check if a host IOMMU device capability is supported. * * Optional callback, if not implemented, hint not supporting query -* of @cap. +* of @cap_id. * * @hiod: pointer to a host IOMMU device instance. * -* @cap: capability to check. +* @cap_id: capability to check. +* +* @out_cap: 0 if a @cap_id is unsupported or else the capability +* value for @cap_id. * * @errp: pass an Error out when fails to query capability. * -* Returns: <0 on failure, 0 if a @cap is unsupported, or else -* 1 or some positive value for some special @cap, -* i.e., HOST_IOMMU_DEVICE_CAP_AW_BITS. +* Returns: <0 if @cap_id is not supported, 0 on success. */ -int (*get_cap)(HostIOMMUDevice *hiod,int cap,Error **errp); +int (*get_cap)(HostIOMMUDevice *hiod,int cap_id,uint64_t *out_cap, +Error **errp);/** * @get_iova_ranges: Return the list of usable iova_ranges along with * @hiod Host IOMMU device @@ -123,6 +125,10 @@ struct HostIOMMUDeviceClass {*/ #define HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE 0#define HOST_IOMMU_DEVICE_CAP_AW_BITS 1 +/* Generic IOMMU HW capability info */ +#define HOST_IOMMU_DEVICE_CAP_GENERIC_HW 2 +/* PASID width */ +#define HOST_IOMMU_DEVICE_CAP_MAX_PASID_LOG2 3#define HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX 64#endif
Re: [PATCH v6 31/33] Extend get_cap() callback to support PASID
In reply to Shameer KolothumQuoted 3 lines · Shameer Kolothum
Modify
get_cap()callback so that it can return cap via an outputuint64_tparam. And add support for generic iommu hw capability info andmax_pasid_log2(pasid width).
This is doing multiple changes. Please split.
Thanks,
C.
Quoted 149 lines
Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- backends/iommufd.c | 23 ++++++++++++++++++----- hw/i386/intel_iommu.c | 8 +++++--- hw/vfio/container-legacy.c | 8 ++++++-- include/system/host_iommu_device.h | 18 ++++++++++++------ 4 files changed, 41 insertions(+), 16 deletions(-)backends/iommufd.c +18
-5@@ -523,19 +523,32 @@ bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *idev,return idevc->detach_hwpt (idev, errp); } -static int hiod_iommufd_get_cap (HostIOMMUDevice *hiod,int cap,Error **errp) +static int hiod_iommufd_get_cap (HostIOMMUDevice *hiod,int cap_id, +uint64_t *out_cap,Error **errp) {HostIOMMUDeviceCaps *caps = &hiod->caps; -switch (cap) { +g_assert (out_cap); + +switch (cap_id) {case HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE : -return caps->type; + *out_cap = caps->type; +break ;case HOST_IOMMU_DEVICE_CAP_AW_BITS : -return vfio_device_get_aw_bits (hiod->agent); + *out_cap =vfio_device_get_aw_bits (hiod->agent); +break ; +case HOST_IOMMU_DEVICE_CAP_GENERIC_HW : + *out_cap = caps->hw_caps; +break ; +case HOST_IOMMU_DEVICE_CAP_MAX_PASID_LOG2 : + *out_cap = caps->max_pasid_log2; +break ;default : -error_setg (errp,"%s: unsupported capability %x" , hiod->name, cap); + *out_cap =0 ; +error_setg (errp,"%s: unsupported capability %x" , hiod->name, cap_id);return -EINVAL ; } +return 0 ; }static void hiod_iommufd_class_init (ObjectClass *oc,const void *data)hw/i386/intel_iommu.c +5
-3@@ -4605,6 +4605,7 @@ static bool vtd_check_hiod(IntelIOMMUState *s, HostIOMMUDevice *hiod, Error **errp) {HostIOMMUDeviceClass *hiodc =HOST_IOMMU_DEVICE_GET_CLASS (hiod); +uint64_t out_cap;int ret;if (!hiodc->get_cap) {@@ -4613,12 +4614,13 @@ static bool vtd_check_hiod(IntelIOMMUState *s, HostIOMMUDevice *hiod, }/* Common checks */ - ret = hiodc->get_cap (hiod,HOST_IOMMU_DEVICE_CAP_AW_BITS , errp); + ret = hiodc->get_cap (hiod,HOST_IOMMU_DEVICE_CAP_AW_BITS , &out_cap, errp);if (ret <0 ) {return false; } -if (s->aw_bits > ret) { -error_setg (errp,"aw-bits %d > host aw-bits %d" , s->aw_bits, ret); +if (s->aw_bits > out_cap) { +error_setg (errp,"aw-bits %d > host aw-bits 0x%" PRIx64, s->aw_bits, + out_cap);return false; }hw/vfio/container-legacy.c +6
-2@@ -1203,15 +1203,19 @@ static bool hiod_legacy_vfio_realize(HostIOMMUDevice *hiod, void *opaque, }static int hiod_legacy_vfio_get_cap (HostIOMMUDevice *hiod,int cap, -Error **errp) +uint64_t *out_cap,Error **errp) { +g_assert (out_cap); +switch (cap) {case HOST_IOMMU_DEVICE_CAP_AW_BITS : -return vfio_device_get_aw_bits (hiod->agent); + *out_cap =vfio_device_get_aw_bits (hiod->agent); +break ;default :error_setg (errp,"%s: unsupported capability %x" , hiod->name, cap);return -EINVAL ; } +return 0 ; } static GList *include/system/host_iommu_device.h +12
-6@@ -88,19 +88,21 @@ struct HostIOMMUDeviceClass {* @get_cap: check if a host IOMMU device capability is supported. * * Optional callback, if not implemented, hint not supporting query -* of @cap. +* of @cap_id. * * @hiod: pointer to a host IOMMU device instance. * -* @cap: capability to check. +* @cap_id: capability to check. +* +* @out_cap: 0 if a @cap_id is unsupported or else the capability +* value for @cap_id. * * @errp: pass an Error out when fails to query capability. * -* Returns: <0 on failure, 0 if a @cap is unsupported, or else -* 1 or some positive value for some special @cap, -* i.e., HOST_IOMMU_DEVICE_CAP_AW_BITS. +* Returns: <0 if @cap_id is not supported, 0 on success. */ -int (*get_cap)(HostIOMMUDevice *hiod,int cap,Error **errp); +int (*get_cap)(HostIOMMUDevice *hiod,int cap_id,uint64_t *out_cap, +Error **errp);/** * @get_iova_ranges: Return the list of usable iova_ranges along with * @hiod Host IOMMU device @@ -123,6 +125,10 @@ struct HostIOMMUDeviceClass {*/ #define HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE 0#define HOST_IOMMU_DEVICE_CAP_AW_BITS 1 +/* Generic IOMMU HW capability info */ +#define HOST_IOMMU_DEVICE_CAP_GENERIC_HW 2 +/* PASID width */ +#define HOST_IOMMU_DEVICE_CAP_MAX_PASID_LOG2 3#define HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX 64#endif
PATCH v6 32/33 vfio: Synthesize vPASID capability to VM
In reply to Shameer KolothumFrom: Yi Liu <[email protected]>
If user wants to expose PASID capability in vIOMMU, then VFIO would also need to report the PASID cap for this device if the underlying hardware supports it as well.
As a start, this chooses to put the vPASID cap in the last 8 bytes of the vconfig space. This is a choice in the good hope of no conflict with any existing cap or hidden registers. For the devices that has hidden registers, user should figure out a proper offset for the vPASID cap. This may require an option for user to config it. Here we leave it as a future extension. There are more discussions on the mechanism of finding the proper offset.
Since we add a check to ensure the vIOMMU supports PASID, only devices under those vIOMMUs can synthesize the vPASID capability. This gives users control over which devices expose vPASID.
--- hw/vfio/pci.c | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/iommu.h | 1 + 2 files changed, 39 insertions(+)
hw/vfio/pci.c +38 -0
@@ -24,6 +24,7 @@#include <sys/ioctl.h> #include "hw/hw.h" +#include "hw/iommu.h" #include "hw/pci/msi.h" #include "hw/pci/msix.h" #include "hw/pci/pci_bridge.h"
@@ -2500,7 +2501,12 @@ static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)static void vfio_add_ext_cap (VFIOPCIDevice *vdev) { +HostIOMMUDevice *hiod = vdev->vbasedev.hiod; +HostIOMMUDeviceClass *hiodc =HOST_IOMMU_DEVICE_GET_CLASS (hiod);PCIDevice *pdev =PCI_DEVICE (vdev); +uint64_t max_pasid_log2 =0 ; +bool pasid_cap_added = false; +uint64_t hw_caps;uint32_t header;uint16_t cap_id, next, size;uint8_t cap_ver;
@@ -2578,12 +2584,44 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)pcie_add_capability (pdev, cap_id, cap_ver, next, size); }break ; +/* +* VFIO kernel does not expose the PASID CAP today. We may synthesize +* one later through IOMMUFD APIs. If VFIO ever starts exposing it, +* record its presence here so we do not create a duplicate CAP. +*/ +case PCI_EXT_CAP_ID_PASID : + pasid_cap_added = true; +/* fallthrough */ default :pcie_add_capability (pdev, cap_id, cap_ver, next, size); } } +#ifdef CONFIG_IOMMUFD +/* Try to retrieve PASID CAP through IOMMUFD APIs */ +if (!pasid_cap_added && hiodc && hiodc->get_cap) { + hiodc->get_cap (hiod,HOST_IOMMU_DEVICE_CAP_GENERIC_HW , &hw_caps,NULL ); + hiodc->get_cap (hiod,HOST_IOMMU_DEVICE_CAP_MAX_PASID_LOG2 , + &max_pasid_log2,NULL ); + } + +/* +* If supported, adds the PASID capability in the end of the PCIe config +* space. TODO: Add option for enabling pasid at a safe offset. +*/ +if (max_pasid_log2 && (pci_device_get_viommu_flags (pdev) & +VIOMMU_FLAG_PASID_SUPPORTED )) { +bool exec_perm = (hw_caps &IOMMU_HW_CAP_PCI_PASID_EXEC ); +bool priv_mod = (hw_caps &IOMMU_HW_CAP_PCI_PASID_PRIV ); + +pcie_pasid_init (pdev,PCIE_CONFIG_SPACE_SIZE -PCI_EXT_CAP_PASID_SIZEOF , + max_pasid_log2, exec_perm, priv_mod); +/* PASID capability is fully emulated by QEMU */ +memset (vdev->emulated_config_bits + pdev->exp.pasid_cap,0xff ,8 ); + } +#endif +/* Cleanup chain head ID if necessary */ if (pci_get_word (pdev->config +PCI_CONFIG_SPACE_SIZE ) ==0xFFFF ) {pci_set_word (pdev->config +PCI_CONFIG_SPACE_SIZE ,0 );
include/hw/iommu.h +1 -0
@@ -20,6 +20,7 @@enum viommu_flags {/* vIOMMU needs nesting parent HWPT to create nested HWPT */ VIOMMU_FLAG_WANT_NESTING_PARENT =BIT_ULL (0 ), +VIOMMU_FLAG_PASID_SUPPORTED =BIT_ULL (1 ), };#endif /* HW_IOMMU_H */
Signature · 1 line
2.43.0
Re: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VM
Quoted 15 lines · Shameer Kolothum
From: Yi Liu <[email protected]>
If user wants to expose PASID capability in vIOMMU, then VFIO would also need to report the PASID cap for this device if the underlying hardware supports it as well.
As a start, this chooses to put the vPASID cap in the last 8 bytes of the vconfig space. This is a choice in the good hope of no conflict with any existing cap or hidden registers. For the devices that has hidden registers, user should figure out a proper offset for the vPASID cap. This may require an option for user to config it. Here we leave it as a future extension. There are more discussions on the mechanism of finding the proper offset.
Quoted 8 lines
Since we add a check to ensure the vIOMMU supports PASID, only devices under those vIOMMUs can synthesize the vPASID capability. This gives users control over which devices expose vPASID.
Signed-off-by Yi Liu <[email protected]>Tested-by Zhangfei Gao <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>
Re: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VM
In reply to Shameer KolothumHi Shameer,
Quoted 103 lines · Shameer Kolothum
From: Yi Liu <[email protected]>
If user wants to expose PASID capability in vIOMMU, then VFIO would also need to report the PASID cap for this device if the underlying hardware supports it as well.
As a start, this chooses to put the vPASID cap in the last 8 bytes of the vconfig space. This is a choice in the good hope of no conflict with any existing cap or hidden registers. For the devices that has hidden registers, user should figure out a proper offset for the vPASID cap. This may require an option for user to config it. Here we leave it as a future extension. There are more discussions on the mechanism of finding the proper offset.
Since we add a check to ensure the vIOMMU supports PASID, only devices under those vIOMMUs can synthesize the vPASID capability. This gives users control over which devices expose vPASID.
Signed-off-by Yi Liu <[email protected]>Tested-by Zhangfei Gao <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/vfio/pci.c | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/iommu.h | 1 + 2 files changed, 39 insertions(+)hw/vfio/pci.c +38
-0@@ -24,6 +24,7 @@#include <sys/ioctl.h> #include "hw/hw.h" +#include "hw/iommu.h" #include "hw/pci/msi.h" #include "hw/pci/msix.h" #include "hw/pci/pci_bridge.h" @@ -2500,7 +2501,12 @@ static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)static void vfio_add_ext_cap (VFIOPCIDevice *vdev) { +HostIOMMUDevice *hiod = vdev->vbasedev.hiod; +HostIOMMUDeviceClass *hiodc =HOST_IOMMU_DEVICE_GET_CLASS (hiod);PCIDevice *pdev =PCI_DEVICE (vdev); +uint64_t max_pasid_log2 =0 ; +bool pasid_cap_added = false; +uint64_t hw_caps;uint32_t header;uint16_t cap_id, next, size;uint8_t cap_ver;@@ -2578,12 +2584,44 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)pcie_add_capability (pdev, cap_id, cap_ver, next, size); }break ; +/* +* VFIO kernel does not expose the PASID CAP today. We may synthesize +* one later through IOMMUFD APIs. If VFIO ever starts exposing it, +* record its presence here so we do not create a duplicate CAP. +*/ +case PCI_EXT_CAP_ID_PASID : + pasid_cap_added = true; +/* fallthrough */ default :pcie_add_capability (pdev, cap_id, cap_ver, next, size); } } +#ifdef CONFIG_IOMMUFD +/* Try to retrieve PASID CAP through IOMMUFD APIs */ +if (!pasid_cap_added && hiodc && hiodc->get_cap) { + hiodc->get_cap (hiod,HOST_IOMMU_DEVICE_CAP_GENERIC_HW , &hw_caps,NULL ); + hiodc->get_cap (hiod,HOST_IOMMU_DEVICE_CAP_MAX_PASID_LOG2 , + &max_pasid_log2,NULL ); + } + +/* +* If supported, adds the PASID capability in the end of the PCIe config +* space. TODO: Add option for enabling pasid at a safe offset. +*/ +if (max_pasid_log2 && (pci_device_get_viommu_flags (pdev) & +VIOMMU_FLAG_PASID_SUPPORTED )) { +bool exec_perm = (hw_caps &IOMMU_HW_CAP_PCI_PASID_EXEC ); +bool priv_mod = (hw_caps &IOMMU_HW_CAP_PCI_PASID_PRIV ); + +pcie_pasid_init (pdev,PCIE_CONFIG_SPACE_SIZE -PCI_EXT_CAP_PASID_SIZEOF , + max_pasid_log2, exec_perm, priv_mod); +/* PASID capability is fully emulated by QEMU */ +memset (vdev->emulated_config_bits + pdev->exp.pasid_cap,0xff ,8 ); + } +#endif +/* Cleanup chain head ID if necessary */ if (pci_get_word (pdev->config +PCI_CONFIG_SPACE_SIZE ) ==0xFFFF ) {pci_set_word (pdev->config +PCI_CONFIG_SPACE_SIZE ,0 );include/hw/iommu.h +0
-0
include/hw/iommu.h line 26
Quoted 7 lines
include/hw/iommu.h +1
-0@@ -20,6 +20,7 @@enum viommu_flags {/* vIOMMU needs nesting parent HWPT to create nested HWPT */ VIOMMU_FLAG_WANT_NESTING_PARENT =BIT_ULL (0 ), +VIOMMU_FLAG_PASID_SUPPORTED =BIT_ULL (1 ), };#endif /* HW_IOMMU_H */
Besides the fact the offset is arbitrarily chosen so that this is the last cap of the vconfig space, the code looks good to me. So
Just wondering whether we couldn't add some generic pcie code that parses the extended cap linked list to check the offset range is not used by another cap before allowing the insertion at a given offset? This wouldn't prevent a subsequent addition from failing but at least we would know if there is some collision.this could be added later on though.
Thanks
Eric
Re: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VM
Quoted 115 lines · Eric Auger
Hi Shameer,
Quoted 103 lines · Shameer Kolothum
From: Yi Liu <[email protected]>
If user wants to expose PASID capability in vIOMMU, then VFIO would also need to report the PASID cap for this device if the underlying hardware supports it as well.
As a start, this chooses to put the vPASID cap in the last 8 bytes of the vconfig space. This is a choice in the good hope of no conflict with any existing cap or hidden registers. For the devices that has hidden registers, user should figure out a proper offset for the vPASID cap. This may require an option for user to config it. Here we leave it as a future extension. There are more discussions on the mechanism of finding the proper offset.
Since we add a check to ensure the vIOMMU supports PASID, only devices under those vIOMMUs can synthesize the vPASID capability. This gives users control over which devices expose vPASID.
Signed-off-by Yi Liu <[email protected]>Tested-by Zhangfei Gao <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/vfio/pci.c | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/iommu.h | 1 + 2 files changed, 39 insertions(+)hw/vfio/pci.c +38
-0@@ -24,6 +24,7 @@#include <sys/ioctl.h> #include "hw/hw.h" +#include "hw/iommu.h" #include "hw/pci/msi.h" #include "hw/pci/msix.h" #include "hw/pci/pci_bridge.h" @@ -2500,7 +2501,12 @@ static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)static void vfio_add_ext_cap (VFIOPCIDevice *vdev) { +HostIOMMUDevice *hiod = vdev->vbasedev.hiod; +HostIOMMUDeviceClass *hiodc =HOST_IOMMU_DEVICE_GET_CLASS (hiod);PCIDevice *pdev =PCI_DEVICE (vdev); +uint64_t max_pasid_log2 =0 ; +bool pasid_cap_added = false; +uint64_t hw_caps;uint32_t header;uint16_t cap_id, next, size;uint8_t cap_ver;@@ -2578,12 +2584,44 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)pcie_add_capability (pdev, cap_id, cap_ver, next, size); }break ; +/* +* VFIO kernel does not expose the PASID CAP today. We may synthesize +* one later through IOMMUFD APIs. If VFIO ever starts exposing it, +* record its presence here so we do not create a duplicate CAP. +*/ +case PCI_EXT_CAP_ID_PASID : + pasid_cap_added = true; +/* fallthrough */ default :pcie_add_capability (pdev, cap_id, cap_ver, next, size); } } +#ifdef CONFIG_IOMMUFD +/* Try to retrieve PASID CAP through IOMMUFD APIs */ +if (!pasid_cap_added && hiodc && hiodc->get_cap) { + hiodc->get_cap (hiod,HOST_IOMMU_DEVICE_CAP_GENERIC_HW , &hw_caps,NULL ); + hiodc->get_cap (hiod,HOST_IOMMU_DEVICE_CAP_MAX_PASID_LOG2 , + &max_pasid_log2,NULL ); + } + +/* +* If supported, adds the PASID capability in the end of the PCIe config +* space. TODO: Add option for enabling pasid at a safe offset. +*/ +if (max_pasid_log2 && (pci_device_get_viommu_flags (pdev) & +VIOMMU_FLAG_PASID_SUPPORTED )) { +bool exec_perm = (hw_caps &IOMMU_HW_CAP_PCI_PASID_EXEC ); +bool priv_mod = (hw_caps &IOMMU_HW_CAP_PCI_PASID_PRIV ); + +pcie_pasid_init (pdev,PCIE_CONFIG_SPACE_SIZE -PCI_EXT_CAP_PASID_SIZEOF , + max_pasid_log2, exec_perm, priv_mod); +/* PASID capability is fully emulated by QEMU */ +memset (vdev->emulated_config_bits + pdev->exp.pasid_cap,0xff ,8 ); + } +#endif +/* Cleanup chain head ID if necessary */ if (pci_get_word (pdev->config +PCI_CONFIG_SPACE_SIZE ) ==0xFFFF ) {pci_set_word (pdev->config +PCI_CONFIG_SPACE_SIZE ,0 );include/hw/iommu.h +0
-0include/hw/iommu.h line 26
Quoted 7 lines
include/hw/iommu.h +1
-0@@ -20,6 +20,7 @@enum viommu_flags {/* vIOMMU needs nesting parent HWPT to create nested HWPT */ VIOMMU_FLAG_WANT_NESTING_PARENT =BIT_ULL (0 ), +VIOMMU_FLAG_PASID_SUPPORTED =BIT_ULL (1 ), };#endif /* HW_IOMMU_H */ Besides the fact the offset is arbitrarily chosen so that this is the last cap of the vconfig space, the code looks good to me. So
Quoted 8 lines
Reviewed-by Eric Auger <[email protected]>Just wondering whether we couldn't add some generic pcie code that parses the extended cap linked list to check the offset range is not used by another cap before allowing the insertion at a given offset? This wouldn't prevent a subsequent addition from failing but at least we would know if there is some collision.this could be added later on though.
You're absolutely right. My approach of using the last 8 bytes was a
shortcut to avoid implementing proper capability parsing logic
(importing pci_regs.h and maintaining a cap_id-to-cap_size mapping table), and it simplified PASID capability detection by only examining the last 8bytes by a simple dump :(. However, this approach is not
good as we cannot guarantee that the last 8bytes are unused by any
device.
Let's just implement the logic to walk the linked list of ext_caps to find an appropriate offset for our use case.
@Shameer, apologies for the delayed response.
Regards,
Yi Liu
RE: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VM
Hi Eric/ Yi,
[Cc: Alex]
Quoted 160 lines
-----Original Message-----
From: Yi Liu <[email protected]>
Sent: 09 December 2025 11:17
To: [email protected]; Shameer Kolothum <[email protected]>; [email protected]; qemu- [email protected]
Cc: [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VMExternal email: Use caution opening links or attachments
Quoted 16 lines · Eric Auger
Hi Shameer,
Quoted 14 lines · Shameer Kolothum
From: Yi Liu <[email protected]>
If user wants to expose PASID capability in vIOMMU, then VFIO would also need to report the PASID cap for this device if the underlying hardware supports it as well.
As a start, this chooses to put the vPASID cap in the last 8 bytes of the vconfig space. This is a choice in the good hope of no conflict with any existing cap or hidden registers. For the devices that has hidden registers, user should figure out a proper offset for the vPASID cap. This may require an option for user to config it. Here we leave it as a future extension. There are more discussions on the mechanism of finding the proper offset.
https://lore.kernel.org/kvm/BN9PR11MB5276318969A212AD0649C7BE8C
[email protected]/Quoted 21 lines
Quoted 21 lines
Since we add a check to ensure the vIOMMU supports PASID, only devices under those vIOMMUs can synthesize the vPASID capability. This gives users control over which devices expose vPASID.
Signed-off-by Yi Liu <[email protected]>Tested-by Zhangfei Gao <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/vfio/pci.c | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/iommu.h | 1 + 2 files changed, 39 insertions(+)hw/vfio/pci.c +0
-0@@ -24,6 +24,7 @@#include <sys/ioctl.h> Quoted 6 lines
hw/vfio/pci.c static int
Quoted 6 lines
hw/vfio/pci.c +1
-0#include "hw/hw.h" +#include "hw/iommu.h" #include "hw/pci/msi.h" #include "hw/pci/msix.h" #include "hw/pci/pci_bridge.h" @@ -2500,7 +2501,12 @@ static int
vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)Quoted 5 lines
hw/vfio/pci.c static int · line 2504
Quoted 5 lines
hw/vfio/pci.c +2
-0static void vfio_add_ext_cap (VFIOPCIDevice *vdev) { +HostIOMMUDevice *hiod = vdev->vbasedev.hiod; + HostIOMMUDeviceClass *hiodc =
HOST_IOMMU_DEVICE_GET_CLASS(hiod);Quoted 8 lines
hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice
Quoted 8 lines
hw/vfio/pci.c +3
-0PCIDevice *pdev =PCI_DEVICE (vdev); +uint64_t max_pasid_log2 =0 ; +bool pasid_cap_added = false; +uint64_t hw_caps;uint32_t header;uint16_t cap_id, next, size;uint8_t cap_ver;@@ -2578,12 +2584,44 @@ static void vfio_add_ext_cap(VFIOPCIDevice*vdev)
Quoted 5 lines
hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice · line 2588
Quoted 5 lines
hw/vfio/pci.c +2
-0pcie_add_capability (pdev, cap_id, cap_ver, next, size); }break ; +/* +* VFIO kernel does not expose the PASID CAP today. We may synthesize
Quoted 10 lines
Quoted 10 lines
hw/vfio/pci.c +6
-0+* one later through IOMMUFD APIs. If VFIO ever starts exposing it, +* record its presence here so we do not create a duplicate CAP. +*/ +case PCI_EXT_CAP_ID_PASID : + pasid_cap_added = true; +/* fallthrough */ default :pcie_add_capability (pdev, cap_id, cap_ver, next, size); }Quoted 6 lines
hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice · line 2604
Quoted 6 lines
hw/vfio/pci.c +4
-0} +#ifdef CONFIG_IOMMUFD +/* Try to retrieve PASID CAP through IOMMUFD APIs */ +if (!pasid_cap_added && hiodc && hiodc->get_cap) { + hiodc->get_cap(hiod, HOST_IOMMU_DEVICE_CAP_GENERIC_HW,
&hw_caps, NULL);Quoted 1 line
hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice · line 2605
Quoted 1 line
hw/vfio/pci.c +1
-0+ hiodc->get_cap(hiod,
HOST_IOMMU_DEVICE_CAP_MAX_PASID_LOG2,Quoted 5 lines
Quoted 5 lines
hw/vfio/pci.c +5
-0+ &max_pasid_log2, NULL); + } + +/* +* If supported, adds the PASID capability in the end of the PCIe config Quoted 8 lines
hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice · line 2618
Quoted 8 lines
hw/vfio/pci.c +8
-0+* space. TODO: Add option for enabling pasid at a safe offset. +*/ +if (max_pasid_log2 && (pci_device_get_viommu_flags (pdev) & +VIOMMU_FLAG_PASID_SUPPORTED )) { +bool exec_perm = (hw_caps &IOMMU_HW_CAP_PCI_PASID_EXEC ); +bool priv_mod = (hw_caps &IOMMU_HW_CAP_PCI_PASID_PRIV ); + + pcie_pasid_init(pdev, PCIE_CONFIG_SPACE_SIZE -
PCI_EXT_CAP_PASID_SIZEOF,Quoted 24 lines
Quoted 14 lines
hw/vfio/pci.c +6
-0+ max_pasid_log2, exec_perm, priv_mod); +/* PASID capability is fully emulated by QEMU */ + memset(vdev->emulated_config_bits + pdev->exp.pasid_cap, 0xff, 8); + } +#endif +/* Cleanup chain head ID if necessary */ if (pci_get_word (pdev->config +PCI_CONFIG_SPACE_SIZE ) ==0xFFFF ) {pci_set_word (pdev->config +PCI_CONFIG_SPACE_SIZE ,0 );include/hw/iommu.h +0
-0include/hw/iommu.h line 26
Quoted 7 lines
include/hw/iommu.h +1
-0@@ -20,6 +20,7 @@enum viommu_flags {/* vIOMMU needs nesting parent HWPT to create nested HWPT */ VIOMMU_FLAG_WANT_NESTING_PARENT =BIT_ULL (0 ), +VIOMMU_FLAG_PASID_SUPPORTED =BIT_ULL (1 ), };#endif /* HW_IOMMU_H */ Besides the fact the offset is arbitrarily chosen so that this is the last cap of the vconfig space, the code looks good to me. So
Quoted 8 lines
Reviewed-by Eric Auger <[email protected]>Just wondering whether we couldn't add some generic pcie code that parses the extended cap linked list to check the offset range is not used by another cap before allowing the insertion at a given offset? This wouldn't prevent a subsequent addition from failing but at least we would know if there is some collision.this could be added later on though.
You're absolutely right. My approach of using the last 8 bytes was a shortcut to avoid implementing proper capability parsing logic (importing
pci_regs.hand maintaining a cap_id-to-cap_size mapping table), and it simplified PASID capability detection by only examining the last 8bytes by a simple dump :(. However, this approach is not good as we cannot guarantee that the last 8bytes are unused by any device.
Quoted 2 lines
Let's just implement the logic to walk the linked list of
ext_capsto find an appropriate offset for our use case.
I had a go at this. Based on my understanding, even if we walk the PCIe extended capability linked list, we still can't easily determine the size occupied by the last capability as the extended capability header does not encode a length, it only provides the "next" pointer, and for the last entry next == 0.
Given that, I tried the following approach,
-locate the last extended capability (using the existing helper), -reserve a fixed window (512 bytes) for that final capability, -and synthesize PASID at the end of PCIe config space (0xff8) only if it looks like there is enough room.
Maybe I am missing something here.. Please let me know if there is a better way to address this.
Thanks,
Shameer
hw/pci/pcie.c +2 -2
@@ -1005,8 +1005,8 @@ bool pcie_cap_is_arifwd_enabled(const PCIDevice *dev)*/ /* Passing a cap_id value > 0xffff will return 0 and put end of list in prev */ -static uint16_t pcie_find_capability_list (PCIDevice *dev,uint32_t cap_id, -uint16_t *prev_p) +uint16_t pcie_find_capability_list (PCIDevice *dev,uint32_t cap_id, +uint16_t *prev_p) {uint16_t prev =0 ;uint16_t next;
hw/vfio/pci.c +77 -0
110 lines not on this page · raw message
include/hw/pci/pcie.h +3 -0
@@ -130,6 +130,8 @@ bool pcie_cap_is_arifwd_enabled(const PCIDevice *dev);/* PCI express extended capability helper functions */ uint16_t pcie_find_capability (PCIDevice *dev,uint16_t cap_id); +uint16_t pcie_find_capability_list (PCIDevice *dev,uint32_t cap_id, +uint16_t *prev_p);void pcie_add_capability (PCIDevice *dev,uint16_t cap_id,uint8_t cap_ver,uint16_t offset,uint16_t size);
@@ -138,6 +140,7 @@ void pcie_sync_bridge_lnk(PCIDevice *dev);void pcie_acs_init (PCIDevice *dev,uint16_t offset);void pcie_acs_reset (PCIDevice *dev); +uint16_t pcie_get_ext_cap_next_offset (PCIDevice *pdev,uint16_t cap_size);void pcie_ari_init (PCIDevice *dev,uint16_t offset);void pcie_dev_ser_num_init (PCIDevice *dev,uint16_t offset,uint64_t ser_num);void pcie_ats_init (PCIDevice *dev,uint16_t offset,bool aligned);
Re: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VM
Hi Shameer,
Quoted 161 lines · Shameer Kolothum
Hi Eric/ Yi,
[Cc: Alex]
Quoted 157 lines
-----Original Message-----
From: Yi Liu <[email protected]>
Sent: 09 December 2025 11:17
To: [email protected]; Shameer Kolothum <[email protected]>; [email protected]; qemu- [email protected]
Cc: [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VMExternal email: Use caution opening links or attachments
Quoted 16 lines · Eric Auger
Hi Shameer,
Quoted 14 lines · Shameer Kolothum
From: Yi Liu <[email protected]>
If user wants to expose PASID capability in vIOMMU, then VFIO would also need to report the PASID cap for this device if the underlying hardware supports it as well.
As a start, this chooses to put the vPASID cap in the last 8 bytes of the vconfig space. This is a choice in the good hope of no conflict with any existing cap or hidden registers. For the devices that has hidden registers, user should figure out a proper offset for the vPASID cap. This may require an option for user to config it. Here we leave it as a future extension. There are more discussions on the mechanism of finding the proper offset.
https://lore.kernel.org/kvm/BN9PR11MB5276318969A212AD0649C7BE8C
[email protected]/Quoted 20 lines
Quoted 20 lines
Since we add a check to ensure the vIOMMU supports PASID, only devices under those vIOMMUs can synthesize the vPASID capability. This gives users control over which devices expose vPASID.
Signed-off-by Yi Liu <[email protected]>Tested-by Zhangfei Gao <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/vfio/pci.c | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/iommu.h | 1 + 2 files changed, 39 insertions(+)hw/vfio/pci.c +0
-0@@ -24,6 +24,7 @@#include <sys/ioctl.h> Quoted 6 lines
hw/vfio/pci.c static int
Quoted 6 lines
hw/vfio/pci.c +1
-0#include "hw/hw.h" +#include "hw/iommu.h" #include "hw/pci/msi.h" #include "hw/pci/msix.h" #include "hw/pci/pci_bridge.h" @@ -2500,7 +2501,12 @@ static int
vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)Quoted 4 lines
hw/vfio/pci.c static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)
Quoted 4 lines
hw/vfio/pci.c +2
-0static void vfio_add_ext_cap (VFIOPCIDevice *vdev) { +HostIOMMUDevice *hiod = vdev->vbasedev.hiod; + HostIOMMUDeviceClass *hiodc =
HOST_IOMMU_DEVICE_GET_CLASS(hiod);Quoted 8 lines
hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice
Quoted 8 lines
hw/vfio/pci.c +3
-0PCIDevice *pdev =PCI_DEVICE (vdev); +uint64_t max_pasid_log2 =0 ; +bool pasid_cap_added = false; +uint64_t hw_caps;uint32_t header;uint16_t cap_id, next, size;uint8_t cap_ver;@@ -2578,12 +2584,44 @@ static void vfio_add_ext_cap(VFIOPCIDevice*vdev)
Quoted 5 lines
hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
Quoted 5 lines
hw/vfio/pci.c +2
-0pcie_add_capability (pdev, cap_id, cap_ver, next, size); }break ; +/* +* VFIO kernel does not expose the PASID CAP today. We may synthesize
Quoted 10 lines
Quoted 10 lines
hw/vfio/pci.c +6
-0+* one later through IOMMUFD APIs. If VFIO ever starts exposing it, +* record its presence here so we do not create a duplicate CAP. +*/ +case PCI_EXT_CAP_ID_PASID : + pasid_cap_added = true; +/* fallthrough */ default :pcie_add_capability (pdev, cap_id, cap_ver, next, size); }Quoted 6 lines
hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice · line 2604
Quoted 6 lines
hw/vfio/pci.c +4
-0} +#ifdef CONFIG_IOMMUFD +/* Try to retrieve PASID CAP through IOMMUFD APIs */ +if (!pasid_cap_added && hiodc && hiodc->get_cap) { + hiodc->get_cap(hiod, HOST_IOMMU_DEVICE_CAP_GENERIC_HW,
&hw_caps, NULL);Quoted 1 line
hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice · line 2605
Quoted 1 line
hw/vfio/pci.c +1
-0+ hiodc->get_cap(hiod,
HOST_IOMMU_DEVICE_CAP_MAX_PASID_LOG2,Quoted 5 lines
Quoted 5 lines
hw/vfio/pci.c +5
-0+ &max_pasid_log2, NULL); + } + +/* +* If supported, adds the PASID capability in the end of the PCIe config Quoted 8 lines
hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice · line 2618
Quoted 8 lines
hw/vfio/pci.c +8
-0+* space. TODO: Add option for enabling pasid at a safe offset. +*/ +if (max_pasid_log2 && (pci_device_get_viommu_flags (pdev) & +VIOMMU_FLAG_PASID_SUPPORTED )) { +bool exec_perm = (hw_caps &IOMMU_HW_CAP_PCI_PASID_EXEC ); +bool priv_mod = (hw_caps &IOMMU_HW_CAP_PCI_PASID_PRIV ); + + pcie_pasid_init(pdev, PCIE_CONFIG_SPACE_SIZE -
PCI_EXT_CAP_PASID_SIZEOF,Quoted 24 lines
Quoted 14 lines
hw/vfio/pci.c +6
-0+ max_pasid_log2, exec_perm, priv_mod); +/* PASID capability is fully emulated by QEMU */ + memset(vdev->emulated_config_bits + pdev->exp.pasid_cap, 0xff, 8); + } +#endif +/* Cleanup chain head ID if necessary */ if (pci_get_word (pdev->config +PCI_CONFIG_SPACE_SIZE ) ==0xFFFF ) {pci_set_word (pdev->config +PCI_CONFIG_SPACE_SIZE ,0 );include/hw/iommu.h +0
-0include/hw/iommu.h line 26
Quoted 7 lines
include/hw/iommu.h +1
-0@@ -20,6 +20,7 @@enum viommu_flags {/* vIOMMU needs nesting parent HWPT to create nested HWPT */ VIOMMU_FLAG_WANT_NESTING_PARENT =BIT_ULL (0 ), +VIOMMU_FLAG_PASID_SUPPORTED =BIT_ULL (1 ), };#endif /* HW_IOMMU_H */ Besides the fact the offset is arbitrarily chosen so that this is the last cap of the vconfig space, the code looks good to me. So
Quoted 8 lines
Reviewed-by Eric Auger <[email protected]>Just wondering whether we couldn't add some generic pcie code that parses the extended cap linked list to check the offset range is not used by another cap before allowing the insertion at a given offset? This wouldn't prevent a subsequent addition from failing but at least we would know if there is some collision.this could be added later on though.
You're absolutely right. My approach of using the last 8 bytes was a shortcut to avoid implementing proper capability parsing logic (importing
pci_regs.hand maintaining a cap_id-to-cap_size mapping table), and it simplified PASID capability detection by only examining the last 8bytes by a simple dump :(. However, this approach is not good as we cannot guarantee that the last 8bytes are unused by any device.
Quoted 7 lines
Quoted 2 lines
Let's just implement the logic to walk the linked list of
ext_capsto find an appropriate offset for our use case.I had a go at this. Based on my understanding, even if we walk the PCIe extended capability linked list, we still can't easily determine the size occupied by the last capability as the extended capability header does not encode a length, it only provides the "next" pointer, and for the last entry next == 0.
If my understanding is correct when walking the linked list, you can enumerate the start index and the PCIe extended Capability variable size which is made of fix header size + register block variable size which depends on the capability ID). After that we shall be able to allocate a slot within holes or at least check that adding the new prop at the end of the 4kB is safe, no?. What do I miss?
Thanks
Eric
Quoted 170 lines
Given that, I tried the following approach,
(quoted diff) +0
-3-locate the last extended capability (using the existing helper), -reserve a fixed window (512 bytes) for that final capability, -and synthesize PASID at the end of PCIe config space (0xff8) only if itlooks like there is enough room.
Maybe I am missing something here.. Please let me know if there is a better way to address this.
Thanks,
Shameerhw/pci/pcie.c +2
-2@@ -1005,8 +1005,8 @@ bool pcie_cap_is_arifwd_enabled(const PCIDevice *dev)*/ /* Passing a cap_id value > 0xffff will return 0 and put end of list in prev */ -static uint16_t pcie_find_capability_list (PCIDevice *dev,uint32_t cap_id, -uint16_t *prev_p) +uint16_t pcie_find_capability_list (PCIDevice *dev,uint32_t cap_id, +uint16_t *prev_p) {uint16_t prev =0 ;uint16_t next;hw/vfio/pci.c +77
-0@@ -24,6 +24,7 @@#include <sys/ioctl.h> #include "hw/hw.h" +#include "hw/iommu.h" #include "hw/pci/msi.h" #include "hw/pci/msix.h" #include "hw/pci/pci_bridge.h" @@ -2498,9 +2499,72 @@ static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)return 0 ; } +/* +* Try to retrieve PASID capability information via IOMMUFD APIs and, +* if supported, synthesize a PASID PCIe extended capability for the +* VFIO device. +* +* The PASID capability is placed at the end of the PCIe extended +* configuration space. Determining the exact size of the last +* existing extended capability is non trivial, as PCIe extended +* capabilities do not generically encode their total size and +* vendor defined extensions are permitted. +* +* For now, reserve a fixed window (512 bytes) for the last extended +* capability and only insert PASID if sufficient space remains. +*/ +static void vfio_pci_synthesize_pasid_cap (VFIOPCIDevice *vdev) +{ +HostIOMMUDevice *hiod = vdev->vbasedev.hiod; +HostIOMMUDeviceClass *hiodc; +HostIOMMUDevicePasidInfo pasid_info; +PCIDevice *pdev =PCI_DEVICE (vdev); +uint16_t last =0 ; +uint16_t pasid_offset; + +if (vdev->vbasedev.mdev) { +return ; + } + + hiodc =HOST_IOMMU_DEVICE_GET_CLASS (hiod); +if (!hiodc || !hiodc->get_pasid_info || + !hiodc->get_pasid_info (hiod, &pasid_info) || + !(pci_device_get_viommu_flags (pdev) &VIOMMU_FLAG_PASID_SUPPORTED )) { +return ; + } + +/* +* Locate the last PCIe extended capability present in the device +* configuration space. +*/ +pcie_find_capability_list (pdev,0x1ffff , &last); + +/* +* Reserve space at the end of PCIe configuration space for PASID. +* If the last extended capability appears too close to the end, +* refuse to insert PASID. +*/ +if (last +512 >PCIE_CONFIG_SPACE_SIZE -PCI_EXT_CAP_PASID_SIZEOF ) { +warn_report ("vfio: no space to synthesize PASID extended capability" ); +return ; + } + + pasid_offset =PCIE_CONFIG_SPACE_SIZE -PCI_EXT_CAP_PASID_SIZEOF ; + +pcie_pasid_init (pdev, pasid_offset, + pasid_info.max_pasid_log2, + pasid_info.exec_perm, + pasid_info.priv_mod); + +/* PASID capability is fully emulated by QEMU */ +memset (vdev->emulated_config_bits + pdev->exp.pasid_cap,0xff , +PCI_EXT_CAP_PASID_SIZEOF ); +} +static void vfio_add_ext_cap (VFIOPCIDevice *vdev) {PCIDevice *pdev =PCI_DEVICE (vdev); +bool pasid_cap_added = false;uint32_t header;uint16_t cap_id, next, size;uint8_t cap_ver;@@ -2562,6 +2626,7 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)* accesses, exact size doesn't seem worthwhile. */ size =vfio_ext_cap_max_size (config, next); +printf ("%s: Shameer: cap_id 0x%x size 0x%x\n" ,__func__, cap_id, size);/* Use emulated next pointer to allow dropping extended caps */ pci_long_test_and_set_mask(vdev->emulated_config_bits + next,@@ -2578,12 +2643,24 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)pcie_add_capability (pdev, cap_id, cap_ver, next, size); }break ; +/* +* VFIO kernel does not expose the PASID CAP today. We may synthesize +* one later through IOMMUFD APIs. If VFIO ever starts exposing it, +* record its presence here so we do not create a duplicate CAP. +*/ +case PCI_EXT_CAP_ID_PASID : + pasid_cap_added = true; +/* fallthrough */ default :pcie_add_capability (pdev, cap_id, cap_ver, next, size); } } +if (!pasid_cap_added) { +vfio_pci_synthesize_pasid_cap (vdev); + } +/* Cleanup chain head ID if necessary */ if (pci_get_word (pdev->config +PCI_CONFIG_SPACE_SIZE ) ==0xFFFF ) {pci_set_word (pdev->config +PCI_CONFIG_SPACE_SIZE ,0 );include/hw/pci/pcie.h +3
-0@@ -130,6 +130,8 @@ bool pcie_cap_is_arifwd_enabled(const PCIDevice *dev);/* PCI express extended capability helper functions */ uint16_t pcie_find_capability (PCIDevice *dev,uint16_t cap_id); +uint16_t pcie_find_capability_list (PCIDevice *dev,uint32_t cap_id, +uint16_t *prev_p);void pcie_add_capability (PCIDevice *dev,uint16_t cap_id,uint8_t cap_ver,uint16_t offset,uint16_t size);@@ -138,6 +140,7 @@ void pcie_sync_bridge_lnk(PCIDevice *dev);void pcie_acs_init (PCIDevice *dev,uint16_t offset);void pcie_acs_reset (PCIDevice *dev); +uint16_t pcie_get_ext_cap_next_offset (PCIDevice *pdev,uint16_t cap_size);void pcie_ari_init (PCIDevice *dev,uint16_t offset);void pcie_dev_ser_num_init (PCIDevice *dev,uint16_t offset,uint64_t ser_num);void pcie_ats_init (PCIDevice *dev,uint16_t offset,bool aligned);
RE: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VM
Hi Eric,
Quoted 18 lines
-----Original Message-----
From: Eric Auger <[email protected]>
Sent: 06 January 2026 10:55
To: Shameer Kolothum <[email protected]>; Yi Liu <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>; [email protected]
Subject: Re: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VMExternal email: Use caution opening links or attachments
Hi Shameer,
[...]
Quoted 26 lines
Quoted 19 lines
Quoted 19 lines
Quoted 11 lines
Besides the fact the offset is arbitrarily chosen so that this is the last cap of the vconfig space, the code looks good to me. So
Reviewed-by Eric Auger <[email protected]>Just wondering whether we couldn't add some generic pcie code that parses the extended cap linked list to check the offset range is not used by another cap before allowing the insertion at a given offset? This wouldn't prevent a subsequent addition from failing but at least we would know if there is some collision.this could be added later on though.
You're absolutely right. My approach of using the last 8 bytes was a shortcut to avoid implementing proper capability parsing logic (importing
pci_regs.hand maintaining a cap_id-to-cap_size mapping table), and it simplified PASID capability detection by only examining the last 8bytes by a simple dump :(. However, this approach is not good as we cannot guarantee that the last 8bytes are unused by any device.Quoted 7 lines
Quoted 2 lines
Let's just implement the logic to walk the linked list of
ext_capsto find an appropriate offset for our use case.I had a go at this. Based on my understanding, even if we walk the PCIe extended capability linked list, we still can't easily determine the size occupied by the last capability as the extended capability header does not encode a length, it only provides the "next" pointer, and for the last entry next == 0.
Quoted 6 lines
If my understanding is correct when walking the linked list, you can enumerate the start index and the PCIe extended Capability variable size which is made of fix header size + register block variable size which depends on the capability ID). After that we shall be able to allocate a slot within holes or at least check that adding the new prop at the end of the 4kB is safe, no?. What do I miss?
I think the main issue is that we can't know whether the apparent "holes" between extended capabilities are actually free. Depending on the vendor implementation, those regions may be reserved or used for vendor specific purposes, and I am not sure(please correct me) PCIe spec guarantee that such gaps are available for reuse. Hence thought of relying on the “next” pointer as a safe bet.
Even if we look at the last CAP ID and derive a size based on the spec defined register layout, we still can;t know whether there is any additional vendor specific data beyond that "size". It is still a best guess and I don't think we gain much in adding this additional check.
Perhaps, I think we could inform the user that we are placing teh PASID at the last offset and the onus is on user to make sure it is safe to do so.
Thoughts?
Thanks,
Shameer
Re: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VM
Quoted 61 lines · Shameer Kolothum
Hi Eric,
Quoted 18 lines
-----Original Message-----
From: Eric Auger <[email protected]>
Sent: 06 January 2026 10:55
To: Shameer Kolothum <[email protected]>; Yi Liu <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>; [email protected]
Subject: Re: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VMExternal email: Use caution opening links or attachments
Hi Shameer,
[...]
Quoted 26 lines
Quoted 19 lines
Quoted 19 lines
Quoted 11 lines
Besides the fact the offset is arbitrarily chosen so that this is the last cap of the vconfig space, the code looks good to me. So
Reviewed-by Eric Auger <[email protected]>Just wondering whether we couldn't add some generic pcie code that parses the extended cap linked list to check the offset range is not used by another cap before allowing the insertion at a given offset? This wouldn't prevent a subsequent addition from failing but at least we would know if there is some collision.this could be added later on though.
You're absolutely right. My approach of using the last 8 bytes was a shortcut to avoid implementing proper capability parsing logic (importing
pci_regs.hand maintaining a cap_id-to-cap_size mapping table), and it simplified PASID capability detection by only examining the last 8bytes by a simple dump :(. However, this approach is not good as we cannot guarantee that the last 8bytes are unused by any device.Quoted 7 lines
Quoted 2 lines
Let's just implement the logic to walk the linked list of
ext_capsto find an appropriate offset for our use case.I had a go at this. Based on my understanding, even if we walk the PCIe extended capability linked list, we still can't easily determine the size occupied by the last capability as the extended capability header does not encode a length, it only provides the "next" pointer, and for the last entry next == 0.
Quoted 6 lines
If my understanding is correct when walking the linked list, you can enumerate the start index and the PCIe extended Capability variable size which is made of fix header size + register block variable size which depends on the capability ID). After that we shall be able to allocate a slot within holes or at least check that adding the new prop at the end of the 4kB is safe, no?. What do I miss?
I think the main issue is that we can't know whether the apparent "holes" between extended capabilities are actually free. Depending on the vendor implementation, those regions may be reserved or used for vendor specific purposes, and I am not sure(please correct me) PCIe spec guarantee that such gaps are available for reuse. Hence thought of relying on the “next” pointer as a safe bet.
Quoted 5 lines
Even if we look at the last CAP ID and derive a size based on the spec defined register layout, we still can;t know whether there is any additional vendor specific data beyond that "size". It is still a best guess and I don't think we gain much in adding this additional check.
Ah OK I see what you mean (you may have discussed that earlier in other threads sorry). So you may have vendor specific private data in the holes. In that case I guess we cannot do much :-/
Quoted 4 lines
Perhaps, I think we could inform the user that we are placing teh PASID at the last offset and the onus is on user to make sure it is safe to do so.
or another solution is to let the user opt-in for this hasardous placement using an explicit x- prefixed option? Dunno
Thanks
Eric
Quoted 6 lines
Thoughts?
Thanks,
Shameer
Re: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VM
Quoted 68 lines · On Tue, 6 Jan 2026 14:22:57 +0100 Eric Auger <[email protected]> wrote:
Quoted 61 lines · Shameer Kolothum
Hi Eric,
Quoted 18 lines
-----Original Message-----
From: Eric Auger <[email protected]>
Sent: 06 January 2026 10:55
To: Shameer Kolothum <[email protected]>; Yi Liu <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>; [email protected]
Subject: Re: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VMExternal email: Use caution opening links or attachments
Hi Shameer,
[...]
Quoted 26 lines
Quoted 19 lines
Quoted 19 lines
Quoted 11 lines
Besides the fact the offset is arbitrarily chosen so that this is the last cap of the vconfig space, the code looks good to me. So
Reviewed-by Eric Auger <[email protected]>Just wondering whether we couldn't add some generic pcie code that parses the extended cap linked list to check the offset range is not used by another cap before allowing the insertion at a given offset? This wouldn't prevent a subsequent addition from failing but at least we would know if there is some collision.this could be added later on though.
You're absolutely right. My approach of using the last 8 bytes was a shortcut to avoid implementing proper capability parsing logic (importing
pci_regs.hand maintaining a cap_id-to-cap_size mapping table), and it simplified PASID capability detection by only examining the last 8bytes by a simple dump :(. However, this approach is not good as we cannot guarantee that the last 8bytes are unused by any device.Quoted 7 lines
Quoted 2 lines
Let's just implement the logic to walk the linked list of
ext_capsto find an appropriate offset for our use case.I had a go at this. Based on my understanding, even if we walk the PCIe extended capability linked list, we still can't easily determine the size occupied by the last capability as the extended capability header does not encode a length, it only provides the "next" pointer, and for the last entry next == 0.
Quoted 6 lines
If my understanding is correct when walking the linked list, you can enumerate the start index and the PCIe extended Capability variable size which is made of fix header size + register block variable size which depends on the capability ID). After that we shall be able to allocate a slot within holes or at least check that adding the new prop at the end of the 4kB is safe, no?. What do I miss?
I think the main issue is that we can't know whether the apparent "holes" between extended capabilities are actually free. Depending on the vendor implementation, those regions may be reserved or used for vendor specific purposes, and I am not sure(please correct me) PCIe spec guarantee that such gaps are available for reuse. Hence thought of relying on the “next” pointer as a safe bet.
Quoted 5 lines
Even if we look at the last CAP ID and derive a size based on the spec defined register layout, we still can;t know whether there is any additional vendor specific data beyond that "size". It is still a best guess and I don't think we gain much in adding this additional check.
Quoted 3 lines
Ah OK I see what you mean (you may have discussed that earlier in other threads sorry). So you may have vendor specific private data in the holes. In that case I guess we cannot do much :-/
Also, we can only know the size of capabilities that are currently defined, we don't do a great job of keeping up with the latest ECNs.
Unless we have device specific knowledge, the best we can do is hope that a gap between capabilities is unused. It might be a helpful indicator to verify the config space we intend to overlap is zero, though we can get false positives with such a method if we overlap a capability that kernel vfio-pci has disconnected from the capability chain an marked read-only.
Quoted 6 lines
Quoted 4 lines
Perhaps, I think we could inform the user that we are placing teh PASID at the last offset and the onus is on user to make sure it is safe to do so.
or another solution is to let the user opt-in for this hasardous placement using an explicit x- prefixed option? Dunno
Yeah, this is probably one of those cases where we expect we don't have a foolproof solution and we should allow an override. I think we're defining the initial 'auto' algorithm that a -x-vpasid_cap_offset= might use by default. It should also take a numerical value as an override though. We'll need a table so that when we find a device that requires a different value, that becomes the auto value for that device.
Also consider how adding subsequent purely virtual capability would work. We don't want to have each capability defining a new algorithm and default offset. To that extent, we might be better served with a command line override that specifies available ranges of config space rather than an offset for a specific vcap. I think our discussions related to a kernel interface were headed more in this direction. Thanks,
Alex
Re: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VM
In reply to Shameer KolothumQuoted 19 lines · Shameer Kolothum
From: Yi Liu <[email protected]>
If user wants to expose PASID capability in vIOMMU, then VFIO would also need to report the PASID cap for this device if the underlying hardware supports it as well.
As a start, this chooses to put the vPASID cap in the last 8 bytes of the vconfig space. This is a choice in the good hope of no conflict with any existing cap or hidden registers. For the devices that has hidden registers, user should figure out a proper offset for the vPASID cap. This may require an option for user to config it. Here we leave it as a future extension. There are more discussions on the mechanism of finding the proper offset.
Since we add a check to ensure the vIOMMU supports PASID, only devices under those vIOMMUs can synthesize the vPASID capability. This gives users control over which devices expose vPASID.
Quoted 8 lines
Signed-off-by Yi Liu <[email protected]>Tested-by Zhangfei Gao <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/vfio/pci.c | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/iommu.h | 1 + 2 files changed, 39 insertions(+)
I just noticed another problem with this change. It relies on the availability of the HostIOMMUDevice which doesn't exist with VFIO mdev devices, such as vGPU. QEMU simply coredumps :/
We will have to check/protect QEMU in some ways. I need to take a closer look because mdev handling seems to be spread across the code and may need to be improved first.
Thanks,
C.
Quoted 83 lines
hw/vfio/pci.c +38
-0@@ -24,6 +24,7 @@#include <sys/ioctl.h> #include "hw/hw.h" +#include "hw/iommu.h" #include "hw/pci/msi.h" #include "hw/pci/msix.h" #include "hw/pci/pci_bridge.h" @@ -2500,7 +2501,12 @@ static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)static void vfio_add_ext_cap (VFIOPCIDevice *vdev) { +HostIOMMUDevice *hiod = vdev->vbasedev.hiod; +HostIOMMUDeviceClass *hiodc =HOST_IOMMU_DEVICE_GET_CLASS (hiod);PCIDevice *pdev =PCI_DEVICE (vdev); +uint64_t max_pasid_log2 =0 ; +bool pasid_cap_added = false; +uint64_t hw_caps;uint32_t header;uint16_t cap_id, next, size;uint8_t cap_ver;@@ -2578,12 +2584,44 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)pcie_add_capability (pdev, cap_id, cap_ver, next, size); }break ; +/* +* VFIO kernel does not expose the PASID CAP today. We may synthesize +* one later through IOMMUFD APIs. If VFIO ever starts exposing it, +* record its presence here so we do not create a duplicate CAP. +*/ +case PCI_EXT_CAP_ID_PASID : + pasid_cap_added = true; +/* fallthrough */ default :pcie_add_capability (pdev, cap_id, cap_ver, next, size); } } +#ifdef CONFIG_IOMMUFD +/* Try to retrieve PASID CAP through IOMMUFD APIs */ +if (!pasid_cap_added && hiodc && hiodc->get_cap) { + hiodc->get_cap (hiod,HOST_IOMMU_DEVICE_CAP_GENERIC_HW , &hw_caps,NULL ); + hiodc->get_cap (hiod,HOST_IOMMU_DEVICE_CAP_MAX_PASID_LOG2 , + &max_pasid_log2,NULL ); + } + +/* +* If supported, adds the PASID capability in the end of the PCIe config +* space. TODO: Add option for enabling pasid at a safe offset. +*/ +if (max_pasid_log2 && (pci_device_get_viommu_flags (pdev) & +VIOMMU_FLAG_PASID_SUPPORTED )) { +bool exec_perm = (hw_caps &IOMMU_HW_CAP_PCI_PASID_EXEC ); +bool priv_mod = (hw_caps &IOMMU_HW_CAP_PCI_PASID_PRIV ); + +pcie_pasid_init (pdev,PCIE_CONFIG_SPACE_SIZE -PCI_EXT_CAP_PASID_SIZEOF , + max_pasid_log2, exec_perm, priv_mod); +/* PASID capability is fully emulated by QEMU */ +memset (vdev->emulated_config_bits + pdev->exp.pasid_cap,0xff ,8 ); + } +#endif +/* Cleanup chain head ID if necessary */ if (pci_get_word (pdev->config +PCI_CONFIG_SPACE_SIZE ) ==0xFFFF ) {pci_set_word (pdev->config +PCI_CONFIG_SPACE_SIZE ,0 );include/hw/iommu.h +1
-0@@ -20,6 +20,7 @@enum viommu_flags {/* vIOMMU needs nesting parent HWPT to create nested HWPT */ VIOMMU_FLAG_WANT_NESTING_PARENT =BIT_ULL (0 ), +VIOMMU_FLAG_PASID_SUPPORTED =BIT_ULL (1 ), };#endif /* HW_IOMMU_H */
RE: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VM
Hi Cédric,
Quoted 50 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: 15 December 2025 10:55
To: Shameer Kolothum <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VMExternal email: Use caution opening links or attachments
Quoted 6 lines · Shameer Kolothum
From: Yi Liu <[email protected]>
If user wants to expose PASID capability in vIOMMU, then VFIO would also need to report the PASID cap for this device if the underlying hardware supports it as well.
Quoted 8 lines
As a start, this chooses to put the vPASID cap in the last 8 bytes of the vconfig space. This is a choice in the good hope of no conflict with any existing cap or hidden registers. For the devices that has hidden registers, user should figure out a proper offset for the vPASID cap. This may require an option for user to config it. Here we leave it as a future extension. There are more discussions on the mechanism of finding the proper offset.
https://lore.kernel.org/kvm/BN9PR11MB5276318969A212AD0649C7BE8CBE2
@BN9PR11MB5276.namprd11.prod.outlook.com/Quoted 5 lines
Since we add a check to ensure the vIOMMU supports PASID, only devices under those vIOMMUs can synthesize the vPASID capability. This gives users control over which devices expose vPASID.
Quoted 8 lines
Signed-off-by Yi Liu <[email protected]>Tested-by Zhangfei Gao <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/vfio/pci.c | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/iommu.h | 1 + 2 files changed, 39 insertions(+)
Quoted 7 lines
I just noticed another problem with this change. It relies on the availability of the HostIOMMUDevice which doesn't exist with VFIO mdev devices, such as vGPU. QEMU simply coredumps :/
We will have to check/protect QEMU in some ways. I need to take a closer look because mdev handling seems to be spread across the code and may need to be improved first.
I did attempt a rework on this patch and the previous one(patch #31) to address the above issue and to avoid the #ifdef CONFIG_IOMMUFD in vfio. Please find below:
Patch #1:
This adds get_pasid_info to HostIOMMUDeviceClass. One thing I am not sure, below is to use #ifdef CONFIG_LINUX or not. Please take a look and let me know if this is the right direction or not.
From e1305b0d44b2002778059decc3d6b220414b0589 Mon Sep 17 00:00:00 2001
From: Shameer Kolothum <[email protected]>
Date: Fri, 2 Jan 2026 14:50:58 +0000
Subject: [PATCH 1/2] backends/iommufd: Add get_pasid_info
TODO:
--- backends/iommufd.c | 17 +++++++++++++++++ include/system/host_iommu_device.h | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+)
backends/iommufd.c +17 -0
@@ -634,11 +634,28 @@ static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **errp) } } +static bool hiod_iommufd_get_pasid_info (HostIOMMUDevice *hiod, +HostIOMMUDevicePasidInfo *pasid_info) +{ +HostIOMMUDeviceCaps *caps = &hiod->caps; + +if (!caps->max_pasid_log2) { +return false; + } + +g_assert (pasid_info); + pasid_info->exec_perm = (caps->hw_caps &IOMMU_HW_CAP_PCI_PASID_EXEC ); + pasid_info->priv_mod = (caps->hw_caps &IOMMU_HW_CAP_PCI_PASID_PRIV ); + pasid_info->max_pasid_log2 = caps->max_pasid_log2; +return true; +} +static void hiod_iommufd_class_init (ObjectClass *oc,const void *data) {HostIOMMUDeviceClass *hioc =HOST_IOMMU_DEVICE_CLASS (oc); hioc->get_cap = hiod_iommufd_get_cap; + hioc->get_pasid_info = hiod_iommufd_get_pasid_info; };static const TypeInfo types[] = {
include/system/host_iommu_device.h +19 -0
@@ -22,6 +22,13 @@ typedef union VendorCaps {struct iommu_hw_info_arm_smmuv3 smmuv3; } VendorCaps; + +typedef struct HostIOMMUDevicePasidInfo { +bool exec_perm; +bool priv_mod; +uint64_t max_pasid_log2; +}HostIOMMUDevicePasidInfo ; +/** * struct HostIOMMUDeviceCaps - Define host IOMMU device capabilities. *
@@ -116,6 +123,18 @@ struct HostIOMMUDeviceClass {* @hiod: handle to the host IOMMU device */ uint64_t (*get_page_size_mask)(HostIOMMUDevice *hiod); +#ifdef CONFIG_LINUX +/** +* @get_pasid_info: Return the PASID information associated with the Host +* IOMMU device. +* +* @pasid_info: If success, returns the PASID related information. +* +* Returns: true on success, false on failure. +*/ +bool (*get_pasid_info)(HostIOMMUDevice *hiod, +HostIOMMUDevicePasidInfo *pasid_info); +#endif };/*
--
Patch #2:
This adds a check for mdev to avoid the coredump mentioned above. Please let me know If you have a nicer/broader solution to address this for mdev devices.
From bbb54b349fccd61d8dab6b95be11c42510db3f95 Mon Sep 17 00:00:00 2001
From: Shameer Kolothum <[email protected]>
Date: Fri, 2 Jan 2026 14:52:26 +0000
Subject: [PATCH 2/2] hw/vfio/pci: Add pasid cap synthesize
TODO:
--- hw/vfio/pci.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
hw/vfio/pci.c +45 -0
72 lines not on this page · raw message
--
2.43.0
Please let me know your thoughts.
Thanks,
Shameer
Re: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VM
Hello Shameer,
Quoted 60 lines · Shameer Kolothum
Hi Cédric,
Quoted 50 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: 15 December 2025 10:55
To: Shameer Kolothum <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 32/33] vfio: Synthesize vPASID capability to VMExternal email: Use caution opening links or attachments
Quoted 6 lines · Shameer Kolothum
From: Yi Liu <[email protected]>
If user wants to expose PASID capability in vIOMMU, then VFIO would also need to report the PASID cap for this device if the underlying hardware supports it as well.
Quoted 8 lines
As a start, this chooses to put the vPASID cap in the last 8 bytes of the vconfig space. This is a choice in the good hope of no conflict with any existing cap or hidden registers. For the devices that has hidden registers, user should figure out a proper offset for the vPASID cap. This may require an option for user to config it. Here we leave it as a future extension. There are more discussions on the mechanism of finding the proper offset.
https://lore.kernel.org/kvm/BN9PR11MB5276318969A212AD0649C7BE8CBE2
@BN9PR11MB5276.namprd11.prod.outlook.com/Quoted 5 lines
Since we add a check to ensure the vIOMMU supports PASID, only devices under those vIOMMUs can synthesize the vPASID capability. This gives users control over which devices expose vPASID.
Quoted 8 lines
Signed-off-by Yi Liu <[email protected]>Tested-by Zhangfei Gao <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Shameer Kolothum <[email protected]>--- hw/vfio/pci.c | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/iommu.h | 1 + 2 files changed, 39 insertions(+)Quoted 7 lines
I just noticed another problem with this change. It relies on the availability of the HostIOMMUDevice which doesn't exist with VFIO mdev devices, such as vGPU. QEMU simply coredumps :/
We will have to check/protect QEMU in some ways. I need to take a closer look because mdev handling seems to be spread across the code and may need to be improved first.
Quoted 8 lines
I did attempt a rework on this patch and the previous one(patch #31) to address the above issue and to avoid the #ifdef
CONFIG_IOMMUFDin vfio. Please find below:Patch #1:
This addsget_pasid_infoto HostIOMMUDeviceClass. One thing I am not sure, below is to use #ifdefCONFIG_LINUXor not. Please take a look and let me know if this is the right direction or not.
I don't think CONFIG_LINUX is needed there because the declarations are not specific to linux. A simple way to try a windows build is with :
--cross-prefix=x86_64-w64-mingw32-
you might need to add :
--disable-sdl
and targets should be aarch64-softmmu,ppc64-softmmu,x86_64-softmmu,s390x-softmmu
You should resend a v7, in whole or in parts, as you wish.
Thanks,
C.
Quoted 190 lines
From
e1305b0d44b2002778059decc3d6b220414b0589Mon Sep 17 00:00:00 2001
From: Shameer Kolothum <[email protected]>
Date: Fri, 2 Jan 2026 14:50:58 +0000
Subject: [PATCH 1/2] backends/iommufd: Addget_pasid_infoTODO:
Signed-off-by Shameer Kolothum <[email protected]>--- backends/iommufd.c | 17 +++++++++++++++++ include/system/host_iommu_device.h | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+)backends/iommufd.c +17
-0@@ -634,11 +634,28 @@ static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **errp) } } +static bool hiod_iommufd_get_pasid_info (HostIOMMUDevice *hiod, +HostIOMMUDevicePasidInfo *pasid_info) +{ +HostIOMMUDeviceCaps *caps = &hiod->caps; + +if (!caps->max_pasid_log2) { +return false; + } + +g_assert (pasid_info); + pasid_info->exec_perm = (caps->hw_caps &IOMMU_HW_CAP_PCI_PASID_EXEC ); + pasid_info->priv_mod = (caps->hw_caps &IOMMU_HW_CAP_PCI_PASID_PRIV ); + pasid_info->max_pasid_log2 = caps->max_pasid_log2; +return true; +} +static void hiod_iommufd_class_init (ObjectClass *oc,const void *data) {HostIOMMUDeviceClass *hioc =HOST_IOMMU_DEVICE_CLASS (oc); hioc->get_cap = hiod_iommufd_get_cap; + hioc->get_pasid_info = hiod_iommufd_get_pasid_info; };static const TypeInfo types[] = {include/system/host_iommu_device.h +19
-1@@ -22,6 +22,13 @@ typedef union VendorCaps {struct iommu_hw_info_arm_smmuv3 smmuv3; } VendorCaps; + +typedef struct HostIOMMUDevicePasidInfo { +bool exec_perm; +bool priv_mod; +uint64_t max_pasid_log2; +}HostIOMMUDevicePasidInfo ; +/** * struct HostIOMMUDeviceCaps - Define host IOMMU device capabilities. * @@ -116,6 +123,18 @@ struct HostIOMMUDeviceClass {* @hiod: handle to the host IOMMU device */ uint64_t (*get_page_size_mask)(HostIOMMUDevice *hiod); +#ifdef CONFIG_LINUX +/** +* @get_pasid_info: Return the PASID information associated with the Host +* IOMMU device. +* +* @pasid_info: If success, returns the PASID related information. +* +* Returns: true on success, false on failure. +*/ +bool (*get_pasid_info)(HostIOMMUDevice *hiod, +HostIOMMUDevicePasidInfo *pasid_info); +#endif };/* -- Patch #2:
This adds a check for mdev to avoid the coredump mentioned above. Please let me know If you have a nicer/broader solution to address this for mdev devices.From
bbb54b349fccd61d8dab6b95be11c42510db3f95Mon Sep 17 00:00:00 2001
From: Shameer Kolothum <[email protected]>
Date: Fri, 2 Jan 2026 14:52:26 +0000
Subject: [PATCH 2/2] hw/vfio/pci: Add pasid cap synthesizeTODO:
Signed-off-by Shameer Kolothum <[email protected]>--- hw/vfio/pci.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)hw/vfio/pci.c +45
-1@@ -24,6 +24,7 @@#include <sys/ioctl.h> #include "hw/hw.h" +#include "hw/iommu.h" #include "hw/pci/msi.h" #include "hw/pci/msix.h" #include "hw/pci/pci_bridge.h" @@ -2498,9 +2499,41 @@ static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)return 0 ; } +/* +* Try to retrieve PASID CAP through IOMMUFD APIs. If available, adds the +* PASID capability in the end of the PCIe config space. +* TODO: Add support for enabling pasid at a safe offset. +*/ +static void vfio_pci_synthesize_pasid_cap (VFIOPCIDevice *vdev) +{ +HostIOMMUDevice *hiod = vdev->vbasedev.hiod; +PCIDevice *pdev =PCI_DEVICE (vdev); +HostIOMMUDeviceClass *hiodc; +HostIOMMUDevicePasidInfo pasid_info; + +if (vdev->vbasedev.mdev) { +return ; + } + + hiodc =HOST_IOMMU_DEVICE_GET_CLASS (hiod); +if (!hiodc->get_pasid_info || + !(pci_device_get_viommu_flags (pdev) &VIOMMU_FLAG_PASID_SUPPORTED )) { +return ; + } + +if (hiodc->get_pasid_info (hiod, &pasid_info)) { +pcie_pasid_init (pdev,PCIE_CONFIG_SPACE_SIZE -PCI_EXT_CAP_PASID_SIZEOF , + pasid_info.max_pasid_log2, pasid_info.exec_perm, + pasid_info.priv_mod); +/* PASID capability is fully emulated by QEMU */ +memset (vdev->emulated_config_bits + pdev->exp.pasid_cap,0xff ,8 ); + } +} +static void vfio_add_ext_cap (VFIOPCIDevice *vdev) {PCIDevice *pdev =PCI_DEVICE (vdev); +bool pasid_cap_added = false;uint32_t header;uint16_t cap_id, next, size;uint8_t cap_ver;@@ -2578,12 +2611,24 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)pcie_add_capability (pdev, cap_id, cap_ver, next, size); }break ; +/* +* VFIO kernel does not expose the PASID CAP today. We may synthesize +* one later through IOMMUFD APIs. If VFIO ever starts exposing it, +* record its presence here so we do not create a duplicate CAP. +*/ +case PCI_EXT_CAP_ID_PASID : + pasid_cap_added = true; +/* fallthrough */ default :pcie_add_capability (pdev, cap_id, cap_ver, next, size); } } +if (!pasid_cap_added) { +vfio_pci_synthesize_pasid_cap (vdev); + } +/* Cleanup chain head ID if necessary */ if (pci_get_word (pdev->config +PCI_CONFIG_SPACE_SIZE ) ==0xFFFF ) {pci_set_word (pdev->config +PCI_CONFIG_SPACE_SIZE ,0 ); --2.43.0
Please let me know your thoughts.
Thanks,
Shameer
PATCH v6 33/33 hw/arm/smmuv3-accel: Add support for PASID enable
In reply to Shameer KolothumQEMU SMMUv3 currently forces SSID (Substream ID) to zero. One key use case for accelerated mode is Shared Virtual Addressing (SVA), which requires SSID support so the guest can maintain multiple context descriptors per substream ID.
Provide an option for user to enable PASID support. A SSIDSIZE of 16 is currently used as default.
--- hw/arm/smmuv3-accel.c | 23 ++++++++++++++++++++++- hw/arm/smmuv3-internal.h | 1 + hw/arm/smmuv3.c | 13 +++++++++++-- include/hw/arm/smmuv3.h | 1 + 4 files changed, 35 insertions(+), 3 deletions(-)
hw/arm/smmuv3-accel.c +22 -1
@@ -67,6 +67,12 @@ smmuv3_accel_check_hw_compatible(SMMUv3State *s,error_setg (errp,"Host SMMUv3 SIDSIZE not compatible" );return false; } +/* If user enables PASID support(pasid=on), QEMU sets SSIDSIZE to 16 */ +if (FIELD_EX32 (info->idr[1 ],IDR1 ,SSIDSIZE ) < +FIELD_EX32 (s->idr[1 ],IDR1 ,SSIDSIZE )) { +error_setg (errp,"Host SMMUv3 SSIDSIZE not compatible" ); +return false; + }/* User can disable QEMU SMMUv3 Range Invalidation support */ if (FIELD_EX32(info->idr[3], IDR3, RIL) >
@@ -643,7 +649,14 @@ static uint64_t smmuv3_accel_get_viommu_flags(void *opaque)* The real HW nested support should be reported from host SMMUv3 and if * it doesn't, the nesting parent allocation will fail anyway in VFIO core. */ -return VIOMMU_FLAG_WANT_NESTING_PARENT ; +uint64_t flags =VIOMMU_FLAG_WANT_NESTING_PARENT ; +SMMUState *bs = opaque; +SMMUv3State *s =ARM_SMMUV3 (bs); + +if (s->pasid) { + flags |=VIOMMU_FLAG_PASID_SUPPORTED ; + } +return flags; }static const PCIIOMMUOps smmuv3_accel_ops = {
@@ -671,6 +684,14 @@ void smmuv3_accel_idr_override(SMMUv3State *s)if (s->oas ==48 ) { s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS ,SMMU_IDR5_OAS_48 ); } + +/* +* By default QEMU SMMUv3 has no PASID(SSID) support. Update IDR1 if user +* has enabled it. +*/ +if (s->pasid) { + s->idr[1 ] =FIELD_DP32 (s->idr[1 ],IDR1 ,SSIDSIZE ,SMMU_IDR1_SSIDSIZE ); + } }/* Based on SMUUv3 GPBA.ABORT configuration, attach a corresponding HWPT */
hw/arm/smmuv3-internal.h +1 -0
@@ -81,6 +81,7 @@ REG32(IDR1, 0x4) FIELD(IDR1, ECMDQ, 31, 1)#define SMMU_IDR1_SIDSIZE 16 +#define SMMU_IDR1_SSIDSIZE 16#define SMMU_CMDQS 19#define SMMU_EVENTQS 19
hw/arm/smmuv3.c +11 -2
@@ -611,9 +611,11 @@ static int decode_ste(SMMUv3State *s, SMMUTransCfg *cfg, } } -if (STE_S1CDMAX (ste) !=0 ) { +/* If pasid not enabled, can't support multiple CDs */ +if (!s->pasid &&STE_S1CDMAX (ste) !=0 ) {qemu_log_mask (LOG_UNIMP , -"SMMUv3 does not support multiple context descriptors yet\n" ); +"SMMUv3: multiple S1 context descriptors require PASID support. " +"Enable PASID with pasid=on (supported only with accel=on)\n" ); goto bad_ste; }
@@ -1950,6 +1952,10 @@ static bool smmu_validate_property(SMMUv3State *s, Error **errp)error_setg (errp,"OAS can only be set to 44 bits if accel=off" );return false; } +if (s->pasid) { +error_setg (errp,"pasid can only be enabled if accel=on" ); +return false; + }return true; }
@@ -2084,6 +2090,7 @@ static const Property smmuv3_properties[] = {DEFINE_PROP_BOOL ("ril" , SMMUv3State, ril, true),DEFINE_PROP_BOOL ("ats" , SMMUv3State, ats, false),DEFINE_PROP_UINT8 ("oas" , SMMUv3State, oas,44 ), + DEFINE_PROP_BOOL("pasid", SMMUv3State, pasid, false), };static void smmuv3_instance_init (Object *obj)
@@ -2117,6 +2124,8 @@ static void smmuv3_class_init(ObjectClass *klass, const void *data)object_class_property_set_description (klass,"oas" ,"Specify Output Address Size (for accel =on). Supported values " "are 44 or 48 bits. Defaults to 44 bits" ); +object_class_property_set_description (klass,"pasid" , +"Enable/disable PASID support (for accel=on)" ); } static int smmuv3_notify_flag_changed(IOMMUMemoryRegion *iommu,
include/hw/arm/smmuv3.h +1 -0
@@ -72,6 +72,7 @@ struct SMMUv3State {bool ril;bool ats;uint8_t oas; +bool pasid; }; typedef enum {
Signature · 1 line
2.43.0
Re: [PATCH v6 33/33] hw/arm/smmuv3-accel: Add support for PASID enable
hw/arm/smmuv3-accel.c smmuv3_accel_check_hw_compatible(SMMUv3State *s, · line 75
Quoted 11 lines · Shameer Kolothum
+++
b/hw/arm/smmuv3-accel.chw/arm/smmuv3-accel.c +6
-0@@ -67,6 +67,12 @@ smmuv3_accel_check_hw_compatible(SMMUv3State *s,error_setg (errp,"Host SMMUv3 SIDSIZE not compatible" );return false; } +/* If user enables PASID support(pasid=on), QEMU sets SSIDSIZE to 16 */ +if (FIELD_EX32 (info->idr[1 ],IDR1 ,SSIDSIZE ) < +FIELD_EX32 (s->idr[1 ],IDR1 ,SSIDSIZE )) { +error_setg (errp,"Host SMMUv3 SSIDSIZE not compatible" ); +return false; + }
I think we can print the values: host vs VM. And at SIDSIZE above as well.
hw/arm/smmuv3.c static const Property smmuv3_properties[] = { · line 2094
Quoted 6 lines
hw/arm/smmuv3.c +1
-0@@ -2084,6 +2090,7 @@ static const Property smmuv3_properties[] = {DEFINE_PROP_BOOL ("ril" , SMMUv3State, ril, true),DEFINE_PROP_BOOL ("ats" , SMMUv3State, ats, false),DEFINE_PROP_UINT8 ("oas" , SMMUv3State, oas,44 ), + DEFINE_PROP_BOOL("pasid", SMMUv3State, pasid, false), };
Instead of doing a boolean "pasid", perhaps ssidsize and sidsize should be configurable. Then, user can follow the not-compatible print to set correct SSIDSIZE and SIDSIZE.
They can also choose to set a higher value if underlying SMMU HW supports that.
Otherwise,
RE: [PATCH v6 33/33] hw/arm/smmuv3-accel: Add support for PASID enable
Quoted 34 lines
-----Original Message-----
From: Nicolin Chen <[email protected]>
Sent: 20 November 2025 22:10
To: Shameer Kolothum <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 33/33] hw/arm/smmuv3-accel: Add support for PASID enableReview smmuv3_accel_check_hw_compatible(SMMUv3State
Quoted 2 lines · Shameer Kolothum
+++
b/hw/arm/smmuv3-accel.c(quoted diff) +0
-0@@ -67,6 +67,12 @@ smmuv3_accel_check_hw_compatible(SMMUv3State*s,
hw/arm/smmuv3-accel.c smmuv3_accel_check_hw_compatible(SMMUv3State *s, · line 75
Quoted 9 lines
hw/arm/smmuv3-accel.c +6
-0error_setg (errp,"Host SMMUv3 SIDSIZE not compatible" );return false; } +/* If user enables PASID support(pasid=on), QEMU sets SSIDSIZE to 16 */ +if (FIELD_EX32 (info->idr[1 ],IDR1 ,SSIDSIZE ) < +FIELD_EX32 (s->idr[1 ],IDR1 ,SSIDSIZE )) { +error_setg (errp,"Host SMMUv3 SSIDSIZE not compatible" ); +return false; + }I think we can print the values: host vs VM. And at SIDSIZE above as well.
Quoted 10 lines
hw/arm/smmuv3.c static const Property smmuv3_properties[] = { · line 2094
Quoted 6 lines
hw/arm/smmuv3.c +1
-0@@ -2084,6 +2090,7 @@ static const Property smmuv3_properties[] = {DEFINE_PROP_BOOL ("ril" , SMMUv3State, ril, true),DEFINE_PROP_BOOL ("ats" , SMMUv3State, ats, false),DEFINE_PROP_UINT8 ("oas" , SMMUv3State, oas,44 ), + DEFINE_PROP_BOOL("pasid", SMMUv3State, pasid, false), };Instead of doing a boolean "pasid", perhaps ssidsize and sidsize should be configurable. Then, user can follow the not-compatible print to set correct SSIDSIZE and SIDSIZE.
Do we really need that? Currently both are set to 16 which means 64K values are supported. I think we can make it configurable when any usecase with >64K requirement comes up.
Thanks,
Shameer
Re: [PATCH v6 33/33] hw/arm/smmuv3-accel: Add support for PASID enable
Quoted 11 lines · Shameer Kolothum
Quoted 10 lines
hw/arm/smmuv3.c static const Property smmuv3_properties[] = { · line 2094
Quoted 6 lines
hw/arm/smmuv3.c +1
-0@@ -2084,6 +2090,7 @@ static const Property smmuv3_properties[] = {DEFINE_PROP_BOOL ("ril" , SMMUv3State, ril, true),DEFINE_PROP_BOOL ("ats" , SMMUv3State, ats, false),DEFINE_PROP_UINT8 ("oas" , SMMUv3State, oas,44 ), + DEFINE_PROP_BOOL("pasid", SMMUv3State, pasid, false), };Instead of doing a boolean "pasid", perhaps ssidsize and sidsize should be configurable. Then, user can follow the not-compatible print to set correct SSIDSIZE and SIDSIZE.
Quoted 3 lines
Do we really need that? Currently both are set to 16 which means 64K values are supported. I think we can make it configurable when any usecase with >64K requirement comes up.
For upper boundary, we have SoCs with SSIDSIZE=0x14 i.e. 20. I am not sure how user space would use this range, but I feel it is better not to cap it. And SIDSIZE=16 is probably way enough given that QEMU only has one PCI Bus domain.
For lower boundary, SMMUv3 spec defines:
SSIDSIZE, bits [10:6]
Max bits of SubstreamID.
Valid range 0 to 20 inclusive, 0 meaning no substreams are supported.
and
SIDSIZE, bits [5:0]
Max bits of StreamID.
This value is between 0 and 32 inclusive.
Note: 0 is a legal value. In this case the SMMU supports one stream.
We apply a hard requirement that a host value must >= VM value. This might not work for hardware that has smaller numbers.
Yes, we may add an SIDSIZE when somebody actually wants it. But the "bool pasid" would be very useless when we add an SSIDSIZE.
So, I think it's nicer to define "uint32 ssidsize" in the first place, which also aligns the QEMU parameter with the HW naming.
Nicolin
Re: [PATCH v6 33/33] hw/arm/smmuv3-accel: Add support for PASID enable
Quoted 1 line · Nicolin Chen
So, I think it's nicer to define "uint32 ssidsize" in the first
Correction: "u8 ssidsize".
Re: [PATCH v6 33/33] hw/arm/smmuv3-accel: Add support for PASID enable
In reply to Nicolin ChenQuoted 12 lines · Nicolin Chen
Quoted 11 lines · Shameer Kolothum
Quoted 10 lines
hw/arm/smmuv3.c static const Property smmuv3_properties[] = { · line 2094
Quoted 6 lines
hw/arm/smmuv3.c +1
-0@@ -2084,6 +2090,7 @@ static const Property smmuv3_properties[] = {DEFINE_PROP_BOOL ("ril" , SMMUv3State, ril, true),DEFINE_PROP_BOOL ("ats" , SMMUv3State, ats, false),DEFINE_PROP_UINT8 ("oas" , SMMUv3State, oas,44 ), + DEFINE_PROP_BOOL("pasid", SMMUv3State, pasid, false), };Instead of doing a boolean "pasid", perhaps ssidsize and sidsize should be configurable. Then, user can follow the not-compatible print to set correct SSIDSIZE and SIDSIZE.
Quoted 8 lines
Quoted 3 lines
Do we really need that? Currently both are set to 16 which means 64K values are supported. I think we can make it configurable when any usecase with >64K requirement comes up.
For upper boundary, we have SoCs with SSIDSIZE=0x14 i.e. 20. I am not sure how user space would use this range, but I feel it is better not to cap it. And SIDSIZE=16 is probably way enough given that QEMU only has one PCI Bus domain.
Yeah, it should be ssize not pasid.
The use case of these values is exactly defining a SMMU instance type so that it can migration between different physical HW. So long as physical can implement the instance type.
Thus you broadly want to make the iidrs configurable in the exact spec language of the iidrs, IMHO.
Jason
RE: [PATCH v6 33/33] hw/arm/smmuv3-accel: Add support for PASID enable
In reply to Nicolin ChenQuoted 30 lines
-----Original Message-----
From: Nicolin Chen <[email protected]>
Sent: 21 November 2025 17:51
To: Shameer Kolothum <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 33/33] hw/arm/smmuv3-accel: Add support for PASID enableQuoted 1 line · Shameer Kolothum
Quoted 1 line
Review static const Property smmuv3_properties[] =
Quoted 1 line
(quoted diff) +0
-0@@ -2084,6 +2090,7 @@ static const Property smmuv3_properties[] ={
Quoted 10 lines
Quoted 9 lines
hw/arm/smmuv3.c static const Property smmuv3_properties[] = { · line 2094
Quoted 5 lines
hw/arm/smmuv3.c +1
-0DEFINE_PROP_BOOL ("ril" , SMMUv3State, ril, true),DEFINE_PROP_BOOL ("ats" , SMMUv3State, ats, false),DEFINE_PROP_UINT8 ("oas" , SMMUv3State, oas,44 ), + DEFINE_PROP_BOOL("pasid", SMMUv3State, pasid, false), };Instead of doing a boolean "pasid", perhaps ssidsize and sidsize should be configurable. Then, user can follow the not-compatible print to set correct SSIDSIZE and SIDSIZE.
Quoted 6 lines
Quoted 3 lines
Do we really need that? Currently both are set to 16 which means 64K values are supported. I think we can make it configurable when any usecase with >64K requirement comes up.
For upper boundary, we have SoCs with SSIDSIZE=0x14 i.e. 20. I am not sure how user space would use this range,
Right. My assumption was that nobody uses that higher range per SID now in real applications even if hardware supports that.
but I feel it
Quoted 13 lines
is better not to cap it. And SIDSIZE=16 is probably way enough given that QEMU only has one PCI Bus domain.
For lower boundary, SMMUv3 spec defines:
SSIDSIZE, bits [10:6]
Max bits of SubstreamID.
Valid range 0 to 20 inclusive, 0 meaning no substreams are supported.
and
SIDSIZE, bits [5:0]
Max bits of StreamID.
This value is between 0 and 32 inclusive.
Note: 0 is a legal value. In this case the SMMU supports one stream.
Quoted 2 lines
We apply a hard requirement that a host value must >= VM value. This might not work for hardware that has smaller numbers.
I guess 16 is a reasonable low value for all hardware's out there now, at least, I am not aware of anyone implementing less than that.
Quoted 2 lines
Yes, we may add an SIDSIZE when somebody actually wants it. But the "bool pasid" would be very useless when we add an SSIDSIZE.
That make sense.
Quoted 2 lines
So, I think it's nicer to define "uint32 ssidsize" in the first place, which also aligns the QEMU parameter with the HW naming.
Ok. Jason also made this argument that it is better to align it with IDR names here. So I will change this to "ssidsize" so that we have all the configurable properties align with ID register field names.
Thanks,
Shameer
Quoted 1 line · Shameer Kolothum
https://github.com/shamiali2008/qemu-master master-smmuv3-accel-v6
I did a quick sanity with two of my VM setups passing through GPU and MLX on NVIDIA Grace. Everything looks normal to me except:
Quoted 1 line
- GBPA-based vSTE update depends on Nicolin's kernel patch [1].
This now becomes a hard requirement that would error out when the
kernel doesn't have this change v.s. v5 just giving a warning. So
make sure to apply that to the kernel tree for testing.
b4 am https://lore.kernel.org/linux-iommu/[email protected]/
Not sure if we should put a hard requirement on the kernel change that isn't merged..
With that,
Zhangfei Gao
Tested-byQuoted 14 lines · Nicolin Chen
Quoted 1 line · Shameer Kolothum
https://github.com/shamiali2008/qemu-master master-smmuv3-accel-v6
I did a quick sanity with two of my VM setups passing through GPU and MLX on NVIDIA Grace. Everything looks normal to me except:
Quoted 1 line
- GBPA-based vSTE update depends on Nicolin's kernel patch [1].
This now becomes a hard requirement that would error out when the
kernel doesn't have this change v.s. v5 just giving a warning. So
make sure to apply that to the kernel tree for testing.
b4 am https://lore.kernel.org/linux-iommu/[email protected]/
Quoted 6 lines
Not sure if we should put a hard requirement on the kernel change that isn't merged..
With that,
Tested-by Nicolin Chen <[email protected]>
Requires stall mode enabled.
https://github.com/Linaro/qemu/tree/master-smmuv3-accel-v6
Thanks
Hi Shameer,
Quoted 35 lines
-----Original Message-----
From: Shameer Kolothum <[email protected]>
Subject: [PATCH v6 00/33] hw/arm/virt: Add support for user-creatable accelerated SMMUv3Hi,
Changes from v5:
https://lore.kernel.org/qemu-devel/20251031105005.24618-1-skolothumtho
@nvidia.com/- Addressed feedback from v5 and picked up R-by tags. Thanks to all!
- The previously split out_DSMfix mini-series is now accepted [0].
- Improved documentation about the rationale behind the design choice of returning an address space aliased to the system address space for vfio-pci endpoint devices (patch #10).
- Added error propagation support forsmmuv3_cmdq_consume()(patch #13).
- Updated vSTE based HWPT installation to check the SMMU enabled case (patch #14).
- Introduced an optional callback to PCIIOMMUOps to retrieve the MSI doorbell GPA directly, allowing us to avoid unsafe page table walks for MSI translation in accelerated SMMUv3 cases (patch #16).
- GBPA-based vSTE update depends on Nicolin's kernel patch [1].
- VFIO/IOMMUFD has dependency on Zhenzhong's patches: 4/5/8 from the pass-through support series [2].PATCH organization:
1–26: Enables accelerated SMMUv3 with features based on default QEMU SMMUv3,
including IORT RMR based MSI support.
27–29: Adds options for specifying RIL, ATS, and OAS features. 30–33: Adds PASID support, including VFIO changes.
Quoted 4 lines
Tests:
Performed basic sanity tests on an NVIDIA GRACE platform with GPU device assignments. A CUDA test application was used to verify the SVA use case. Further tests are always welcome.
I see PASID capability is exposed to guest but no pasid attachment in this series. Was the nested hwpt attached to SID instead of pasid? How was page fault handled in stage1?
Thanks
Zhenzhong
Quoted 61 lines
-----Original Message-----
From: Duan, Zhenzhong <[email protected]>
Sent: 08 December 2025 10:08
To: Shameer Kolothum <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Liu, Yi L <[email protected]>; Krishnakant Jaju <[email protected]>
Subject: RE: [PATCH v6 00/33] hw/arm/virt: Add support for user-creatable accelerated SMMUv3External email: Use caution opening links or attachments
Hi Shameer,
Quoted 10 lines
-----Original Message-----
From: Shameer Kolothum <[email protected]>
Subject: [PATCH v6 00/33] hw/arm/virt: Add support for user-creatable accelerated SMMUv3Hi,
Changes from v5:
skolothumtho
Quoted 25 lines
@nvidia.com/
- Addressed feedback from v5 and picked up R-by tags. Thanks to all!
- The previously split out_DSMfix mini-series is now accepted [0].
- Improved documentation about the rationale behind the design choice of returning an address space aliased to the system address space for vfio-pci endpoint devices (patch #10).
- Added error propagation support forsmmuv3_cmdq_consume()(patch #13).
- Updated vSTE based HWPT installation to check the SMMU enabled case (patch #14).
- Introduced an optional callback to PCIIOMMUOps to retrieve the MSI doorbell GPA directly, allowing us to avoid unsafe page table walks for MSI translation in accelerated SMMUv3 cases (patch #16).
- GBPA-based vSTE update depends on Nicolin's kernel patch [1].
- VFIO/IOMMUFD has dependency on Zhenzhong's patches: 4/5/8 from the pass-through support series [2].PATCH organization:
1–26: Enables accelerated SMMUv3 with features based on default QEMU SMMUv3,
including IORT RMR based MSI support.
27–29: Adds options for specifying RIL, ATS, and OAS features. 30–33: Adds PASID support, including VFIO changes.Quoted 3 lines
Tests:
Performed basic sanity tests on an NVIDIA GRACE platform with GPU device assignments. A CUDA test application was used to verify the SVA use
Quoted 6 lines
case.
Quoted 1 line
Further tests are always welcome.
I see PASID capability is exposed to guest but no pasid attachment in this series.
Was the nested hwpt attached to SID instead of pasid?
In ARM world there is no specific PASID attachment. ARM uses a Context Descriptor (CD) table indexed by PASID(substream in ARM) which is owned by Guest. Hence, no specific PASID attach handling is required in QEMU.
How was page fault
Quoted 1 line
handled in stage1?
If you meant PRI CAP that is not supported yet.
However, Zhangfei is maintaining a branch to add support for devices that supports SMMUv3 STALL feature and handles S1 page fault.
https://github.com/Linaro/qemu/commits/master-smmuv3-accel-v6/
Thanks,
Shameer
Quoted 75 lines
-----Original Message-----
From: Shameer Kolothum <[email protected]>
Subject: RE: [PATCH v6 00/33] hw/arm/virt: Add support for user-creatable accelerated SMMUv3Quoted 7 lines
-----Original Message-----
From: Duan, Zhenzhong <[email protected]>
Sent: 08 December 2025 10:08
To: Shameer Kolothum <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>;Quoted 18 lines
[email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Liu, Yi L <[email protected]>; Krishnakant Jaju <[email protected]>
Subject: RE: [PATCH v6 00/33] hw/arm/virt: Add support for user-creatable accelerated SMMUv3External email: Use caution opening links or attachments
Hi Shameer,
Quoted 5 lines
-----Original Message-----
From: Shameer Kolothum <[email protected]>
Subject: [PATCH v6 00/33] hw/arm/virt: Add support for user-creatable accelerated SMMUv3Quoted 11 lines
Quoted 5 lines
Hi,
Changes from v5:
skolothumtho
Quoted 5 lines
@nvidia.com/
- Addressed feedback from v5 and picked up R-by tags. Thanks to all!
- The previously split out_DSMfix mini-series is now accepted [0].
- Improved documentation about the rationale behind the design choiceof
Quoted 11 lines
Quoted 11 lines
returning an address space aliased to the system address space for vfio-pci endpoint devices (patch #10).
- Added error propagation support forsmmuv3_cmdq_consume()(patch #13).
- Updated vSTE based HWPT installation to check the SMMU enabled case (patch #14).
- Introduced an optional callback to PCIIOMMUOps to retrieve the MSI doorbell GPA directly, allowing us to avoid unsafe page table walks for MSI translation in accelerated SMMUv3 cases (patch #16).
- GBPA-based vSTE update depends on Nicolin's kernel patch [1].
- VFIO/IOMMUFD has dependency on Zhenzhong's patches: 4/5/8 fromthe
Quoted 9 lines
Quoted 9 lines
pass-through support series [2].
PATCH organization:
1–26: Enables accelerated SMMUv3 with features based on default QEMU SMMUv3,
including IORT RMR based MSI support.
27–29: Adds options for specifying RIL, ATS, and OAS features. 30–33: Adds PASID support, including VFIO changes.Quoted 3 lines
Quoted 3 lines
Tests:
Performed basic sanity tests on an NVIDIA GRACE platform with GPU device assignments. A CUDA test application was used to verify the SVAuse
Quoted 3 lines
case.
Quoted 1 line
Further tests are always welcome.
Quoted 7 lines
Quoted 3 lines
I see PASID capability is exposed to guest but no pasid attachment in this series.
Was the nested hwpt attached to SID instead of pasid?In ARM world there is no specific PASID attachment. ARM uses a Context Descriptor (CD) table indexed by PASID(substream in ARM) which is owned by Guest. Hence, no specific PASID attach handling is required in QEMU.
I just realized a nested hwpt in ARM is “stage2 hwpt + guest CD table” rather than “stage2 hwpt + a guest s1 hwpt”. When creating nested hwpt, guest S1ContextPtr is passed to host rather than a stage1 TTB. Do I understand right?
Quoted 10 lines
How was page fault
Quoted 1 line
handled in stage1?
If you meant PRI CAP that is not supported yet.
However, Zhangfei is maintaining a branch to add support for devices that supports
SMMUv3 STALL feature and handles S1 page fault.
https://github.com/Linaro/qemu/commits/master-smmuv3-accel-v6/
Thanks for sharing.
BRs,
Zhenzhong
Quoted 79 lines · Zhenzhong
Quoted 79 lines
-----Original Message-----
From: Shameer Kolothum <[email protected]>
Subject: RE: [PATCH v6 00/33] hw/arm/virt: Add support for user-creatable accelerated SMMUv3Quoted 7 lines
-----Original Message-----
From: Duan, Zhenzhong <[email protected]>
Sent: 08 December 2025 10:08
To: Shameer Kolothum <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>;Quoted 18 lines
[email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Liu, Yi L <[email protected]>; Krishnakant Jaju <[email protected]>
Subject: RE: [PATCH v6 00/33] hw/arm/virt: Add support for user-creatable accelerated SMMUv3External email: Use caution opening links or attachments
Hi Shameer,
Quoted 5 lines
-----Original Message-----
From: Shameer Kolothum <[email protected]>
Subject: [PATCH v6 00/33] hw/arm/virt: Add support for user-creatable accelerated SMMUv3Quoted 11 lines
Quoted 5 lines
Hi,
Changes from v5:
skolothumtho
Quoted 5 lines
@nvidia.com/
- Addressed feedback from v5 and picked up R-by tags. Thanks to all!
- The previously split out_DSMfix mini-series is now accepted [0].
- Improved documentation about the rationale behind the design choiceof
Quoted 11 lines
Quoted 11 lines
returning an address space aliased to the system address space for vfio-pci endpoint devices (patch #10).
- Added error propagation support forsmmuv3_cmdq_consume()(patch #13).
- Updated vSTE based HWPT installation to check the SMMU enabled case (patch #14).
- Introduced an optional callback to PCIIOMMUOps to retrieve the MSI doorbell GPA directly, allowing us to avoid unsafe page table walks for MSI translation in accelerated SMMUv3 cases (patch #16).
- GBPA-based vSTE update depends on Nicolin's kernel patch [1].
- VFIO/IOMMUFD has dependency on Zhenzhong's patches: 4/5/8 fromthe
Quoted 9 lines
Quoted 9 lines
pass-through support series [2].
PATCH organization:
1–26: Enables accelerated SMMUv3 with features based on default QEMU SMMUv3,
including IORT RMR based MSI support.
27–29: Adds options for specifying RIL, ATS, and OAS features. 30–33: Adds PASID support, including VFIO changes.Quoted 3 lines
Quoted 3 lines
Tests:
Performed basic sanity tests on an NVIDIA GRACE platform with GPU device assignments. A CUDA test application was used to verify the SVAuse
Quoted 6 lines
case.
Quoted 1 line
Further tests are always welcome.
I see PASID capability is exposed to guest but no pasid attachment in this series.
Was the nested hwpt attached to SID instead of pasid?
Quoted 7 lines
Quoted 3 lines
In ARM world there is no specific PASID attachment. ARM uses a Context Descriptor (CD) table indexed by PASID(substream in ARM) which is owned by Guest. Hence, no specific PASID attach handling is required in QEMU.
I just realized a nested hwpt in ARM is “stage2 hwpt + guest CD table” rather than “stage2 hwpt + a guest s1 hwpt”. When creating nested hwpt, guest S1ContextPtr is passed to host rather than a stage1 TTB. Do I understand right?
yeah. ARM SMMUv3 and AMD iommu does not attach pasid to host explicitly. This should be done in the time of enabling nesting.
Regards,
Yi Liu
Quoted 185 lines · Shameer Kolothum
Hi,
Changes from v5:
https://lore.kernel.org/qemu-devel/[email protected]/- Addressed feedback from v5 and picked up R-by tags. Thanks to all!
- The previously split out_DSMfix mini-series is now accepted [0].
- Improved documentation about the rationale behind the design choice of returning an address space aliased to the system address space for vfio-pci endpoint devices (patch #10).
- Added error propagation support forsmmuv3_cmdq_consume()(patch #13).
- Updated vSTE based HWPT installation to check the SMMU enabled case(patch #14).- Introduced an optional callback to PCIIOMMUOps to retrieve the MSI doorbell GPA directly, allowing us to avoid unsafe page table walks for MSI translation in accelerated SMMUv3 cases (patch #16).
- GBPA-based vSTE update depends on Nicolin's kernel patch [1].
- VFIO/IOMMUFD has dependency on Zhenzhong's patches: 4/5/8 from the pass-through support series [2].PATCH organization:
1–26: Enables accelerated SMMUv3 with features based on default QEMU SMMUv3,
including IORT RMR based MSI support.
27–29: Adds options for specifying RIL, ATS, and OAS features. 30–33: Adds PASID support, including VFIO changes.Tests:
Performed basic sanity tests on an NVIDIA GRACE platform with GPU device assignments. A CUDA test application was used to verify the SVA use case. Further tests are always welcome.Eg: Qemu Cmd line:
qemu-system-aarch64 -machine virt,gic-version=3,highmem-mmio-size=2T \
(quoted diff) +0
-21-cpu host -smp cpus=4 -m size=16G,slots=2,maxmem=66G -nographic \ -bios QEMU_EFI.fd -object iommufd,id=iommufd0 -enable-kvm \ -object memory-backend-ram,size=8G,id=m0 \ -object memory-backend-ram,size=8G,id=m1 \ -numa node,memdev=m0,cpus=0-3,nodeid=0 -numa node,memdev=m1,nodeid=1 \ -numa node,nodeid=2 -numa node,nodeid=3 -numa node,nodeid=4 -numa node,nodeid=5 \ -numa node,nodeid=6 -numa node,nodeid=7 -numa node,nodeid=8 -numa node,nodeid=9 \ -device pxb-pcie,id=pcie.1,bus_nr=1,bus=pcie.0 \ -device arm-smmuv3,primary-bus=pcie.1,id=smmuv3.0,accel=on,ats=on,ril=off,pasid=on,oas=48 \ -device pcie-root-port,id=pcie.port1,bus=pcie.1,chassis=1,pref64-reserve=512G,id=dev0 \ -device vfio-pci,host=0019:06:00.0,rombar=0,id=dev0,iommufd=iommufd0,bus=pcie.port1 \ -object acpi-generic-initiator,id=gi0,pci-dev=dev0,node=2 \ -object acpi-generic-initiator,id=gi7,pci-dev=dev0,node=9 \ -device pxb-pcie,id=pcie.2,bus_nr=8,bus=pcie.0 \ -device arm-smmuv3,primary-bus=pcie.2,id=smmuv3.1,accel=on,ats=on,ril=off,pasid=on \ -device pcie-root-port,id=pcie.port2,bus=pcie.2,chassis=2,pref64-reserve=512G \ -device vfio-pci,host=0018:06:00.0,rombar=0,id=dev1,iommufd=iommufd0,bus=pcie.port2 \ -device virtio-blk-device,drive=fs \ -drive file=image.qcow2,index=0,media=disk,format=qcow2,if=none,id=fs \ -net none \ -nographicA complete branch can be found here,
https://github.com/shamiali2008/qemu-master master-smmuv3-accel-v6Please take a look and let me know your feedback.
Thanks,
Shameer[0] https://lore.kernel.org/qemu-devel/[email protected]/
[1] https://lore.kernel.org/linux-iommu/[email protected]/
[2] https://lore.kernel.org/qemu-devel/[email protected]/Details from RFCv3 Cover letter:
-------------------------------
https://lore.kernel.org/qemu-devel/[email protected]/This patch series introduces initial support for a user-creatable, accelerated SMMUv3 device (-device arm-smmuv3,accel=on) in QEMU.
This is based on the user-creatable SMMUv3 device series [0].
Why this is needed:
On ARM, to enable vfio-pci pass-through devices in a VM, the host SMMUv3 must be set up in nested translation mode (Stage 1 + Stage 2), with Stage 1 (S1) controlled by the guest and Stage 2 (S2) managed by the host.
This series introduces an optional accel property for the SMMUv3 device, indicating that the guest will try to leverage host SMMUv3 features for acceleration. By default, enabling accel configures the host SMMUv3 in nested mode to support vfio-pci pass-through.
This new accelerated, user-creatable SMMUv3 device lets you:
-Set up a VM with multiple SMMUv3s, each tied to a different physical SMMUv3
on the host. Typically, you’d have multiple PCIe PXB root complexes in the VM (one per virtual NUMA node), and each of them can have its own SMMUv3. This setup mirrors the host's layout, where each NUMA node has its own SMMUv3, and helps build VMs that are more aligned with the host's NUMA topology.-The host–guest SMMUv3 association results in reduced invalidation broadcasts
and lookups for devices behind different physical SMMUv3s.-Simplifies handling of host SMMUv3s with differing feature sets.
-Lays the groundwork for additional capabilities like vCMDQ support.
-------------------------------Eric Auger (2):
hw/pci-host/gpex: Allow to generate preserve boot config DSM #5 hw/arm/virt-acpi-build: Add IORT RMR regions to handle MSI nested
bindingNicolin Chen (4):
backends/iommufd: Introduceiommufd_backend_alloc_viommubackends/iommufd: Introduceiommufd_backend_alloc_vdevhw/arm/smmuv3-accel: Add set/unset_iommu_device callback hw/arm/smmuv3-accel: Add nested vSTE install/uninstall supportShameer Kolothum (26):
hw/arm/smmu-common: Factor out common helper functions and export hw/arm/smmu-common: Make iommu ops part of SMMUState hw/arm/smmuv3-accel: Introduce smmuv3 accel device hw/arm/smmuv3-accel: Initialize shared system address space hw/pci/pci: Movepci_init_bus_master()after adding device to bus hw/pci/pci: Add optionalsupports_address_space()callback hw/pci-bridge/pci_expander_bridge: MoveTYPE_PXB_PCIE_DEVto header hw/arm/smmuv3-accel: Restrict accelerated SMMUv3 to vfio-pci endpoints
with iommufd
hw/arm/smmuv3: Implementget_viommu_cap()callback hw/arm/smmuv3: propagatesmmuv3_cmdq_consume()errors to caller hw/arm/smmuv3-accel: Install SMMUv3 GBPA based hwpt hw/pci/pci: Introduce a callback to retrieve the MSI doorbell GPA
directly
hw/arm/smmuv3: Add support for providing a direct MSI doorbell GPA hw/arm/smmuv3-accel: Add support to issue invalidation cmd to host hw/arm/smmuv3: Initialize ID registers early duringrealize()hw/arm/smmuv3-accel: Get host SMMUv3 hw info and validate hw/arm/virt: Set PCIpreserve_configfor accel SMMUv3 tests/qtest/bios-tables-test: Prepare for IORT revison upgrade tests/qtest/bios-tables-test: Update IORT blobs after revision upgrade hw/arm/smmuv3: Add accel property for SMMUv3 device hw/arm/smmuv3-accel: Add a property to specify RIL support hw/arm/smmuv3-accel: Add support for ATS hw/arm/smmuv3-accel: Add property to specify OAS bits backends/iommufd: Retrieve PASID width from
iommufd_backend_get_device_info()
Extendget_cap()callback to support PASID hw/arm/smmuv3-accel: Add support for PASID enableYi Liu (1):
vfio: Synthesize vPASID capability to VMbackends/iommufd.c | 82 +- backends/trace-events | 2 + hw/arm/Kconfig | 5 + hw/arm/meson.build | 3 +- hw/arm/smmu-common.c | 51 +- hw/arm/smmuv3-accel.c | 756 ++++++++++++++++++ hw/arm/smmuv3-accel.h | 86 ++ hw/arm/smmuv3-internal.h | 27 +- hw/arm/smmuv3.c | 206 ++++- hw/arm/trace-events | 6 + hw/arm/virt-acpi-build.c | 127 ++- hw/arm/virt.c | 30 + hw/i386/intel_iommu.c | 8 +- hw/pci-bridge/pci_expander_bridge.c | 1 - hw/pci-host/gpex-acpi.c | 29 +- hw/pci/pci.c | 43 +- hw/vfio/container-legacy.c | 8 +- hw/vfio/iommufd.c | 7 +- hw/vfio/pci.c | 38 + include/hw/arm/smmu-common.h | 7 + include/hw/arm/smmuv3.h | 10 + include/hw/arm/virt.h | 1 + include/hw/iommu.h | 1 + include/hw/pci-host/gpex.h | 1 + include/hw/pci/pci.h | 34 + include/hw/pci/pci_bridge.h | 1 + include/system/host_iommu_device.h | 21 +- include/system/iommufd.h | 29 +- target/arm/kvm.c | 18 +- tests/data/acpi/aarch64/virt/IORT | Bin 128 -> 128 bytes tests/data/acpi/aarch64/virt/IORT.its_off | Bin 172 -> 172 bytes tests/data/acpi/aarch64/virt/IORT.smmuv3-dev | Bin 364 -> 364 bytes .../data/acpi/aarch64/virt/IORT.smmuv3-legacy | Bin 276 -> 276 bytes 33 files changed, 1536 insertions(+), 102 deletions(-)
Quoted 3 lines
create mode 100644
hw/arm/smmuv3-accel.c
create mode 100644hw/arm/smmuv3-accel.h
FYI, I am seeing configure errors :
The following clauses were found for ARM_SMMUV3_ACCEL
select ARM_SMMUV3_ACCEL if ARM_VIRT
config ARM_SMMUV3_ACCEL depends on (ARM_SMMUV3 && IOMMUFD)
KconfigDataError: contradiction between clauses when setting ARM_SMMUV3_ACCEL
Thanks,
C.
Quoted 18 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: 09 December 2025 10:32
To: Shameer Kolothum <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 00/33] hw/arm/virt: Add support for user-creatable accelerated SMMUv3
[...]
Quoted 6 lines
FYI, I am seeing configure errors :
The following clauses were found for
ARM_SMMUV3_ACCEL
selectARM_SMMUV3_ACCELifARM_VIRT
configARM_SMMUV3_ACCELdepends on (ARM_SMMUV3&& IOMMUFD)
- select ARM_SMMUV3_ACCEL
+ imply ARM_SMMUV3_ACCEL
the above will fix it?
Quoted 3 lines
KconfigDataError: contradiction between clauses when setting
ARM_SMMUV3_ACCEL
Just curious, how to trigger these errors easily? Any scripts?
Thanks,
Shameer
Quoted 4 lines
Thanks,
C.
Quoted 30 lines · Shameer Kolothum
Quoted 18 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: 09 December 2025 10:32
To: Shameer Kolothum <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; Nicolin Chen <[email protected]>; [email protected]; [email protected]; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v6 00/33] hw/arm/virt: Add support for user-creatable accelerated SMMUv3[...]
Quoted 6 lines
FYI, I am seeing configure errors :
The following clauses were found for
ARM_SMMUV3_ACCEL
selectARM_SMMUV3_ACCELifARM_VIRT
configARM_SMMUV3_ACCELdepends on (ARM_SMMUV3&& IOMMUFD)(quoted diff) +1
-1- select ARM_SMMUV3_ACCEL + imply ARM_SMMUV3_ACCEL
Quoted 1 line
the above will fix it?
No. I would propose :
@@ -12,7 +12,6 @@ config ARM_VIRT
select ARM_GIC
select ACPI
select ARM_SMMUV3
- select ARM_SMMUV3_ACCEL
select GPIO_KEY
select DEVICE_TREE
select FW_CFG_DMA
@@ -627,12 +626,13 @@ config FSL_IMX8MP_EVK
depends on TCG
select FSL_IMX8MP
-config ARM_SMMUV3
+config ARM_SMMUV3_ACCEL
bool
+ depends on ARM_SMMUV3
-config ARM_SMMUV3_ACCEL
+config ARM_SMMUV3
bool
- depends on ARM_SMMUV3 && IOMMUFD
+ select ARM_SMMUV3_ACCEL if IOMMUFD
config FSL_IMX6UL
bool
Quoted 5 lines
Quoted 3 lines
KconfigDataError: contradiction between clauses when setting
ARM_SMMUV3_ACCELJust curious, how to trigger these errors easily? Any scripts?
Try the windows build :
../configure --cross-prefix=x86_64-w64-mingw32- \
--disable-sdl \
--prefix=/path/to/install-mingw64 \
--target-list=aarch64-softmmu,ppc64-softmmu,x86_64-softmmu,s390x-softmmu \
--disable-docsproblems such as :
../hw/arm/smmuv3-accel.h:14:10: fatal error: linux/iommufd.h: No such file or directory
14 | #include <linux/iommufd.h>
| ^~~~~~~~~~~~~~~~~
should be fixed too.
Thanks,
C.