From: Sean Christopherson <seanjc@google.com>
To: Wanpeng Li <kernellwp@gmail.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
Paolo Bonzini <pbonzini@redhat.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>
Subject: Re: [PATCH v2] KVM: x86/xen: Take srcu lock when accessing kvm_memslots()
Date: Fri, 23 Apr 2021 15:18:22 +0000 [thread overview]
Message-ID: <YILlPmN0fgLA8RkJ@google.com> (raw)
In-Reply-To: <1619166200-9215-1-git-send-email-wanpengli@tencent.com>
On Fri, Apr 23, 2021, Wanpeng Li wrote:
> From: Wanpeng Li <wanpengli@tencent.com>
>
> kvm_memslots() will be called by kvm_write_guest_offset_cached() so we should
> take the srcu lock. Let's pull the srcu lock operation from kvm_steal_time_set_preempted()
> again to fix xen part.
>
> Fixes: 30b5c851af7 (KVM: x86/xen: Add support for vCPU runstate information)
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> ---
> arch/x86/kvm/x86.c | 20 +++++++++-----------
> 1 file changed, 9 insertions(+), 11 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 3bf52ba..c775d24 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -4097,7 +4097,6 @@ static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)
> {
> struct kvm_host_map map;
> struct kvm_steal_time *st;
> - int idx;
>
> if (!(vcpu->arch.st.msr_val & KVM_MSR_ENABLED))
> return;
> @@ -4105,15 +4104,9 @@ static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)
> if (vcpu->arch.st.preempted)
> return;
>
> - /*
> - * Take the srcu lock as memslots will be accessed to check the gfn
> - * cache generation against the memslots generation.
> - */
> - idx = srcu_read_lock(&vcpu->kvm->srcu);
> -
> if (kvm_map_gfn(vcpu, vcpu->arch.st.msr_val >> PAGE_SHIFT, &map,
> &vcpu->arch.st.cache, true))
> - goto out;
> + return;
>
> st = map.hva +
> offset_in_page(vcpu->arch.st.msr_val & KVM_STEAL_VALID_BITS);
> @@ -4121,20 +4114,25 @@ static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)
> st->preempted = vcpu->arch.st.preempted = KVM_VCPU_PREEMPTED;
>
> kvm_unmap_gfn(vcpu, &map, &vcpu->arch.st.cache, true, true);
> -
> -out:
> - srcu_read_unlock(&vcpu->kvm->srcu, idx);
> }
>
> void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
> {
> + int idx;
> +
> if (vcpu->preempted && !vcpu->arch.guest_state_protected)
> vcpu->arch.preempted_in_kernel = !static_call(kvm_x86_get_cpl)(vcpu);
>
> + /*
> + * Take the srcu lock as memslots will be accessed to check the gfn
> + * cache generation against the memslots generation.
> + */
> + idx = srcu_read_lock(&vcpu->kvm->srcu);
Might be worth grabbing "kvm" in a local variable? Either way:
Reviewed-by: Sean Christopherson <seanjc@google.com>
> if (kvm_xen_msr_enabled(vcpu->kvm))
> kvm_xen_runstate_set_preempted(vcpu);
> else
> kvm_steal_time_set_preempted(vcpu);
> + srcu_read_unlock(&vcpu->kvm->srcu, idx);
>
> static_call(kvm_x86_vcpu_put)(vcpu);
> vcpu->arch.last_host_tsc = rdtsc();
> --
> 2.7.4
>
prev parent reply other threads:[~2021-04-23 15:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-23 8:23 [PATCH v2] KVM: x86/xen: Take srcu lock when accessing kvm_memslots() Wanpeng Li
2021-04-23 15:18 ` Sean Christopherson [this message]
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=YILlPmN0fgLA8RkJ@google.com \
--to=seanjc@google.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kernellwp@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
/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