hw/arm: Enable 'nested' SMMU in virt, sbsa-ref
cover hw/arm: Enable 'nested' SMMU in virt, sbsa-ref
This patchset enables support for nested (two stage) translations in the SMMU in the virt and sbsa-ref boards.
Patch 1 is Cornelia's compat-machine machinery patch, which we need to make this change only happen for virt-9.2 and later; patch 2 is a trivial "missing comment update" change; patches 3 and 4 are the board changes.
Enabling nested support should be transparent to guests, which will only enable stage 2 if they actually want it.
thanks
-- PMM
Cornelia Huck (1):
hw: add compat machines for 9.2
Peter Maydell (3):
hw/arm/smmuv3: Update comment documenting "stage" property hw/arm/virt: Default to two-stage SMMU from virt-9.2 hw/arm/sbsa-ref: Use two-stage SMMU
include/hw/arm/virt.h | 1 + include/hw/boards.h | 3 +++ include/hw/i386/pc.h | 3 +++ hw/arm/sbsa-ref.c | 1 + hw/arm/smmuv3.c | 1 + hw/arm/virt.c | 19 +++++++++++++++++-- hw/core/machine.c | 3 +++ hw/i386/pc.c | 3 +++ hw/i386/pc_piix.c | 15 ++++++++++++--- hw/i386/pc_q35.c | 13 +++++++++++-- hw/m68k/virt.c | 11 +++++++++-- hw/ppc/spapr.c | 17 ++++++++++++++--- hw/s390x/s390-virtio-ccw.c | 14 +++++++++++++- 13 files changed, 91 insertions(+), 13 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/4 hw: add compat machines for 9.2
From: Cornelia Huck <[email protected]>
Add 9.2 machine types for arm/i440fx/m68k/q35/s390x/spapr.
Message-id: [email protected]
--- include/hw/boards.h | 3 +++ include/hw/i386/pc.h | 3 +++ hw/arm/virt.c | 11 +++++++++-- hw/core/machine.c | 3 +++ hw/i386/pc.c | 3 +++ hw/i386/pc_piix.c | 15 ++++++++++++--- hw/i386/pc_q35.c | 13 +++++++++++-- hw/m68k/virt.c | 11 +++++++++-- hw/ppc/spapr.c | 17 ++++++++++++++--- hw/s390x/s390-virtio-ccw.c | 14 +++++++++++++- 10 files changed, 80 insertions(+), 13 deletions(-)
include/hw/boards.h +3 -0
@@ -732,6 +732,9 @@ struct MachineState { } \ type_init(machine_initfn##_register_types) +extern GlobalProperty hw_compat_9_1[]; +extern const size_t hw_compat_9_1_len; +extern GlobalProperty hw_compat_9_0[];extern const size_t hw_compat_9_0_len;
include/hw/i386/pc.h +3 -0
@@ -215,6 +215,9 @@ void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size);/* sgx.c */ void pc_machine_init_sgx_epc (PCMachineState *pcms); +extern GlobalProperty pc_compat_9_1[]; +extern const size_t pc_compat_9_1_len; +extern GlobalProperty pc_compat_9_0[];extern const size_t pc_compat_9_0_len;
hw/arm/virt.c +9 -2
@@ -3301,10 +3301,17 @@ static void machvirt_machine_init(void) }type_init (machvirt_machine_init); -static void virt_machine_9_1_options (MachineClass *mc) +static void virt_machine_9_2_options (MachineClass *mc) { } -DEFINE_VIRT_MACHINE_AS_LATEST(9, 1) +DEFINE_VIRT_MACHINE_AS_LATEST(9, 2) + +static void virt_machine_9_1_options (MachineClass *mc) +{ +virt_machine_9_2_options (mc); +compat_props_add (mc->compat_props, hw_compat_9_1, hw_compat_9_1_len); +} +DEFINE_VIRT_MACHINE(9, 1)static void virt_machine_9_0_options (MachineClass *mc) {
hw/core/machine.c +3 -0
@@ -34,6 +34,9 @@#include "hw/virtio/virtio-iommu.h" #include "audio/audio.h" +GlobalProperty hw_compat_9_1[] = {}; +const size_t hw_compat_9_1_len =G_N_ELEMENTS (hw_compat_9_1); +GlobalProperty hw_compat_9_0[] = { {"arm-cpu" ,"backcompat-cntfrq" ,"true" }, {"scsi-hd" ,"migrate-emulated-scsi-request" ,"false" },
hw/i386/pc.c +3 -0
@@ -79,6 +79,9 @@ { "qemu64-" TYPE_X86_CPU, "model-id", "QEMU Virtual CPU version " v, },\ { "athlon-" TYPE_X86_CPU, "model-id", "QEMU Virtual CPU version " v, }, +GlobalProperty pc_compat_9_1[] = {}; +const size_t pc_compat_9_1_len =G_N_ELEMENTS (pc_compat_9_1); +GlobalProperty pc_compat_9_0[] = { {TYPE_X86_CPU ,"x-amd-topoext-features-only" ,"false" }, { TYPE_X86_CPU, "x-l1-cache-per-thread", "false" },
hw/i386/pc_piix.c +12 -3
@@ -479,13 +479,24 @@ static void pc_i440fx_machine_options(MachineClass *m) "Use a different south bridge than PIIX3"); } -static void pc_i440fx_machine_9_1_options (MachineClass *m) +static void pc_i440fx_machine_9_2_options (MachineClass *m) {pc_i440fx_machine_options (m); m->alias ="pc" ; m->is_default = true; } +DEFINE_I440FX_MACHINE (9 ,2 ); + +static void pc_i440fx_machine_9_1_options (MachineClass *m) +{ +pc_i440fx_machine_9_2_options (m); + m->alias =NULL ; + m->is_default = false; +compat_props_add (m->compat_props, hw_compat_9_1, hw_compat_9_1_len); +compat_props_add (m->compat_props, pc_compat_9_1, pc_compat_9_1_len); +} +DEFINE_I440FX_MACHINE (9 ,1 );static void pc_i440fx_machine_9_0_options (MachineClass *m)
@@ -493,8 +504,6 @@ static void pc_i440fx_machine_9_0_options(MachineClass *m)PCMachineClass *pcmc =PC_MACHINE_CLASS (m);pc_i440fx_machine_9_1_options (m); - m->alias =NULL ; - m->is_default = false; m->smbios_memory_device_size =16 * GiB;compat_props_add (m->compat_props, hw_compat_9_0, hw_compat_9_0_len);
hw/i386/pc_q35.c +11 -2
@@ -361,19 +361,28 @@ static void pc_q35_machine_options(MachineClass *m) pc_q35_compat_defaults, pc_q35_compat_defaults_len); } -static void pc_q35_machine_9_1_options (MachineClass *m) +static void pc_q35_machine_9_2_options (MachineClass *m) {pc_q35_machine_options (m); m->alias ="q35" ; } +DEFINE_Q35_MACHINE (9 ,2 ); + +static void pc_q35_machine_9_1_options (MachineClass *m) +{ +pc_q35_machine_9_2_options (m); + m->alias =NULL ; +compat_props_add (m->compat_props, hw_compat_9_1, hw_compat_9_1_len); +compat_props_add (m->compat_props, pc_compat_9_1, pc_compat_9_1_len); +} +DEFINE_Q35_MACHINE (9 ,1 );static void pc_q35_machine_9_0_options (MachineClass *m) {PCMachineClass *pcmc =PC_MACHINE_CLASS (m);pc_q35_machine_9_1_options (m); - m->alias =NULL ; m->smbios_memory_device_size =16 * GiB;compat_props_add (m->compat_props, hw_compat_9_0, hw_compat_9_0_len);compat_props_add (m->compat_props, pc_compat_9_0, pc_compat_9_0_len);
hw/m68k/virt.c +9 -2
@@ -366,10 +366,17 @@ type_init(virt_machine_register_types)#define DEFINE_VIRT_MACHINE (major, minor) \ DEFINE_VIRT_MACHINE_IMPL(false, major, minor) -static void virt_machine_9_1_options (MachineClass *mc) +static void virt_machine_9_2_options (MachineClass *mc) { } -DEFINE_VIRT_MACHINE_AS_LATEST(9, 1) +DEFINE_VIRT_MACHINE_AS_LATEST(9, 2) + +static void virt_machine_9_1_options (MachineClass *mc) +{ +virt_machine_9_2_options (mc); +compat_props_add (mc->compat_props, hw_compat_9_1, hw_compat_9_1_len); +} +DEFINE_VIRT_MACHINE(9, 1)static void virt_machine_9_0_options (MachineClass *mc) {
hw/ppc/spapr.c +14 -3
@@ -4838,14 +4838,25 @@ static void spapr_machine_latest_class_options(MachineClass *mc)DEFINE_SPAPR_MACHINE_IMPL (false, major, minor, _, tag)/* -* pseries-9.1 +* pseries-9.2 */ -static void spapr_machine_9_1_class_options (MachineClass *mc) +static void spapr_machine_9_2_class_options (MachineClass *mc) {/* Defaults for the latest behaviour inherited from the base class */ } -DEFINE_SPAPR_MACHINE_AS_LATEST (9 ,1 ); +DEFINE_SPAPR_MACHINE_AS_LATEST (9 ,2 ); + +/* +* pseries-9.1 +*/ +static void spapr_machine_9_1_class_options (MachineClass *mc) +{ +spapr_machine_9_2_class_options (mc); +compat_props_add (mc->compat_props, hw_compat_9_1, hw_compat_9_1_len); +} + +DEFINE_SPAPR_MACHINE (9 ,1 );/* * pseries-9.0
hw/s390x/s390-virtio-ccw.c +13 -1
@@ -871,14 +871,26 @@ static const TypeInfo ccw_machine_info = { DEFINE_CCW_MACHINE_IMPL(false, major, minor) +static void ccw_machine_9_2_instance_options (MachineState *machine) +{ +} + +static void ccw_machine_9_2_class_options (MachineClass *mc) +{ +} +DEFINE_CCW_MACHINE_AS_LATEST (9 ,2 ); +static void ccw_machine_9_1_instance_options (MachineState *machine) { +ccw_machine_9_2_instance_options (machine); }static void ccw_machine_9_1_class_options (MachineClass *mc) { +ccw_machine_9_2_class_options (mc); +compat_props_add (mc->compat_props, hw_compat_9_1, hw_compat_9_1_len); } -DEFINE_CCW_MACHINE_AS_LATEST (9 ,1 ); +DEFINE_CCW_MACHINE (9 ,1 );static void ccw_machine_9_0_instance_options (MachineState *machine) {
Signature · 1 line
2.34.1
PATCH 2/4 hw/arm/smmuv3: Update comment documenting "stage" property
In reply to Peter MaydellWhen we added support for nested (stage 1 + stage 2) translation to the SMMU in commit 58377c363291d we forgot to update the comment that documents the valid values of the "stage" property. Add the new "nested" value to it.
--- hw/arm/smmuv3.c | 1 + 1 file changed, 1 insertion(+)
hw/arm/smmuv3.c +1 -0
@@ -1981,6 +1981,7 @@ static Property smmuv3_properties[] = {* Stages of translation advertised. * "1": Stage 1 * "2": Stage 2 +* "nested": Both stage 1 and stage 2 * Defaults to stage 1 */ DEFINE_PROP_STRING("stage", SMMUv3State, stage),
Signature · 1 line
2.34.1
PATCH 3/4 hw/arm/virt: Default to two-stage SMMU from virt-9.2
In reply to Peter MaydellNow that our SMMU model supports enabling both stages of translation at once, we can enable this in the virt board. This is no change in behaviour for guests, because if they simply ignore stage 2 and never configure it then it has no effect. For the usual backwards compatibility reasons we enable this only for machine types starting with 9.2.
(Note that the SMMU is disabled by default on the virt board and is only created if the user passes the 'iommu=smmuv3' machine option.)
--- include/hw/arm/virt.h | 1 + hw/arm/virt.c | 8 ++++++++ 2 files changed, 9 insertions(+)
include/hw/arm/virt.h +1 -0
@@ -134,6 +134,7 @@ struct VirtMachineClass {bool no_cpu_topology;bool no_tcg_lpa2;bool no_ns_el2_virt_timer_irq; +bool no_nested_smmu; };struct VirtMachineState {
hw/arm/virt.c +8 -0
@@ -1408,6 +1408,7 @@ static void create_pcie_irq_map(const MachineState *ms,static void create_smmu (const VirtMachineState *vms,PCIBus *bus) { +VirtMachineClass *vmc =VIRT_MACHINE_GET_CLASS (vms);char *node;const char compat[] ="arm,smmu-v3" ;int irq = vms->irqmap[VIRT_SMMU ];
@@ -1424,6 +1425,9 @@ static void create_smmu(const VirtMachineState *vms, dev =qdev_new (TYPE_ARM_SMMUV3 ); +if (!vmc->no_nested_smmu) { +object_property_set_str (OBJECT (dev),"stage" ,"nested" , &error_fatal); + }object_property_set_link (OBJECT (dev),"primary-bus" ,OBJECT (bus), &error_abort);sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal);
@@ -3308,8 +3312,12 @@ DEFINE_VIRT_MACHINE_AS_LATEST(9, 2)static void virt_machine_9_1_options (MachineClass *mc) { +VirtMachineClass *vmc =VIRT_MACHINE_CLASS (OBJECT_CLASS (mc)); +virt_machine_9_2_options (mc);compat_props_add (mc->compat_props, hw_compat_9_1, hw_compat_9_1_len); +/* 9.1 and earlier have only a stage-1 SMMU, not a nested s1+2 one */ + vmc->no_nested_smmu = true; }DEFINE_VIRT_MACHINE (9 ,1 )
Signature · 1 line
2.34.1
PATCH 4/4 hw/arm/sbsa-ref: Use two-stage SMMU
In reply to Peter MaydellNow that our SMMU model supports enabling both stages of translation at once, we can enable this in the sbsa-ref board. Existing guest code that only programs stage 1 and doesn't care about stage 2 should continue to run with the same behaviour, but guests that do want to do nested SMMU configurations can now do so.
--- hw/arm/sbsa-ref.c | 1 + 1 file changed, 1 insertion(+)
hw/arm/sbsa-ref.c +1 -0
@@ -621,6 +621,7 @@ static void create_smmu(const SBSAMachineState *sms, PCIBus *bus) dev =qdev_new (TYPE_ARM_SMMUV3 ); +object_property_set_str (OBJECT (dev),"stage" ,"nested" , &error_abort);object_property_set_link (OBJECT (dev),"primary-bus" ,OBJECT (bus), &error_abort);sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal);
Signature · 1 line
2.34.1
Re: [PATCH 4/4] hw/arm/sbsa-ref: Use two-stage SMMU
W dniu 16.08.2024 o 18:13, Peter Maydell pisze:
Quoted 7 lines
Now that our SMMU model supports enabling both stages of translation at once, we can enable this in the sbsa-ref board. Existing guest code that only programs stage 1 and doesn't care about stage 2 should continue to run with the same behaviour, but guests that do want to do nested SMMU configurations can now do so.
Signed-off-by Peter Maydell <[email protected]>
Yay! Another step in getting (S)BSA ACS pass done:
Operating System View:
304 : Check SMMU S-EL2 & stage1 support : Result: PASS
Hypervisor View:
352 : Check SMMU S-EL2 & stage2 support : Result: PASS
Quoted 16 lines
--- hw/arm/sbsa-ref.c | 1 + 1 file changed, 1 insertion(+)hw/arm/sbsa-ref.c +1
-0@@ -621,6 +621,7 @@ static void create_smmu(const SBSAMachineState *sms, PCIBus *bus) dev =qdev_new (TYPE_ARM_SMMUV3 ); +object_property_set_str (OBJECT (dev),"stage" ,"nested" , &error_abort);object_property_set_link (OBJECT (dev),"primary-bus" ,OBJECT (bus), &error_abort);sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal);
Hi Peter,
Quoted 8 lines · Peter Maydell
This patchset enables support for nested (two stage) translations in the SMMU in the virt and sbsa-ref boards.
Patch 1 is Cornelia's compat-machine machinery patch, which we need to make this change only happen for virt-9.2 and later; patch 2 is a trivial "missing comment update" change; patches 3 and 4 are the board changes.
Quoted 5 lines
Enabling nested support should be transparent to guests, which will only enable stage 2 if they actually want it.
thanks
-- PMM
For the whole series:
Thanks
Eric
Quoted 24 lines
Cornelia Huck (1):
hw: add compat machines for 9.2Peter Maydell (3):
hw/arm/smmuv3: Update comment documenting "stage" property hw/arm/virt: Default to two-stage SMMU from virt-9.2 hw/arm/sbsa-ref: Use two-stage SMMUinclude/hw/arm/virt.h | 1 + include/hw/boards.h | 3 +++ include/hw/i386/pc.h | 3 +++ hw/arm/sbsa-ref.c | 1 + hw/arm/smmuv3.c | 1 + hw/arm/virt.c | 19 +++++++++++++++++-- hw/core/machine.c | 3 +++ hw/i386/pc.c | 3 +++ hw/i386/pc_piix.c | 15 ++++++++++++--- hw/i386/pc_q35.c | 13 +++++++++++-- hw/m68k/virt.c | 11 +++++++++-- hw/ppc/spapr.c | 17 ++++++++++++++--- hw/s390x/s390-virtio-ccw.c | 14 +++++++++++++- 13 files changed, 91 insertions(+), 13 deletions(-)