Message ID | 20241211094514.4152415-1-keirf@google.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [kvmtool] Reset all VCPUs before any entering run loops | expand |
On Wed, 11 Dec 2024 09:45:14 +0000, Keir Fraser wrote: > 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,
diff --git a/kvm-cpu.c b/kvm-cpu.c index 1c566b3..f66dcd0 100644 --- a/kvm-cpu.c +++ b/kvm-cpu.c @@ -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;
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. Signed-off-by: Keir Fraser <keirf@google.com> --- kvm-cpu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)