kvm: Remove KVM_CREATE_IRQCHIP support assumption
PATCH 1/1 kvm: Remove KVM_CREATE_IRQCHIP support assumption
Since Linux commit 00f918f61c56 ("RISC-V: KVM: Skeletal in-kernel AIA irqchip support") checking KVM_CAP_IRQCHIP returns non-zero when the RISC-V platform has AIA. The cap indicates KVM supports at least one of the following ioctls:
KVM_CREATE_IRQCHIP
KVM_IRQ_LINE
KVM_GET_IRQCHIP
KVM_SET_IRQCHIP
KVM_GET_LAPIC
KVM_SET_LAPIC
but the cap doesn't imply that KVM must support any of those ioctls in particular. However, QEMU was assuming the KVM_CREATE_IRQCHIP ioctl was supported. Stop making that assumption by introducing a KVM parameter that each architecture which supports KVM_CREATE_IRQCHIP sets. Adding parameters isn't awesome, but given how the KVM_CAP_IRQCHIP isn't very helpful on its own, we don't have a lot of options.
---
While this fixes booting guests on riscv KVM with AIA it's unlikely to get merged before the QEMU support for KVM AIA[1] lands, which would also fix the issue. I think this patch is still worth considering though since QEMU's assumption is wrong.
[1] https://lore.kernel.org/all/[email protected]/
accel/kvm/kvm-all.c | 5 ++++- include/sysemu/kvm.h | 1 + target/arm/kvm.c | 3 +++ target/i386/kvm/kvm.c | 2 ++ target/s390x/kvm/kvm.c | 3 +++ 5 files changed, 13 insertions(+), 1 deletion(-)
accel/kvm/kvm-all.c +4 -1
@@ -86,6 +86,7 @@ struct KVMParkedVcpu { };KVMState *kvm_state; +bool kvm_has_create_irqchip;bool kvm_kernel_irqchip;bool kvm_split_irqchip;bool kvm_async_interrupts_allowed;
@@ -2377,8 +2378,10 @@ static void kvm_irqchip_create(KVMState *s)if (s->kernel_irqchip_split ==ON_OFF_AUTO_ON ) {error_report ("Split IRQ chip mode not supported." );exit (1 ); - }else { + }else if (kvm_has_create_irqchip) { ret =kvm_vm_ioctl (s,KVM_CREATE_IRQCHIP ); + }else { +return ; } }if (ret <0 ) {
include/sysemu/kvm.h +1 -0
@@ -32,6 +32,7 @@#ifdef CONFIG_KVM_IS_POSSIBLE extern bool kvm_allowed; +extern bool kvm_has_create_irqchip;extern bool kvm_kernel_irqchip;extern bool kvm_split_irqchip;extern bool kvm_async_interrupts_allowed;
target/arm/kvm.c +3 -0
@@ -250,6 +250,9 @@ int kvm_arm_get_max_vm_ipa_size(MachineState *ms, bool *fixed_ipa)int kvm_arch_init (MachineState *ms,KVMState *s) {int ret =0 ; + + kvm_has_create_irqchip =kvm_check_extension (s,KVM_CAP_IRQCHIP ); +/* For ARM interrupt delivery is always asynchronous, * whether we are using an in-kernel VGIC or not. */
target/i386/kvm/kvm.c +2 -0
@@ -2771,6 +2771,8 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } } + kvm_has_create_irqchip =kvm_check_extension (s,KVM_CAP_IRQCHIP ); +return 0 ; }
target/s390x/kvm/kvm.c +3 -0
@@ -391,6 +391,9 @@ int kvm_arch_init(MachineState *ms, KVMState *s) }kvm_set_max_memslot_size (KVM_SLOT_MAX_BYTES ); + + kvm_has_create_irqchip =kvm_check_extension (s,KVM_CAP_S390_IRQCHIP ); +return 0 ; }
Signature · 1 line
2.41.0
Quoted 52 lines · Andrew Jones
Since Linux commit
00f918f61c56("RISC-V: KVM: Skeletal in-kernel AIA irqchip support") checkingKVM_CAP_IRQCHIPreturns non-zero when the RISC-V platform has AIA. The cap indicates KVM supports at least one of the following ioctls:
KVM_CREATE_IRQCHIP
KVM_IRQ_LINE
KVM_GET_IRQCHIP
KVM_SET_IRQCHIP
KVM_GET_LAPIC
KVM_SET_LAPICbut the cap doesn't imply that KVM must support any of those ioctls in particular. However, QEMU was assuming the
KVM_CREATE_IRQCHIPioctl was supported. Stop making that assumption by introducing a KVM parameter that each architecture which supportsKVM_CREATE_IRQCHIPsets. Adding parameters isn't awesome, but given how theKVM_CAP_IRQCHIPisn't very helpful on its own, we don't have a lot of options.Signed-off-by Andrew Jones <[email protected]>---
While this fixes booting guests on riscv KVM with AIA it's unlikely to get merged before the QEMU support for KVM AIA[1] lands, which would also fix the issue. I think this patch is still worth considering though since QEMU's assumption is wrong.
[1] https://lore.kernel.org/all/[email protected]/
accel/kvm/kvm-all.c | 5 ++++- include/sysemu/kvm.h | 1 + target/arm/kvm.c | 3 +++ target/i386/kvm/kvm.c | 2 ++ target/s390x/kvm/kvm.c | 3 +++ 5 files changed, 13 insertions(+), 1 deletion(-)accel/kvm/kvm-all.c +1
-0@@ -86,6 +86,7 @@ struct KVMParkedVcpu { };KVMState *kvm_state; +bool kvm_has_create_irqchip;bool kvm_kernel_irqchip;bool kvm_split_irqchip;bool kvm_async_interrupts_allowed;@@ -2377,8 +2378,10 @@ static void kvm_irqchip_create(KVMState *s)if (s->kernel_irqchip_split ==ON_OFF_AUTO_ON ) {
accel/kvm/kvm-all.c static void kvm_irqchip_create(KVMState *s) · line 2387
Quoted 10 lines
accel/kvm/kvm-all.c +3
-1error_report ("Split IRQ chip mode not supported." );exit (1 ); - }else { + }else if (kvm_has_create_irqchip) { ret =kvm_vm_ioctl (s,KVM_CREATE_IRQCHIP ); + }else { +return ; } }if (ret <0 ) {
I think I'd do this differntly... at the beginning of the function, there is a check for kvm_check_extension(s, KVM_CAP_IRQCHIP) etc. ... I think you could now replace that check with a simple
if (!kvm_has_create_irqchip) {
return;
}The "kvm_vm_enable_cap(s, KVM_CAP_S390_IRQCHIP, 0)" of course has to be moved to the target/s390x/kvm/kvm.c file, too.
Thomas
Quoted 53 lines
include/sysemu/kvm.h +1
-0@@ -32,6 +32,7 @@#ifdef CONFIG_KVM_IS_POSSIBLE extern bool kvm_allowed; +extern bool kvm_has_create_irqchip;extern bool kvm_kernel_irqchip;extern bool kvm_split_irqchip;extern bool kvm_async_interrupts_allowed;target/arm/kvm.c +3
-0@@ -250,6 +250,9 @@ int kvm_arm_get_max_vm_ipa_size(MachineState *ms, bool *fixed_ipa)int kvm_arch_init (MachineState *ms,KVMState *s) {int ret =0 ; + + kvm_has_create_irqchip =kvm_check_extension (s,KVM_CAP_IRQCHIP ); +/* For ARM interrupt delivery is always asynchronous, * whether we are using an in-kernel VGIC or not. */ target/i386/kvm/kvm.c +2
-0@@ -2771,6 +2771,8 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } } + kvm_has_create_irqchip =kvm_check_extension (s,KVM_CAP_IRQCHIP ); +return 0 ; }target/s390x/kvm/kvm.c +3
-0@@ -391,6 +391,9 @@ int kvm_arch_init(MachineState *ms, KVMState *s) }kvm_set_max_memslot_size (KVM_SLOT_MAX_BYTES ); + + kvm_has_create_irqchip =kvm_check_extension (s,KVM_CAP_S390_IRQCHIP ); +return 0 ; }
Quoted 67 lines · Thomas Huth
Quoted 51 lines · Andrew Jones
Since Linux commit
00f918f61c56("RISC-V: KVM: Skeletal in-kernel AIA irqchip support") checkingKVM_CAP_IRQCHIPreturns non-zero when the RISC-V platform has AIA. The cap indicates KVM supports at least one of the following ioctls:
KVM_CREATE_IRQCHIP
KVM_IRQ_LINE
KVM_GET_IRQCHIP
KVM_SET_IRQCHIP
KVM_GET_LAPIC
KVM_SET_LAPICbut the cap doesn't imply that KVM must support any of those ioctls in particular. However, QEMU was assuming the
KVM_CREATE_IRQCHIPioctl was supported. Stop making that assumption by introducing a KVM parameter that each architecture which supportsKVM_CREATE_IRQCHIPsets. Adding parameters isn't awesome, but given how theKVM_CAP_IRQCHIPisn't very helpful on its own, we don't have a lot of options.Signed-off-by Andrew Jones <[email protected]>---
While this fixes booting guests on riscv KVM with AIA it's unlikely to get merged before the QEMU support for KVM AIA[1] lands, which would also fix the issue. I think this patch is still worth considering though since QEMU's assumption is wrong.
[1] https://lore.kernel.org/all/[email protected]/
accel/kvm/kvm-all.c | 5 ++++- include/sysemu/kvm.h | 1 + target/arm/kvm.c | 3 +++ target/i386/kvm/kvm.c | 2 ++ target/s390x/kvm/kvm.c | 3 +++ 5 files changed, 13 insertions(+), 1 deletion(-)accel/kvm/kvm-all.c +1
-0@@ -86,6 +86,7 @@ struct KVMParkedVcpu { };KVMState *kvm_state; +bool kvm_has_create_irqchip;bool kvm_kernel_irqchip;bool kvm_split_irqchip;bool kvm_async_interrupts_allowed;@@ -2377,8 +2378,10 @@ static void kvm_irqchip_create(KVMState *s)if (s->kernel_irqchip_split ==ON_OFF_AUTO_ON ) {accel/kvm/kvm-all.c static void kvm_irqchip_create(KVMState *s) · line 2387
Quoted 10 lines
accel/kvm/kvm-all.c +3
-1error_report ("Split IRQ chip mode not supported." );exit (1 ); - }else { + }else if (kvm_has_create_irqchip) { ret =kvm_vm_ioctl (s,KVM_CREATE_IRQCHIP ); + }else { +return ; } }if (ret <0 ) {I think I'd do this differntly... at the beginning of the function, there is a check for
kvm_check_extension(s, KVM_CAP_IRQCHIP)etc. ... I think you could now replace that check with a simple
Quoted 7 lines
if (!kvm_has_create_irqchip) { return; }The "
kvm_vm_enable_cap(s, KVM_CAP_S390_IRQCHIP, 0)" of course has to be moved to thetarget/s390x/kvm/kvm.cfile, too.
Sounds good. I'll do that for v2.
Thanks,
drew
Quoted 67 lines · Thomas Huth
Quoted 51 lines · Andrew Jones
Since Linux commit
00f918f61c56("RISC-V: KVM: Skeletal in-kernel AIA irqchip support") checkingKVM_CAP_IRQCHIPreturns non-zero when the RISC-V platform has AIA. The cap indicates KVM supports at least one of the following ioctls:
KVM_CREATE_IRQCHIP
KVM_IRQ_LINE
KVM_GET_IRQCHIP
KVM_SET_IRQCHIP
KVM_GET_LAPIC
KVM_SET_LAPICbut the cap doesn't imply that KVM must support any of those ioctls in particular. However, QEMU was assuming the
KVM_CREATE_IRQCHIPioctl was supported. Stop making that assumption by introducing a KVM parameter that each architecture which supportsKVM_CREATE_IRQCHIPsets. Adding parameters isn't awesome, but given how theKVM_CAP_IRQCHIPisn't very helpful on its own, we don't have a lot of options.Signed-off-by Andrew Jones <[email protected]>---
While this fixes booting guests on riscv KVM with AIA it's unlikely to get merged before the QEMU support for KVM AIA[1] lands, which would also fix the issue. I think this patch is still worth considering though since QEMU's assumption is wrong.
[1] https://lore.kernel.org/all/[email protected]/
accel/kvm/kvm-all.c | 5 ++++- include/sysemu/kvm.h | 1 + target/arm/kvm.c | 3 +++ target/i386/kvm/kvm.c | 2 ++ target/s390x/kvm/kvm.c | 3 +++ 5 files changed, 13 insertions(+), 1 deletion(-)accel/kvm/kvm-all.c +1
-0@@ -86,6 +86,7 @@ struct KVMParkedVcpu { };KVMState *kvm_state; +bool kvm_has_create_irqchip;bool kvm_kernel_irqchip;bool kvm_split_irqchip;bool kvm_async_interrupts_allowed;@@ -2377,8 +2378,10 @@ static void kvm_irqchip_create(KVMState *s)if (s->kernel_irqchip_split ==ON_OFF_AUTO_ON ) {accel/kvm/kvm-all.c static void kvm_irqchip_create(KVMState *s) · line 2387
Quoted 10 lines
accel/kvm/kvm-all.c +3
-1error_report ("Split IRQ chip mode not supported." );exit (1 ); - }else { + }else if (kvm_has_create_irqchip) { ret =kvm_vm_ioctl (s,KVM_CREATE_IRQCHIP ); + }else { +return ; } }if (ret <0 ) {I think I'd do this differntly... at the beginning of the function, there is a check for
kvm_check_extension(s, KVM_CAP_IRQCHIP)etc. ... I think you could now replace that check with a simple
Quoted 6 lines
if (!kvm_has_create_irqchip) { return; }The "
kvm_vm_enable_cap(s, KVM_CAP_S390_IRQCHIP, 0)" of course has to be moved to thetarget/s390x/kvm/kvm.cfile, too.
Actually, once we've moved the s390 cap enablement to the s390 file we can just drop the whole if-else chain. We don't want the
if (!kvm_has_create_irqchip) at the top because we want to try kvm_arch_irqchip_create() even when kvm_has_create_irqchip is false, and we don't need to check KVM_CREATE_IRQCHIP for kvm_arch_irqchip_create() either. Keeping the check, as it is above in this v1, of kvm_has_create_irqchip for KVM_CREATE_IRQCHIP is still necessary, though.
Thanks,
drew