Skip to content

Commit 2dcc48b

Browse files
danielhbMichael Tokarev
authored andcommitted
target/riscv/kvm: tolerate KVM disable ext errors
Running a KVM guest using a 6.9-rc3 kernel, in a 6.8 host that has zkr enabled, will fail with a kernel oops SIGILL right at the start. The reason is that we can't expose zkr without implementing the SEED CSR. Disabling zkr in the guest would be a workaround, but if the KVM doesn't allow it we'll error out and never boot. In hindsight this is too strict. If we keep proceeding, despite not disabling the extension in the KVM vcpu, we'll not add the extension in the riscv,isa. The guest kernel will be unaware of the extension, i.e. it doesn't matter if the KVM vcpu has it enabled underneath or not. So it's ok to keep booting in this case. Change our current logic to not error out if we fail to disable an extension in kvm_set_one_reg(), but show a warning and keep booting. It is important to throw a warning because we must make the user aware that the extension is still available in the vcpu, meaning that an ill-behaved guest can ignore the riscv,isa settings and use the extension. The case we're handling happens with an EINVAL error code. If we fail to disable the extension in KVM for any other reason, error out. We'll also keep erroring out when we fail to enable an extension in KVM, since adding the extension in riscv,isa at this point will cause a guest malfunction because the extension isn't enabled in the vcpu. Suggested-by: Andrew Jones <[email protected]> Signed-off-by: Daniel Henrique Barboza <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Cc: qemu-stable <[email protected]> Message-ID: <[email protected]> Signed-off-by: Alistair Francis <[email protected]> (cherry picked from commit 1215d45) Signed-off-by: Michael Tokarev <[email protected]>
1 parent 2ae8e12 commit 2dcc48b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

target/riscv/kvm/kvm-cpu.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,14 @@ static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs)
427427
reg = kvm_cpu_cfg_get(cpu, multi_ext_cfg);
428428
ret = kvm_set_one_reg(cs, id, &reg);
429429
if (ret != 0) {
430-
error_report("Unable to %s extension %s in KVM, error %d",
431-
reg ? "enable" : "disable",
432-
multi_ext_cfg->name, ret);
433-
exit(EXIT_FAILURE);
430+
if (!reg && ret == -EINVAL) {
431+
warn_report("KVM cannot disable extension %s",
432+
multi_ext_cfg->name);
433+
} else {
434+
error_report("Unable to enable extension %s in KVM, error %d",
435+
multi_ext_cfg->name, ret);
436+
exit(EXIT_FAILURE);
437+
}
434438
}
435439
}
436440
}

0 commit comments

Comments
 (0)