[PATCH v2 0/7] virtio-iommu: Support setting aw-bits and granule
v2 of: https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/thread/3HN67... diff to v1: - setting of granule is done in a subelement of driver now Michal Prívozník (7): conf: Teach virDomainParseMemory() new retval qemu_capabilities: Introduce QEMU_CAPS_VIRTIO_IOMMU_AW_BITS conf: Allow aw_bits for virtio-iommu qemu_command: Generate aw_bits prop for virtio-iommu conf: Introduce granule attribute for virtio-iommu qemu_validate: Check whether granule of virtio-iommu is supported qemu_command: Generate granule prop for virtio-iommu docs/formatdomain.rst | 40 +++++++- src/conf/domain_conf.c | 95 +++++++++++++++++-- src/conf/domain_conf.h | 1 + src/conf/domain_validate.c | 21 +++- src/conf/schemas/domaincommon.rng | 22 +++++ src/qemu/qemu_capabilities.c | 2 + src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 11 +++ src/qemu/qemu_validate.c | 30 +++++- .../caps_10.0.0_aarch64.xml | 1 + .../caps_10.0.0_ppc64.xml | 1 + .../caps_10.0.0_s390x.xml | 1 + .../caps_10.0.0_x86_64+amdsev.xml | 1 + .../caps_10.0.0_x86_64.xml | 1 + .../caps_10.1.0_s390x.xml | 1 + .../caps_10.1.0_x86_64+inteltdx.xml | 1 + .../caps_10.1.0_x86_64.xml | 1 + .../caps_10.2.0_aarch64.xml | 1 + .../caps_10.2.0_x86_64+mshv.xml | 1 + .../caps_10.2.0_x86_64.xml | 1 + .../caps_11.0.0_aarch64.xml | 1 + .../caps_11.0.0_x86_64.xml | 1 + .../caps_9.0.0_x86_64.xml | 1 + .../caps_9.1.0_riscv64.xml | 1 + .../qemucapabilitiesdata/caps_9.1.0_s390x.xml | 1 + .../caps_9.1.0_x86_64.xml | 1 + .../caps_9.2.0_aarch64+hvf.xml | 1 + .../qemucapabilitiesdata/caps_9.2.0_s390x.xml | 1 + .../caps_9.2.0_x86_64+amdsev.xml | 1 + .../caps_9.2.0_x86_64.xml | 1 + .../virtio-iommu-aarch64.aarch64-latest.args | 2 +- .../virtio-iommu-aarch64.aarch64-latest.xml | 3 + .../qemuxmlconfdata/virtio-iommu-aarch64.xml | 6 +- ...io-iommu-dma-translation.x86_64-latest.err | 2 +- .../virtio-iommu-x86_64.x86_64-latest.args | 2 +- .../virtio-iommu-x86_64.x86_64-latest.xml | 3 + tests/qemuxmlconfdata/virtio-iommu-x86_64.xml | 6 +- 37 files changed, 247 insertions(+), 21 deletions(-) -- 2.52.0
From: Michal Privoznik <mprivozn@redhat.com> So far, virDomainParseMemory() returns either 0 or -1. While this allows callers to distinguish a success case from an error it doesn't allow them to differentiate the case when no value was provided in the XML, thus nothing was parsed and nothing was required. Therefore, make virDomainParseMemory() return 1 on success, 0 in case nothing was parsed and nothing was required, and -1 on failure. Arguably, no caller needs this distinction currently, but that is about to change. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9672168df9..1b2a439ca4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8719,7 +8719,9 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, * if @capped is true, the value must fit within an unsigned long * (only matters on 32-bit platforms). * - * Return 0 on success, -1 on failure after issuing error. + * Returns: 1 if value was parsed successfully, + * 0 if value wasn't present and @required is false, + * -1 on failure after issuing error. */ int virDomainParseMemory(const char *xpath, @@ -8730,21 +8732,27 @@ virDomainParseMemory(const char *xpath, bool capped) { unsigned long long bytes, max; + int rc; max = virMemoryMaxValue(capped); - if (virParseScaledValue(xpath, units_xpath, ctxt, - &bytes, 1024, max, required) < 0) + rc = virParseScaledValue(xpath, units_xpath, ctxt, + &bytes, 1024, max, required); + if (rc < 0) { return -1; + } else if (rc == 0) { + *mem = 0; + return 0; + } - /* Yes, we really do use kibibytes for our internal sizing. */ + /* Yes, we really do use kibibytes for our internal sizing. */ *mem = VIR_DIV_UP(bytes, 1024); if (*mem >= VIR_DIV_UP(max, 1024)) { virReportError(VIR_ERR_OVERFLOW, "%s", _("size value too large")); return -1; } - return 0; + return 1; } -- 2.52.0
From: Michal Privoznik <mprivozn@redhat.com> This capability tracks whether the virtio-iommu device has aw-bits attribute. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + tests/qemucapabilitiesdata/caps_10.0.0_aarch64.xml | 1 + tests/qemucapabilitiesdata/caps_10.0.0_ppc64.xml | 1 + tests/qemucapabilitiesdata/caps_10.0.0_s390x.xml | 1 + tests/qemucapabilitiesdata/caps_10.0.0_x86_64+amdsev.xml | 1 + tests/qemucapabilitiesdata/caps_10.0.0_x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_10.1.0_s390x.xml | 1 + tests/qemucapabilitiesdata/caps_10.1.0_x86_64+inteltdx.xml | 1 + tests/qemucapabilitiesdata/caps_10.1.0_x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_10.2.0_aarch64.xml | 1 + tests/qemucapabilitiesdata/caps_10.2.0_x86_64+mshv.xml | 1 + tests/qemucapabilitiesdata/caps_10.2.0_x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_11.0.0_aarch64.xml | 1 + tests/qemucapabilitiesdata/caps_11.0.0_x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_9.0.0_x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_9.1.0_riscv64.xml | 1 + tests/qemucapabilitiesdata/caps_9.1.0_s390x.xml | 1 + tests/qemucapabilitiesdata/caps_9.1.0_x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_9.2.0_aarch64+hvf.xml | 1 + tests/qemucapabilitiesdata/caps_9.2.0_s390x.xml | 1 + tests/qemucapabilitiesdata/caps_9.2.0_x86_64+amdsev.xml | 1 + tests/qemucapabilitiesdata/caps_9.2.0_x86_64.xml | 1 + 23 files changed, 24 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index f456e8a378..b4d52eebcd 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -755,6 +755,7 @@ VIR_ENUM_IMPL(virQEMUCaps, "disk-timed-stats", /* QEMU_CAPS_DISK_TIMED_STATS */ "query-accelerators", /* QEMU_CAPS_QUERY_ACCELERATORS */ "mshv", /* QEMU_CAPS_MSHV */ + "virtio-iommu.aw-bits", /* QEMU_CAPS_VIRTIO_IOMMU_AW_BITS */ ); @@ -1612,6 +1613,7 @@ static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsVirtioMemPCI[] = static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsVirtioIOMMU[] = { { "boot-bypass", QEMU_CAPS_VIRTIO_IOMMU_BOOT_BYPASS, NULL }, + { "aw-bits", QEMU_CAPS_VIRTIO_IOMMU_AW_BITS, NULL }, }; static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsVirtioBlkCCW[] = { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index f180844e66..b02385ab0f 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -730,6 +730,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for syntax-check */ QEMU_CAPS_DISK_TIMED_STATS, /* timed stats support ('stats-intervals' property of disk frontends) */ QEMU_CAPS_QUERY_ACCELERATORS, /* query-accelerators command */ QEMU_CAPS_MSHV, /* -accel mshv */ + QEMU_CAPS_VIRTIO_IOMMU_AW_BITS, /* virtio-iommu.aw-bits */ QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/tests/qemucapabilitiesdata/caps_10.0.0_aarch64.xml b/tests/qemucapabilitiesdata/caps_10.0.0_aarch64.xml index 90e8d868cc..c2bffe88ad 100644 --- a/tests/qemucapabilitiesdata/caps_10.0.0_aarch64.xml +++ b/tests/qemucapabilitiesdata/caps_10.0.0_aarch64.xml @@ -163,6 +163,7 @@ <flag name='nvme-ns'/> <flag name='usb-bot'/> <flag name='acpi-generic-initiator'/> + <flag name='virtio-iommu.aw-bits'/> <version>10000000</version> <microcodeVersion>61700285</microcodeVersion> <package>v10.0.0</package> diff --git a/tests/qemucapabilitiesdata/caps_10.0.0_ppc64.xml b/tests/qemucapabilitiesdata/caps_10.0.0_ppc64.xml index 4b3cded2d1..0b9613b921 100644 --- a/tests/qemucapabilitiesdata/caps_10.0.0_ppc64.xml +++ b/tests/qemucapabilitiesdata/caps_10.0.0_ppc64.xml @@ -170,6 +170,7 @@ <flag name='nvme'/> <flag name='nvme-ns'/> <flag name='usb-bot'/> + <flag name='virtio-iommu.aw-bits'/> <version>10000000</version> <microcodeVersion>42900285</microcodeVersion> <package>v10.0.0</package> diff --git a/tests/qemucapabilitiesdata/caps_10.0.0_s390x.xml b/tests/qemucapabilitiesdata/caps_10.0.0_s390x.xml index 82a66a6524..410f7c324c 100644 --- a/tests/qemucapabilitiesdata/caps_10.0.0_s390x.xml +++ b/tests/qemucapabilitiesdata/caps_10.0.0_s390x.xml @@ -136,6 +136,7 @@ <flag name='nvme'/> <flag name='nvme-ns'/> <flag name='usb-bot'/> + <flag name='virtio-iommu.aw-bits'/> <version>10000000</version> <microcodeVersion>39100285</microcodeVersion> <package>v10.0.0</package> diff --git a/tests/qemucapabilitiesdata/caps_10.0.0_x86_64+amdsev.xml b/tests/qemucapabilitiesdata/caps_10.0.0_x86_64+amdsev.xml index cfce1c963d..a7166aba44 100644 --- a/tests/qemucapabilitiesdata/caps_10.0.0_x86_64+amdsev.xml +++ b/tests/qemucapabilitiesdata/caps_10.0.0_x86_64+amdsev.xml @@ -209,6 +209,7 @@ <flag name='amd-iommu'/> <flag name='usb-bot'/> <flag name='acpi-generic-initiator'/> + <flag name='virtio-iommu.aw-bits'/> <version>10000000</version> <microcodeVersion>43100285</microcodeVersion> <package>v10.0.0</package> diff --git a/tests/qemucapabilitiesdata/caps_10.0.0_x86_64.xml b/tests/qemucapabilitiesdata/caps_10.0.0_x86_64.xml index f94c8388d6..4177eb06b6 100644 --- a/tests/qemucapabilitiesdata/caps_10.0.0_x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_10.0.0_x86_64.xml @@ -209,6 +209,7 @@ <flag name='amd-iommu.pci-id'/> <flag name='usb-bot'/> <flag name='acpi-generic-initiator'/> + <flag name='virtio-iommu.aw-bits'/> <version>10000000</version> <microcodeVersion>43100285</microcodeVersion> <package>v10.0.0</package> diff --git a/tests/qemucapabilitiesdata/caps_10.1.0_s390x.xml b/tests/qemucapabilitiesdata/caps_10.1.0_s390x.xml index 8d59566cc0..9faa853da2 100644 --- a/tests/qemucapabilitiesdata/caps_10.1.0_s390x.xml +++ b/tests/qemucapabilitiesdata/caps_10.1.0_s390x.xml @@ -140,6 +140,7 @@ <flag name='nvme-ns'/> <flag name='usb-bot'/> <flag name='qom-list-get'/> + <flag name='virtio-iommu.aw-bits'/> <version>10001000</version> <microcodeVersion>39100286</microcodeVersion> <package>v10.1.0</package> diff --git a/tests/qemucapabilitiesdata/caps_10.1.0_x86_64+inteltdx.xml b/tests/qemucapabilitiesdata/caps_10.1.0_x86_64+inteltdx.xml index 377541ff53..d5566234a2 100644 --- a/tests/qemucapabilitiesdata/caps_10.1.0_x86_64+inteltdx.xml +++ b/tests/qemucapabilitiesdata/caps_10.1.0_x86_64+inteltdx.xml @@ -192,6 +192,7 @@ <flag name='tdx-guest'/> <flag name='qom-list-get'/> <flag name='acpi-generic-initiator'/> + <flag name='virtio-iommu.aw-bits'/> <version>10001000</version> <microcodeVersion>43100286</microcodeVersion> <package>v10.1.0</package> diff --git a/tests/qemucapabilitiesdata/caps_10.1.0_x86_64.xml b/tests/qemucapabilitiesdata/caps_10.1.0_x86_64.xml index 520a3d8ee8..12d2b262a5 100644 --- a/tests/qemucapabilitiesdata/caps_10.1.0_x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_10.1.0_x86_64.xml @@ -214,6 +214,7 @@ <flag name='tdx-guest'/> <flag name='qom-list-get'/> <flag name='acpi-generic-initiator'/> + <flag name='virtio-iommu.aw-bits'/> <version>10001000</version> <microcodeVersion>43100286</microcodeVersion> <package>v10.1.0</package> diff --git a/tests/qemucapabilitiesdata/caps_10.2.0_aarch64.xml b/tests/qemucapabilitiesdata/caps_10.2.0_aarch64.xml index d0c22d2541..7154cdb66c 100644 --- a/tests/qemucapabilitiesdata/caps_10.2.0_aarch64.xml +++ b/tests/qemucapabilitiesdata/caps_10.2.0_aarch64.xml @@ -182,6 +182,7 @@ <flag name='acpi-generic-initiator'/> <flag name='disk-timed-stats'/> <flag name='query-accelerators'/> + <flag name='virtio-iommu.aw-bits'/> <version>10002000</version> <microcodeVersion>61700287</microcodeVersion> <package>v10.2.0</package> diff --git a/tests/qemucapabilitiesdata/caps_10.2.0_x86_64+mshv.xml b/tests/qemucapabilitiesdata/caps_10.2.0_x86_64+mshv.xml index 2b6708be6a..0d627136e8 100644 --- a/tests/qemucapabilitiesdata/caps_10.2.0_x86_64+mshv.xml +++ b/tests/qemucapabilitiesdata/caps_10.2.0_x86_64+mshv.xml @@ -202,6 +202,7 @@ <flag name='disk-timed-stats'/> <flag name='query-accelerators'/> <flag name='mshv'/> + <flag name='virtio-iommu.aw-bits'/> <version>10002000</version> <microcodeVersion>43100287</microcodeVersion> <package>v10.2.0</package> diff --git a/tests/qemucapabilitiesdata/caps_10.2.0_x86_64.xml b/tests/qemucapabilitiesdata/caps_10.2.0_x86_64.xml index 06f7bf784d..5eae704512 100644 --- a/tests/qemucapabilitiesdata/caps_10.2.0_x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_10.2.0_x86_64.xml @@ -215,6 +215,7 @@ <flag name='acpi-generic-initiator'/> <flag name='disk-timed-stats'/> <flag name='query-accelerators'/> + <flag name='virtio-iommu.aw-bits'/> <version>10002000</version> <microcodeVersion>43100287</microcodeVersion> <package>v10.2.0</package> diff --git a/tests/qemucapabilitiesdata/caps_11.0.0_aarch64.xml b/tests/qemucapabilitiesdata/caps_11.0.0_aarch64.xml index f626f3ea46..3600be0301 100644 --- a/tests/qemucapabilitiesdata/caps_11.0.0_aarch64.xml +++ b/tests/qemucapabilitiesdata/caps_11.0.0_aarch64.xml @@ -182,6 +182,7 @@ <flag name='acpi-generic-initiator'/> <flag name='disk-timed-stats'/> <flag name='query-accelerators'/> + <flag name='virtio-iommu.aw-bits'/> <version>10002050</version> <microcodeVersion>61700286</microcodeVersion> <package>v10.2.0-476-gcf3e71d8fc</package> diff --git a/tests/qemucapabilitiesdata/caps_11.0.0_x86_64.xml b/tests/qemucapabilitiesdata/caps_11.0.0_x86_64.xml index f5ef2b2e45..6aa17de843 100644 --- a/tests/qemucapabilitiesdata/caps_11.0.0_x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_11.0.0_x86_64.xml @@ -215,6 +215,7 @@ <flag name='acpi-generic-initiator'/> <flag name='disk-timed-stats'/> <flag name='query-accelerators'/> + <flag name='virtio-iommu.aw-bits'/> <version>10002050</version> <microcodeVersion>43100286</microcodeVersion> <package>v10.2.0-476-gcf3e71d8fc</package> diff --git a/tests/qemucapabilitiesdata/caps_9.0.0_x86_64.xml b/tests/qemucapabilitiesdata/caps_9.0.0_x86_64.xml index 1f2e27a218..43c174e0e6 100644 --- a/tests/qemucapabilitiesdata/caps_9.0.0_x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_9.0.0_x86_64.xml @@ -204,6 +204,7 @@ <flag name='amd-iommu'/> <flag name='usb-bot'/> <flag name='acpi-generic-initiator'/> + <flag name='virtio-iommu.aw-bits'/> <version>9000000</version> <microcodeVersion>43100245</microcodeVersion> <package>v9.0.0</package> diff --git a/tests/qemucapabilitiesdata/caps_9.1.0_riscv64.xml b/tests/qemucapabilitiesdata/caps_9.1.0_riscv64.xml index 85c013a724..b5ca67b445 100644 --- a/tests/qemucapabilitiesdata/caps_9.1.0_riscv64.xml +++ b/tests/qemucapabilitiesdata/caps_9.1.0_riscv64.xml @@ -162,6 +162,7 @@ <flag name='nvme-ns'/> <flag name='usb-bot'/> <flag name='acpi-generic-initiator'/> + <flag name='virtio-iommu.aw-bits'/> <version>9001000</version> <microcodeVersion>0</microcodeVersion> <package>v9.1.0</package> diff --git a/tests/qemucapabilitiesdata/caps_9.1.0_s390x.xml b/tests/qemucapabilitiesdata/caps_9.1.0_s390x.xml index b961f79808..78b7493b53 100644 --- a/tests/qemucapabilitiesdata/caps_9.1.0_s390x.xml +++ b/tests/qemucapabilitiesdata/caps_9.1.0_s390x.xml @@ -126,6 +126,7 @@ <flag name='nvme'/> <flag name='nvme-ns'/> <flag name='usb-bot'/> + <flag name='virtio-iommu.aw-bits'/> <version>9001000</version> <microcodeVersion>39100246</microcodeVersion> <package>v9.1.0</package> diff --git a/tests/qemucapabilitiesdata/caps_9.1.0_x86_64.xml b/tests/qemucapabilitiesdata/caps_9.1.0_x86_64.xml index 35ddf30736..d68bb783e8 100644 --- a/tests/qemucapabilitiesdata/caps_9.1.0_x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_9.1.0_x86_64.xml @@ -203,6 +203,7 @@ <flag name='amd-iommu'/> <flag name='usb-bot'/> <flag name='acpi-generic-initiator'/> + <flag name='virtio-iommu.aw-bits'/> <version>9001000</version> <microcodeVersion>43100246</microcodeVersion> <package>v9.1.0</package> diff --git a/tests/qemucapabilitiesdata/caps_9.2.0_aarch64+hvf.xml b/tests/qemucapabilitiesdata/caps_9.2.0_aarch64+hvf.xml index 79784d553f..9c843f9e5c 100644 --- a/tests/qemucapabilitiesdata/caps_9.2.0_aarch64+hvf.xml +++ b/tests/qemucapabilitiesdata/caps_9.2.0_aarch64+hvf.xml @@ -135,6 +135,7 @@ <flag name='nvme-ns'/> <flag name='usb-bot'/> <flag name='acpi-generic-initiator'/> + <flag name='virtio-iommu.aw-bits'/> <version>9002002</version> <microcodeVersion>61700247</microcodeVersion> <package></package> diff --git a/tests/qemucapabilitiesdata/caps_9.2.0_s390x.xml b/tests/qemucapabilitiesdata/caps_9.2.0_s390x.xml index e9f79261f7..01fb50038d 100644 --- a/tests/qemucapabilitiesdata/caps_9.2.0_s390x.xml +++ b/tests/qemucapabilitiesdata/caps_9.2.0_s390x.xml @@ -129,6 +129,7 @@ <flag name='nvme'/> <flag name='nvme-ns'/> <flag name='usb-bot'/> + <flag name='virtio-iommu.aw-bits'/> <version>9002000</version> <microcodeVersion>39100247</microcodeVersion> <package>v9.2.0</package> diff --git a/tests/qemucapabilitiesdata/caps_9.2.0_x86_64+amdsev.xml b/tests/qemucapabilitiesdata/caps_9.2.0_x86_64+amdsev.xml index 0e52c3e23d..ac936bc17b 100644 --- a/tests/qemucapabilitiesdata/caps_9.2.0_x86_64+amdsev.xml +++ b/tests/qemucapabilitiesdata/caps_9.2.0_x86_64+amdsev.xml @@ -207,6 +207,7 @@ <flag name='amd-iommu'/> <flag name='usb-bot'/> <flag name='acpi-generic-initiator'/> + <flag name='virtio-iommu.aw-bits'/> <version>9002000</version> <microcodeVersion>43100247</microcodeVersion> <package>v9.2.0</package> diff --git a/tests/qemucapabilitiesdata/caps_9.2.0_x86_64.xml b/tests/qemucapabilitiesdata/caps_9.2.0_x86_64.xml index 95f8a4d878..fd851d9201 100644 --- a/tests/qemucapabilitiesdata/caps_9.2.0_x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_9.2.0_x86_64.xml @@ -205,6 +205,7 @@ <flag name='amd-iommu'/> <flag name='usb-bot'/> <flag name='acpi-generic-initiator'/> + <flag name='virtio-iommu.aw-bits'/> <version>9002000</version> <microcodeVersion>43100247</microcodeVersion> <package>v9.2.0</package> -- 2.52.0
From: Michal Privoznik <mprivozn@redhat.com> Introduced in QEMU commit of v9.0.0-rc0~9^2~7 the virtio-iommu device is also capable of using different addres width. The corresponding attribute is also called 'aw-bits', just like in case of intel-iommu. Wire up the missing pieces. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com> --- docs/formatdomain.rst | 2 +- src/conf/domain_validate.c | 12 ++++++++++-- src/qemu/qemu_validate.c | 7 +++++-- .../virtio-iommu-aarch64.aarch64-latest.xml | 1 + tests/qemuxmlconfdata/virtio-iommu-aarch64.xml | 4 +++- .../virtio-iommu-dma-translation.x86_64-latest.err | 2 +- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 04ef319a73..4b34a8a963 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -9243,7 +9243,7 @@ Example: ``aw_bits`` The ``aw_bits`` attribute can be used to set the address width to allow mapping larger iova addresses in the guest. :since:`Since 6.5.0` (QEMU/KVM - and ``intel`` model only) + and ``intel`` or ``virtio`` models only) ``dma_translation`` The ``dma_translation`` attribute with possible values ``on`` and ``off`` can diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 4482203087..c83fff132b 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -3206,14 +3206,22 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *iommu) iommu->caching_mode != VIR_TRISTATE_SWITCH_ABSENT || iommu->eim != VIR_TRISTATE_SWITCH_ABSENT || iommu->iotlb != VIR_TRISTATE_SWITCH_ABSENT || - iommu->aw_bits != 0 || iommu->dma_translation != VIR_TRISTATE_SWITCH_ABSENT || iommu->pci_bus >= 0) { virReportError(VIR_ERR_XML_ERROR, - _("iommu model '%1$s' doesn't support additional attributes"), + _("iommu model '%1$s' doesn't support some additional attributes"), virDomainIOMMUModelTypeToString(iommu->model)); return -1; } + + /* QEMU mandates address width of the IOVA address space to be inside + * [32,64] range, but since it stems from virtio specification it can + * be assumed to be hypervisor agnostic and thus can live here. */ + if (iommu->aw_bits != 0 && (iommu->aw_bits < 32 || iommu->aw_bits > 64)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("aw-bits must be within [32,64]")); + return -1; + } break; case VIR_DOMAIN_IOMMU_MODEL_AMD: diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 184c23d307..ab8a1938c1 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -5551,6 +5551,8 @@ qemuValidateDomainDeviceDefIOMMU(const virDomainIOMMUDef *iommu, const virDomainDef *def, virQEMUCaps *qemuCaps) { + bool aw_bits_supported = false; + switch (iommu->model) { case VIR_DOMAIN_IOMMU_MODEL_INTEL: if (!qemuDomainIsQ35(def)) { @@ -5565,6 +5567,7 @@ qemuValidateDomainDeviceDefIOMMU(const virDomainIOMMUDef *iommu, virDomainIOMMUModelTypeToString(iommu->model)); return -1; } + aw_bits_supported = virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_AW_BITS); break; case VIR_DOMAIN_IOMMU_MODEL_SMMUV3: @@ -5610,6 +5613,7 @@ qemuValidateDomainDeviceDefIOMMU(const virDomainIOMMUDef *iommu, virDomainIOMMUModelTypeToString(iommu->model)); return -1; } + aw_bits_supported = virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_IOMMU_AW_BITS); break; case VIR_DOMAIN_IOMMU_MODEL_AMD: @@ -5669,8 +5673,7 @@ qemuValidateDomainDeviceDefIOMMU(const virDomainIOMMUDef *iommu, _("iommu: device IOTLB is not supported with this QEMU binary")); return -1; } - if (iommu->aw_bits > 0 && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_AW_BITS)) { + if (iommu->aw_bits > 0 && !aw_bits_supported) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("iommu: aw_bits is not supported with this QEMU binary")); return -1; diff --git a/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.xml b/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.xml index 3cb794cbc9..4ae628ab5a 100644 --- a/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.xml +++ b/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.xml @@ -29,6 +29,7 @@ <audio id='1' type='none'/> <memballoon model='none'/> <iommu model='virtio'> + <driver aw_bits='48'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> </iommu> </devices> diff --git a/tests/qemuxmlconfdata/virtio-iommu-aarch64.xml b/tests/qemuxmlconfdata/virtio-iommu-aarch64.xml index 8d252bfcf9..96e5ea05ae 100644 --- a/tests/qemuxmlconfdata/virtio-iommu-aarch64.xml +++ b/tests/qemuxmlconfdata/virtio-iommu-aarch64.xml @@ -13,6 +13,8 @@ <emulator>/usr/bin/qemu-system-aarch64</emulator> <controller type='usb' model='none'/> <memballoon model='none'/> - <iommu model='virtio'/> + <iommu model='virtio'> + <driver aw_bits='48'/> + </iommu> </devices> </domain> diff --git a/tests/qemuxmlconfdata/virtio-iommu-dma-translation.x86_64-latest.err b/tests/qemuxmlconfdata/virtio-iommu-dma-translation.x86_64-latest.err index 2c3a272725..f4405a9b7d 100644 --- a/tests/qemuxmlconfdata/virtio-iommu-dma-translation.x86_64-latest.err +++ b/tests/qemuxmlconfdata/virtio-iommu-dma-translation.x86_64-latest.err @@ -1 +1 @@ -XML error: iommu model 'virtio' doesn't support additional attributes +XML error: iommu model 'virtio' doesn't support some additional attributes -- 2.52.0
From: Michal Privoznik <mprivozn@redhat.com> Resolves: https://issues.redhat.com/browse/RHEL-76269 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_command.c | 1 + tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.args | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index e81efdfde7..953156ce2a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6309,6 +6309,7 @@ qemuBuildIOMMUCommandLine(virCommand *cmd, if (virJSONValueObjectAdd(&props, "s:driver", "virtio-iommu", "s:id", iommu->info.alias, + "p:aw-bits", iommu->aw_bits, NULL) < 0) { return -1; } diff --git a/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.args b/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.args index 40b5bf7766..071bc00b34 100644 --- a/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.args +++ b/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.args @@ -28,7 +28,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-guest/.config \ -rtc base=utc \ -no-shutdown \ -boot strict=on \ --device '{"driver":"virtio-iommu","id":"iommu0","bus":"pcie.0","addr":"0x1"}' \ +-device '{"driver":"virtio-iommu","id":"iommu0","aw-bits":48,"bus":"pcie.0","addr":"0x1"}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ -msg timestamp=on -- 2.52.0
From: Michal Privoznik <mprivozn@redhat.com> In PCI assignment scenario the virtio-iommu needs to know the guest page size also known as granule. Expose it as an attribute to the <driver/> element of a virtio-iommu. This is possibly interesting only for aarch64 since it supports virtio-iommu and also supports running guests with different page size than the host. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- docs/formatdomain.rst | 38 ++++++++- src/conf/domain_conf.c | 77 ++++++++++++++++++- src/conf/domain_conf.h | 1 + src/conf/domain_validate.c | 9 ++- src/conf/schemas/domaincommon.rng | 22 ++++++ src/qemu/qemu_validate.c | 11 +++ .../virtio-iommu-aarch64.aarch64-latest.xml | 4 +- .../qemuxmlconfdata/virtio-iommu-aarch64.xml | 4 +- .../virtio-iommu-x86_64.x86_64-latest.xml | 3 + tests/qemuxmlconfdata/virtio-iommu-x86_64.xml | 6 +- 10 files changed, 166 insertions(+), 9 deletions(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 4b34a8a963..50563741a0 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -9194,7 +9194,7 @@ IOMMU devices The ``iommu`` element can be used to add an IOMMU device. :since:`Since 2.1.0` -Example: +Examples: :: @@ -9206,6 +9206,17 @@ Example: </devices> ... + + ... + <devices> + <iommu model='virtio'> + <driver aw_bits='48'> + <granule size='64' unit='KiB'/> + </driver> + </iommu> + </devices> + ... + ``model`` Supported values are ``intel`` (for Q35 guests) ``smmuv3`` (:since:`since 5.5.0`, for ARM virt guests), ``virtio`` @@ -9264,6 +9275,31 @@ Example: The ``pciBus`` attribute notes the index of the controller that an IOMMU device is attached to. (QEMU/KVM and ``smmuv3`` model only) +In case of ``virtio`` IOMMU device, the ``driver`` element can optionally +contain ``granule`` subelement that allows to choose which granule will be +used by default. It is useful when running guests with different page size +than the host. :since:`Since 12.1.0` (QEMU/KVM and ``virtio`` model only). +There are two possible options: + +:: + + <iommu model='virtio'> + <driver> + <granule mode='host'/> + </driver> + </iommu> + + <iommu model='virtio'> + <driver> + <granule size='64' unit='KiB'/> + </driver> + </iommu> + +The ``mode='host'`` case matches the host page size, the other sets desired +granule size. Please note that hypervisor might support only some selected +values. For instance, QEMU supports only 4KiB, 8KiB, 16KiB and 64KiB large +granules. + The ``virtio`` IOMMU devices can further have ``address`` element as described in `Device addresses`_ (address has to by type of ``pci``). diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1b2a439ca4..4503fc0095 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1592,6 +1592,21 @@ VIR_ENUM_IMPL(virDomainChrSourceMode, ); +/*virDomainIOMMUGranuleModeTypeToString: + * @val: value to format + * + * Reuturns: an allocated string. Caller must free it. + */ +static char * +virDomainIOMMUGranuleModeTypeToString(int val) +{ + if (val == -1) + return g_strdup("host"); + + return g_strdup_printf("%dKiB", val); +} + + static virClass *virDomainObjClass; static virClass *virDomainXMLOptionClass; static void virDomainObjDispose(void *obj); @@ -14487,6 +14502,8 @@ virDomainIOMMUDefParseXML(virDomainXMLOption *xmlopt, return NULL; if ((driver = virXPathNode("./driver", ctxt))) { + xmlNodePtr granule; + if (virXMLPropTristateSwitch(driver, "intremap", VIR_XML_PROP_NONE, &iommu->intremap) < 0) return NULL; @@ -14522,6 +14539,41 @@ virDomainIOMMUDefParseXML(virDomainXMLOption *xmlopt, if (virXMLPropInt(driver, "pciBus", 10, VIR_XML_PROP_NONE, &iommu->pci_bus, -1) < 0) return NULL; + + if ((granule = virXPathNode("./driver/granule", ctxt))) { + g_autofree char *mode = virXMLPropString(granule, "mode"); + unsigned long long size; + int rc; + + rc = virDomainParseMemory("./driver/granule/@size", + "./driver/granule/@unit", + ctxt, &size, false, false); + if (rc < 0) { + return NULL; + } else if (rc > 0) { + if (mode) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("'mode' and 'size' can't be specified at the same time for 'granule'")); + return NULL; + } + + if (size != (int) size) { + virReportError(VIR_ERR_OVERFLOW, "%s", _("size value too large")); + return NULL; + } + + iommu->granule = (int)size; + } else { + if (STREQ_NULLABLE(mode, "host")) { + iommu->granule = -1; + } else if (mode) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%1$s' in element '%2$s': '%3$s'."), + "mode", "granule", mode); + return NULL; + } + } + } } if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, @@ -16585,7 +16637,8 @@ virDomainIOMMUDefEquals(const virDomainIOMMUDef *a, a->eim != b->eim || a->iotlb != b->iotlb || a->aw_bits != b->aw_bits || - a->dma_translation != b->dma_translation) + a->dma_translation != b->dma_translation || + a->granule != b->granule) return false; if (a->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && @@ -22340,6 +22393,16 @@ virDomainIOMMUDefCheckABIStability(virDomainIOMMUDef *src, virTristateSwitchTypeToString(src->xtsup)); return false; } + if (src->granule != dst->granule) { + g_autofree char *src_granule = virDomainIOMMUGranuleModeTypeToString(src->granule); + g_autofree char *dst_granule = virDomainIOMMUGranuleModeTypeToString(dst->granule); + + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target domain IOMMU device granule '%1$s' does not match source '%2$s'"), + dst_granule, + src_granule); + return false; + } return virDomainDeviceInfoCheckABIStability(&src->info, &dst->info); } @@ -28628,6 +28691,7 @@ virDomainIOMMUDefFormat(virBuffer *buf, g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) driverChildBuf = VIR_BUFFER_INIT_CHILD(&childBuf); if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT) { virBufferAsprintf(&driverAttrBuf, " intremap='%s'", @@ -28665,8 +28729,17 @@ virDomainIOMMUDefFormat(virBuffer *buf, virBufferAsprintf(&driverAttrBuf, " pciBus='%d'", iommu->pci_bus); } + if (iommu->granule != 0) { + if (iommu->granule == -1) { + virBufferAddLit(&driverChildBuf, "<granule mode='host'/>\n"); + } else { + virBufferAsprintf(&driverChildBuf, + "<granule size='%d' unit='KiB'/>\n", + iommu->granule); + } + } - virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL); + virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, &driverChildBuf); virDomainDeviceInfoFormat(&childBuf, &iommu->info, 0); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 83d49969d3..72badb32a6 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3062,6 +3062,7 @@ struct _virDomainIOMMUDef { virTristateSwitch dma_translation; virTristateSwitch xtsup; virTristateSwitch pt; + int granule; /* -1 means 'host', 0 unset, page size in KiB otherwise */ }; typedef enum { diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index c83fff132b..1ad614935f 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -3194,7 +3194,8 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *iommu) iommu->aw_bits != 0 || iommu->dma_translation != VIR_TRISTATE_SWITCH_ABSENT || iommu->xtsup != VIR_TRISTATE_SWITCH_ABSENT || - iommu->pt != VIR_TRISTATE_SWITCH_ABSENT) { + iommu->pt != VIR_TRISTATE_SWITCH_ABSENT || + iommu->granule != 0) { virReportError(VIR_ERR_XML_ERROR, _("iommu model '%1$s' doesn't support some additional attributes"), virDomainIOMMUModelTypeToString(iommu->model)); @@ -3229,7 +3230,8 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *iommu) iommu->eim != VIR_TRISTATE_SWITCH_ABSENT || iommu->aw_bits != 0 || iommu->dma_translation != VIR_TRISTATE_SWITCH_ABSENT || - iommu->pci_bus >= 0) { + iommu->pci_bus >= 0 || + iommu->granule != 0) { virReportError(VIR_ERR_XML_ERROR, _("iommu model '%1$s' doesn't support some additional attributes"), virDomainIOMMUModelTypeToString(iommu->model)); @@ -3240,7 +3242,8 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *iommu) case VIR_DOMAIN_IOMMU_MODEL_INTEL: if (iommu->pt != VIR_TRISTATE_SWITCH_ABSENT || iommu->xtsup != VIR_TRISTATE_SWITCH_ABSENT || - iommu->pci_bus >= 0) { + iommu->pci_bus >= 0 || + iommu->granule != 0) { virReportError(VIR_ERR_XML_ERROR, _("iommu model '%1$s' doesn't support some additional attributes"), virDomainIOMMUModelTypeToString(iommu->model)); diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincommon.rng index 114dd3f96f..3d5eb7d4f3 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -6329,6 +6329,28 @@ <data type="unsignedInt"/> </attribute> </optional> + <optional> + <element name="granule"> + <choice> + <group> + <attribute name="mode"> + <value>host</value> + </attribute> + </group> + <group> + <attribute name="size"> + <ref name="unsignedInt"/> + </attribute> + <optional> + <attribute name="unit"> + <ref name="unit"/> + </attribute> + </optional> + </group> + </choice> + <empty/> + </element> + </optional> </element> </optional> <optional> diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index ab8a1938c1..8f85334cf9 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -5685,6 +5685,17 @@ qemuValidateDomainDeviceDefIOMMU(const virDomainIOMMUDef *iommu, return -1; } + /* QEMU supports only 4KiB, 8KiB, 16KiB and 64KiB granule size */ + if (iommu->granule > 0 && + !(iommu->granule == 4 || + iommu->granule == 8 || + iommu->granule == 16 || + iommu->granule == 64)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("iommu: unsupported granule size. Supported values are 4, 8, 16 and 64 KiB")); + return -1; + } + return 0; } diff --git a/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.xml b/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.xml index 4ae628ab5a..ad2fedaab7 100644 --- a/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.xml +++ b/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.xml @@ -29,7 +29,9 @@ <audio id='1' type='none'/> <memballoon model='none'/> <iommu model='virtio'> - <driver aw_bits='48'/> + <driver aw_bits='48'> + <granule size='64' unit='KiB'/> + </driver> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> </iommu> </devices> diff --git a/tests/qemuxmlconfdata/virtio-iommu-aarch64.xml b/tests/qemuxmlconfdata/virtio-iommu-aarch64.xml index 96e5ea05ae..8d5f081b92 100644 --- a/tests/qemuxmlconfdata/virtio-iommu-aarch64.xml +++ b/tests/qemuxmlconfdata/virtio-iommu-aarch64.xml @@ -14,7 +14,9 @@ <controller type='usb' model='none'/> <memballoon model='none'/> <iommu model='virtio'> - <driver aw_bits='48'/> + <driver aw_bits='48'> + <granule size='64' unit='KiB'/> + </driver> </iommu> </devices> </domain> diff --git a/tests/qemuxmlconfdata/virtio-iommu-x86_64.x86_64-latest.xml b/tests/qemuxmlconfdata/virtio-iommu-x86_64.x86_64-latest.xml index f458f9a706..56cee393d3 100644 --- a/tests/qemuxmlconfdata/virtio-iommu-x86_64.x86_64-latest.xml +++ b/tests/qemuxmlconfdata/virtio-iommu-x86_64.x86_64-latest.xml @@ -31,6 +31,9 @@ <watchdog model='itco' action='reset'/> <memballoon model='none'/> <iommu model='virtio'> + <driver> + <granule mode='host'/> + </driver> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> </iommu> </devices> diff --git a/tests/qemuxmlconfdata/virtio-iommu-x86_64.xml b/tests/qemuxmlconfdata/virtio-iommu-x86_64.xml index 51c13d2ef6..db0af57f69 100644 --- a/tests/qemuxmlconfdata/virtio-iommu-x86_64.xml +++ b/tests/qemuxmlconfdata/virtio-iommu-x86_64.xml @@ -13,6 +13,10 @@ <emulator>/usr/bin/qemu-system-x86_64</emulator> <controller type='usb' model='none'/> <memballoon model='none'/> - <iommu model='virtio'/> + <iommu model='virtio'> + <driver> + <granule mode='host'/> + </driver> + </iommu> </devices> </domain> -- 2.52.0
From: Michal Privoznik <mprivozn@redhat.com> Just like with other features, check whether QEMU supports them based on capabilities. Now, instead of inventing a new QEMU capability, an existing one can be used: QEMU_CAPS_VIRTIO_IOMMU_AW_BITS. This is because the aw-bits and granule attributes were introduced into QEMU in close succession (v9.0.0-rc0~9^2~7 v9.0.0-rc0~9^2~11), neither can be disabled at compile time and backporting just one without the other makes almost no sense. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_validate.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 8f85334cf9..6b44d8d785 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -5685,15 +5685,27 @@ qemuValidateDomainDeviceDefIOMMU(const virDomainIOMMUDef *iommu, return -1; } - /* QEMU supports only 4KiB, 8KiB, 16KiB and 64KiB granule size */ - if (iommu->granule > 0 && - !(iommu->granule == 4 || - iommu->granule == 8 || - iommu->granule == 16 || - iommu->granule == 64)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("iommu: unsupported granule size. Supported values are 4, 8, 16 and 64 KiB")); - return -1; + if (iommu->granule > 0) { + /* QEMU supports only 4KiB, 8KiB, 16KiB and 64KiB granule size */ + if (!(iommu->granule == 4 || + iommu->granule == 8 || + iommu->granule == 16 || + iommu->granule == 64)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("iommu: unsupported granule size. Supported values are 4, 8, 16 and 64 KiB")); + return -1; + } + + /* While the QEMU_CAPS_VIRTIO_IOMMU_AW_BITS tracks .aw-bits attribute of + * virtio-iommu it is also a good indicator of .granule attribute as both + * attributes were introduced in neighboring commits, in the same release, + * neither can be disabled at compile time and backporting one without the + * other makes no sense. */ + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_IOMMU_AW_BITS)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("iommu: page granule is not supported with this QEMU binary")); + return -1; + } } return 0; -- 2.52.0
From: Michal Privoznik <mprivozn@redhat.com> Resolves: https://issues.redhat.com/browse/RHEL-76269 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_command.c | 10 ++++++++++ .../virtio-iommu-aarch64.aarch64-latest.args | 2 +- .../virtio-iommu-x86_64.x86_64-latest.args | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 953156ce2a..b271f48dbf 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6285,6 +6285,7 @@ qemuBuildIOMMUCommandLine(virCommand *cmd, virDomainIOMMUDef *iommu = def->iommus[i]; g_autoptr(virJSONValue) props = NULL; g_autoptr(virJSONValue) wrapperProps = NULL; + g_autofree char *granule_mode = NULL; switch (iommu->model) { case VIR_DOMAIN_IOMMU_MODEL_INTEL: @@ -6306,10 +6307,19 @@ qemuBuildIOMMUCommandLine(virCommand *cmd, break; case VIR_DOMAIN_IOMMU_MODEL_VIRTIO: + if (iommu->granule != 0) { + if (iommu->granule == -1) { + granule_mode = g_strdup("host"); + } else { + granule_mode = g_strdup_printf("%dk", iommu->granule); + } + } + if (virJSONValueObjectAdd(&props, "s:driver", "virtio-iommu", "s:id", iommu->info.alias, "p:aw-bits", iommu->aw_bits, + "S:granule", granule_mode, NULL) < 0) { return -1; } diff --git a/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.args b/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.args index 071bc00b34..3c9cc0e9d1 100644 --- a/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.args +++ b/tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.args @@ -28,7 +28,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-guest/.config \ -rtc base=utc \ -no-shutdown \ -boot strict=on \ --device '{"driver":"virtio-iommu","id":"iommu0","aw-bits":48,"bus":"pcie.0","addr":"0x1"}' \ +-device '{"driver":"virtio-iommu","id":"iommu0","aw-bits":48,"granule":"64k","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/qemuxmlconfdata/virtio-iommu-x86_64.x86_64-latest.args b/tests/qemuxmlconfdata/virtio-iommu-x86_64.x86_64-latest.args index c2dbfd25ad..0d49128149 100644 --- a/tests/qemuxmlconfdata/virtio-iommu-x86_64.x86_64-latest.args +++ b/tests/qemuxmlconfdata/virtio-iommu-x86_64.x86_64-latest.args @@ -26,7 +26,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ -rtc base=utc \ -no-shutdown \ -boot strict=on \ --device '{"driver":"virtio-iommu","id":"iommu0","bus":"pcie.0","addr":"0x1"}' \ +-device '{"driver":"virtio-iommu","id":"iommu0","granule":"host","bus":"pcie.0","addr":"0x1"}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -global ICH9-LPC.noreboot=off \ -watchdog-action reset \ -- 2.52.0
participants (1)
-
Michal Privoznik