hw/arm/virt: Deprecate 'its', introduce 'msi'
cover hw/arm/virt: Deprecate 'its', introduce 'msi'
This patchset is an RFC sketch of cleaning up the logic that we have for selecting the MSI controller, so we can add the handling for "hvf and whpx give you a GICv3 without an ITS" in a hopefully clear manner.
thanks
-- PMM
Peter Maydell (4):
hw/arm/virt: Clean up MSI controller selection logic hw/arm/virt: Don't use vms->tcg_its in create_gic() hw/arm/virt: Drop VirtMachineState::tcg_its hw/arm/virt: new "msi" property
docs/system/arm/virt.rst | 21 +++++++- hw/arm/virt.c | 108 +++++++++++++++++++++++++++++++++------ include/hw/arm/virt.h | 2 +- 3 files changed, 114 insertions(+), 17 deletions(-)
Signature · 1 line
2.47.3
RFC PATCH 1/4 hw/arm/virt: Clean up MSI controller selection logic
The virt board might have multiple different ways to handle MSI
interrupts: via an ITS, via the GICv2M device, or not at all. The logic to select which of these we use is confusing because it is controlled by a mix of versioned-board compatibility flags, board option flags, and open-coded logic inside the create_gic() and create_its() functions.
Currently we set VirtMachineState::msi_controller as the very last part of this, inside create_its() or create_gicv2m(). This field is then used only in the hotplug pre-plug callback function.
As a first step in making this clearer to understand, move the logic into a single finalize_msi_controller() function, which sets VirtMachineState::msi_controller. The actual machine creation code can then look only at that field. (This is a parallel to what we do with the GIC, where finalize_gic_version() sets the VirtMachineState::gic_version field.)
--- hw/arm/virt.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-)
hw/arm/virt.c +27 -11
@@ -738,13 +738,6 @@ static void create_its(VirtMachineState *vms)DeviceState *dev;assert (vms->its); -if (!kvm_irqchip_in_kernel () && !vms->tcg_its) { -/* -* Do nothing if ITS is neither supported by the host nor emulated by -* the machine. -*/ -return ; - } dev =qdev_new (its_class_name ());
@@ -754,7 +747,6 @@ static void create_its(VirtMachineState *vms)sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , vms->memmap[VIRT_GIC_ITS ].base);fdt_add_its_gic_node (vms); - vms->msi_controller =VIRT_MSI_CTRL_ITS ; }static void create_v2m (VirtMachineState *vms)
@@ -775,7 +767,6 @@ static void create_v2m(VirtMachineState *vms) }fdt_add_v2m_gic_node (vms); - vms->msi_controller =VIRT_MSI_CTRL_GICV2M ; }/*
@@ -957,10 +948,15 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem)fdt_add_gic_node (vms); -if (vms->gic_version !=VIRT_GIC_VERSION_2 && vms->its) { +switch (vms->msi_controller) { +case VIRT_MSI_CTRL_NONE : +break ; +case VIRT_MSI_CTRL_ITS :create_its (vms); - }else if (vms->gic_version ==VIRT_GIC_VERSION_2 ) { +break ; +case VIRT_MSI_CTRL_GICV2M :create_v2m (vms); +break ; } }
@@ -2079,6 +2075,24 @@ static VirtGICType finalize_gic_version_do(const char *accel_name,return gic_version; } +static void finalize_msi_controller (VirtMachineState *vms) +{ +/* +* Determine the final msi_controller according to +* the relevant user settings and compat data. Called +* after finalizing the GIC version. +*/ +if (vms->gic_version !=VIRT_GIC_VERSION_2 && vms->its) { +if (!kvm_irqchip_in_kernel () && !vms->tcg_its) { + vms->msi_controller =VIRT_MSI_CTRL_NONE ; + }else { + vms->msi_controller =VIRT_MSI_CTRL_ITS ; + } + }else if (vms->gic_version ==VIRT_GIC_VERSION_2 ) { + vms->msi_controller =VIRT_MSI_CTRL_GICV2M ; + } +} +/* * finalize_gic_version - Determines the final gic_version * according to the gic-version property
@@ -2251,6 +2265,8 @@ static void machvirt_init(MachineState *machine)* KVM is not available yet */ finalize_gic_version (vms); +/* MSI controller type depends on GIC version */ +finalize_msi_controller (vms);if (vms->secure) {/*
Signature · 1 line
2.47.3
Re: [RFC PATCH 1/4] hw/arm/virt: Clean up MSI controller selection logic
Quoted 18 lines · Peter Maydell
The virt board might have multiple different ways to handle MSI
interrupts: via an ITS, via the GICv2M device, or not at all. The logic to select which of these we use is confusing because it is controlled by a mix of versioned-board compatibility flags, board option flags, and open-coded logic inside thecreate_gic()andcreate_its()functions.Currently we set
VirtMachineState::msi_controlleras the very last part of this, insidecreate_its()orcreate_gicv2m(). This field is then used only in the hotplug pre-plug callback function.As a first step in making this clearer to understand, move the logic into a single
finalize_msi_controller()function, which setsVirtMachineState::msi_controller. The actual machine creation code can then look only at that field. (This is a parallel to what we do with the GIC, wherefinalize_gic_version()sets theVirtMachineState::gic_versionfield.)
Quoted 4 lines
Signed-off-by Peter Maydell <[email protected]>--- hw/arm/virt.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-)
Re: [RFC PATCH 1/4] hw/arm/virt: Clean up MSI controller selection logic
In reply to Peter MaydellQuoted 15 lines · Peter Maydell
The virt board might have multiple different ways to handle MSI
interrupts: via an ITS, via the GICv2M device, or not at all. The logic to select which of these we use is confusing because it is controlled by a mix of versioned-board compatibility flags, board option flags, and open-coded logic inside thecreate_gic()andcreate_its()functions.Currently we set
VirtMachineState::msi_controlleras the very last part of this, insidecreate_its()orcreate_gicv2m(). This field is then used only in the hotplug pre-plug callback function.
Quoted 8 lines
As a first step in making this clearer to understand, move the logic into a single
finalize_msi_controller()function, which setsVirtMachineState::msi_controller. The actual machine creation code can then look only at that field. (This is a parallel to what we do with the GIC, wherefinalize_gic_version()sets theVirtMachineState::gic_versionfield.)Signed-off-by Peter Maydell <[email protected]>
Hello,
Did put a separate implementation of a chunk of this patch as part of https://patchew.org/QEMU/[email protected]/[email protected]/
Thank you,
Quoted 30 lines
---
hw/arm/virt.c| 38 +++++++++++++++++++++++++++-----------1 file changed, 27 insertions(+), 11 deletions(-)hw/arm/virt.c +0
-8@@ -738,13 +738,6 @@ static void create_its(VirtMachineState *vms)DeviceState *dev;assert (vms->its); -if (!kvm_irqchip_in_kernel () && !vms->tcg_its) { -/* -* Do nothing if ITS is neither supported by the host nor emulated by -* the machine. -*/ -return ; - } dev =qdev_new (its_class_name ());@@ -754,7 +747,6 @@ static void create_its(VirtMachineState *vms)sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , vms->memmap[VIRT_GIC_ITS ].base);fdt_add_its_gic_node (vms); - vms->msi_controller =VIRT_MSI_CTRL_ITS ; }static void create_v2m (VirtMachineState *vms)
hw/arm/virt.c static void create_v2m(VirtMachineState *vms) · line 771
Quoted 6 lines
hw/arm/virt.c +0
-1@@ -775,7 +767,6 @@ static void create_v2m(VirtMachineState *vms) }fdt_add_v2m_gic_node (vms); - vms->msi_controller =VIRT_MSI_CTRL_GICV2M ; }
Parts above still apply even after that patch.
Quoted 57 lines
hw/arm/virt.c +27
-2/* @@ -957,10 +948,15 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem)fdt_add_gic_node (vms); -if (vms->gic_version !=VIRT_GIC_VERSION_2 && vms->its) { +switch (vms->msi_controller) { +case VIRT_MSI_CTRL_NONE : +break ; +case VIRT_MSI_CTRL_ITS :create_its (vms); - }else if (vms->gic_version ==VIRT_GIC_VERSION_2 ) { +break ; +case VIRT_MSI_CTRL_GICV2M :create_v2m (vms); +break ; } }@@ -2079,6 +2075,24 @@ static VirtGICType finalize_gic_version_do(const char *accel_name,return gic_version; } +static void finalize_msi_controller (VirtMachineState *vms) +{ +/* +* Determine the final msi_controller according to +* the relevant user settings and compat data. Called +* after finalizing the GIC version. +*/ +if (vms->gic_version !=VIRT_GIC_VERSION_2 && vms->its) { +if (!kvm_irqchip_in_kernel () && !vms->tcg_its) { + vms->msi_controller =VIRT_MSI_CTRL_NONE ; + }else { + vms->msi_controller =VIRT_MSI_CTRL_ITS ; + } + }else if (vms->gic_version ==VIRT_GIC_VERSION_2 ) { + vms->msi_controller =VIRT_MSI_CTRL_GICV2M ; + } +} +/* * finalize_gic_version - Determines the final gic_version * according to the gic-version property @@ -2251,6 +2265,8 @@ static void machvirt_init(MachineState *machine)* KVM is not available yet */ finalize_gic_version (vms); +/* MSI controller type depends on GIC version */ +finalize_msi_controller (vms);if (vms->secure) {/* Signature · 1 line
2.47.3
RFC PATCH 2/4 hw/arm/virt: Don't use vms->tcg_its in create_gic()
In reply to Peter MaydellThe create_gic() function needs to know whether the GIC has a TCG ITS attached, as it should set the "sysmem" and "has-lpi" properties of the GICv3 only in that case. Currently it does this with
(!kvm_irqchip_in_kernel() && vms->tcg_its)
which implicitly relies on knowing that the only case where we aren't using a KVM GIC and we don't have an ITS is where we suppressed the TCG ITS because of the board-version-compatibility no_tcg_its setting.
We can avoid direct use of vms->tcg_its now that we can identify what MSI controller we are using from the vms->msi_controller field.
This means that the only use of vms->tcg_its is in the logic in finalize_msi_controller().
--- hw/arm/virt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/virt.c +1 -1
@@ -851,7 +851,7 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem) redist_region_count);if (!kvm_irqchip_in_kernel ()) { -if (vms->tcg_its) { +if (vms->msi_controller ==VIRT_MSI_CTRL_ITS ) {object_property_set_link (OBJECT (vms->gic),"sysmem" ,OBJECT (mem), &error_fatal);qdev_prop_set_bit (vms->gic,"has-lpi" , true);
Signature · 1 line
2.47.3
Re: [RFC PATCH 2/4] hw/arm/virt: Don't use vms->tcg_its in create_gic()
Quoted 14 lines · Peter Maydell
The
create_gic()function needs to know whether the GIC has a TCG ITS attached, as it should set the "sysmem" and "has-lpi" properties of the GICv3 only in that case. Currently it does this with
(!kvm_irqchip_in_kernel() &&vms->tcg_its)
which implicitly relies on knowing that the only case where we aren't using a KVM GIC and we don't have an ITS is where we suppressed the TCG ITS because of the board-version-compatibilityno_tcg_itssetting.We can avoid direct use of
vms->tcg_itsnow that we can identify what MSI controller we are using from thevms->msi_controllerfield.
Quoted 7 lines
This means that the only use of
vms->tcg_itsis in the logic infinalize_msi_controller().Signed-off-by Peter Maydell <[email protected]>--- hw/arm/virt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Re: [RFC PATCH 2/4] hw/arm/virt: Don't use vms->tcg_its in create_gic()
In reply to Peter MaydellQuoted 43 lines · Peter Maydell
The
create_gic()function needs to know whether the GIC has a TCG ITS attached, as it should set the "sysmem" and "has-lpi" properties of the GICv3 only in that case. Currently it does this with (!kvm_irqchip_in_kernel() &&vms->tcg_its)
which implicitly relies on knowing that the only case where we aren't using a KVM GIC and we don't have an ITS is where we suppressed the TCG ITS because of the board-version-compatibilityno_tcg_itssetting.We can avoid direct use of
vms->tcg_itsnow that we can identify what MSI controller we are using from thevms->msi_controllerfield.This means that the only use of
vms->tcg_itsis in the logic infinalize_msi_controller().Signed-off-by Peter Maydell <[email protected]>---
hw/arm/virt.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)hw/arm/virt.c +1
-1@@ -851,7 +851,7 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem) redist_region_count);if (!kvm_irqchip_in_kernel ()) { -if (vms->tcg_its) { +if (vms->msi_controller ==VIRT_MSI_CTRL_ITS ) {object_property_set_link (OBJECT (vms->gic),"sysmem" ,OBJECT (mem), &error_fatal);qdev_prop_set_bit (vms->gic,"has-lpi" , true);Signature · 1 line
2.47.3
RFC PATCH 3/4 hw/arm/virt: Drop VirtMachineState::tcg_its
In reply to Peter MaydellWe now use VirtMachineState::tcg_its only in the finalize_msi_controller() function, and it is always the inverse of the VirtMachineClass::no_tcg_its class field. We can simplify to use no_tcg_its and drop the VirtMachineState field entirely.
--- hw/arm/virt.c | 6 +++--- include/hw/arm/virt.h | 1 - 2 files changed, 3 insertions(+), 4 deletions(-)
hw/arm/virt.c +3 -3
@@ -2082,8 +2082,10 @@ static void finalize_msi_controller(VirtMachineState *vms)* the relevant user settings and compat data. Called * after finalizing the GIC version. */ +VirtMachineClass *vmc =VIRT_MACHINE_GET_CLASS (vms); +if (vms->gic_version !=VIRT_GIC_VERSION_2 && vms->its) { -if (!kvm_irqchip_in_kernel () && !vms->tcg_its) { +if (!kvm_irqchip_in_kernel () && vmc->no_tcg_its) { vms->msi_controller =VIRT_MSI_CTRL_NONE ; }else { vms->msi_controller =VIRT_MSI_CTRL_ITS ;
@@ -3511,8 +3513,6 @@ static void virt_instance_init(Object *obj)/* Default allows ITS instantiation */ vms->its = true; -/* Allow ITS emulation if the machine version supports it */ - vms->tcg_its = !vmc->no_tcg_its;/* Default disallows iommu instantiation */ vms->iommu =VIRT_IOMMU_NONE ;
include/hw/arm/virt.h +0 -1
@@ -147,7 +147,6 @@ struct VirtMachineState {bool highmem_mmio;bool highmem_redists;bool its; -bool tcg_its;bool virt;bool ras;bool mte;
Signature · 1 line
2.47.3
Re: [RFC PATCH 3/4] hw/arm/virt: Drop VirtMachineState::tcg_its
Quoted 10 lines · Peter Maydell
We now use
VirtMachineState::tcg_itsonly in thefinalize_msi_controller()function, and it is always the inverse of theVirtMachineClass::no_tcg_itsclass field. We can simplify to useno_tcg_itsand drop the VirtMachineState field entirely.Signed-off-by Peter Maydell <[email protected]>--- hw/arm/virt.c | 6 +++--- include/hw/arm/virt.h | 1 - 2 files changed, 3 insertions(+), 4 deletions(-)
RFC PATCH 4/4 hw/arm/virt: new "msi" property
In reply to Peter MaydellThe virt board currently only supports either a GICv2 with a possible GICv2m for handling MSI interrupts, or else a GICv3 with a possible ITS for handling MSI interrupts. There is one board property, which lets you say "its=(off|on)" and controls only whether there is an ITS or not.
This is awkward for macOS HVF, where you get a GICv3 without ITS and MSI handling needs a GICv2m.
Create a new board property "msi" which gives the user clearer control over how MSI interrupts are handled:
- msi=its : create an ITS
- msi=gicv2m : create a GICv2m
- msi=off : do not create any MSI handling device
- msi=auto : create the best MSI handling device available for the GIC version and accelerator
The default is 'auto'.
The existing 'its' property becomes a deprecated property kept for compatibility. Existing users of "its=on" should prefer "msi=auto"; users of "its=off" should use "msi=off".
The backwards compatibility cases we need to support are:
(1) TCG, virt-6.1 and earlier: no_tcg_its is set
-- you can have a gicv2 (always with a gicv2m)
-- if you specify gic-version=3 you get a GICv3 without ITS
(2) TCG, virt-6.2 and later:
-- gic-version=2 still has gicv2m
-- gic-version=3 by default gives you an ITS; if you also
say its=off you get GICv3 with no ITS
-- there is no case where we provide a GICv3 and are
unable to provide an ITS for it
(3) KVM (any version):
-- gic-version=2 has a gicv2m
-- gic-version=3 gives you an ITS by default; its=off
will remove it
-- there is no case where we provide a GICv3 and are
unable to provide an ITS for it
(4) HVF:
-- only gic-version=2 works, you get a gicv2m
--- docs/system/arm/virt.rst | 21 ++++++++++++- hw/arm/virt.c | 64 +++++++++++++++++++++++++++++++++++++++- include/hw/arm/virt.h | 1 + 3 files changed, 84 insertions(+), 2 deletions(-)
docs/system/arm/virt.rst +20 -1
@@ -167,9 +167,28 @@ gic-version with TCG this is currently ``3`` if ``virtualization`` is ``off`` and ``4`` if ``virtualization`` is ``on``, but this may change in future) +msi + Specify the MSI controller to use to handle MSI and MSI-X interrupts + from PCI devices. Valid values are: + + ``its`` + ITS, which can be used with a GICv3 or better. + ``gicv2m`` + The GICv2m; this is typically used with a GICv2, but it is possible + to use it with a GICv3. + ``none`` + Do not provide any MSI controller. MSI and MSI-X interrupts will + not be supported. + ``auto`` + Pick the best available controller. This will be an ITS if the + GIC and virtualization accelerator support it, and a GICv2m if not. + This is the default. + its Set ``on``/``off`` to enable/disable ITS instantiation. The default is ``on`` - for machine types later than ``virt-2.7``. + for machine types later than ``virt-2.7``. This is a deprecated option; + instead of ``its=on`` use ``msi=its`` or ``msi=auto``, and instead of + ``its=off`` use ``msi=none``. iommu Set the IOMMU type to create for the guest. Valid values are:
hw/arm/virt.c +63 -1
106 lines not on this page · raw message
include/hw/arm/virt.h +1 -0
@@ -103,6 +103,7 @@ typedef enum VirtMSIControllerType {VIRT_MSI_CTRL_NONE ,VIRT_MSI_CTRL_GICV2M ,VIRT_MSI_CTRL_ITS , +VIRT_MSI_CTRL_NOSEL , } VirtMSIControllerType; typedef enum VirtGICType {
Signature · 1 line
2.47.3
Re: [RFC PATCH 4/4] hw/arm/virt: new "msi" property
Quoted 34 lines · Peter Maydell
The virt board currently only supports either a GICv2 with a possible GICv2m for handling MSI interrupts, or else a GICv3 with a possible ITS for handling MSI interrupts. There is one board property, which lets you say "its=(off|on)" and controls only whether there is an ITS or not.
This is awkward for macOS HVF, where you get a GICv3 without ITS and MSI handling needs a GICv2m.
Create a new board property "msi" which gives the user clearer control over how MSI interrupts are handled:
- msi=its : create an ITS
- msi=gicv2m : create a GICv2m
- msi=off : do not create any MSI handling device
- msi=auto : create the best MSI handling device available for the GIC version and acceleratorThe default is 'auto'.
The existing 'its' property becomes a deprecated property kept for compatibility. Existing users of "its=on" should prefer "msi=auto"; users of "its=off" should use "msi=off".
The backwards compatibility cases we need to support are:
(1) TCG, virt-6.1 and earlier:no_tcg_itsis set
-- you can have a gicv2 (always with a gicv2m)
-- if you specify gic-version=3 you get a GICv3 without ITS
(2) TCG, virt-6.2 and later:
-- gic-version=2 still has gicv2m
-- gic-version=3 by default gives you an ITS; if you also
say its=off you get GICv3 with no ITS
-- there is no case where we provide a GICv3 and are
unable to provide an ITS for it
Quoted 8 lines
(3) KVM (any version):
-- gic-version=2 has a gicv2m
-- gic-version=3 gives you an ITS by default; its=off
will remove it
-- there is no case where we provide a GICv3 and are
unable to provide an ITS for it
(4) HVF:
-- only gic-version=2 works, you get a gicv2m
Thanks for this verbose enumeration. I suppose you started writting that down before your first line of code :)
Quoted 16 lines
Signed-off-by Peter Maydell <[email protected]>--- docs/system/arm/virt.rst | 21 ++++++++++++- hw/arm/virt.c | 64 +++++++++++++++++++++++++++++++++++++++- include/hw/arm/virt.h | 1 + 3 files changed, 84 insertions(+), 2 deletions(-)hw/arm/virt.c +0
-0
hw/arm/virt.c static void virt_machine_class_init(ObjectClass *oc, const void *data) · line 3511
Quoted 6 lines
hw/arm/virt.c +2
-1@@ -3454,7 +3507,13 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data) virt_set_its);object_class_property_set_description (oc,"its" ,"Set on/off to enable/disable " -"ITS instantiation" ); +"ITS instantiation. Deprecated; " +"use the msi option instead" );
"use the msi= option instead"
include/hw/arm/virt.h typedef enum VirtMSIControllerType { · line 107
Quoted 10 lines
include/hw/arm/virt.h +1
-0@@ -103,6 +103,7 @@ typedef enum VirtMSIControllerType {VIRT_MSI_CTRL_NONE ,VIRT_MSI_CTRL_GICV2M ,VIRT_MSI_CTRL_ITS , +VIRT_MSI_CTRL_NOSEL , } VirtMSIControllerType;
Pre-existing, no need to expose these, we should restrict to virt.c.
Quoted 14 lines · Peter Maydell
This patchset is an RFC sketch of cleaning up the logic that we have for selecting the MSI controller, so we can add the handling for "hvf and whpx give you a GICv3 without an ITS" in a hopefully clear manner.
thanks
-- PMMPeter Maydell (4):
hw/arm/virt: Clean up MSI controller selection logic hw/arm/virt: Don't usevms->tcg_itsincreate_gic()hw/arm/virt: DropVirtMachineState::tcg_itshw/arm/virt: new "msi" property
Quoted 5 lines
docs/system/arm/virt.rst | 21 +++++++- hw/arm/virt.c | 108 +++++++++++++++++++++++++++++++++------ include/hw/arm/virt.h | 2 +- 3 files changed, 114 insertions(+), 17 deletions(-)
Maybe Mohamed could integrate this in his series, once you're happy with the result Peter.
Quoted 16 lines · Pierrick Bouvier
Quoted 14 lines · Peter Maydell
This patchset is an RFC sketch of cleaning up the logic that we have for selecting the MSI controller, so we can add the handling for "hvf and whpx give you a GICv3 without an ITS" in a hopefully clear manner.
thanks
-- PMMPeter Maydell (4):
hw/arm/virt: Clean up MSI controller selection logic hw/arm/virt: Don't usevms->tcg_itsincreate_gic()hw/arm/virt: DropVirtMachineState::tcg_itshw/arm/virt: new "msi" property
Quoted 8 lines
Quoted 5 lines
docs/system/arm/virt.rst | 21 +++++++- hw/arm/virt.c | 108 +++++++++++++++++++++++++++++++++------ include/hw/arm/virt.h | 2 +- 3 files changed, 114 insertions(+), 17 deletions(-)Maybe Mohamed could integrate this in his series, once you're happy with the result Peter.
Yes; I have the latest version of that on my to-review queue.
-- PMM