From: Thomas Gleixner <tglx@linutronix.de>
To: Paolo Bonzini <pbonzini@redhat.com>,
"Tian, Kevin" <kevin.tian@intel.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"Yamahata, Isaku" <isaku.yamahata@intel.com>,
"Huang, Kai" <kai.huang@intel.com>,
"Nakajima, Jun" <jun.nakajima@intel.com>,
"Hansen, Dave" <dave.hansen@intel.com>,
"Gao, Chao" <chao.gao@intel.com>,
Peter Zijlstra <peterz@infradead.org>
Subject: Re: Q. about KVM and CPU hotplug
Date: Tue, 30 Nov 2021 15:05:50 +0100 [thread overview]
Message-ID: <8735ndd9hd.ffs@tglx> (raw)
In-Reply-To: <3d3296f0-9245-40f9-1b5a-efffdb082de9@redhat.com>
On Tue, Nov 30 2021 at 10:28, Paolo Bonzini wrote:
> On 11/30/21 09:27, Tian, Kevin wrote:
>> r = kvm_arch_hardware_enable();
>>
>> if (r) {
>> cpumask_clear_cpu(cpu, cpus_hardware_enabled);
>> atomic_inc(&hardware_enable_failed);
>> pr_info("kvm: enabling virtualization on CPU%d failed\n", cpu);
>> }
>> }
>>
>> Upon error hardware_enable_failed is incremented. However this variable
>> is checked only in hardware_enable_all() called when the 1st VM is called.
>>
>> This implies that KVM may be left in a state where it doesn't know a CPU
>> not ready to host VMX operations.
>>
>> Then I'm curious what will happen if a vCPU is scheduled to this CPU. Does
>> KVM indirectly catch it (e.g. vmenter fail) and return a deterministic error
>> to Qemu at some point or may it lead to undefined behavior? And is there
>> any method to prevent vCPU thread from being scheduled to the CPU?
>
> It should fail the first vmptrld instruction. It will result in a few
> WARN_ONCE and pr_warn_ratelimited (see vmx_insn_failed). For VMX this
> should be a pretty bad firmware bug, and it has never been reported.
> KVM did find some undocumented errata but not this one!
>
> I don't think there's any fix other than pinning userspace. The WARNs
> can be eliminated by calling KVM_BUG_ON in the sched_in notifier, plus
> checking if the VM is bugged before entering the guest or doing a
> VMREAD/VMWRITE (usually the check is done only in a ioctl). But some
> refactoring is probably needed to make the code more robust in general.
Why is this hotplug callback in the CPU starting section to begin with?
If you stick it into the online section which runs on the hotplugged CPU
in thread context:
CPUHP_AP_ONLINE_IDLE,
--> CPUHP_AP_KVM_STARTING,
CPUHP_AP_SCHED_WAIT_EMPTY,
then it is allowed to fail and it still works in the right way.
When onlining a CPU then there cannot be any vCPU task run on the
CPU at that point.
When offlining a CPU then it's guaranteed that all user tasks and
non-pinned kernel tasks have left the CPU, i.e. there cannot be a vCPU
task around either.
Thanks,
tglx
next prev parent reply other threads:[~2021-11-30 14:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-30 8:27 Q. about KVM and CPU hotplug Tian, Kevin
2021-11-30 9:28 ` Paolo Bonzini
2021-11-30 14:05 ` Thomas Gleixner [this message]
2021-11-30 16:27 ` Paolo Bonzini
2021-12-01 7:18 ` Tian, Kevin
2021-11-30 20:02 ` Sean Christopherson
2021-12-01 6:59 ` Tian, Kevin
2021-12-01 10:30 ` Thomas Gleixner
2021-12-04 3:57 ` Tian, Kevin
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=8735ndd9hd.ffs@tglx \
--to=tglx@linutronix.de \
--cc=chao.gao@intel.com \
--cc=dave.hansen@intel.com \
--cc=isaku.yamahata@intel.com \
--cc=jun.nakajima@intel.com \
--cc=kai.huang@intel.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.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