On Mon, Feb 24, 2025 at 02:39:59PM +0530, Aneesh Kumar K.V (Arm) wrote: > The return value for kernel VM exit handlers is confusing and has led to > errors in different kernel exit handlers. A return value of 0 indicates > a return to the VMM, whereas a return value of 1 indicates resuming > execution in the guest. Some handlers mistakenly return 0 to force a > return to the guest. > > This worked in kvmtool because the exit_reason defaulted to > 0 (KVM_EXIT_UNKNOWN), and kvmtool did not error out on an unknown exit > reason. However, forcing a VMM exit with error on KVM_EXIT_UNKNOWN > exit_reson would help catch these bugs early. > > Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@xxxxxxxxxx> > --- > kvm-cpu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kvm-cpu.c b/kvm-cpu.c > index f66dcd07220c..7c62bfc56679 100644 > --- a/kvm-cpu.c > +++ b/kvm-cpu.c > @@ -170,7 +170,7 @@ int kvm_cpu__start(struct kvm_cpu *cpu) > > switch (cpu->kvm_run->exit_reason) { > case KVM_EXIT_UNKNOWN: > - break; > + goto panic_kvm; > case KVM_EXIT_DEBUG: > kvm_cpu__show_registers(cpu); > kvm_cpu__show_code(cpu); > -- > 2.43.0 This breaks SMP boot on my x86 machine: # ./lkvm run ... [ 0.628472] smp: Bringing up secondary CPUs ... [ 0.630401] smpboot: x86: Booting SMP configuration: Error: KVM exit reason: 0 ("KVM_EXIT_UNKNOWN") Error: KVM exit code: 0 Registers: ---------- rip: 0000000000000000 rsp: 0000000000000000 flags: 0000000000000002 rax: 0000000000000000 rbx: 0000000000000000 rcx: 0000000000000000 rdx: 0000000000050654 rsi: 0000000000000000 rdi: 0000000000000000 rbp: 0000000000000000 r8: 0000000000000000 r9: 0000000000000000 r10: 0000000000000000 r11: 0000000000000000 r12: 0000000000000000 r13: 0000000000000000 r14: 0000000000000000 r15: 0000000000000000 cr0: 0000000060000010 cr2: 0000000000000000 cr3: 0000000000000000 cr4: 0000000000000000 cr8: 0000000000000000 Segment registers: ------------------ register selector base limit type p dpl db s l g avl cs 9900 0000000000099000 0000ffff 0b 1 0 0 1 0 0 0 ss 0000 0000000000000000 0000ffff 03 1 0 0 1 0 0 0 ds 0000 0000000000000000 0000ffff 03 1 0 0 1 0 0 0 es 0000 0000000000000000 0000ffff 03 1 0 0 1 0 0 0 fs 0000 0000000000000000 0000ffff 03 1 0 0 1 0 0 0 gs 0000 0000000000000000 0000ffff 03 1 0 0 1 0 0 0 tr 0000 0000000000000000 0000ffff 0b 1 0 0 0 0 0 0 ldt 0000 0000000000000000 0000ffff 02 1 0 0 0 0 0 0 gdt 0000000000000000 0000ffff idt 0000000000000000 0000ffff APIC: ----- efer: 0000000000000000 apic base: 00000000fee00800 nmi: enabled Interrupt bitmap: ----------------- 0000000000000000 0000000000000000 0000000000000000 0000000000000000 Code: ----- Warning: symbol_lookup() failed to find symbol with error: -2 rip: [<0000000000000000>] <unknown> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 <fa> 0f 09 ea 08 10 00 98 8c c8 8e d8 8e c0 8e d0 66 f0 0f ba 2e Stack: ------ rsp: [<0000000000000000>] 0x00000000: 30 00 00 f0 30 00 00 f0 0x00000008: 30 00 00 f0 30 00 00 f0 0x00000010: 30 00 00 f0 30 00 00 f0 0x00000018: 30 00 00 f0 30 00 00 f0 Page Tables: ------ Not in protected mode