[PATCH 0/1] qemu: Use pci_bus to identify multi-smmuv3 model
The previous qemu virt-machine smmuv3 model and the new arm-smmuv3 model cannot both be specified at the same time. When launching a Libvirt VM with a single arm-smmuv3 model denoted by the <pciBus> attribute, qemuBuildMachineCommandLine() still appends the iommu=smmuv3 -machine parameter in addition to the arm-smmuv3 model passed to -device, preventing the VM from booting. Use the presence of a non-negative pci_bus to identify the multi-smmuv3 IOMMU model, instead of the niommus attribute. This allows for specifying a single arm-smmuv3 on the qemu command line, instead of both the virt-machine smmuv3 and arm-smmuv3 being specified at the same time. This patch is available on Github [0]. [0] https://github.com/NathanChenNVIDIA/libvirt/commits/single-smmuv3-12-25/ Signed-off-by: Nathan Chen <nathanc@nvidia.com> Nathan Chen (1): qemu: Use pci_bus to identify multi-smmuv3 model src/qemu/qemu_command.c | 2 +- src/qemu/qemu_postparse.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) -- 2.43.0
Use presence of non-negative pci_bus to identify multi-smmuv3 IOMMU model, instead of the niommus attribute. This allows for specifying a single arm-smmuv3 on the qemu command line, instead of both the virt-machine smmuv3 and arm-smmuv3 being specified at the same time. Signed-off-by: Nathan Chen <nathanc@nvidia.com> --- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_postparse.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index b69fe23236..fb89dbec27 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7192,7 +7192,7 @@ qemuBuildMachineCommandLine(virCommand *cmd, if (qemuAppendDomainFeaturesMachineParam(&buf, def, qemuCaps) < 0) return -1; - if (def->niommus == 1) { + if (def->iommus && def->iommus[0]->pci_bus < 0) { switch (def->iommus[0]->model) { case VIR_DOMAIN_IOMMU_MODEL_SMMUV3: virBufferAddLit(&buf, ",iommu=smmuv3"); diff --git a/src/qemu/qemu_postparse.c b/src/qemu/qemu_postparse.c index dc5ade829a..840d6a1174 100644 --- a/src/qemu/qemu_postparse.c +++ b/src/qemu/qemu_postparse.c @@ -1559,7 +1559,7 @@ qemuDomainDefEnableDefaultFeatures(virDomainDef *def, * domain already has IOMMU without inremap. This will be fixed in * qemuDomainIOMMUDefPostParse() but there domain definition can't be * modified so change it now. */ - if (def->iommus && def->niommus == 1 && + if (def->iommus && def->iommus[0]->pci_bus < 0 && (def->iommus[0]->intremap == VIR_TRISTATE_SWITCH_ON || qemuDomainNeedsIOMMUWithEIM(def)) && def->features[VIR_DOMAIN_FEATURE_IOAPIC] == VIR_DOMAIN_IOAPIC_NONE) { -- 2.43.0
On 12/2/2025 11:59 AM, Nathan Chen wrote:
Use presence of non-negative pci_bus to identify multi-smmuv3 IOMMU model, instead of the niommus attribute. This allows for specifying a single arm-smmuv3 on the qemu command line, instead of both the virt-machine smmuv3 and arm-smmuv3 being specified at the same time.
Signed-off-by: Nathan Chen<nathanc@nvidia.com>
This commit description should also include the following fixes tag. Fixes: e70c4d54d365 conf: Support multiple device-pluggable smmuv3 IOMMUs Thanks, Nathan
On a Thursday in 2025, Nathan Chen via Devel wrote:
On 12/2/2025 11:59 AM, Nathan Chen wrote:
Use presence of non-negative pci_bus to identify multi-smmuv3 IOMMU model, instead of the niommus attribute. This allows for specifying a single arm-smmuv3 on the qemu command line, instead of both the virt-machine smmuv3 and arm-smmuv3 being specified at the same time.
Signed-off-by: Nathan Chen<nathanc@nvidia.com>
This commit description should also include the following fixes tag.
Fixes: e70c4d54d365 conf: Support multiple device-pluggable smmuv3 IOMMUs
Reviewed-by: Ján Tomko <jtomko@redhat.com> I've also added a test case for this I'll be pushing once the pipeline passes: https://gitlab.com/janotomko/libvirt/-/pipelines/2197800364 Jano
Thanks, Nathan
On 12/5/2025 12:18 AM, Ján Tomko wrote:
On a Thursday in 2025, Nathan Chen via Devel wrote:
On 12/2/2025 11:59 AM, Nathan Chen wrote:
Use presence of non-negative pci_bus to identify multi-smmuv3 IOMMU model, instead of the niommus attribute. This allows for specifying a single arm-smmuv3 on the qemu command line, instead of both the virt-machine smmuv3 and arm-smmuv3 being specified at the same time.
Signed-off-by: Nathan Chen<nathanc@nvidia.com>
This commit description should also include the following fixes tag.
Fixes: e70c4d54d365 conf: Support multiple device-pluggable smmuv3 IOMMUs
Reviewed-by: Ján Tomko <jtomko@redhat.com>
I've also added a test case for this I'll be pushing once the pipeline passes: https://gitlab.com/janotomko/libvirt/-/pipelines/2197800364
Jano
Thanks for reviewing and adding the test case. I have verified that the test config looks OK and succeeds during compilation. -Nathan
From: Ján Tomko <jtomko@redhat.com> Signed-off-by: Ján Tomko <jtomko@redhat.com> --- ...-smmuv3-pci-bus-single.aarch64-latest.args | 40 +++++++++++++ ...u-smmuv3-pci-bus-single.aarch64-latest.xml | 59 +++++++++++++++++++ .../iommu-smmuv3-pci-bus-single.xml | 46 +++++++++++++++ tests/qemuxmlconftest.c | 1 + 4 files changed, 146 insertions(+) create mode 100644 tests/qemuxmlconfdata/iommu-smmuv3-pci-bus-single.aarch64-latest.args create mode 100644 tests/qemuxmlconfdata/iommu-smmuv3-pci-bus-single.aarch64-latest.xml create mode 100644 tests/qemuxmlconfdata/iommu-smmuv3-pci-bus-single.xml diff --git a/tests/qemuxmlconfdata/iommu-smmuv3-pci-bus-single.aarch64-latest.args b/tests/qemuxmlconfdata/iommu-smmuv3-pci-bus-single.aarch64-latest.args new file mode 100644 index 0000000000..976467e641 --- /dev/null +++ b/tests/qemuxmlconfdata/iommu-smmuv3-pci-bus-single.aarch64-latest.args @@ -0,0 +1,40 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/var/lib/libvirt/qemu/domain--1-guest \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/var/lib/libvirt/qemu/domain--1-guest/.local/share \ +XDG_CACHE_HOME=/var/lib/libvirt/qemu/domain--1-guest/.cache \ +XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-guest/.config \ +/usr/bin/qemu-system-aarch64 \ +-name guest=guest,debug-threads=on \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/var/lib/libvirt/qemu/domain--1-guest/master-key.aes"}' \ +-machine virt,usb=off,gic-version=2,iommu=smmuv3,dump-guest-core=off,memory-backend=mach-virt.ram,acpi=off \ +-accel tcg \ +-cpu cortex-a15 \ +-m size=1048576k \ +-object '{"qom-type":"memory-backend-ram","id":"mach-virt.ram","size":1073741824}' \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid 1ccfd97d-5eb4-478a-bbe6-88d254c16db7 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-boot strict=on \ +-device '{"driver":"pxb-pcie","bus_nr":252,"id":"pci.1","bus":"pcie.0","addr":"0x1"}' \ +-device '{"driver":"pxb-pcie","bus_nr":248,"id":"pci.2","bus":"pcie.0","addr":"0x2"}' \ +-device '{"driver":"pcie-root-port","port":0,"chassis":21,"id":"pci.3","bus":"pci.1","addr":"0x0"}' \ +-device '{"driver":"pcie-root-port","port":168,"chassis":22,"id":"pci.4","bus":"pci.2","addr":"0x0"}' \ +-device '{"driver":"arm-smmuv3","primary-bus":"pci.1","id":"iommu0"}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-object '{"qom-type":"rng-random","id":"objrng0","filename":"/dev/urandom"}' \ +-device '{"driver":"virtio-rng-pci","rng":"objrng0","id":"rng0","bus":"pci.3","addr":"0x0"}' \ +-object '{"qom-type":"rng-random","id":"objrng1","filename":"/dev/urandom"}' \ +-device '{"driver":"virtio-rng-pci","rng":"objrng1","id":"rng1","bus":"pci.4","addr":"0x0"}' \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxmlconfdata/iommu-smmuv3-pci-bus-single.aarch64-latest.xml b/tests/qemuxmlconfdata/iommu-smmuv3-pci-bus-single.aarch64-latest.xml new file mode 100644 index 0000000000..e6071fd71b --- /dev/null +++ b/tests/qemuxmlconfdata/iommu-smmuv3-pci-bus-single.aarch64-latest.xml @@ -0,0 +1,59 @@ +<domain type='qemu'> + <name>guest</name> + <uuid>1ccfd97d-5eb4-478a-bbe6-88d254c16db7</uuid> + <memory unit='KiB'>1048576</memory> + <currentMemory unit='KiB'>1048576</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='aarch64' machine='virt'>hvm</type> + <boot dev='hd'/> + </os> + <features> + <gic version='2'/> + </features> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>cortex-a15</model> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-aarch64</emulator> + <controller type='usb' index='0' model='none'/> + <controller type='pci' index='0' model='pcie-root'/> + <controller type='pci' index='1' model='pcie-expander-bus'> + <model name='pxb-pcie'/> + <target busNr='252'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> + </controller> + <controller type='pci' index='2' model='pcie-expander-bus'> + <model name='pxb-pcie'/> + <target busNr='248'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </controller> + <controller type='pci' index='3' model='pcie-root-port'> + <model name='pcie-root-port'/> + <target chassis='21' port='0x0'/> + <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> + </controller> + <controller type='pci' index='4' model='pcie-root-port'> + <model name='pcie-root-port'/> + <target chassis='22' port='0xa8'/> + <address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/> + </controller> + <audio id='1' type='none'/> + <memballoon model='none'/> + <rng model='virtio'> + <backend model='random'>/dev/urandom</backend> + <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/> + </rng> + <rng model='virtio'> + <backend model='random'>/dev/urandom</backend> + <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/> + </rng> + <iommu model='smmuv3'> + <driver pciBus='1'/> + </iommu> + </devices> +</domain> diff --git a/tests/qemuxmlconfdata/iommu-smmuv3-pci-bus-single.xml b/tests/qemuxmlconfdata/iommu-smmuv3-pci-bus-single.xml new file mode 100644 index 0000000000..6f40a19740 --- /dev/null +++ b/tests/qemuxmlconfdata/iommu-smmuv3-pci-bus-single.xml @@ -0,0 +1,46 @@ +<domain type='qemu'> + <name>guest</name> + <uuid>1ccfd97d-5eb4-478a-bbe6-88d254c16db7</uuid> + <memory unit='KiB'>1048576</memory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='aarch64' machine='virt'>hvm</type> + </os> + <devices> + <emulator>/usr/bin/qemu-system-aarch64</emulator> + <controller type='usb' model='none'/> + <memballoon model='none'/> + <controller type='pci' index='0' model='pcie-root'/> + <controller type='pci' index='1' model='pcie-expander-bus'> + <model name='pxb-pcie'/> + <target busNr='252'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> + </controller> + <controller type='pci' index='2' model='pcie-expander-bus'> + <model name='pxb-pcie'/> + <target busNr='248'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </controller> + <controller type='pci' index='3' model='pcie-root-port'> + <model name='pcie-root-port'/> + <target chassis='21' port='0x0'/> + <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> + </controller> + <controller type='pci' index='4' model='pcie-root-port'> + <model name='pcie-root-port'/> + <target chassis='22' port='0xa8'/> + <address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/> + </controller> + <rng model='virtio'> + <backend model='random'>/dev/urandom</backend> + <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/> + </rng> + <rng model='virtio'> + <backend model='random'>/dev/urandom</backend> + <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/> + </rng> + <iommu model='smmuv3'> + <driver pciBus='1'/> + </iommu> + </devices> +</domain> diff --git a/tests/qemuxmlconftest.c b/tests/qemuxmlconftest.c index de03c58c8a..9a3257ea55 100644 --- a/tests/qemuxmlconftest.c +++ b/tests/qemuxmlconftest.c @@ -3039,6 +3039,7 @@ mymain(void) DO_TEST_CAPS_LATEST_ABI_UPDATE("intel-iommu-eim-autoadd-v2"); DO_TEST_CAPS_ARCH_LATEST("iommu-smmuv3", "aarch64"); DO_TEST_CAPS_ARCH_LATEST("iommu-smmuv3-pci-bus", "aarch64"); + DO_TEST_CAPS_ARCH_LATEST("iommu-smmuv3-pci-bus-single", "aarch64"); DO_TEST_CAPS_LATEST("virtio-iommu-x86_64"); DO_TEST_CAPS_ARCH_LATEST("virtio-iommu-aarch64", "aarch64"); DO_TEST_CAPS_LATEST_PARSE_ERROR("virtio-iommu-wrong-machine"); -- 2.51.1
participants (2)
-
Ján Tomko -
Nathan Chen