riscv: AIA userspace irqchip_split support
cover riscv: AIA userspace irqchip_split support
Hi,
This series adds AIA irqchip_split support, effective when using AIA with aia=aplic-imsic and -accel kvm,kernel-irqchip=split.
The main difference between what we currently have and irqchip_split() mode is that, when using split mode, QEMU will emulate the APLIC controller instead of using the in-kernel APLIC controller provided by KVM.
After this series this is the matrix of which interrupt controllers we're emulating based on 'virt' machine configuration and accelerator properties:
Accel Accel props AIA type APLIC-m IMSIC-m APLIC-s IMSIC-s tcg ---- aplic emul n/a emul n/a tcg ---- aplic-imsic emul emul emul emul kvm ---- aplic n/a n/a emul n/a kvm none aplic-imsic n/a n/a in-kernel in-kernel
kvm irqchip=split aplic-imsic n/a n/a emul in-kernel
Patches based on alistair/riscv-to-apply.next.
Daniel Henrique Barboza (8):
hw/intc/riscv_aplic: rename is_kvm_aia() hw/riscv/virt.c: reduce virt_use_kvm_aia() usage hw/riscv/virt.c: rename helper to virt_use_kvm_aia_aplic_imsic() target/riscv/kvm: consider irqchip_split() in aia_create() hw/riscv/virt.c, riscv_aplic.c: add 'emulated_aplic' helpers hw/intc/riscv_aplic: add kvm_msicfgaddr for split mode aplic-imsic target/riscv/kvm: remove irqchip_split() restriction
docs: update riscv/virt.rst with kernel-irqchip=split support
docs/specs/index.rst | 1 + docs/specs/riscv-aia.rst | 83 +++++++++++++++++++++++++++++++++++ docs/system/riscv/virt.rst | 7 +++ hw/intc/riscv_aplic.c | 68 ++++++++++++++++++++++------ hw/riscv/virt.c | 38 +++++++++++----- include/hw/intc/riscv_aplic.h | 8 ++++ target/riscv/kvm/kvm-cpu.c | 41 +++++++++-------- 7 files changed, 202 insertions(+), 44 deletions(-) create mode 100644 docs/specs/riscv-aia.rst
Signature · 1 line
2.45.2
PATCH 1/8 hw/intc/riscv_aplic: rename is_kvm_aia()
The helper is_kvm_aia() is checking not only for AIA, but for aplic-imsic (i.e. "aia=aplic-imsic" in 'virt' RISC-V machine) with an in-kernel chip present.
Rename it to be a bit clear what the helper is doing since we'll add more AIA helpers in the next patches.
Make the helper public because the 'virt' machine will use it as well.
--- hw/intc/riscv_aplic.c | 8 ++++---- include/hw/intc/riscv_aplic.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-)
hw/intc/riscv_aplic.c +4 -4
@@ -154,7 +154,7 @@* KVM AIA only supports APLIC MSI, fallback to QEMU emulation if we want to use * APLIC Wired. */ -static bool is_kvm_aia (bool msimode) +bool riscv_is_kvm_aia_aplic_imsic (bool msimode) {return kvm_irqchip_in_kernel () && msimode; }
@@ -853,7 +853,7 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp)uint32_t i;RISCVAPLICState *aplic =RISCV_APLIC (dev); -if (!is_kvm_aia (aplic->msimode)) { +if (!riscv_is_kvm_aia_aplic_imsic (aplic->msimode)) { aplic->bitfield_words = (aplic->num_irqs +31 ) >>5 ; aplic->sourcecfg =g_new0 (uint32_t, aplic->num_irqs); aplic->state =g_new0 (uint32_t, aplic->num_irqs);
@@ -877,7 +877,7 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp)* have IRQ lines delegated by their parent APLIC. */ if (!aplic->parent) { -if (kvm_enabled () &&is_kvm_aia (aplic->msimode)) { +if (kvm_enabled () &&riscv_is_kvm_aia_aplic_imsic (aplic->msimode)) {qdev_init_gpio_in (dev, riscv_kvm_aplic_request, aplic->num_irqs); }else {qdev_init_gpio_in (dev, riscv_aplic_request, aplic->num_irqs);
@@ -1021,7 +1021,7 @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size,sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); -if (!is_kvm_aia (msimode)) { +if (!riscv_is_kvm_aia_aplic_imsic (msimode)) {sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , addr); }
include/hw/intc/riscv_aplic.h +1 -0
@@ -71,6 +71,7 @@ struct RISCVAPLICState { };void riscv_aplic_add_child (DeviceState *parent,DeviceState *child); +bool riscv_is_kvm_aia_aplic_imsic (bool msimode); DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources,
Signature · 1 line
2.45.2
Re: [PATCH 1/8] hw/intc/riscv_aplic: rename is_kvm_aia()
Quoted 11 lines · Daniel Henrique Barboza
The helper
is_kvm_aia()is checking not only for AIA, but for aplic-imsic (i.e. "aia=aplic-imsic" in 'virt' RISC-V machine) with an in-kernel chip present.Rename it to be a bit clear what the helper is doing since we'll add more AIA helpers in the next patches.
Make the helper public because the 'virt' machine will use it as well.
Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 61 lines
--- hw/intc/riscv_aplic.c | 8 ++++---- include/hw/intc/riscv_aplic.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-)hw/intc/riscv_aplic.c +4
-4@@ -154,7 +154,7 @@* KVM AIA only supports APLIC MSI, fallback to QEMU emulation if we want to use * APLIC Wired. */ -static bool is_kvm_aia (bool msimode) +bool riscv_is_kvm_aia_aplic_imsic (bool msimode) {return kvm_irqchip_in_kernel () && msimode; }@@ -853,7 +853,7 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp)uint32_t i;RISCVAPLICState *aplic =RISCV_APLIC (dev); -if (!is_kvm_aia (aplic->msimode)) { +if (!riscv_is_kvm_aia_aplic_imsic (aplic->msimode)) { aplic->bitfield_words = (aplic->num_irqs +31 ) >>5 ; aplic->sourcecfg =g_new0 (uint32_t, aplic->num_irqs); aplic->state =g_new0 (uint32_t, aplic->num_irqs);@@ -877,7 +877,7 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp)* have IRQ lines delegated by their parent APLIC. */ if (!aplic->parent) { -if (kvm_enabled () &&is_kvm_aia (aplic->msimode)) { +if (kvm_enabled () &&riscv_is_kvm_aia_aplic_imsic (aplic->msimode)) {qdev_init_gpio_in (dev, riscv_kvm_aplic_request, aplic->num_irqs); }else {qdev_init_gpio_in (dev, riscv_aplic_request, aplic->num_irqs);@@ -1021,7 +1021,7 @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size,sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); -if (!is_kvm_aia (msimode)) { +if (!riscv_is_kvm_aia_aplic_imsic (msimode)) {sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , addr); }include/hw/intc/riscv_aplic.h +1
-1@@ -71,6 +71,7 @@ struct RISCVAPLICState { };void riscv_aplic_add_child (DeviceState *parent,DeviceState *child); +bool riscv_is_kvm_aia_aplic_imsic (bool msimode); DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources, --2.45.2
PATCH 2/8 hw/riscv/virt.c: reduce virt_use_kvm_aia() usage
In reply to Daniel Henrique BarbozaIn create_fdt_sockets() we have the following pattern:
if (kvm_enabled() && virt_use_kvm_aia(s)) {
(... do stuff ...)
} else {
(... do other stuff ...)
}
if (kvm_enabled() && virt_use_kvm_aia(s)) {
(... do more stuff ...)
} else {
(... do more other stuff)
}Do everything in a single if/else clause to reduce the usage of virt_use_kvm_aia() helper and to make the code a bit less repetitive.
--- hw/riscv/virt.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
hw/riscv/virt.c +4 -6
@@ -780,6 +780,10 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, msi_m_phandle, msi_s_phandle, phandle, &intc_phandles[0 ], xplic_phandles, ms->smp.cpus); + + *irq_mmio_phandle = xplic_phandles[0 ]; + *irq_virtio_phandle = xplic_phandles[0 ]; + *irq_pcie_phandle = xplic_phandles[0 ]; }else { phandle_pos = ms->smp.cpus;for (socket = (socket_count -1 ); socket >=0 ; socket--) {
@@ -797,13 +801,7 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, s->soc[socket].num_harts); } } - } -if (kvm_enabled () &&virt_use_kvm_aia (s)) { - *irq_mmio_phandle = xplic_phandles[0 ]; - *irq_virtio_phandle = xplic_phandles[0 ]; - *irq_pcie_phandle = xplic_phandles[0 ]; - }else {for (socket =0 ; socket < socket_count; socket++) {if (socket ==0 ) { *irq_mmio_phandle = xplic_phandles[socket];
Signature · 1 line
2.45.2
Re: [PATCH 2/8] hw/riscv/virt.c: reduce virt_use_kvm_aia() usage
Quoted 14 lines · Daniel Henrique Barboza
In
create_fdt_sockets()we have the following pattern:if (kvm_enabled() && virt_use_kvm_aia(s)) { (... do stuff ...) } else { (... do other stuff ...) } if (kvm_enabled() && virt_use_kvm_aia(s)) { (... do more stuff ...) } else { (... do more other stuff) }
Quoted 4 lines
Do everything in a single if/else clause to reduce the usage of
virt_use_kvm_aia()helper and to make the code a bit less repetitive.Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 37 lines
--- hw/riscv/virt.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)hw/riscv/virt.c +4
-7@@ -780,6 +780,10 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, msi_m_phandle, msi_s_phandle, phandle, &intc_phandles[0 ], xplic_phandles, ms->smp.cpus); + + *irq_mmio_phandle = xplic_phandles[0 ]; + *irq_virtio_phandle = xplic_phandles[0 ]; + *irq_pcie_phandle = xplic_phandles[0 ]; }else { phandle_pos = ms->smp.cpus;for (socket = (socket_count -1 ); socket >=0 ; socket--) {@@ -797,13 +801,7 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, s->soc[socket].num_harts); } } - } -if (kvm_enabled () &&virt_use_kvm_aia (s)) { - *irq_mmio_phandle = xplic_phandles[0 ]; - *irq_virtio_phandle = xplic_phandles[0 ]; - *irq_pcie_phandle = xplic_phandles[0 ]; - }else {for (socket =0 ; socket < socket_count; socket++) {if (socket ==0 ) { *irq_mmio_phandle = xplic_phandles[socket]; --2.45.2
PATCH 3/8 hw/riscv/virt.c: rename helper to virt_use_kvm_aia_aplic_imsic()
In reply to Daniel Henrique BarbozaSimilar to the riscv_is_kvm_aia_aplic_imsic() helper from riscv_aplic.c, the existing virt_use_kvm_aia() is testing for KVM aia=aplic-imsic with in-kernel irqchip enabled. It is not checking for a generic AIA support.
Rename the helper to virt_use_kvm_aia_aplic_imsic() to reflect what the helper is doing, and use the existing riscv_is_kvm_aia_aplic_imsic() to obscure details such as the presence of the in-kernel irqchip.
--- hw/riscv/virt.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
hw/riscv/virt.c +7 -5
@@ -57,9 +57,11 @@#include "hw/virtio/virtio-iommu.h" /* KVM AIA only supports APLIC MSI. APLIC Wired is always emulated by QEMU. */ -static bool virt_use_kvm_aia (RISCVVirtState *s) +static bool virt_use_kvm_aia_aplic_imsic (RISCVVirtAIAType aia_type) { -return kvm_irqchip_in_kernel () && s->aia_type ==VIRT_AIA_TYPE_APLIC_IMSIC ; +bool msimode = aia_type ==VIRT_AIA_TYPE_APLIC_IMSIC ; + +return riscv_is_kvm_aia_aplic_imsic (msimode); }static bool virt_aclint_allowed (void )
@@ -774,8 +776,8 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, *msi_pcie_phandle = msi_s_phandle; } -/* KVM AIA only has one APLIC instance */ -if (kvm_enabled () &&virt_use_kvm_aia (s)) { +/* KVM AIA aplic-imsic only has one APLIC instance */ +if (kvm_enabled () &&virt_use_kvm_aia_aplic_imsic (s->aia_type)) { create_fdt_socket_aplic(s, memmap, 0, msi_m_phandle, msi_s_phandle, phandle, &intc_phandles[0], xplic_phandles,
@@ -1540,7 +1542,7 @@ static void virt_machine_init(MachineState *machine) } } -if (kvm_enabled () &&virt_use_kvm_aia (s)) { +if (kvm_enabled () &&virt_use_kvm_aia_aplic_imsic (s->aia_type)) { kvm_riscv_aia_create(machine, IMSIC_MMIO_GROUP_MIN_SHIFT, VIRT_IRQCHIP_NUM_SOURCES, VIRT_IRQCHIP_NUM_MSIS, memmap[VIRT_APLIC_S].base,
Signature · 1 line
2.45.2
Re: [PATCH 3/8] hw/riscv/virt.c: rename helper to virt_use_kvm_aia_aplic_imsic()
Quoted 10 lines · Daniel Henrique Barboza
Similar to the
riscv_is_kvm_aia_aplic_imsic()helper fromriscv_aplic.c, the existingvirt_use_kvm_aia()is testing for KVM aia=aplic-imsic with in-kernel irqchip enabled. It is not checking for a generic AIA support.Rename the helper to
virt_use_kvm_aia_aplic_imsic()to reflect what the helper is doing, and use the existingriscv_is_kvm_aia_aplic_imsic()to obscure details such as the presence of the in-kernel irqchip.Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 46 lines
--- hw/riscv/virt.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)hw/riscv/virt.c +7
-6@@ -57,9 +57,11 @@#include "hw/virtio/virtio-iommu.h" /* KVM AIA only supports APLIC MSI. APLIC Wired is always emulated by QEMU. */ -static bool virt_use_kvm_aia (RISCVVirtState *s) +static bool virt_use_kvm_aia_aplic_imsic (RISCVVirtAIAType aia_type) { -return kvm_irqchip_in_kernel () && s->aia_type ==VIRT_AIA_TYPE_APLIC_IMSIC ; +bool msimode = aia_type ==VIRT_AIA_TYPE_APLIC_IMSIC ; + +return riscv_is_kvm_aia_aplic_imsic (msimode); }static bool virt_aclint_allowed (void )@@ -774,8 +776,8 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, *msi_pcie_phandle = msi_s_phandle; } -/* KVM AIA only has one APLIC instance */ -if (kvm_enabled () &&virt_use_kvm_aia (s)) { +/* KVM AIA aplic-imsic only has one APLIC instance */ +if (kvm_enabled () &&virt_use_kvm_aia_aplic_imsic (s->aia_type)) { create_fdt_socket_aplic(s, memmap, 0, msi_m_phandle, msi_s_phandle, phandle, &intc_phandles[0], xplic_phandles,@@ -1540,7 +1542,7 @@ static void virt_machine_init(MachineState *machine) } } -if (kvm_enabled () &&virt_use_kvm_aia (s)) { +if (kvm_enabled () &&virt_use_kvm_aia_aplic_imsic (s->aia_type)) { kvm_riscv_aia_create(machine, IMSIC_MMIO_GROUP_MIN_SHIFT, VIRT_IRQCHIP_NUM_SOURCES, VIRT_IRQCHIP_NUM_MSIS, memmap[VIRT_APLIC_S].base, --2.45.2
PATCH 4/8 target/riscv/kvm: consider irqchip_split() in aia_create()
In reply to Daniel Henrique BarbozaBefore adding support to kernel-irqchip=split when using KVM AIA we need to change how we create the in-kernel AIA device.
In the use case we have so far, i.e. in-kernel irqchip without split mode, both the s-mode APLIC and IMSIC controllers are provided by the irqchip. In irqchip_split() mode we'll emulate the s-mode APLIC controller, which will send MSIs to the in-kernel IMSIC controller. To do that we need to change kvm_riscv_aia_create() to not create the in-kernel s-mode APLIC controller.
In the kernel source arch/riscv/kvm/aia_aplic.c, function kvm_riscv_aia_aplic_init(), we verify that the APLIC controller won't be instantiated by KVM if we do not set 'nr_sources', which is set via KVM_DEV_RISCV_AIA_CONFIG_SRCS. For QEMU this means that we should not set 'aia_irq_num' during kvm_riscv_aia_create() in irqchip_split() mode.
In this same condition, skip KVM_DEV_RISCV_AIA_ADDR_APLIC as well since it is used to set the base address for the in-kernel APLIC controller.
--- target/riscv/kvm/kvm-cpu.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-)
target/riscv/kvm/kvm-cpu.c +22 -14
@@ -1725,12 +1725,28 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, kvm_aia_mode_str(aia_mode)); } - ret =kvm_device_access (aia_fd,KVM_DEV_RISCV_AIA_GRP_CONFIG , -KVM_DEV_RISCV_AIA_CONFIG_SRCS , - &aia_irq_num, true,NULL ); -if (ret <0 ) { -error_report ("KVM AIA: failed to set number of input irq lines" ); -exit (1 ); +/* +* Skip APLIC creation in KVM if we're running split mode. +* This is done by leaving KVM_DEV_RISCV_AIA_CONFIG_SRCS +* unset. We can also skip KVM_DEV_RISCV_AIA_ADDR_APLIC +* since KVM won't be using it. +*/ +if (!kvm_kernel_irqchip_split ()) { + ret =kvm_device_access (aia_fd,KVM_DEV_RISCV_AIA_GRP_CONFIG , +KVM_DEV_RISCV_AIA_CONFIG_SRCS , + &aia_irq_num, true,NULL ); +if (ret <0 ) { +error_report ("KVM AIA: failed to set number of input irq lines" ); +exit (1 ); + } + + ret =kvm_device_access (aia_fd,KVM_DEV_RISCV_AIA_GRP_ADDR , +KVM_DEV_RISCV_AIA_ADDR_APLIC , + &aplic_base, true,NULL ); +if (ret <0 ) { +error_report ("KVM AIA: failed to set the base address of APLIC" ); +exit (1 ); + } } ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
@@ -1772,14 +1788,6 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,exit (1 ); } - ret =kvm_device_access (aia_fd,KVM_DEV_RISCV_AIA_GRP_ADDR , -KVM_DEV_RISCV_AIA_ADDR_APLIC , - &aplic_base, true,NULL ); -if (ret <0 ) { -error_report ("KVM AIA: failed to set the base address of APLIC" ); -exit (1 ); - } -for (socket =0 ; socket < socket_count; socket++) { socket_imsic_base = imsic_base + socket * (1U << group_shift); hart_count =riscv_socket_hart_count (machine, socket);
Signature · 1 line
2.45.2
Re: [PATCH 4/8] target/riscv/kvm: consider irqchip_split() in aia_create()
Quoted 17 lines · Daniel Henrique Barboza
Before adding support to kernel-irqchip=split when using KVM AIA we need to change how we create the in-kernel AIA device.
In the use case we have so far, i.e. in-kernel irqchip without split mode, both the s-mode APLIC and IMSIC controllers are provided by the irqchip. In
irqchip_split()mode we'll emulate the s-mode APLIC controller, which will send MSIs to the in-kernel IMSIC controller. To do that we need to changekvm_riscv_aia_create()to not create the in-kernel s-mode APLIC controller.In the kernel source
arch/riscv/kvm/aia_aplic.c, functionkvm_riscv_aia_aplic_init(), we verify that the APLIC controller won't be instantiated by KVM if we do not set 'nr_sources', which is set viaKVM_DEV_RISCV_AIA_CONFIG_SRCS. For QEMU this means that we should not set 'aia_irq_num' duringkvm_riscv_aia_create()inirqchip_split()mode.
Quoted 4 lines
In this same condition, skip
KVM_DEV_RISCV_AIA_ADDR_APLICas well since it is used to set the base address for the in-kernel APLIC controller.Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 62 lines
--- target/riscv/kvm/kvm-cpu.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-)target/riscv/kvm/kvm-cpu.c +22
-15@@ -1725,12 +1725,28 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, kvm_aia_mode_str(aia_mode)); } - ret =kvm_device_access (aia_fd,KVM_DEV_RISCV_AIA_GRP_CONFIG , -KVM_DEV_RISCV_AIA_CONFIG_SRCS , - &aia_irq_num, true,NULL ); -if (ret <0 ) { -error_report ("KVM AIA: failed to set number of input irq lines" ); -exit (1 ); +/* +* Skip APLIC creation in KVM if we're running split mode. +* This is done by leaving KVM_DEV_RISCV_AIA_CONFIG_SRCS +* unset. We can also skip KVM_DEV_RISCV_AIA_ADDR_APLIC +* since KVM won't be using it. +*/ +if (!kvm_kernel_irqchip_split ()) { + ret =kvm_device_access (aia_fd,KVM_DEV_RISCV_AIA_GRP_CONFIG , +KVM_DEV_RISCV_AIA_CONFIG_SRCS , + &aia_irq_num, true,NULL ); +if (ret <0 ) { +error_report ("KVM AIA: failed to set number of input irq lines" ); +exit (1 ); + } + + ret =kvm_device_access (aia_fd,KVM_DEV_RISCV_AIA_GRP_ADDR , +KVM_DEV_RISCV_AIA_ADDR_APLIC , + &aplic_base, true,NULL ); +if (ret <0 ) { +error_report ("KVM AIA: failed to set the base address of APLIC" ); +exit (1 ); + } } ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,@@ -1772,14 +1788,6 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,exit (1 ); } - ret =kvm_device_access (aia_fd,KVM_DEV_RISCV_AIA_GRP_ADDR , -KVM_DEV_RISCV_AIA_ADDR_APLIC , - &aplic_base, true,NULL ); -if (ret <0 ) { -error_report ("KVM AIA: failed to set the base address of APLIC" ); -exit (1 ); - } -for (socket =0 ; socket < socket_count; socket++) { socket_imsic_base = imsic_base + socket * (1U << group_shift); hart_count =riscv_socket_hart_count (machine, socket); --2.45.2
PATCH 5/8 hw/riscv/virt.c, riscv_aplic.c: add 'emulated_aplic' helpers
In reply to Daniel Henrique BarbozaThe current logic to determine if we don't need an emulated APLIC controller, i.e. KVM will provide for us, is to determine if we're running KVM, with in-kernel irqchip support, and running aia=aplic-imsic. This is modelled by riscv_is_kvm_aia_aplic_imsic() and virt_use_kvm_aia_aplic_imsic().
This won't suffice to support irqchip_split() mode: it will match exactly the same conditions as the one above, but setting the irqchip to 'split' mode will now require us to emulate an APLIC s-mode controller, like we're doing with 'aia=aplic'.
Create a new riscv_use_emulated_aplic() helper that will encapsulate this logic. Replace the uses of "riscv_is_kvm_aia_aplic_imsic()" with this helper every time we're taking a decision on emulate an APLIC controller or not. Do the same in virt.c with virt_use_emulated_aplic().
--- hw/intc/riscv_aplic.c | 24 +++++++++++++++++++++--- hw/riscv/virt.c | 14 ++++++++++++-- include/hw/intc/riscv_aplic.h | 1 + 3 files changed, 34 insertions(+), 5 deletions(-)
hw/intc/riscv_aplic.c +21 -3
@@ -32,6 +32,7 @@#include "target/riscv/cpu.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" +#include "sysemu/tcg.h" #include "kvm/kvm_riscv.h" #include "migration/vmstate.h"
@@ -159,6 +160,23 @@ bool riscv_is_kvm_aia_aplic_imsic(bool msimode)return kvm_irqchip_in_kernel () && msimode; } +bool riscv_use_emulated_aplic (bool msimode) +{ +#ifdef CONFIG_KVM +if (tcg_enabled ()) { +return true; + } + +if (!riscv_is_kvm_aia_aplic_imsic (msimode)) { +return true; + } + +return kvm_kernel_irqchip_split (); +#else +return true; +#endif +} +static bool riscv_aplic_irq_rectified_val (RISCVAPLICState *aplic,uint32_t irq) {
@@ -853,7 +871,7 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp)uint32_t i;RISCVAPLICState *aplic =RISCV_APLIC (dev); -if (!riscv_is_kvm_aia_aplic_imsic (aplic->msimode)) { +if (riscv_use_emulated_aplic (aplic->msimode)) { aplic->bitfield_words = (aplic->num_irqs +31 ) >>5 ; aplic->sourcecfg =g_new0 (uint32_t, aplic->num_irqs); aplic->state =g_new0 (uint32_t, aplic->num_irqs);
@@ -877,7 +895,7 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp)* have IRQ lines delegated by their parent APLIC. */ if (!aplic->parent) { -if (kvm_enabled () &&riscv_is_kvm_aia_aplic_imsic (aplic->msimode)) { +if (kvm_enabled () && !riscv_use_emulated_aplic (aplic->msimode)) {qdev_init_gpio_in (dev, riscv_kvm_aplic_request, aplic->num_irqs); }else {qdev_init_gpio_in (dev, riscv_aplic_request, aplic->num_irqs);
@@ -1021,7 +1039,7 @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size,sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); -if (!riscv_is_kvm_aia_aplic_imsic (msimode)) { +if (riscv_use_emulated_aplic (msimode)) {sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , addr); }
hw/riscv/virt.c +12 -2
@@ -64,6 +64,13 @@ static bool virt_use_kvm_aia_aplic_imsic(RISCVVirtAIAType aia_type)return riscv_is_kvm_aia_aplic_imsic (msimode); } +static bool virt_use_emulated_aplic (RISCVVirtAIAType aia_type) +{ +bool msimode = aia_type ==VIRT_AIA_TYPE_APLIC_IMSIC ; + +return riscv_use_emulated_aplic (msimode); +} +static bool virt_aclint_allowed (void ) {return tcg_enabled () ||qtest_enabled ();
@@ -776,8 +783,11 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, *msi_pcie_phandle = msi_s_phandle; } -/* KVM AIA aplic-imsic only has one APLIC instance */ -if (kvm_enabled () &&virt_use_kvm_aia_aplic_imsic (s->aia_type)) { +/* +* With KVM AIA aplic-imsic, using an irqchip without split +* mode, we'll use only one APLIC instance. +*/ +if (!virt_use_emulated_aplic (s->aia_type)) { create_fdt_socket_aplic(s, memmap, 0, msi_m_phandle, msi_s_phandle, phandle, &intc_phandles[0], xplic_phandles,
include/hw/intc/riscv_aplic.h +1 -0
@@ -72,6 +72,7 @@ struct RISCVAPLICState {void riscv_aplic_add_child (DeviceState *parent,DeviceState *child);bool riscv_is_kvm_aia_aplic_imsic (bool msimode); +bool riscv_use_emulated_aplic (bool msimode); DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources,
Signature · 1 line
2.45.2
Re: [PATCH 5/8] hw/riscv/virt.c, riscv_aplic.c: add 'emulated_aplic' helpers
Quoted 12 lines · Daniel Henrique Barboza
The current logic to determine if we don't need an emulated APLIC controller, i.e. KVM will provide for us, is to determine if we're running KVM, with in-kernel irqchip support, and running aia=aplic-imsic. This is modelled by
riscv_is_kvm_aia_aplic_imsic()andvirt_use_kvm_aia_aplic_imsic().This won't suffice to support
irqchip_split()mode: it will match exactly the same conditions as the one above, but setting the irqchip to 'split' mode will now require us to emulate an APLIC s-mode controller, like we're doing with 'aia=aplic'.
Quoted 6 lines
Create a new
riscv_use_emulated_aplic()helper that will encapsulate this logic. Replace the uses of "riscv_is_kvm_aia_aplic_imsic()" with this helper every time we're taking a decision on emulate an APLIC controller or not. Do the same invirt.cwithvirt_use_emulated_aplic().Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 117 lines
--- hw/intc/riscv_aplic.c | 24 +++++++++++++++++++++--- hw/riscv/virt.c | 14 ++++++++++++-- include/hw/intc/riscv_aplic.h | 1 + 3 files changed, 34 insertions(+), 5 deletions(-)hw/intc/riscv_aplic.c +21
-3@@ -32,6 +32,7 @@#include "target/riscv/cpu.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" +#include "sysemu/tcg.h" #include "kvm/kvm_riscv.h" #include "migration/vmstate.h" @@ -159,6 +160,23 @@ bool riscv_is_kvm_aia_aplic_imsic(bool msimode)return kvm_irqchip_in_kernel () && msimode; } +bool riscv_use_emulated_aplic (bool msimode) +{ +#ifdef CONFIG_KVM +if (tcg_enabled ()) { +return true; + } + +if (!riscv_is_kvm_aia_aplic_imsic (msimode)) { +return true; + } + +return kvm_kernel_irqchip_split (); +#else +return true; +#endif +} +static bool riscv_aplic_irq_rectified_val (RISCVAPLICState *aplic,uint32_t irq) {@@ -853,7 +871,7 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp)uint32_t i;RISCVAPLICState *aplic =RISCV_APLIC (dev); -if (!riscv_is_kvm_aia_aplic_imsic (aplic->msimode)) { +if (riscv_use_emulated_aplic (aplic->msimode)) { aplic->bitfield_words = (aplic->num_irqs +31 ) >>5 ; aplic->sourcecfg =g_new0 (uint32_t, aplic->num_irqs); aplic->state =g_new0 (uint32_t, aplic->num_irqs);@@ -877,7 +895,7 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp)* have IRQ lines delegated by their parent APLIC. */ if (!aplic->parent) { -if (kvm_enabled () &&riscv_is_kvm_aia_aplic_imsic (aplic->msimode)) { +if (kvm_enabled () && !riscv_use_emulated_aplic (aplic->msimode)) {qdev_init_gpio_in (dev, riscv_kvm_aplic_request, aplic->num_irqs); }else {qdev_init_gpio_in (dev, riscv_aplic_request, aplic->num_irqs);@@ -1021,7 +1039,7 @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size,sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); -if (!riscv_is_kvm_aia_aplic_imsic (msimode)) { +if (riscv_use_emulated_aplic (msimode)) {sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , addr); }hw/riscv/virt.c +12
-2@@ -64,6 +64,13 @@ static bool virt_use_kvm_aia_aplic_imsic(RISCVVirtAIAType aia_type)return riscv_is_kvm_aia_aplic_imsic (msimode); } +static bool virt_use_emulated_aplic (RISCVVirtAIAType aia_type) +{ +bool msimode = aia_type ==VIRT_AIA_TYPE_APLIC_IMSIC ; + +return riscv_use_emulated_aplic (msimode); +} +static bool virt_aclint_allowed (void ) {return tcg_enabled () ||qtest_enabled ();@@ -776,8 +783,11 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, *msi_pcie_phandle = msi_s_phandle; } -/* KVM AIA aplic-imsic only has one APLIC instance */ -if (kvm_enabled () &&virt_use_kvm_aia_aplic_imsic (s->aia_type)) { +/* +* With KVM AIA aplic-imsic, using an irqchip without split +* mode, we'll use only one APLIC instance. +*/ +if (!virt_use_emulated_aplic (s->aia_type)) { create_fdt_socket_aplic(s, memmap, 0, msi_m_phandle, msi_s_phandle, phandle, &intc_phandles[0], xplic_phandles,include/hw/intc/riscv_aplic.h +1
-1@@ -72,6 +72,7 @@ struct RISCVAPLICState {void riscv_aplic_add_child (DeviceState *parent,DeviceState *child);bool riscv_is_kvm_aia_aplic_imsic (bool msimode); +bool riscv_use_emulated_aplic (bool msimode); DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources, --2.45.2
PATCH 6/8 hw/intc/riscv_aplic: add kvm_msicfgaddr for split mode aplic-imsic
In reply to Daniel Henrique BarbozaThe last step to enable KVM AIA aplic-imsic with irqchip in split mode is to deal with how MSIs are going to be sent. In our current design we don't allow an APLIC controller to send MSIs unless it's on m-mode. And we also do not allow Supervisor MSI address configuration via the 'smsiaddrcfg' and 'smsiaddrcfgh' registers unless it's also a m-mode APLIC controller.
Add a new RISCVACPLICState attribute called 'kvm_msicfgaddr'. This attribute represents the base configuration address for MSIs, in our case the base addr of the IMSIC controller. This attribute is being set only when running irqchip_split() mode with aia=aplic-imsic.
During riscv_aplic_msi_send() we'll check if the attribute was set to skip the check for a m-mode APLIC controller and to change the resulting MSI addr by adding kvm_msicfgaddr right before address_space_stl_le().
--- hw/intc/riscv_aplic.c | 42 +++++++++++++++++++++++++++-------- hw/riscv/virt.c | 6 ++++- include/hw/intc/riscv_aplic.h | 6 +++++ 3 files changed, 44 insertions(+), 10 deletions(-)
hw/intc/riscv_aplic.c +33 -9
@@ -177,6 +177,16 @@ bool riscv_use_emulated_aplic(bool msimode)#endif } +void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr) +{ +#ifdef CONFIG_KVM +if (riscv_use_emulated_aplic (aplic->msimode)) { + aplic->kvm_msicfgaddr =extract64 (addr,0 ,32 ); + aplic->kvm_msicfgaddrH =extract64 (addr,32 ,32 ); + } +#endif +} +static bool riscv_aplic_irq_rectified_val (RISCVAPLICState *aplic,uint32_t irq) {
@@ -377,13 +387,16 @@ static void riscv_aplic_msi_send(RISCVAPLICState *aplic,uint32_t lhxs, lhxw, hhxs, hhxw, group_idx, msicfgaddr, msicfgaddrH; aplic_m = aplic; -while (aplic_m && !aplic_m->mmode) { - aplic_m = aplic_m->parent; - } -if (!aplic_m) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: m-level APLIC not found\n" , - __func__); -return ; + +if (!aplic->kvm_splitmode) { +while (aplic_m && !aplic_m->mmode) { + aplic_m = aplic_m->parent; + } +if (!aplic_m) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: m-level APLIC not found\n" , + __func__); +return ; + } }if (aplic->mmode) {
@@ -415,6 +428,11 @@ static void riscv_aplic_msi_send(RISCVAPLICState *aplic, addr |= (uint64_t )(guest_idx &APLIC_xMSICFGADDR_PPN_HART (lhxs)); addr <<= APLIC_xMSICFGADDR_PPN_SHIFT; +if (aplic->kvm_splitmode) { + addr |= aplic->kvm_msicfgaddr; + addr |= ((uint64_t )aplic->kvm_msicfgaddrH <<32 ); + } +address_space_stl_le (&address_space_memory, addr, eiid,MEMTXATTRS_UNSPECIFIED , &result);if (result !=MEMTX_OK ) {
@@ -888,6 +906,10 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp)memory_region_init_io (&aplic->mmio,OBJECT (dev), &riscv_aplic_ops, aplic,TYPE_RISCV_APLIC , aplic->aperture_size);sysbus_init_mmio (SYS_BUS_DEVICE (dev), &aplic->mmio); + +if (kvm_enabled ()) { + aplic->kvm_splitmode = true; + } }/*
@@ -935,8 +957,8 @@ static Property riscv_aplic_properties[] = {static const VMStateDescription vmstate_riscv_aplic = { .name ="riscv_aplic" , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , .fields = (const VMStateField []) {VMSTATE_UINT32 (domaincfg, RISCVAPLICState),VMSTATE_UINT32 (mmsicfgaddr, RISCVAPLICState),
@@ -944,6 +966,8 @@ static const VMStateDescription vmstate_riscv_aplic = {VMSTATE_UINT32 (smsicfgaddr, RISCVAPLICState),VMSTATE_UINT32 (smsicfgaddrH, RISCVAPLICState),VMSTATE_UINT32 (genmsi, RISCVAPLICState), +VMSTATE_UINT32 (kvm_msicfgaddr, RISCVAPLICState), +VMSTATE_UINT32 (kvm_msicfgaddrH, RISCVAPLICState),VMSTATE_VARRAY_UINT32 (sourcecfg, RISCVAPLICState, num_irqs,0 , vmstate_info_uint32, uint32_t),
hw/riscv/virt.c +5 -1
@@ -1221,7 +1221,7 @@ static DeviceState *virt_create_aia(RISCVVirtAIAType aia_type, int aia_guests, int base_hartid, int hart_count) { int i; -hwaddr addr; +hwaddr addr =0 ;uint32_t guest_bits;DeviceState *aplic_s =NULL ;DeviceState *aplic_m =NULL ;
@@ -1271,6 +1271,10 @@ static DeviceState *virt_create_aia(RISCVVirtAIAType aia_type, int aia_guests,VIRT_IRQCHIP_NUM_PRIO_BITS , msimode, false, aplic_m); +if (kvm_enabled () && msimode) { +riscv_aplic_set_kvm_msicfgaddr (RISCV_APLIC (aplic_s), addr); + } +return kvm_enabled () ? aplic_s : aplic_m; }
include/hw/intc/riscv_aplic.h +6 -0
@@ -68,11 +68,17 @@ struct RISCVAPLICState {uint32_t num_irqs;bool msimode;bool mmode; + +/* To support KVM aia=aplic-imsic with irqchip split mode */ +bool kvm_splitmode; +uint32_t kvm_msicfgaddr; +uint32_t kvm_msicfgaddrH; };void riscv_aplic_add_child (DeviceState *parent,DeviceState *child);bool riscv_is_kvm_aia_aplic_imsic (bool msimode);bool riscv_use_emulated_aplic (bool msimode); +void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr); DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources,
Signature · 1 line
2.45.2
Re: [PATCH 6/8] hw/intc/riscv_aplic: add kvm_msicfgaddr for split mode aplic-imsic
Quoted 13 lines · Daniel Henrique Barboza
The last step to enable KVM AIA aplic-imsic with irqchip in split mode is to deal with how MSIs are going to be sent. In our current design we don't allow an APLIC controller to send MSIs unless it's on m-mode. And we also do not allow Supervisor MSI address configuration via the 'smsiaddrcfg' and 'smsiaddrcfgh' registers unless it's also a m-mode APLIC controller.
Add a new RISCVACPLICState attribute called '
kvm_msicfgaddr'. This attribute represents the base configuration address for MSIs, in our case the base addr of the IMSIC controller. This attribute is being set only when runningirqchip_split()mode with aia=aplic-imsic.
Quoted 5 lines
During
riscv_aplic_msi_send()we'll check if the attribute was set to skip the check for a m-mode APLIC controller and to change the resulting MSI addr by addingkvm_msicfgaddrright beforeaddress_space_stl_le().Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 144 lines
--- hw/intc/riscv_aplic.c | 42 +++++++++++++++++++++++++++-------- hw/riscv/virt.c | 6 ++++- include/hw/intc/riscv_aplic.h | 6 +++++ 3 files changed, 44 insertions(+), 10 deletions(-)hw/intc/riscv_aplic.c +33
-9@@ -177,6 +177,16 @@ bool riscv_use_emulated_aplic(bool msimode)#endif } +void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr) +{ +#ifdef CONFIG_KVM +if (riscv_use_emulated_aplic (aplic->msimode)) { + aplic->kvm_msicfgaddr =extract64 (addr,0 ,32 ); + aplic->kvm_msicfgaddrH =extract64 (addr,32 ,32 ); + } +#endif +} +static bool riscv_aplic_irq_rectified_val (RISCVAPLICState *aplic,uint32_t irq) {@@ -377,13 +387,16 @@ static void riscv_aplic_msi_send(RISCVAPLICState *aplic,uint32_t lhxs, lhxw, hhxs, hhxw, group_idx, msicfgaddr, msicfgaddrH; aplic_m = aplic; -while (aplic_m && !aplic_m->mmode) { - aplic_m = aplic_m->parent; - } -if (!aplic_m) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: m-level APLIC not found\n" , - __func__); -return ; + +if (!aplic->kvm_splitmode) { +while (aplic_m && !aplic_m->mmode) { + aplic_m = aplic_m->parent; + } +if (!aplic_m) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: m-level APLIC not found\n" , + __func__); +return ; + } }if (aplic->mmode) {@@ -415,6 +428,11 @@ static void riscv_aplic_msi_send(RISCVAPLICState *aplic, addr |= (uint64_t )(guest_idx &APLIC_xMSICFGADDR_PPN_HART (lhxs)); addr <<= APLIC_xMSICFGADDR_PPN_SHIFT; +if (aplic->kvm_splitmode) { + addr |= aplic->kvm_msicfgaddr; + addr |= ((uint64_t )aplic->kvm_msicfgaddrH <<32 ); + } +address_space_stl_le (&address_space_memory, addr, eiid,MEMTXATTRS_UNSPECIFIED , &result);if (result !=MEMTX_OK ) {@@ -888,6 +906,10 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp)memory_region_init_io (&aplic->mmio,OBJECT (dev), &riscv_aplic_ops, aplic,TYPE_RISCV_APLIC , aplic->aperture_size);sysbus_init_mmio (SYS_BUS_DEVICE (dev), &aplic->mmio); + +if (kvm_enabled ()) { + aplic->kvm_splitmode = true; + } }/* @@ -935,8 +957,8 @@ static Property riscv_aplic_properties[] = {static const VMStateDescription vmstate_riscv_aplic = { .name ="riscv_aplic" , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , .fields = (const VMStateField []) {VMSTATE_UINT32 (domaincfg, RISCVAPLICState),VMSTATE_UINT32 (mmsicfgaddr, RISCVAPLICState),@@ -944,6 +966,8 @@ static const VMStateDescription vmstate_riscv_aplic = {VMSTATE_UINT32 (smsicfgaddr, RISCVAPLICState),VMSTATE_UINT32 (smsicfgaddrH, RISCVAPLICState),VMSTATE_UINT32 (genmsi, RISCVAPLICState), +VMSTATE_UINT32 (kvm_msicfgaddr, RISCVAPLICState), +VMSTATE_UINT32 (kvm_msicfgaddrH, RISCVAPLICState),VMSTATE_VARRAY_UINT32 (sourcecfg, RISCVAPLICState, num_irqs,0 , vmstate_info_uint32, uint32_t),hw/riscv/virt.c +5
-1@@ -1221,7 +1221,7 @@ static DeviceState *virt_create_aia(RISCVVirtAIAType aia_type, int aia_guests, int base_hartid, int hart_count) { int i; -hwaddr addr; +hwaddr addr =0 ;uint32_t guest_bits;DeviceState *aplic_s =NULL ;DeviceState *aplic_m =NULL ;@@ -1271,6 +1271,10 @@ static DeviceState *virt_create_aia(RISCVVirtAIAType aia_type, int aia_guests,VIRT_IRQCHIP_NUM_PRIO_BITS , msimode, false, aplic_m); +if (kvm_enabled () && msimode) { +riscv_aplic_set_kvm_msicfgaddr (RISCV_APLIC (aplic_s), addr); + } +return kvm_enabled () ? aplic_s : aplic_m; }include/hw/intc/riscv_aplic.h +6
-1@@ -68,11 +68,17 @@ struct RISCVAPLICState {uint32_t num_irqs;bool msimode;bool mmode; + +/* To support KVM aia=aplic-imsic with irqchip split mode */ +bool kvm_splitmode; +uint32_t kvm_msicfgaddr; +uint32_t kvm_msicfgaddrH; };void riscv_aplic_add_child (DeviceState *parent,DeviceState *child);bool riscv_is_kvm_aia_aplic_imsic (bool msimode);bool riscv_use_emulated_aplic (bool msimode); +void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr); DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources, --2.45.2
PATCH 7/8 target/riscv/kvm: remove irqchip_split() restriction
In reply to Daniel Henrique BarbozaRemove the 'irqchip_split()' restriction in kvm_arch_init() now that we have support for "-accel kvm,kernel-irqchip=split".
--- target/riscv/kvm/kvm-cpu.c | 5 ----- 1 file changed, 5 deletions(-)
target/riscv/kvm/kvm-cpu.c +0 -5
@@ -1401,11 +1401,6 @@ int kvm_arch_init(MachineState *ms, KVMState *s)int kvm_arch_irqchip_create (KVMState *s) { -if (kvm_kernel_irqchip_split ()) { -error_report ("-machine kernel_irqchip=split is not supported on RISC-V." ); -exit (1 ); - } -/* * We can create the VAIA using the newer device control API. */
Signature · 1 line
2.45.2
Re: [PATCH 7/8] target/riscv/kvm: remove irqchip_split() restriction
Quoted 5 lines · Daniel Henrique Barboza
Remove the '
irqchip_split()' restriction inkvm_arch_init()now that we have support for "-accel kvm,kernel-irqchip=split".Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 24 lines
--- target/riscv/kvm/kvm-cpu.c | 5 ----- 1 file changed, 5 deletions(-)target/riscv/kvm/kvm-cpu.c +0
-6@@ -1401,11 +1401,6 @@ int kvm_arch_init(MachineState *ms, KVMState *s)int kvm_arch_irqchip_create (KVMState *s) { -if (kvm_kernel_irqchip_split ()) { -error_report ("-machine kernel_irqchip=split is not supported on RISC-V." ); -exit (1 ); - } -/* * We can create the VAIA using the newer device control API. */ --2.45.2
PATCH 8/8 docs: update riscv/virt.rst with kernel-irqchip=split support
In reply to Daniel Henrique BarbozaAlso add a new page, docs/specs/riscv-aia.rst, where we're documenting the state of AIA support in QEMU w.r.t the controllers being emulated or not depending on the AIA and accelerator settings.
--- docs/specs/index.rst | 1 + docs/specs/riscv-aia.rst | 83 ++++++++++++++++++++++++++++++++++++++ docs/system/riscv/virt.rst | 7 ++++ 3 files changed, 91 insertions(+) create mode 100644 docs/specs/riscv-aia.rst
docs/specs/index.rst +1 -0
@@ -36,3 +36,4 @@ guest hardware that is specific to QEMU. vmgenid rapl-msr rocker + riscv-aia
docs/specs/riscv-aia.rst new file +83 -0
83 lines not on this page · raw message
docs/system/riscv/virt.rst +7 -0
@@ -110,6 +110,13 @@ The following machine-specific options are supported: MSIs. When not specified, this option is assumed to be "none" which selects SiFive PLIC to handle wired interrupts. + This option also interacts with '-accel kvm'. When using "aia=aplic-imsic" + with KVM, it is possible to set the use of the kernel irqchip in split mode + by using "-accel kvm,kernel-irqchip=split". In this case the ``virt`` machine + will emulate the APLIC controller instead of using the APLIC controller from + the irqchip. See :ref:`riscv-aia` for more details on all available AIA + modes. + - aia-guests=nnn The number of per-HART VS-level AIA IMSIC pages to be emulated for a guest
Signature · 1 line
2.45.2
Re: [PATCH 8/8] docs: update riscv/virt.rst with kernel-irqchip=split support
Quoted 6 lines · Daniel Henrique Barboza
Also add a new page,
docs/specs/riscv-aia.rst, where we're documenting the state of AIA support in QEMU w.r.t the controllers being emulated or not depending on the AIA and accelerator settings.Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 127 lines
--- docs/specs/index.rst | 1 + docs/specs/riscv-aia.rst | 83 ++++++++++++++++++++++++++++++++++++++ docs/system/riscv/virt.rst | 7 ++++ 3 files changed, 91 insertions(+) create mode 100644 docs/specs/riscv-aia.rstdocs/specs/index.rst +1
-0@@ -36,3 +36,4 @@ guest hardware that is specific to QEMU. vmgenid rapl-msr rocker + riscv-aiadocs/specs/riscv-aia.rst new file +83
-0@@ -0,0 +1,83 @@ +.. _riscv-aia: + +RISC-V AIA support for RISC-V machines +====================================== + +AIA (Advanced Interrupt Architecture) support is implemented in the ``virt`` +RISC-V machine for TCG and KVM accelerators. + +The support consists of two main modes: + +- "aia=aplic": adds one or more APLIC (Advanced Platform Level Interrupt Controller) + devices +- "aia=aplic-imsic": adds one or more APLIC device and an IMSIC (Incoming MSI + Controller) device for each CPU + +From an user standpoint, these modes will behave the same regardless of the accelerator +used. From a developer standpoint the accelerator settings will change what it being +emulated in userspace versus what is being emulated by an in-kernel irqchip. + +When running TCG, all controllers are emulated in userspace, including machine mode +(m-mode) APLIC and IMSIC (when applicable). + +When running KVM: + +- no m-mode is provided, so there is no m-mode APLIC or IMSIC emulation regardless of + the AIA mode chosen +- with "aia=aplic", s-mode APLIC will be emulated by userspace +- with "aia=aplic-imsic" there are two possibilities. If no additional KVM option + is provided there will be no APLIC or IMSIC emulation in userspace, and the virtual + machine will use the provided in-kernel APLIC and IMSIC controllers. If the user + chooses to use the irqchip in split mode via "-accel kvm,kernel-irqchip=split", + s-mode APLIC will be emulated while using the s-mode IMSIC from the irqchip + +The following table summarizes how the AIA and accelerator options defines what +we will emulate in userspace: + + +.. list-table:: How AIA and accel options changes controller emulation + :widths: 25 25 25 25 25 25 25 + :header-rows: 1 + + * - Accel + - Accel props + - AIA type + - APLIC m-mode + - IMSIC m-mode + - APLIC s-mode + - IMSIC s-mode + * - tcg + - --- + - aplic + - emul + - n/a + - emul + - n/a + * - tcg + - --- + - aplic-imsic + - emul + - emul + - emul + - emul + * - kvm + - --- + - aplic + - n/a + - n/a + - emul + - n/a + * - kvm + - none + - aplic-imsic + - n/a + - n/a + - in-kernel + - in-kernel + * - kvm + - irqchip=split + - aplic-imsic + - n/a + - n/a + - emul + - in-kerneldocs/system/riscv/virt.rst +7
-1@@ -110,6 +110,13 @@ The following machine-specific options are supported: MSIs. When not specified, this option is assumed to be "none" which selects SiFive PLIC to handle wired interrupts. + This option also interacts with '-accel kvm'. When using "aia=aplic-imsic" + with KVM, it is possible to set the use of the kernel irqchip in split mode + by using "-accel kvm,kernel-irqchip=split". In this case the ``virt`` machine + will emulate the APLIC controller instead of using the APLIC controller from + the irqchip. See :ref:`riscv-aia` for more details on all available AIA + modes. + - aia-guests=nnn The number of per-HART VS-level AIA IMSIC pages to be emulated for a guest --2.45.2
Quoted 20 lines · Daniel Henrique Barboza
Hi,
This series adds AIA
irqchip_splitsupport, effective when using AIA with aia=aplic-imsic and -accel kvm,kernel-irqchip=split.The main difference between what we currently have and
irqchip_split()mode is that, when using split mode, QEMU will emulate the APLIC controller instead of using the in-kernel APLIC controller provided by KVM.After this series this is the matrix of which interrupt controllers we're emulating based on 'virt' machine configuration and accelerator properties:
Accel Accel props AIA type APLIC-m IMSIC-m APLIC-s IMSIC-s tcg ---- aplic emul n/a emul n/a tcg ---- aplic-imsic emul emul emul emul kvm ---- aplic n/a n/a emul n/a kvm none aplic-imsic n/a n/a in-kernel in-kernel
Quoted 4 lines
kvm irqchip=split aplic-imsic n/a n/a emul in-kernel
Patches based on alistair/riscv-to-apply.next.
Thanks!
Do you mind rebasing this again?
Alistair
Quoted 25 lines · Alistair Francis
Quoted 23 lines · Daniel Henrique Barboza
Hi,
This series adds AIA
irqchip_splitsupport, effective when using AIA with aia=aplic-imsic and -accel kvm,kernel-irqchip=split.The main difference between what we currently have and
irqchip_split()mode is that, when using split mode, QEMU will emulate the APLIC controller instead of using the in-kernel APLIC controller provided by KVM.After this series this is the matrix of which interrupt controllers we're emulating based on 'virt' machine configuration and accelerator properties:
Accel Accel props AIA type APLIC-m IMSIC-m APLIC-s IMSIC-s tcg ---- aplic emul n/a emul n/a tcg ---- aplic-imsic emul emul emul emul kvm ---- aplic n/a n/a emul n/a kvm none aplic-imsic n/a n/a in-kernel in-kernelkvm irqchip=split aplic-imsic n/a n/a emul in-kernel
Quoted 5 lines
Quoted 1 line
Patches based on alistair/riscv-to-apply.next.
Thanks!
Do you mind rebasing this again?
Thanks for the reviews!
I'm not sure which branch should I use for rebasing (it doesn't seem that your riscv-to-apply.next or riscv-to-apply.for-upstream branches are updated), so I rebased it on top of 'master', fixed a couple of conflicts.
Let me know if you want a rebase based on a different branch. Thanks,
Daniel
Quoted 2 lines
Alistair