From: David Matlack <dmatlack@google.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Yosry Ahmed <yosryahmed@google.com>,
Mingwei Zhang <mizhang@google.com>,
Ben Gardon <bgardon@google.com>
Subject: Re: [PATCH v2 5/6] KVM: x86/mmu: Add helper to convert SPTE value to its shadow page
Date: Mon, 25 Jul 2022 16:23:52 -0700 [thread overview]
Message-ID: <Yt8mCI7MFhZbT+5R@google.com> (raw)
In-Reply-To: <20220723012325.1715714-6-seanjc@google.com>
On Sat, Jul 23, 2022 at 01:23:24AM +0000, Sean Christopherson wrote:
> Add a helper to convert a SPTE to its shadow page to deduplicate a
> variety of flows and hopefully avoid future bugs, e.g. if KVM attempts to
> get the shadow page for a SPTE without dropping high bits.
>
> Opportunistically add a comment in mmu_free_root_page() documenting why
> it treats the root HPA as a SPTE.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
[...]
> --- a/arch/x86/kvm/mmu/spte.h
> +++ b/arch/x86/kvm/mmu/spte.h
> @@ -207,6 +207,23 @@ static inline int spte_index(u64 *sptep)
> */
> extern u64 __read_mostly shadow_nonpresent_or_rsvd_lower_gfn_mask;
>
> +static inline struct kvm_mmu_page *to_shadow_page(hpa_t shadow_page)
> +{
> + struct page *page = pfn_to_page((shadow_page) >> PAGE_SHIFT);
> +
> + return (struct kvm_mmu_page *)page_private(page);
> +}
> +
> +static inline struct kvm_mmu_page *spte_to_sp(u64 spte)
> +{
> + return to_shadow_page(spte & SPTE_BASE_ADDR_MASK);
> +}
spte_to_sp() and sptep_to_sp() are a bit hard to differentiate visually.
Maybe spte_to_child_sp() or to_child_sp()?
> +
> +static inline struct kvm_mmu_page *sptep_to_sp(u64 *sptep)
> +{
> + return to_shadow_page(__pa(sptep));
> +}
> +
> static inline bool is_mmio_spte(u64 spte)
> {
> return (spte & shadow_mmio_mask) == shadow_mmio_value &&
> diff --git a/arch/x86/kvm/mmu/tdp_mmu.h b/arch/x86/kvm/mmu/tdp_mmu.h
> index c163f7cc23ca..d3714200b932 100644
> --- a/arch/x86/kvm/mmu/tdp_mmu.h
> +++ b/arch/x86/kvm/mmu/tdp_mmu.h
> @@ -5,6 +5,8 @@
>
> #include <linux/kvm_host.h>
>
> +#include "spte.h"
> +
> hpa_t kvm_tdp_mmu_get_vcpu_root_hpa(struct kvm_vcpu *vcpu);
>
> __must_check static inline bool kvm_tdp_mmu_get_root(struct kvm_mmu_page *root)
> --
> 2.37.1.359.gd136c6c3e2-goog
>
next prev parent reply other threads:[~2022-07-25 23:24 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-23 1:23 [PATCH v2 0/6] KVM: x86: Apply NX mitigation more precisely Sean Christopherson
2022-07-23 1:23 ` [PATCH v2 1/6] KVM: x86/mmu: Tag disallowed NX huge pages even if they're not tracked Sean Christopherson
2022-07-25 22:49 ` David Matlack
2022-07-25 23:26 ` Sean Christopherson
2022-07-25 23:45 ` David Matlack
2022-07-26 0:01 ` Sean Christopherson
2022-07-28 22:11 ` Paolo Bonzini
2022-07-23 1:23 ` [PATCH v2 2/6] KVM: x86/mmu: Properly account NX huge page workaround for nonpaging MMUs Sean Christopherson
2022-07-25 23:05 ` David Matlack
2022-07-25 23:08 ` David Matlack
2022-07-28 20:15 ` Paolo Bonzini
2022-07-23 1:23 ` [PATCH v2 3/6] KVM: x86/mmu: Set disallowed_nx_huge_page in TDP MMU before setting SPTE Sean Christopherson
2022-07-25 23:16 ` David Matlack
2022-07-23 1:23 ` [PATCH v2 4/6] KVM: x86/mmu: Track the number of TDP MMU pages, but not the actual pages Sean Christopherson
2022-07-25 23:21 ` David Matlack
2022-07-25 23:27 ` Sean Christopherson
2022-07-27 2:41 ` Yan Zhao
2022-07-27 19:04 ` Sean Christopherson
2022-07-29 1:02 ` Yan Zhao
2022-07-23 1:23 ` [PATCH v2 5/6] KVM: x86/mmu: Add helper to convert SPTE value to its shadow page Sean Christopherson
2022-07-25 23:23 ` David Matlack [this message]
2022-07-25 23:33 ` Sean Christopherson
2022-07-23 1:23 ` [PATCH v2 6/6] KVM: x86/mmu: explicitly check nx_hugepage in disallowed_hugepage_adjust() Sean Christopherson
2022-07-25 23:28 ` David Matlack
2022-07-26 5:37 ` [PATCH v2 0/6] KVM: x86: Apply NX mitigation more precisely Mingwei Zhang
2022-07-26 16:40 ` Sean Christopherson
2022-07-26 17:21 ` Sean Christopherson
2022-07-28 20:17 ` Paolo Bonzini
2022-07-28 21:20 ` Sean Christopherson
2022-07-28 21:41 ` Mingwei Zhang
2022-07-28 22:09 ` Paolo Bonzini
2022-07-28 22:15 ` Sean Christopherson
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=Yt8mCI7MFhZbT+5R@google.com \
--to=dmatlack@google.com \
--cc=bgardon@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mizhang@google.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=yosryahmed@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.