Reset all VCPUs before any entering run loops
VCPU threads may currently enter their run loops before all other VCPUs have "reset" to an appropriate initial state.
Actually this normally works okay, but on pKVM-ARM the VM's Hyp state (including boot VCPU's initial state) gets set up by the first VCPU thread to call ioctl(KVM_RUN). This races boot VCPU thread's intialisation of register state, and can result in the boot VCPU starting execution at PC=0.
The simplest fix is to reset each VCPU when it is first created, before the VCPU run threads are even created.
--- kvm-cpu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kvm-cpu.c +1 -2
@@ -154,8 +154,6 @@ int kvm_cpu__start(struct kvm_cpu *cpu)signal (SIGKVMPAUSE , kvm_cpu_signal_handler);signal (SIGKVMTASK , kvm_cpu_signal_handler); -kvm_cpu__reset_vcpu (cpu); -if (cpu->kvm->cfg.single_step)kvm_cpu__enable_singlestep (cpu);
@@ -293,6 +291,7 @@ int kvm_cpu__init(struct kvm *kvm)pr_err ("unable to initialize KVM VCPU" ); goto fail_alloc; } +kvm_cpu__reset_vcpu (kvm->cpus[i]); }return 0 ;
Signature · 1 line
2.47.1.545.g3c1d2e2a6a-goog
Will Deacon
AppliedQuoted 10 lines · Keir Fraser
VCPU threads may currently enter their run loops before all other VCPUs have "reset" to an appropriate initial state.
Actually this normally works okay, but on pKVM-ARM the VM's Hyp state (including boot VCPU's initial state) gets set up by the first VCPU thread to call
ioctl(KVM_RUN). This races boot VCPU thread's intialisation of register state, and can result in the boot VCPU starting execution at PC=0.[...]
Applied to kvmtool (master), thanks!
[1/1] Reset all VCPUs before any entering run loops
https://git.kernel.org/will/kvmtool/c/6d754d01fe2c
Cheers,
Signature · 5 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev