riscv: Fix guest poweroff when using PLIC emulation
Subsystems (3)
PATCH 1/1 riscv: Fix guest poweroff when using PLIC emulation
Recently due to commit 74af1456dfa0, the virtio device emulation in KVMTOOL now calls irq__update_msix_route() upon guest poweroff which results in KVMTOOL crash when Guest uses PLIC emulation in user space. This is because irq__update_msix_route() expects the irq_routing table to be available but the KVMTOOL PLIC emulation does not populate any irq_routing entries.
--- riscv/plic.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
riscv/plic.c +32 -0
@@ -95,6 +95,8 @@#define REG_SIZE 0x1000000 +#define IRQCHIP_PLIC_NR 0 +struct plic_state ;struct plic_context {
@@ -500,6 +502,33 @@ static void plic__generate_fdt_node(void *fdt, struct kvm *kvm)free (irq_cells); } +static int plic__irq_routing_init (struct kvm *kvm) +{ +int r; + +/* +* This describes the default routing that the kernel uses without +* any routing explicitly set up via KVM_SET_GSI_ROUTING. So we +* don't need to commit these setting right now. The first actual +* user (MSI routing) will engage these mappings then. +*/ +for (next_gsi =0 ; next_gsi <MAX_DEVICES ; next_gsi++) { + r =irq__allocate_routing_entry (); +if (r) +return r; + + irq_routing->entries[irq_routing->nr++] = + (struct kvm_irq_routing_entry ) { + .gsi = next_gsi, + .type =KVM_IRQ_ROUTING_IRQCHIP , + .u.irqchip.irqchip =IRQCHIP_PLIC_NR , + .u.irqchip.pin = next_gsi, + }; + } + +return 0 ; +} +static int plic__init (struct kvm *kvm) {u32 i;
@@ -535,6 +564,9 @@ static int plic__init(struct kvm *kvm)if (ret)return ret; +/* Setup default IRQ routing */ +plic__irq_routing_init (kvm); + plic.ready = true;return 0 ;
Signature · 1 line
2.34.1
Will Deacon
AppliedQuoted 8 lines · Anup Patel
Recently due to commit
74af1456dfa0, the virtio device emulation in KVMTOOL now callsirq__update_msix_route()upon guest poweroff which results in KVMTOOL crash when Guest uses PLIC emulation in user space. This is becauseirq__update_msix_route()expects theirq_routingtable to be available but the KVMTOOL PLIC emulation does not populate anyirq_routingentries.[...]
Applied to kvmtool (master), thanks!
[1/1] riscv: Fix guest poweroff when using PLIC emulation
https://git.kernel.org/will/kvmtool/c/f6cc06d6b535
Cheers,
Signature · 5 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev