* [kvmtool] Reset all VCPUs before any entering run loops
@ 2024-12-11 9:45 Keir Fraser
2024-12-11 23:44 ` Will Deacon
0 siblings, 1 reply; 2+ messages in thread
From: Keir Fraser @ 2024-12-11 9:45 UTC (permalink / raw)
To: kvm; +Cc: Will Deacon, 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.
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(-)
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;
--
2.47.1.545.g3c1d2e2a6a-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [kvmtool] Reset all VCPUs before any entering run loops
2024-12-11 9:45 [kvmtool] Reset all VCPUs before any entering run loops Keir Fraser
@ 2024-12-11 23:44 ` Will Deacon
0 siblings, 0 replies; 2+ messages in thread
From: Will Deacon @ 2024-12-11 23:44 UTC (permalink / raw)
To: kvm, Keir Fraser; +Cc: catalin.marinas, kernel-team, Will Deacon
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,
--
Will
https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-12-11 23:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-11 9:45 [kvmtool] Reset all VCPUs before any entering run loops Keir Fraser
2024-12-11 23:44 ` Will Deacon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox