Message ID | 20240307134445.92296-8-eric.auger@redhat.com |
---|---|
State | New |
Headers | show |
Series | VIRTIO-IOMMU: Introduce aw-bits and granule options | expand |
>-----Original Message----- >From: Eric Auger <eric.auger@redhat.com> >Subject: [PATCH v8 7/9] hw/i386/q35: Set virtio-iommu aw-bits default >value to 39 > >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. > >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. > >Signed-off-by: Eric Auger <eric.auger@redhat.com> Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com> Thanks Zhenzhong > >--- > >v6 -> v7: >- use static pc_q35_compat_defaults >- remove spurious header addition >- s/32/UINT32_MAX in the qtest > >v5 -> v6: >- split pc/arm settings > >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/core/machine.c | 1 + > hw/i386/pc_q35.c | 9 +++++++++ > tests/qtest/virtio-iommu-test.c | 2 +- > 3 files changed, 11 insertions(+), 1 deletion(-) > >diff --git a/hw/core/machine.c b/hw/core/machine.c >index 6bd09d4592..4b89172d1c 100644 >--- a/hw/core/machine.c >+++ b/hw/core/machine.c >@@ -35,6 +35,7 @@ > > GlobalProperty hw_compat_8_2[] = { > { TYPE_VIRTIO_IOMMU_PCI, "granule", "4k" }, >+ { TYPE_VIRTIO_IOMMU_PCI, "aw-bits", "64" }, > }; > const size_t hw_compat_8_2_len = G_N_ELEMENTS(hw_compat_8_2); > >diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c >index 45a4102e75..1e7464d39a 100644 >--- a/hw/i386/pc_q35.c >+++ b/hw/i386/pc_q35.c >@@ -45,6 +45,7 @@ > #include "hw/i386/pc.h" > #include "hw/i386/amd_iommu.h" > #include "hw/i386/intel_iommu.h" >+#include "hw/virtio/virtio-iommu.h" > #include "hw/display/ramfb.h" > #include "hw/ide/pci.h" > #include "hw/ide/ahci-pci.h" >@@ -63,6 +64,12 @@ > /* ICH9 AHCI has 6 ports */ > #define MAX_SATA_PORTS 6 > >+static GlobalProperty pc_q35_compat_defaults[] = { >+ { TYPE_VIRTIO_IOMMU_PCI, "aw-bits", "39" }, >+}; >+static const size_t pc_q35_compat_defaults_len = >+ G_N_ELEMENTS(pc_q35_compat_defaults); >+ > struct ehci_companions { > const char *name; > int func; >@@ -356,6 +363,8 @@ static void pc_q35_machine_options(MachineClass >*m) > machine_class_allow_dynamic_sysbus_dev(m, >TYPE_INTEL_IOMMU_DEVICE); > machine_class_allow_dynamic_sysbus_dev(m, TYPE_RAMFB_DEVICE); > machine_class_allow_dynamic_sysbus_dev(m, TYPE_VMBUS_BRIDGE); >+ compat_props_add(m->compat_props, >+ pc_q35_compat_defaults, pc_q35_compat_defaults_len); > } > > static void pc_q35_9_0_machine_options(MachineClass *m) >diff --git a/tests/qtest/virtio-iommu-test.c b/tests/qtest/virtio-iommu-test.c >index 068e7a9e6c..afb225971d 100644 >--- a/tests/qtest/virtio-iommu-test.c >+++ b/tests/qtest/virtio-iommu-test.c >@@ -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, >=, UINT32_MAX); > g_assert_cmpint(domain_range_start, ==, 0); > g_assert_cmpint(domain_range_end, ==, UINT32_MAX); > g_assert_cmpint(bypass, ==, 1); >-- >2.41.0
diff --git a/hw/core/machine.c b/hw/core/machine.c index 6bd09d4592..4b89172d1c 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -35,6 +35,7 @@ GlobalProperty hw_compat_8_2[] = { { TYPE_VIRTIO_IOMMU_PCI, "granule", "4k" }, + { TYPE_VIRTIO_IOMMU_PCI, "aw-bits", "64" }, }; const size_t hw_compat_8_2_len = G_N_ELEMENTS(hw_compat_8_2); diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 45a4102e75..1e7464d39a 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -45,6 +45,7 @@ #include "hw/i386/pc.h" #include "hw/i386/amd_iommu.h" #include "hw/i386/intel_iommu.h" +#include "hw/virtio/virtio-iommu.h" #include "hw/display/ramfb.h" #include "hw/ide/pci.h" #include "hw/ide/ahci-pci.h" @@ -63,6 +64,12 @@ /* ICH9 AHCI has 6 ports */ #define MAX_SATA_PORTS 6 +static GlobalProperty pc_q35_compat_defaults[] = { + { TYPE_VIRTIO_IOMMU_PCI, "aw-bits", "39" }, +}; +static const size_t pc_q35_compat_defaults_len = + G_N_ELEMENTS(pc_q35_compat_defaults); + struct ehci_companions { const char *name; int func; @@ -356,6 +363,8 @@ static void pc_q35_machine_options(MachineClass *m) machine_class_allow_dynamic_sysbus_dev(m, TYPE_INTEL_IOMMU_DEVICE); machine_class_allow_dynamic_sysbus_dev(m, TYPE_RAMFB_DEVICE); machine_class_allow_dynamic_sysbus_dev(m, TYPE_VMBUS_BRIDGE); + compat_props_add(m->compat_props, + pc_q35_compat_defaults, pc_q35_compat_defaults_len); } static void pc_q35_9_0_machine_options(MachineClass *m) diff --git a/tests/qtest/virtio-iommu-test.c b/tests/qtest/virtio-iommu-test.c index 068e7a9e6c..afb225971d 100644 --- a/tests/qtest/virtio-iommu-test.c +++ b/tests/qtest/virtio-iommu-test.c @@ -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, >=, UINT32_MAX); g_assert_cmpint(domain_range_start, ==, 0); g_assert_cmpint(domain_range_end, ==, UINT32_MAX); g_assert_cmpint(bypass, ==, 1);
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. 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. Signed-off-by: Eric Auger <eric.auger@redhat.com> --- v6 -> v7: - use static pc_q35_compat_defaults - remove spurious header addition - s/32/UINT32_MAX in the qtest v5 -> v6: - split pc/arm settings 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/core/machine.c | 1 + hw/i386/pc_q35.c | 9 +++++++++ tests/qtest/virtio-iommu-test.c | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-)