From: Paolo Bonzini <pbonzini@redhat.com>
To: Wanpeng Li <kernellwp@gmail.com>,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: "Radim Krčmář" <rkrcmar@redhat.com>,
stable@vger.kernel.org, "Marc Zyngier" <Marc.Zyngier@arm.com>,
"Christian Borntraeger" <borntraeger@de.ibm.com>
Subject: Re: [PATCH v2 3/3] KVM: Fix leak vCPU's VMCS value into other pCPU
Date: Wed, 31 Jul 2019 14:55:33 +0200 [thread overview]
Message-ID: <9240ada8-8e18-d2b2-006e-41ededb89efb@redhat.com> (raw)
In-Reply-To: <1564573198-16219-1-git-send-email-wanpengli@tencent.com>
On 31/07/19 13:39, Wanpeng Li wrote:
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index ed061d8..12f2c91 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -2506,7 +2506,7 @@ void kvm_vcpu_on_spin(struct kvm_vcpu *me, bool yield_to_kernel_mode)
> continue;
> if (vcpu == me)
> continue;
> - if (swait_active(&vcpu->wq) && !kvm_arch_vcpu_runnable(vcpu))
> + if (READ_ONCE(vcpu->preempted) && swait_active(&vcpu->wq))
> continue;
> if (READ_ONCE(vcpu->preempted) && yield_to_kernel_mode &&
> !kvm_arch_vcpu_in_kernel(vcpu))
>
This cannot work. swait_active means you are waiting, so you cannot be
involuntarily preempted.
The problem here is simply that kvm_vcpu_has_events is being called
without holding the lock. So kvm_arch_vcpu_runnable is okay, it's the
implementation that's wrong.
Just rename the existing function to just vcpu_runnable and make a new
arch callback kvm_arch_dy_runnable. kvm_arch_dy_runnable can be
conservative and only returns true for a subset of events, in particular
for x86 it can check:
- vcpu->arch.pv.pv_unhalted
- KVM_REQ_NMI or KVM_REQ_SMI or KVM_REQ_EVENT
- PIR.ON if APICv is set
Ultimately, all variables accessed in kvm_arch_dy_runnable should be
accessed with READ_ONCE or atomic_read.
And for all architectures, kvm_vcpu_on_spin should check
list_empty_careful(&vcpu->async_pf.done)
It's okay if your patch renames the function in non-x86 architectures,
leaving the fix to maintainers. So, let's CC Marc and Christian since
ARM and s390 have pretty complex kvm_arch_vcpu_runnable as well.
Paolo
next prev parent reply other threads:[~2019-07-31 12:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-31 11:27 [PATCH 1/3] KVM: Don't need to wakeup vCPU twice afer timer fire Wanpeng Li
2019-07-31 11:27 ` [PATCH 2/3] KVM: Check preempted_in_kernel for involuntary preemption Wanpeng Li
2019-07-31 11:27 ` [PATCH 3/3] KVM: Fix leak vCPU's VMCS value into other pCPU Wanpeng Li
2019-07-31 11:39 ` [PATCH v2 " Wanpeng Li
2019-07-31 12:55 ` Paolo Bonzini [this message]
2019-08-01 3:35 ` Wanpeng Li
2019-07-31 12:56 ` [PATCH 1/3] KVM: Don't need to wakeup vCPU twice afer timer fire Paolo Bonzini
2019-07-31 13:14 ` Vitaly Kuznetsov
2019-07-31 16:39 ` Paolo Bonzini
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=9240ada8-8e18-d2b2-006e-41ededb89efb@redhat.com \
--to=pbonzini@redhat.com \
--cc=Marc.Zyngier@arm.com \
--cc=borntraeger@de.ibm.com \
--cc=kernellwp@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rkrcmar@redhat.com \
--cc=stable@vger.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