kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ben Gardon <bgardon@google.com>
To: Sean Christopherson <seanjc@google.com>
Cc: 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>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: x86/mmu: Properly dereference rcu-protected TDP MMU sptep iterator
Date: Wed, 3 Nov 2021 09:36:23 -0700	[thread overview]
Message-ID: <CANgfPd9VVAdP0umt6Odz_-f+nUmKfsNa0hqvUzuto6=G6b=M+A@mail.gmail.com> (raw)
In-Reply-To: <20211103161833.3769487-1-seanjc@google.com>

On Wed, Nov 3, 2021 at 9:18 AM Sean Christopherson <seanjc@google.com> wrote:
>
> Wrap the read of iter->sptep in tdp_mmu_map_handle_target_level() with
> rcu_dereference().  Shadow pages in the TDP MMU, and thus their SPTEs,
> are protected by rcu.
>
> This fixes a Sparse warning at tdp_mmu.c:900:51:
>   warning: incorrect type in argument 1 (different address spaces)
>   expected unsigned long long [usertype] *sptep
>   got unsigned long long [noderef] [usertype] __rcu *[usertype] sptep
>
> Fixes: 7158bee4b475 ("KVM: MMU: pass kvm_mmu_page struct to make_spte")
> Cc: Ben Gardon <bgardon@google.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>

Reviewed-by: Ben Gardon <bgardon@google.com>

This change looks good to me. It also reminds me that the struct
kvm_mmu_pages are also protected by RCU.
I wonder if it would be worth creating something similar to tdp_ptep_t
for the struct kvm_mmu_pages to add RCU annotations to them as well.

> ---
>  arch/x86/kvm/mmu/tdp_mmu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
> index 7c5dd83e52de..a54c3491af42 100644
> --- a/arch/x86/kvm/mmu/tdp_mmu.c
> +++ b/arch/x86/kvm/mmu/tdp_mmu.c
> @@ -897,7 +897,7 @@ static int tdp_mmu_map_handle_target_level(struct kvm_vcpu *vcpu,
>                                           struct kvm_page_fault *fault,
>                                           struct tdp_iter *iter)
>  {
> -       struct kvm_mmu_page *sp = sptep_to_sp(iter->sptep);
> +       struct kvm_mmu_page *sp = sptep_to_sp(rcu_dereference(iter->sptep));
>         u64 new_spte;
>         int ret = RET_PF_FIXED;
>         bool wrprot = false;
> --
> 2.33.1.1089.g2158813163f-goog
>

      reply	other threads:[~2021-11-03 16:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-03 16:18 [PATCH] KVM: x86/mmu: Properly dereference rcu-protected TDP MMU sptep iterator Sean Christopherson
2021-11-03 16:36 ` Ben Gardon [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='CANgfPd9VVAdP0umt6Odz_-f+nUmKfsNa0hqvUzuto6=G6b=M+A@mail.gmail.com' \
    --to=bgardon@google.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.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;
as well as URLs for NNTP newsgroup(s).