VIRTIO-IOMMU: Introduce an aw-bits option
v5 cover VIRTIO-IOMMU: Introduce an aw-bits option
In [1] and [2] we attempted to fix a case where a VFIO-PCI device protected with a virtio-iommu is assigned to an x86 guest. On x86 the physical IOMMU may have an address width (gaw) of 39 or 48 bits whereas the virtio-iommu exposes a 64b input address space by default. Hence the guest may try to use the full 64b space and DMA MAP failures may be encountered. To work around this issue we endeavoured to pass usable host IOVA regions (excluding the out of range space) from VFIO to the virtio-iommu device so that the virtio-iommu driver can query those latter during the probe request and let the guest iommu kernel subsystem carve them out.
However if there are several devices in the same iommu group, only the reserved regions of the first one are taken into account by the iommu subsystem of the guest. This generally works on baremetal because devices are not going to expose different reserved regions. However in our case, this may prevent from taking into account the host iommu geometry.
So the simplest solution to this problem looks to introduce an input address width option, aw-bits, which matches what is done on the intel-iommu. By default, from now on it is set to 39 bits with pc_q35 and 48 with arm virt. This replaces the previous default value of 64b. So we need to introduce a compat for machines older than 9.0 to behave similarly. We use hw_compat_8_2 to acheive that goal.
Outstanding series [2] remains useful to let resv regions beeing communicated on time before the probe request.
[1] [PATCH v4 00/12] VIRTIO-IOMMU/VFIO: Don't assume 64b IOVA space
https://lore.kernel.org/all/[email protected]/
- This is merged -
[2] [RFC 0/7] VIRTIO-IOMMU/VFIO: Fix host iommu geometry handling for hotplugged devices
https://lore.kernel.org/all/[email protected]/
- This is pending for review on the ML -
This series can be found at:
https://github.com/eauger/qemu/tree/virtio-iommu-aw-bits-v5
History:
v4 -> v5:
- small change in the aw-bits options description [Cédric]
v3 -> v4:
- remove dependency on
[PATCH v2] virtio-iommu: Use qemu_real_host_page_mask as default page_size_mask
- Fix qtest error [Michael]
- add doc entry in qemu-options.hx
v2 -> v3:
- Collected Zhenzhong and Cédric's R-b + Yanghang's T-b
- use &error_abort instead of NULL error handle on object_property_get_uint() call (Cédric)
- use VTD_HOST_AW_39BIT (Cédric)
v1 -> v2
- Limit aw to 48b on ARM
- Check aw is within [32,64]
- Use hw_compat_8_2
Eric Auger (4):
virtio-iommu: Add an option to define the input range width
virtio-iommu: Trace domain range limits as unsigned int
hw: Set virtio-iommu aw-bits default value on pc_q35 and arm virt qemu-options.hx: Add an entry for virtio-iommu-pci and document
aw-bits
include/hw/virtio/virtio-iommu.h | 1 + hw/arm/virt.c | 6 ++++++ hw/core/machine.c | 5 ++++- hw/i386/pc.c | 6 ++++++ hw/virtio/virtio-iommu.c | 7 ++++++- tests/qtest/virtio-iommu-test.c | 2 +- hw/virtio/trace-events | 2 +- qemu-options.hx | 8 ++++++++ 8 files changed, 33 insertions(+), 4 deletions(-)
Signature · 1 line
2.41.0
PATCH v5 1/4 virtio-iommu: Add an option to define the input range width
aw-bits is a new option that allows to set the bit width of the input address range. This value will be used as a default for the device config input_range.end. By default it is set to 64 bits which is the current value.
---
v1 -> v2:
- Check the aw-bits value is within [32,64]
--- include/hw/virtio/virtio-iommu.h | 1 + hw/virtio/virtio-iommu.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-)
include/hw/virtio/virtio-iommu.h +1 -0
@@ -66,6 +66,7 @@ struct VirtIOIOMMU {bool boot_bypass;Notifier machine_done;bool granule_frozen; + uint8_t aw_bits; };#endif
hw/virtio/virtio-iommu.c +6 -1
@@ -1314,7 +1314,11 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp)*/ s->config.bypass = s->boot_bypass; s->config.page_size_mask =qemu_target_page_mask (); - s->config.input_range.end =UINT64_MAX ; +if (s->aw_bits <32 || s->aw_bits >64 ) { +error_setg (errp,"aw-bits must be within [32,64]" ); + } + s->config.input_range.end = + s->aw_bits ==64 ?UINT64_MAX :BIT_ULL (s->aw_bits) -1 ; s->config.domain_range.end =UINT32_MAX ; s->config.probe_size =VIOMMU_PROBE_SIZE ;
@@ -1522,6 +1526,7 @@ static Property virtio_iommu_properties[] = {DEFINE_PROP_LINK ("primary-bus" , VirtIOIOMMU, primary_bus, TYPE_PCI_BUS, PCIBus *),DEFINE_PROP_BOOL ("boot-bypass" , VirtIOIOMMU, boot_bypass, true), +DEFINE_PROP_UINT8 ("aw-bits" , VirtIOIOMMU, aw_bits,64 ), DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
2.41.0
PATCH v5 2/4 virtio-iommu: Trace domain range limits as unsigned int
In reply to Eric AugerUse %u format to trace domain_range limits.
--- hw/virtio/trace-events | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/trace-events +1 -1
@@ -111,7 +111,7 @@ virtio_iommu_device_reset(void) "reset!" virtio_iommu_system_reset(void) "system reset!" virtio_iommu_get_features(uint64_t features) "device supports features=0x%"PRIx64 virtio_iommu_device_status(uint8_t status) "driver status = %d" -virtio_iommu_get_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_start, uint32_t domain_end, uint32_t probe_size, uint8_t bypass) "page_size_mask=0x%"PRIx64" input range start=0x%"PRIx64" input range end=0x%"PRIx64" domain range start=%d domain range end=%d probe_size=0x%x bypass=0x%x" +virtio_iommu_get_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_start, uint32_t domain_end, uint32_t probe_size, uint8_t bypass) "page_size_mask=0x%"PRIx64" input range start=0x%"PRIx64" input range end=0x%"PRIx64" domain range start=%u domain range end=%u probe_size=0x%x bypass=0x%x" virtio_iommu_set_config(uint8_t bypass) "bypass=0x%x" virtio_iommu_attach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d" virtio_iommu_detach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d"
Signature · 1 line
2.41.0
PATCH v5 3/4 hw: Set virtio-iommu aw-bits default value on pc_q35 and arm virt
In reply to Eric AugerCurrently the default input range can extend to 64 bits. On x86, when the virtio-iommu protects vfio devices, the physical iommu may support only 39 bits. Let's set the default to 39, as done for the intel-iommu. On ARM we set 48b as a default (matching SMMUv3 SMMU_IDR5.VAX == 0).
We use hw_compat_8_2 to handle the compatibility for machines before 9.0 which used to have a virtio-iommu default input range of 64 bits.
Of course if aw-bits is set from the command line, the default is overriden.
---
v3 -> v4:
- update the qos test to relax the check on the max input IOVA
v2 -> v3:
- collected Zhenzhong's R-b
- use &error_abort instead of NULL error handle
on object_property_get_uint() call (Cédric)
- use VTD_HOST_AW_39BIT (Cédric)
v1 -> v2:
- set aw-bits to 48b on ARM
- use hw_compat_8_2 to handle the compat for older machines which used 64b as a default
--- hw/arm/virt.c | 6 ++++++ hw/core/machine.c | 5 ++++- hw/i386/pc.c | 6 ++++++ hw/virtio/virtio-iommu.c | 2 +- tests/qtest/virtio-iommu-test.c | 2 +- 5 files changed, 18 insertions(+), 3 deletions(-)
hw/arm/virt.c +6 -0
@@ -2716,10 +2716,16 @@ static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MD_PCI )) {virtio_md_pci_pre_plug (VIRTIO_MD_PCI (dev),MACHINE (hotplug_dev), errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) { +uint8_t aw_bits =object_property_get_uint (OBJECT (dev), +"aw-bits" , &error_abort);hwaddr db_start =0 , db_end =0 ;QList *reserved_regions;char *resv_prop_str; +if (!aw_bits) { +qdev_prop_set_uint8 (dev,"aw-bits" ,48 ); + } +if (vms->iommu !=VIRT_IOMMU_NONE ) {error_setg (errp,"virt machine does not support multiple IOMMUs" );return ;
hw/core/machine.c +4 -1
@@ -30,9 +30,12 @@#include "exec/confidential-guest-support.h" #include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-net.h" +#include "hw/virtio/virtio-iommu.h" #include "audio/audio.h" -GlobalProperty hw_compat_8_2[] = {}; +GlobalProperty hw_compat_8_2[] = { + {TYPE_VIRTIO_IOMMU_PCI ,"aw-bits" ,"64" }, +};const size_t hw_compat_8_2_len =G_N_ELEMENTS (hw_compat_8_2);GlobalProperty hw_compat_8_1[] = {
hw/i386/pc.c +6 -0
@@ -1456,6 +1456,8 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MD_PCI )) {virtio_md_pci_pre_plug (VIRTIO_MD_PCI (dev),MACHINE (hotplug_dev), errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) { +uint8_t aw_bits =object_property_get_uint (OBJECT (dev), +"aw-bits" , &error_abort);/* Declare the APIC range as the reserved MSI region */ char *resv_prop_str =g_strdup_printf ("0xfee00000:0xfeefffff:%d" ,VIRTIO_IOMMU_RESV_MEM_T_MSI );
@@ -1464,6 +1466,10 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,qlist_append_str (reserved_regions, resv_prop_str);qdev_prop_set_array (dev,"reserved-regions" , reserved_regions); +if (!aw_bits) { +qdev_prop_set_uint8 (dev,"aw-bits" ,VTD_HOST_AW_39BIT ); + } +g_free (resv_prop_str); }
hw/virtio/virtio-iommu.c +1 -1
@@ -1526,7 +1526,7 @@ static Property virtio_iommu_properties[] = {DEFINE_PROP_LINK ("primary-bus" , VirtIOIOMMU, primary_bus, TYPE_PCI_BUS, PCIBus *),DEFINE_PROP_BOOL ("boot-bypass" , VirtIOIOMMU, boot_bypass, true), -DEFINE_PROP_UINT8 ("aw-bits" , VirtIOIOMMU, aw_bits,64 ), +DEFINE_PROP_UINT8 ("aw-bits" , VirtIOIOMMU, aw_bits,0 ), DEFINE_PROP_END_OF_LIST(), };
tests/qtest/virtio-iommu-test.c +1 -1
@@ -34,7 +34,7 @@ static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc)uint8_t bypass =qvirtio_config_readb (dev,36 ); g_assert_cmpint(input_range_start, ==, 0); - g_assert_cmphex(input_range_end, ==, UINT64_MAX); + g_assert_cmphex(input_range_end, >=, 32); g_assert_cmpint(domain_range_start, ==, 0); g_assert_cmpint(domain_range_end, ==, UINT32_MAX); g_assert_cmpint(bypass, ==, 1);
Signature · 1 line
2.41.0
Re: [PATCH v5 3/4] hw: Set virtio-iommu aw-bits default value on pc_q35 and arm virt
Hello Eric,
Quoted 10 lines · Eric Auger
Currently the default input range can extend to 64 bits. On x86, when the virtio-iommu protects vfio devices, the physical iommu may support only 39 bits. Let's set the default to 39, as done for the intel-iommu. On ARM we set 48b as a default (matching SMMUv3 SMMU_IDR5.VAX == 0).
We use
hw_compat_8_2to handle the compatibility for machines before 9.0 which used to have a virtio-iommu default input range of 64 bits.
Quoted 6 lines
Of course if aw-bits is set from the command line, the default is overriden.
Signed-off-by Eric Auger <[email protected]>Reviewed-by Zhenzhong Duan <[email protected]>Tested-by Yanghang Liu<[email protected]>
We need a property fixup for pseries also:
$ build/ppc64-softmmu/qemu-system-ppc64 -M pseries -device virtio-iommu-pci,addr=04.0 qemu-system-ppc64: -device virtio-iommu-pci,addr=04.0: aw-bits must be within [32,64]
Thanks,
C.
Quoted 112 lines
---
v3 -> v4:
- update the qos test to relax the check on the max input IOVAv2 -> v3:
- collected Zhenzhong's R-b
- use&error_abortinstead of NULL error handle
onobject_property_get_uint()call (Cédric)
- useVTD_HOST_AW_39BIT(Cédric)v1 -> v2:
- set aw-bits to 48b on ARM
- usehw_compat_8_2to handle the compat for older machines which used 64b as a default--- hw/arm/virt.c | 6 ++++++ hw/core/machine.c | 5 ++++- hw/i386/pc.c | 6 ++++++ hw/virtio/virtio-iommu.c | 2 +- tests/qtest/virtio-iommu-test.c | 2 +- 5 files changed, 18 insertions(+), 3 deletions(-)hw/arm/virt.c +6
-0@@ -2716,10 +2716,16 @@ static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MD_PCI )) {virtio_md_pci_pre_plug (VIRTIO_MD_PCI (dev),MACHINE (hotplug_dev), errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) { +uint8_t aw_bits =object_property_get_uint (OBJECT (dev), +"aw-bits" , &error_abort);hwaddr db_start =0 , db_end =0 ;QList *reserved_regions;char *resv_prop_str; +if (!aw_bits) { +qdev_prop_set_uint8 (dev,"aw-bits" ,48 ); + } +if (vms->iommu !=VIRT_IOMMU_NONE ) {error_setg (errp,"virt machine does not support multiple IOMMUs" );return ;hw/core/machine.c +4
-1@@ -30,9 +30,12 @@#include "exec/confidential-guest-support.h" #include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-net.h" +#include "hw/virtio/virtio-iommu.h" #include "audio/audio.h" -GlobalProperty hw_compat_8_2[] = {}; +GlobalProperty hw_compat_8_2[] = { + {TYPE_VIRTIO_IOMMU_PCI ,"aw-bits" ,"64" }, +};const size_t hw_compat_8_2_len =G_N_ELEMENTS (hw_compat_8_2);GlobalProperty hw_compat_8_1[] = {hw/i386/pc.c +6
-0@@ -1456,6 +1456,8 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MD_PCI )) {virtio_md_pci_pre_plug (VIRTIO_MD_PCI (dev),MACHINE (hotplug_dev), errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) { +uint8_t aw_bits =object_property_get_uint (OBJECT (dev), +"aw-bits" , &error_abort);/* Declare the APIC range as the reserved MSI region */ char *resv_prop_str =g_strdup_printf ("0xfee00000:0xfeefffff:%d" ,VIRTIO_IOMMU_RESV_MEM_T_MSI );@@ -1464,6 +1466,10 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,qlist_append_str (reserved_regions, resv_prop_str);qdev_prop_set_array (dev,"reserved-regions" , reserved_regions); +if (!aw_bits) { +qdev_prop_set_uint8 (dev,"aw-bits" ,VTD_HOST_AW_39BIT ); + } +g_free (resv_prop_str); }hw/virtio/virtio-iommu.c +1
-1@@ -1526,7 +1526,7 @@ static Property virtio_iommu_properties[] = {DEFINE_PROP_LINK ("primary-bus" , VirtIOIOMMU, primary_bus, TYPE_PCI_BUS, PCIBus *),DEFINE_PROP_BOOL ("boot-bypass" , VirtIOIOMMU, boot_bypass, true), -DEFINE_PROP_UINT8 ("aw-bits" , VirtIOIOMMU, aw_bits,64 ), +DEFINE_PROP_UINT8 ("aw-bits" , VirtIOIOMMU, aw_bits,0 ), DEFINE_PROP_END_OF_LIST(), };tests/qtest/virtio-iommu-test.c +1
-1@@ -34,7 +34,7 @@ static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc)uint8_t bypass =qvirtio_config_readb (dev,36 ); g_assert_cmpint(input_range_start, ==, 0); - g_assert_cmphex(input_range_end, ==, UINT64_MAX); + g_assert_cmphex(input_range_end, >=, 32); g_assert_cmpint(domain_range_start, ==, 0); g_assert_cmpint(domain_range_end, ==, UINT32_MAX); g_assert_cmpint(bypass, ==, 1);
Re: [PATCH v5 3/4] hw: Set virtio-iommu aw-bits default value on pc_q35 and arm virt
Hi Cédric,
Quoted 20 lines · Cédric Le Goater
Hello Eric,
Quoted 10 lines · Eric Auger
Currently the default input range can extend to 64 bits. On x86, when the virtio-iommu protects vfio devices, the physical iommu may support only 39 bits. Let's set the default to 39, as done for the intel-iommu. On ARM we set 48b as a default (matching SMMUv3 SMMU_IDR5.VAX == 0).
We use
hw_compat_8_2to handle the compatibility for machines before 9.0 which used to have a virtio-iommu default input range of 64 bits.Quoted 6 lines
Of course if aw-bits is set from the command line, the default is overriden.
Signed-off-by Eric Auger <[email protected]>Reviewed-by Zhenzhong Duan <[email protected]>Tested-by Yanghang Liu<[email protected]>
Quoted 6 lines
We need a property fixup for pseries also:
$ build/ppc64-softmmu/qemu-system-ppc64 -M pseries -device virtio-iommu-pci,addr=04.0 qemu-system-ppc64: -device virtio-iommu-pci,addr=04.0: aw-bits must be within [32,64]
as stated in the doc (now! see [PATCH v5 4/4] qemu-options.hx: Add an entry for virtio-iommu-pci and document aw-bits) , the virtio-iommu-pci device only is supported in q35 and arm virt.
If you want to support virtio-iommu on other machines, you need to take care of this aw-bits settings and also of the exposed reserved regions.
Thanks
Eric
Quoted 129 lines
Thanks,
C.
Quoted 120 lines
---
v3 -> v4:
- update the qos test to relax the check on the max input IOVAv2 -> v3:
- collected Zhenzhong's R-b
- use&error_abortinstead of NULL error handle
onobject_property_get_uint()call (Cédric)
- useVTD_HOST_AW_39BIT(Cédric)v1 -> v2:
- set aw-bits to 48b on ARM
- usehw_compat_8_2to handle the compat for older machines which used 64b as a default
---
hw/arm/virt.c | 6 ++++++ hw/core/machine.c | 5 ++++- hw/i386/pc.c | 6 ++++++ hw/virtio/virtio-iommu.c | 2 +-tests/qtest/virtio-iommu-test.c| 2 +-5 files changed, 18 insertions(+), 3 deletions(-)hw/arm/virt.c +2
-0@@ -2716,10 +2716,16 @@ static voidvirt_machine_device_pre_plug_cb (HotplugHandler *hotplug_dev, } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) { virtio_md_pci_pre_plug(VIRTIO_MD_PCI(dev), MACHINE(hotplug_dev), errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { + uint8_t aw_bits = object_property_get_uint(OBJECT(dev), + "aw-bits", &error_abort); hwaddr db_start = 0, db_end = 0; QList *reserved_regions; char *resv_prop_str;+ if (!aw_bits) {
+qdev_prop_set_uint8(dev, "aw-bits", 48); + }
+
if (vms->iommu!=VIRT_IOMMU_NONE) {error_setg(errp, "virt machine does not support multiple IOMMUs");
return;hw/core/machine.c +4
-0@@ -30,9 +30,12 @@ #include "exec/confidential-guest-support.h" #include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-net.h" +#include "hw/virtio/virtio-iommu.h" #include "audio/audio.h" -GlobalProperty hw_compat_8_2[] = {}; +GlobalProperty hw_compat_8_2[] = { + { TYPE_VIRTIO_IOMMU_PCI, "aw-bits", "64" }, +}; const size_t hw_compat_8_2_len = G_N_ELEMENTS(hw_compat_8_2); GlobalProperty hw_compat_8_1[] = {hw/i386/pc.c +2
-0@@ -1456,6 +1456,8 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) { virtio_md_pci_pre_plug(VIRTIO_MD_PCI(dev), MACHINE(hotplug_dev), errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { + uint8_t aw_bits = object_property_get_uint(OBJECT(dev), + "aw-bits",
&error_abort);
/* Declare the APIC range as the reserved MSI region */ char*resv_prop_str= g_strdup_printf("0xfee00000:0xfeefffff:%d",VIRTIO_IOMMU_RESV_MEM_T_MSI);hw/i386/pc.c +3
-0@@ -1464,6 +1466,10 @@ static voidpc_machine_device_pre_plug_cb (HotplugHandler *hotplug_dev, qlist_append_str(reserved_regions, resv_prop_str); qdev_prop_set_array(dev, "reserved-regions", reserved_regions); + if (!aw_bits) { + qdev_prop_set_uint8(dev, "aw-bits", VTD_HOST_AW_39BIT); + } + g_free(resv_prop_str);}
diff --gita/hw/virtio/virtio-iommu.cb/hw/virtio/virtio-iommu.cindex8b541de850..2ec5ef3cd1100644hw/virtio/virtio-iommu.c +1
-1@@ -1526,7 +1526,7 @@ static Property virtio_iommu_properties[] = { DEFINE_PROP_LINK("primary-bus", VirtIOIOMMU, primary_bus, TYPE_PCI_BUS, PCIBus *), DEFINE_PROP_BOOL("boot-bypass", VirtIOIOMMU, boot_bypass, true), - DEFINE_PROP_UINT8("aw-bits", VirtIOIOMMU, aw_bits, 64), + DEFINE_PROP_UINT8("aw-bits", VirtIOIOMMU, aw_bits, 0), DEFINE_PROP_END_OF_LIST(), };diff --git
a/tests/qtest/virtio-iommu-test.cb/tests/qtest/virtio-iommu-test.c
index068e7a9e6c..0f36381acb100644tests/qtest/virtio-iommu-test.c +1
-1@@ -34,7 +34,7 @@ static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc) uint8_t bypass = qvirtio_config_readb(dev, 36); g_assert_cmpint(input_range_start, ==, 0); - g_assert_cmphex(input_range_end, ==, UINT64_MAX); + g_assert_cmphex(input_range_end, >=, 32); g_assert_cmpint(domain_range_start, ==, 0); g_assert_cmpint(domain_range_end, ==, UINT32_MAX); g_assert_cmpint(bypass, ==, 1);
Re: [PATCH v5 3/4] hw: Set virtio-iommu aw-bits default value on pc_q35 and arm virt
In reply to Cédric Le GoaterHi,
Quoted 20 lines · Cédric Le Goater
Hello Eric,
Quoted 10 lines · Eric Auger
Currently the default input range can extend to 64 bits. On x86, when the virtio-iommu protects vfio devices, the physical iommu may support only 39 bits. Let's set the default to 39, as done for the intel-iommu. On ARM we set 48b as a default (matching SMMUv3 SMMU_IDR5.VAX == 0).
We use
hw_compat_8_2to handle the compatibility for machines before 9.0 which used to have a virtio-iommu default input range of 64 bits.Quoted 6 lines
Of course if aw-bits is set from the command line, the default is overriden.
Signed-off-by Eric Auger <[email protected]>Reviewed-by Zhenzhong Duan <[email protected]>Tested-by Yanghang Liu<[email protected]>
Quoted 6 lines
We need a property fixup for pseries also:
$ build/ppc64-softmmu/qemu-system-ppc64 -M pseries -device virtio-iommu-pci,addr=04.0 qemu-system-ppc64: -device virtio-iommu-pci,addr=04.0: aw-bits must be within [32,64]
after offline discssion with Cédric, despite the virtio-iommu-pci device is not supported on ppc64 the
tests/qtest/qos-test attempts to execute the tests/qtest/virtio-iommu-test.c because the machine has a pci bus. Since by default the aw-bits is 0 the test fails. I need to rework that. Thanks! Eric
Quoted 129 lines
Thanks,
C.
Quoted 120 lines
---
v3 -> v4:
- update the qos test to relax the check on the max input IOVAv2 -> v3:
- collected Zhenzhong's R-b
- use&error_abortinstead of NULL error handle
onobject_property_get_uint()call (Cédric)
- useVTD_HOST_AW_39BIT(Cédric)v1 -> v2:
- set aw-bits to 48b on ARM
- usehw_compat_8_2to handle the compat for older machines which used 64b as a default
---
hw/arm/virt.c | 6 ++++++ hw/core/machine.c | 5 ++++- hw/i386/pc.c | 6 ++++++ hw/virtio/virtio-iommu.c | 2 +-tests/qtest/virtio-iommu-test.c| 2 +-5 files changed, 18 insertions(+), 3 deletions(-)hw/arm/virt.c +2
-0@@ -2716,10 +2716,16 @@ static voidvirt_machine_device_pre_plug_cb (HotplugHandler *hotplug_dev, } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) { virtio_md_pci_pre_plug(VIRTIO_MD_PCI(dev), MACHINE(hotplug_dev), errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { + uint8_t aw_bits = object_property_get_uint(OBJECT(dev), + "aw-bits", &error_abort); hwaddr db_start = 0, db_end = 0; QList *reserved_regions; char *resv_prop_str;+ if (!aw_bits) {
+qdev_prop_set_uint8(dev, "aw-bits", 48); + }
+
if (vms->iommu!=VIRT_IOMMU_NONE) {error_setg(errp, "virt machine does not support multiple IOMMUs");
return;hw/core/machine.c +4
-0@@ -30,9 +30,12 @@ #include "exec/confidential-guest-support.h" #include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-net.h" +#include "hw/virtio/virtio-iommu.h" #include "audio/audio.h" -GlobalProperty hw_compat_8_2[] = {}; +GlobalProperty hw_compat_8_2[] = { + { TYPE_VIRTIO_IOMMU_PCI, "aw-bits", "64" }, +}; const size_t hw_compat_8_2_len = G_N_ELEMENTS(hw_compat_8_2); GlobalProperty hw_compat_8_1[] = {hw/i386/pc.c +2
-0@@ -1456,6 +1456,8 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) { virtio_md_pci_pre_plug(VIRTIO_MD_PCI(dev), MACHINE(hotplug_dev), errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { + uint8_t aw_bits = object_property_get_uint(OBJECT(dev), + "aw-bits",
&error_abort);
/* Declare the APIC range as the reserved MSI region */ char*resv_prop_str= g_strdup_printf("0xfee00000:0xfeefffff:%d",VIRTIO_IOMMU_RESV_MEM_T_MSI);hw/i386/pc.c +3
-0@@ -1464,6 +1466,10 @@ static voidpc_machine_device_pre_plug_cb (HotplugHandler *hotplug_dev, qlist_append_str(reserved_regions, resv_prop_str); qdev_prop_set_array(dev, "reserved-regions", reserved_regions); + if (!aw_bits) { + qdev_prop_set_uint8(dev, "aw-bits", VTD_HOST_AW_39BIT); + } + g_free(resv_prop_str);}
diff --gita/hw/virtio/virtio-iommu.cb/hw/virtio/virtio-iommu.cindex8b541de850..2ec5ef3cd1100644hw/virtio/virtio-iommu.c +1
-1@@ -1526,7 +1526,7 @@ static Property virtio_iommu_properties[] = { DEFINE_PROP_LINK("primary-bus", VirtIOIOMMU, primary_bus, TYPE_PCI_BUS, PCIBus *), DEFINE_PROP_BOOL("boot-bypass", VirtIOIOMMU, boot_bypass, true), - DEFINE_PROP_UINT8("aw-bits", VirtIOIOMMU, aw_bits, 64), + DEFINE_PROP_UINT8("aw-bits", VirtIOIOMMU, aw_bits, 0), DEFINE_PROP_END_OF_LIST(), };diff --git
a/tests/qtest/virtio-iommu-test.cb/tests/qtest/virtio-iommu-test.c
index068e7a9e6c..0f36381acb100644tests/qtest/virtio-iommu-test.c +1
-1@@ -34,7 +34,7 @@ static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc) uint8_t bypass = qvirtio_config_readb(dev, 36); g_assert_cmpint(input_range_start, ==, 0); - g_assert_cmphex(input_range_end, ==, UINT64_MAX); + g_assert_cmphex(input_range_end, >=, 32); g_assert_cmpint(domain_range_start, ==, 0); g_assert_cmpint(domain_range_end, ==, UINT32_MAX); g_assert_cmpint(bypass, ==, 1);
Re: [PATCH v5 3/4] hw: Set virtio-iommu aw-bits default value on pc_q35 and arm virt
In reply to Eric AugerQuoted 9 lines · On Thu, 15 Feb 2024 09:42:13 +0100 Eric Auger <[email protected]> wrote:
Currently the default input range can extend to 64 bits. On x86, when the virtio-iommu protects vfio devices, the physical iommu may support only 39 bits. Let's set the default to 39, as done for the intel-iommu. On ARM we set 48b as a default (matching SMMUv3 SMMU_IDR5.VAX == 0).
We use
hw_compat_8_2to handle the compatibility for machines before 9.0 which used to have a virtio-iommu default input range of 64 bits.
so we have different defaults per target/machine
while open codding fixup in _pre_plug_ works it's
a bit unexpected place to manage defaults and
avoid adding 0 magic.
How about using compat machinery instead to set
machine dependent defaults:
For example:
pc_i440fx_machine_options(MachineClass *m)
{
...
+ compat_props_add(m->compat_props, pc_compat_defaults,pc_compat_defaults_len);
}
Quoted 36 lines
Of course if aw-bits is set from the command line, the default is overriden.
Signed-off-by Eric Auger <[email protected]>Reviewed-by Zhenzhong Duan <[email protected]>Tested-by Yanghang Liu<[email protected]>---
v3 -> v4:
- update the qos test to relax the check on the max input IOVAv2 -> v3:
- collected Zhenzhong's R-b
- use&error_abortinstead of NULL error handle
onobject_property_get_uint()call (Cédric)
- useVTD_HOST_AW_39BIT(Cédric)v1 -> v2:
- set aw-bits to 48b on ARM
- usehw_compat_8_2to handle the compat for older machines which used 64b as a default--- hw/arm/virt.c | 6 ++++++ hw/core/machine.c | 5 ++++- hw/i386/pc.c | 6 ++++++ hw/virtio/virtio-iommu.c | 2 +- tests/qtest/virtio-iommu-test.c | 2 +- 5 files changed, 18 insertions(+), 3 deletions(-)hw/arm/virt.c +0
-0@@ -2716,10 +2716,16 @@ static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MD_PCI )) {
hw/arm/virt.c static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, · line 2726
Quoted 10 lines
hw/arm/virt.c +4
-0virtio_md_pci_pre_plug (VIRTIO_MD_PCI (dev),MACHINE (hotplug_dev), errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) { +uint8_t aw_bits =object_property_get_uint (OBJECT (dev), +"aw-bits" , &error_abort);hwaddr db_start =0 , db_end =0 ;QList *reserved_regions;char *resv_prop_str; +if (!aw_bits) { +qdev_prop_set_uint8 (dev,"aw-bits" ,48 );
s/48/macro name/?
Quoted 53 lines
hw/arm/virt.c +1
-0+ }if (vms->iommu !=VIRT_IOMMU_NONE ) {error_setg (errp,"virt machine does not support multiple IOMMUs" );return ;hw/core/machine.c +4
-1@@ -30,9 +30,12 @@#include "exec/confidential-guest-support.h" #include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-net.h" +#include "hw/virtio/virtio-iommu.h" #include "audio/audio.h" -GlobalProperty hw_compat_8_2[] = {}; +GlobalProperty hw_compat_8_2[] = { + {TYPE_VIRTIO_IOMMU_PCI ,"aw-bits" ,"64" }, +};const size_t hw_compat_8_2_len =G_N_ELEMENTS (hw_compat_8_2);GlobalProperty hw_compat_8_1[] = {hw/i386/pc.c +6
-0@@ -1456,6 +1456,8 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MD_PCI )) {virtio_md_pci_pre_plug (VIRTIO_MD_PCI (dev),MACHINE (hotplug_dev), errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) { +uint8_t aw_bits =object_property_get_uint (OBJECT (dev), +"aw-bits" , &error_abort);/* Declare the APIC range as the reserved MSI region */ char *resv_prop_str =g_strdup_printf ("0xfee00000:0xfeefffff:%d" ,VIRTIO_IOMMU_RESV_MEM_T_MSI );@@ -1464,6 +1466,10 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,qlist_append_str (reserved_regions, resv_prop_str);qdev_prop_set_array (dev,"reserved-regions" , reserved_regions); +if (!aw_bits) { +qdev_prop_set_uint8 (dev,"aw-bits" ,VTD_HOST_AW_39BIT ); + } +g_free (resv_prop_str); }hw/virtio/virtio-iommu.c +0
-0
hw/virtio/virtio-iommu.c static Property virtio_iommu_properties[] = { · line 1529
Quoted 5 lines
hw/virtio/virtio-iommu.c +1
-1@@ -1526,7 +1526,7 @@ static Property virtio_iommu_properties[] = {DEFINE_PROP_LINK ("primary-bus" , VirtIOIOMMU, primary_bus, TYPE_PCI_BUS, PCIBus *),DEFINE_PROP_BOOL ("boot-bypass" , VirtIOIOMMU, boot_bypass, true), - DEFINE_PROP_UINT8("aw-bits", VirtIOIOMMU, aw_bits, 64), + DEFINE_PROP_UINT8("aw-bits", VirtIOIOMMU, aw_bits, 0),
I'd set some valid value here (obviously not universal) and skip default property setting for that machine/target
For example pick x86 one.
Quoted 16 lines
hw/virtio/virtio-iommu.c +0
-0DEFINE_PROP_END_OF_LIST(), };tests/qtest/virtio-iommu-test.c +1
-1@@ -34,7 +34,7 @@ static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc)uint8_t bypass =qvirtio_config_readb (dev,36 ); g_assert_cmpint(input_range_start, ==, 0); - g_assert_cmphex(input_range_end, ==, UINT64_MAX); + g_assert_cmphex(input_range_end, >=, 32); g_assert_cmpint(domain_range_start, ==, 0); g_assert_cmpint(domain_range_end, ==, UINT32_MAX); g_assert_cmpint(bypass, ==, 1);
Re: [PATCH v5 3/4] hw: Set virtio-iommu aw-bits default value on pc_q35 and arm virt
Hi Igor,
Quoted 21 lines · Igor Mammedov
Quoted 9 lines · On Thu, 15 Feb 2024 09:42:13 +0100 Eric Auger <[email protected]> wrote:
Currently the default input range can extend to 64 bits. On x86, when the virtio-iommu protects vfio devices, the physical iommu may support only 39 bits. Let's set the default to 39, as done for the intel-iommu. On ARM we set 48b as a default (matching SMMUv3 SMMU_IDR5.VAX == 0).
We use
hw_compat_8_2to handle the compatibility for machines before 9.0 which used to have a virtio-iommu default input range of 64 bits.so we have different defaults per target/machine
while open codding fixup in _pre_plug_ works it's
a bit unexpected place to manage defaults and
avoid adding 0 magic.How about using compat machinery instead to set
machine dependent defaults:
For example:
Quoted 5 lines
pc_i440fx_machine_options(MachineClass *m)
{
...
+compat_props_add(m->compat_props, pc_compat_defaults,pc_compat_defaults_len);
}
Yes I can go this way.
Quoted 45 lines
Quoted 45 lines
Of course if aw-bits is set from the command line, the default is overriden.
Signed-off-by Eric Auger <[email protected]>Reviewed-by Zhenzhong Duan <[email protected]>Tested-by Yanghang Liu<[email protected]>---
v3 -> v4:
- update the qos test to relax the check on the max input IOVAv2 -> v3:
- collected Zhenzhong's R-b
- use&error_abortinstead of NULL error handle
onobject_property_get_uint()call (Cédric)
- useVTD_HOST_AW_39BIT(Cédric)v1 -> v2:
- set aw-bits to 48b on ARM
- usehw_compat_8_2to handle the compat for older machines which used 64b as a default--- hw/arm/virt.c | 6 ++++++ hw/core/machine.c | 5 ++++- hw/i386/pc.c | 6 ++++++ hw/virtio/virtio-iommu.c | 2 +- tests/qtest/virtio-iommu-test.c | 2 +- 5 files changed, 18 insertions(+), 3 deletions(-)hw/arm/virt.c +2
-0@@ -2716,10 +2716,16 @@ static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MD_PCI )) {virtio_md_pci_pre_plug (VIRTIO_MD_PCI (dev),MACHINE (hotplug_dev), errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) { +uint8_t aw_bits =object_property_get_uint (OBJECT (dev), +"aw-bits" , &error_abort);hwaddr db_start =0 , db_end =0 ;QList *reserved_regions;char *resv_prop_str;
Quoted 3 lines
hw/arm/virt.c static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, · line 2726
Quoted 2 lines
hw/arm/virt.c +2
-0+if (!aw_bits) { +qdev_prop_set_uint8 (dev,"aw-bits" ,48 );s/48/macro name/?
with compats it becomes a string. So I cannot directly reuse X86_64 VTD or ARM SMMU macros. I would introduce a dummy VIRTIO_IOMMU string which does not sound really helpful.
Quoted 49 lines
Quoted 49 lines
hw/arm/virt.c +1
-0+ }if (vms->iommu !=VIRT_IOMMU_NONE ) {error_setg (errp,"virt machine does not support multiple IOMMUs" );return ;hw/core/machine.c +4
-1@@ -30,9 +30,12 @@#include "exec/confidential-guest-support.h" #include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-net.h" +#include "hw/virtio/virtio-iommu.h" #include "audio/audio.h" -GlobalProperty hw_compat_8_2[] = {}; +GlobalProperty hw_compat_8_2[] = { + {TYPE_VIRTIO_IOMMU_PCI ,"aw-bits" ,"64" }, +};const size_t hw_compat_8_2_len =G_N_ELEMENTS (hw_compat_8_2);GlobalProperty hw_compat_8_1[] = {hw/i386/pc.c +6
-0@@ -1456,6 +1456,8 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MD_PCI )) {virtio_md_pci_pre_plug (VIRTIO_MD_PCI (dev),MACHINE (hotplug_dev), errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) { +uint8_t aw_bits =object_property_get_uint (OBJECT (dev), +"aw-bits" , &error_abort);/* Declare the APIC range as the reserved MSI region */ char *resv_prop_str =g_strdup_printf ("0xfee00000:0xfeefffff:%d" ,VIRTIO_IOMMU_RESV_MEM_T_MSI );@@ -1464,6 +1466,10 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,qlist_append_str (reserved_regions, resv_prop_str);qdev_prop_set_array (dev,"reserved-regions" , reserved_regions); +if (!aw_bits) { +qdev_prop_set_uint8 (dev,"aw-bits" ,VTD_HOST_AW_39BIT ); + } +g_free (resv_prop_str); }
Quoted 13 lines
hw/virtio/virtio-iommu.c static Property virtio_iommu_properties[] = { · line 1529
Quoted 10 lines
hw/virtio/virtio-iommu.c +1
-1@@ -1526,7 +1526,7 @@ static Property virtio_iommu_properties[] = {DEFINE_PROP_LINK ("primary-bus" , VirtIOIOMMU, primary_bus, TYPE_PCI_BUS, PCIBus *),DEFINE_PROP_BOOL ("boot-bypass" , VirtIOIOMMU, boot_bypass, true), - DEFINE_PROP_UINT8("aw-bits", VirtIOIOMMU, aw_bits, 64), + DEFINE_PROP_UINT8("aw-bits", VirtIOIOMMU, aw_bits, 0),I'd set some valid value here (obviously not universal) and skip default property setting for that machine/target
For example pick x86 one.
Yes the purpose is to have a non null aw_bits value which makes the virtio-iommu unusable without proper machine integration and puts the mess on the libqos tests.
Quoted 11 lines
Quoted 11 lines
hw/virtio/virtio-iommu.c +0
-0DEFINE_PROP_END_OF_LIST(), };tests/qtest/virtio-iommu-test.c +0
-0@@ -34,7 +34,7 @@ static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc)uint8_t bypass =qvirtio_config_readb (dev,36 );
Quoted 6 lines
tests/qtest/virtio-iommu-test.c static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc) · line 40
Quoted 6 lines
tests/qtest/virtio-iommu-test.c +1
-1g_assert_cmpint(input_range_start, ==, 0); - g_assert_cmphex(input_range_end, ==, UINT64_MAX); + g_assert_cmphex(input_range_end, >=, 32); g_assert_cmpint(domain_range_start, ==, 0); g_assert_cmpint(domain_range_end, ==, UINT32_MAX); g_assert_cmpint(bypass, ==, 1);
Thank you for the suggestions
Eric
PATCH v5 4/4 qemu-options.hx: Add an entry for virtio-iommu-pci and document aw-bits
In reply to Eric AugerWe are missing an entry for the virtio-iommu-pci device. Add the information on which machine it is currently supported and document the new aw-bits option.
---
v4 -> v5
- tweek the aw-bits option description according to Cédric's suggestion
--- qemu-options.hx | 8 ++++++++ 1 file changed, 8 insertions(+)
qemu-options.hx +8 -0
@@ -1172,6 +1172,14 @@ SRST Please also refer to the wiki page for general scenarios of VT-d emulation in QEMU: https://wiki.qemu.org/Features/VT-d. +``-device virtio-iommu-pci[,option=...]`` + This is only supported by ``-machine q35`` and ``-machine virt``. + It supports below options: + + ``aw-bits=val`` (val between 32 and 64, default depends on machine) + This decides the address width of IOVA address space. It defaults + to 39 bits on q35 machines and 48 bits on ARM virt machines. + ERST DEF("name", HAS_ARG, QEMU_OPTION_name,
Signature · 1 line
2.41.0
Re: [PATCH v5 4/4] qemu-options.hx: Add an entry for virtio-iommu-pci and document aw-bits
Quoted 5 lines · Eric Auger
We are missing an entry for the virtio-iommu-pci device. Add the information on which machine it is currently supported and document the new aw-bits option.
Signed-off-by Eric Auger <[email protected]>
argh forgot to add Cédric R-b collected on v4
Michael, please apply it when/if you decide to pull it
Eric
Quoted 29 lines
---
v4 -> v5
- tweek the aw-bits option description according to Cédric's suggestion--- qemu-options.hx | 8 ++++++++ 1 file changed, 8 insertions(+)qemu-options.hx +8
-0@@ -1172,6 +1172,14 @@ SRST Please also refer to the wiki page for general scenarios of VT-d emulation in QEMU: https://wiki.qemu.org/Features/VT-d. +``-device virtio-iommu-pci[,option=...]`` + This is only supported by ``-machine q35`` and ``-machine virt``. + It supports below options: + + ``aw-bits=val`` (val between 32 and 64, default depends on machine) + This decides the address width of IOVA address space. It defaults + to 39 bits on q35 machines and 48 bits on ARM virt machines. + ERST DEF("name", HAS_ARG, QEMU_OPTION_name,