From: Keir Fraser <keirf@google.com>
To: kvm@vger.kernel.org
Cc: Will Deacon <will@kernel.org>, Keir Fraser <keirf@google.com>
Subject: [kvmtool] Reset all VCPUs before any entering run loops
Date: Wed, 11 Dec 2024 09:45:14 +0000 [thread overview]
Message-ID: <20241211094514.4152415-1-keirf@google.com> (raw)
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
next reply other threads:[~2024-12-11 9:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-11 9:45 Keir Fraser [this message]
2024-12-11 23:44 ` [kvmtool] Reset all VCPUs before any entering run loops Will Deacon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241211094514.4152415-1-keirf@google.com \
--to=keirf@google.com \
--cc=kvm@vger.kernel.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox