[libvirt PATCH 0/3] qemu: Allow IOMMU devices to have aliases

Andrea Bolognani (3): schema: Allow IOMMU devices to have aliases qemu: Assign default alias to IOMMU devices qemu: Add IOMMU device alias to command line src/conf/schemas/domaincommon.rng | 3 +++ src/qemu/qemu_alias.c | 10 ++++++++++ src/qemu/qemu_command.c | 2 ++ .../intel-iommu-aw-bits.x86_64-latest.args | 2 +- .../intel-iommu-caching-mode.x86_64-latest.args | 2 +- .../intel-iommu-device-iotlb.x86_64-latest.args | 2 +- .../intel-iommu-eim.x86_64-latest.args | 2 +- tests/qemuxml2argvdata/intel-iommu.x86_64-latest.args | 2 +- .../virtio-iommu-aarch64.aarch64-latest.args | 2 +- .../virtio-iommu-x86_64.x86_64-latest.args | 2 +- 10 files changed, 22 insertions(+), 7 deletions(-) -- 2.35.3

Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/conf/schemas/domaincommon.rng | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincommon.rng index 2f07c25430..d15dd33f47 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -5658,6 +5658,9 @@ <optional> <ref name="address"/> </optional> + <optional> + <ref name="alias"/> + </optional> </interleave> </element> </define> -- 2.35.3

Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/qemu/qemu_alias.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index 7efd91051e..7b91fe3141 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -597,6 +597,14 @@ qemuAssignDeviceVsockAlias(virDomainVsockDef *vsock) } +static void +qemuAssignDeviceIOMMUAlias(virDomainIOMMUDef *iommu) +{ + if (!iommu->info.alias) + iommu->info.alias = g_strdup("iommu0"); +} + + int qemuAssignDeviceAliases(virDomainDef *def, virQEMUCaps *qemuCaps) { @@ -681,6 +689,8 @@ qemuAssignDeviceAliases(virDomainDef *def, virQEMUCaps *qemuCaps) if (def->vsock) { qemuAssignDeviceVsockAlias(def->vsock); } + if (def->iommu) + qemuAssignDeviceIOMMUAlias(def->iommu); return 0; } -- 2.35.3

Note that we can only do this for intel-iommu and virtio-iommu, which are configured using -device; smmuv3 is configured using a machine type property, so there's no room on the command line for an alias in that case. https://bugzilla.redhat.com/show_bug.cgi?id=2108483 Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/qemu/qemu_command.c | 2 ++ tests/qemuxml2argvdata/intel-iommu-aw-bits.x86_64-latest.args | 2 +- .../intel-iommu-caching-mode.x86_64-latest.args | 2 +- .../intel-iommu-device-iotlb.x86_64-latest.args | 2 +- tests/qemuxml2argvdata/intel-iommu-eim.x86_64-latest.args | 2 +- tests/qemuxml2argvdata/intel-iommu.x86_64-latest.args | 2 +- tests/qemuxml2argvdata/virtio-iommu-aarch64.aarch64-latest.args | 2 +- tests/qemuxml2argvdata/virtio-iommu-x86_64.x86_64-latest.args | 2 +- 8 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 262fffe5fe..30c9bbbf2e 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6441,6 +6441,7 @@ qemuBuildIOMMUCommandLine(virCommand *cmd, case VIR_DOMAIN_IOMMU_MODEL_INTEL: if (virJSONValueObjectAdd(&props, "s:driver", "intel-iommu", + "s:id", iommu->info.alias, "S:intremap", qemuOnOffAuto(iommu->intremap), "T:caching-mode", iommu->caching_mode, "S:eim", qemuOnOffAuto(iommu->eim), @@ -6457,6 +6458,7 @@ qemuBuildIOMMUCommandLine(virCommand *cmd, case VIR_DOMAIN_IOMMU_MODEL_VIRTIO: if (virJSONValueObjectAdd(&props, "s:driver", "virtio-iommu", + "s:id", iommu->info.alias, NULL) < 0) { return -1; } diff --git a/tests/qemuxml2argvdata/intel-iommu-aw-bits.x86_64-latest.args b/tests/qemuxml2argvdata/intel-iommu-aw-bits.x86_64-latest.args index f61ff3f8ff..df11e3ddab 100644 --- a/tests/qemuxml2argvdata/intel-iommu-aw-bits.x86_64-latest.args +++ b/tests/qemuxml2argvdata/intel-iommu-aw-bits.x86_64-latest.args @@ -27,7 +27,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ -no-shutdown \ -no-acpi \ -boot strict=on \ --device '{"driver":"intel-iommu","intremap":"on","aw-bits":48}' \ +-device '{"driver":"intel-iommu","id":"iommu0","intremap":"on","aw-bits":48}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ -msg timestamp=on diff --git a/tests/qemuxml2argvdata/intel-iommu-caching-mode.x86_64-latest.args b/tests/qemuxml2argvdata/intel-iommu-caching-mode.x86_64-latest.args index 083c6bfe4b..47976fa6a7 100644 --- a/tests/qemuxml2argvdata/intel-iommu-caching-mode.x86_64-latest.args +++ b/tests/qemuxml2argvdata/intel-iommu-caching-mode.x86_64-latest.args @@ -27,7 +27,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ -no-shutdown \ -no-acpi \ -boot strict=on \ --device '{"driver":"intel-iommu","intremap":"on","caching-mode":true}' \ +-device '{"driver":"intel-iommu","id":"iommu0","intremap":"on","caching-mode":true}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ -msg timestamp=on diff --git a/tests/qemuxml2argvdata/intel-iommu-device-iotlb.x86_64-latest.args b/tests/qemuxml2argvdata/intel-iommu-device-iotlb.x86_64-latest.args index fc06e15191..af36c45292 100644 --- a/tests/qemuxml2argvdata/intel-iommu-device-iotlb.x86_64-latest.args +++ b/tests/qemuxml2argvdata/intel-iommu-device-iotlb.x86_64-latest.args @@ -27,7 +27,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ -no-shutdown \ -no-acpi \ -boot strict=on \ --device '{"driver":"intel-iommu","intremap":"on","device-iotlb":true}' \ +-device '{"driver":"intel-iommu","id":"iommu0","intremap":"on","device-iotlb":true}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ -msg timestamp=on diff --git a/tests/qemuxml2argvdata/intel-iommu-eim.x86_64-latest.args b/tests/qemuxml2argvdata/intel-iommu-eim.x86_64-latest.args index c8dd31c5fe..8e2b54d1f9 100644 --- a/tests/qemuxml2argvdata/intel-iommu-eim.x86_64-latest.args +++ b/tests/qemuxml2argvdata/intel-iommu-eim.x86_64-latest.args @@ -27,7 +27,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ -no-shutdown \ -no-acpi \ -boot strict=on \ --device '{"driver":"intel-iommu","intremap":"on","eim":"on"}' \ +-device '{"driver":"intel-iommu","id":"iommu0","intremap":"on","eim":"on"}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ -msg timestamp=on diff --git a/tests/qemuxml2argvdata/intel-iommu.x86_64-latest.args b/tests/qemuxml2argvdata/intel-iommu.x86_64-latest.args index db69543298..c99efd229b 100644 --- a/tests/qemuxml2argvdata/intel-iommu.x86_64-latest.args +++ b/tests/qemuxml2argvdata/intel-iommu.x86_64-latest.args @@ -27,7 +27,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ -no-shutdown \ -no-acpi \ -boot strict=on \ --device '{"driver":"intel-iommu"}' \ +-device '{"driver":"intel-iommu","id":"iommu0"}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ -msg timestamp=on diff --git a/tests/qemuxml2argvdata/virtio-iommu-aarch64.aarch64-latest.args b/tests/qemuxml2argvdata/virtio-iommu-aarch64.aarch64-latest.args index 9c1de8ae9b..54f069c350 100644 --- a/tests/qemuxml2argvdata/virtio-iommu-aarch64.aarch64-latest.args +++ b/tests/qemuxml2argvdata/virtio-iommu-aarch64.aarch64-latest.args @@ -30,7 +30,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-guest/.config \ -rtc base=utc \ -no-shutdown \ -boot strict=on \ --device '{"driver":"virtio-iommu","bus":"pcie.0","addr":"0x1"}' \ +-device '{"driver":"virtio-iommu","id":"iommu0","bus":"pcie.0","addr":"0x1"}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ -msg timestamp=on diff --git a/tests/qemuxml2argvdata/virtio-iommu-x86_64.x86_64-latest.args b/tests/qemuxml2argvdata/virtio-iommu-x86_64.x86_64-latest.args index 7e0aa7192d..744367c6c0 100644 --- a/tests/qemuxml2argvdata/virtio-iommu-x86_64.x86_64-latest.args +++ b/tests/qemuxml2argvdata/virtio-iommu-x86_64.x86_64-latest.args @@ -26,7 +26,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ -rtc base=utc \ -no-shutdown \ -boot strict=on \ --device '{"driver":"virtio-iommu","bus":"pcie.0","addr":"0x1"}' \ +-device '{"driver":"virtio-iommu","id":"iommu0","bus":"pcie.0","addr":"0x1"}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ -msg timestamp=on -- 2.35.3

On 7/21/22 11:32, Andrea Bolognani wrote:
Andrea Bolognani (3): schema: Allow IOMMU devices to have aliases qemu: Assign default alias to IOMMU devices qemu: Add IOMMU device alias to command line
src/conf/schemas/domaincommon.rng | 3 +++ src/qemu/qemu_alias.c | 10 ++++++++++ src/qemu/qemu_command.c | 2 ++ .../intel-iommu-aw-bits.x86_64-latest.args | 2 +- .../intel-iommu-caching-mode.x86_64-latest.args | 2 +- .../intel-iommu-device-iotlb.x86_64-latest.args | 2 +- .../intel-iommu-eim.x86_64-latest.args | 2 +- tests/qemuxml2argvdata/intel-iommu.x86_64-latest.args | 2 +- .../virtio-iommu-aarch64.aarch64-latest.args | 2 +- .../virtio-iommu-x86_64.x86_64-latest.args | 2 +- 10 files changed, 22 insertions(+), 7 deletions(-)
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal
participants (2)
-
Andrea Bolognani
-
Michal Prívozník