kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: David Matlack <dmatlack@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org, Ben Gardon <bgardon@google.com>,
	Joerg Roedel <joro@8bytes.org>, Jim Mattson <jmattson@google.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Janis Schoetterl-Glausch <scgl@linux.vnet.ibm.com>,
	Junaid Shahid <junaids@google.com>,
	Oliver Upton <oupton@google.com>,
	Harish Barathvajasankar <hbarath@google.com>,
	Peter Xu <peterx@redhat.com>, Peter Shier <pshier@google.com>,
	"Nikunj A . Dadhania" <nikunj@amd.com>
Subject: Re: [PATCH v1 05/13] KVM: x86/mmu: Move restore_acc_track_spte to spte.c
Date: Thu, 6 Jan 2022 20:27:38 +0000	[thread overview]
Message-ID: <YddQutP4wnCylJwn@google.com> (raw)
In-Reply-To: <20211213225918.672507-6-dmatlack@google.com>

On Mon, Dec 13, 2021, David Matlack wrote:
> restore_acc_track_spte is purely an SPTE manipulation, making it a good
> fit for spte.c. It is also needed in spte.c in a follow-up commit so we
> can construct child SPTEs during large page splitting.
> 
> No functional change intended.
> 
> Signed-off-by: David Matlack <dmatlack@google.com>
> Reviewed-by: Ben Gardon <bgardon@google.com>
> ---
>  arch/x86/kvm/mmu/mmu.c  | 18 ------------------
>  arch/x86/kvm/mmu/spte.c | 18 ++++++++++++++++++
>  arch/x86/kvm/mmu/spte.h |  1 +
>  3 files changed, 19 insertions(+), 18 deletions(-)
> 
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index 8b702f2b6a70..3c2cb4dd1f11 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -646,24 +646,6 @@ static u64 mmu_spte_get_lockless(u64 *sptep)
>  	return __get_spte_lockless(sptep);
>  }
>  
> -/* Restore an acc-track PTE back to a regular PTE */
> -static u64 restore_acc_track_spte(u64 spte)
> -{
> -	u64 new_spte = spte;
> -	u64 saved_bits = (spte >> SHADOW_ACC_TRACK_SAVED_BITS_SHIFT)
> -			 & SHADOW_ACC_TRACK_SAVED_BITS_MASK;
> -
> -	WARN_ON_ONCE(spte_ad_enabled(spte));
> -	WARN_ON_ONCE(!is_access_track_spte(spte));
> -
> -	new_spte &= ~shadow_acc_track_mask;
> -	new_spte &= ~(SHADOW_ACC_TRACK_SAVED_BITS_MASK <<
> -		      SHADOW_ACC_TRACK_SAVED_BITS_SHIFT);
> -	new_spte |= saved_bits;
> -
> -	return new_spte;
> -}
> -
>  /* Returns the Accessed status of the PTE and resets it at the same time. */
>  static bool mmu_spte_age(u64 *sptep)
>  {
> diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c
> index 8a7b03207762..fd34ae5d6940 100644
> --- a/arch/x86/kvm/mmu/spte.c
> +++ b/arch/x86/kvm/mmu/spte.c
> @@ -268,6 +268,24 @@ u64 mark_spte_for_access_track(u64 spte)
>  	return spte;
>  }
>  
> +/* Restore an acc-track PTE back to a regular PTE */
> +u64 restore_acc_track_spte(u64 spte)
> +{
> +	u64 new_spte = spte;
> +	u64 saved_bits = (spte >> SHADOW_ACC_TRACK_SAVED_BITS_SHIFT)
> +			 & SHADOW_ACC_TRACK_SAVED_BITS_MASK;

Obviously not your code, but this could be:

	u64 saved_bits = (spte >> SHADOW_ACC_TRACK_SAVED_BITS_SHIFT) &
			 SHADOW_ACC_TRACK_SAVED_BITS_MASK;

	WARN_ON_ONCE(spte_ad_enabled(spte));
	WARN_ON_ONCE(!is_access_track_spte(spte));

	spte &= ~shadow_acc_track_mask;
	spte &= ~(SHADOW_ACC_TRACK_SAVED_BITS_MASK <<
		  SHADOW_ACC_TRACK_SAVED_BITS_SHIFT);
	spte |= saved_bits;

	return spte;

which is really just an excuse to move the ampersand up a line :-)

And looking at the two callers, the WARNs are rather silly.  The spte_ad_enabled()
WARN is especially pointless because that's also checked by is_access_track_spte().
I like paranoid WARNs as much as anyone, but I don't see why this code warrants
extra checking relative to the other SPTE helpers that have more subtle requirements.

At that point, make make this an inline helper?

  static inline u64 restore_acc_track_spte(u64 spte)
  {
	u64 saved_bits = (spte >> SHADOW_ACC_TRACK_SAVED_BITS_SHIFT) &
			 SHADOW_ACC_TRACK_SAVED_BITS_MASK;

	spte &= ~shadow_acc_track_mask;
	spte &= ~(SHADOW_ACC_TRACK_SAVED_BITS_MASK <<
		  SHADOW_ACC_TRACK_SAVED_BITS_SHIFT);
	spte |= saved_bits;

	return spte;
  }

> +	WARN_ON_ONCE(spte_ad_enabled(spte));
> +	WARN_ON_ONCE(!is_access_track_spte(spte));
> +
> +	new_spte &= ~shadow_acc_track_mask;
> +	new_spte &= ~(SHADOW_ACC_TRACK_SAVED_BITS_MASK <<
> +		      SHADOW_ACC_TRACK_SAVED_BITS_SHIFT);
> +	new_spte |= saved_bits;
> +
> +	return new_spte;
> +}
> +
>  void kvm_mmu_set_mmio_spte_mask(u64 mmio_value, u64 mmio_mask, u64 access_mask)
>  {
>  	BUG_ON((u64)(unsigned)access_mask != access_mask);
> diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h
> index a4af2a42695c..9b0c7b27f23f 100644
> --- a/arch/x86/kvm/mmu/spte.h
> +++ b/arch/x86/kvm/mmu/spte.h
> @@ -337,6 +337,7 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
>  u64 make_nonleaf_spte(u64 *child_pt, bool ad_disabled);
>  u64 make_mmio_spte(struct kvm_vcpu *vcpu, u64 gfn, unsigned int access);
>  u64 mark_spte_for_access_track(u64 spte);
> +u64 restore_acc_track_spte(u64 spte);
>  u64 kvm_mmu_changed_pte_notifier_make_spte(u64 old_spte, kvm_pfn_t new_pfn);
>  
>  void kvm_mmu_reset_all_pte_masks(void);
> -- 
> 2.34.1.173.g76aa8bc2d0-goog
> 

  parent reply	other threads:[~2022-01-06 20:27 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-13 22:59 [PATCH v1 00/13] KVM: x86/mmu: Eager Page Splitting for the TDP MMU David Matlack
2021-12-13 22:59 ` [PATCH v1 01/13] KVM: x86/mmu: Rename rmap_write_protect to kvm_vcpu_write_protect_gfn David Matlack
2022-01-06  0:35   ` Sean Christopherson
2021-12-13 22:59 ` [PATCH v1 02/13] KVM: x86/mmu: Rename __rmap_write_protect to rmap_write_protect David Matlack
2022-01-06  0:35   ` Sean Christopherson
2021-12-13 22:59 ` [PATCH v1 03/13] KVM: x86/mmu: Automatically update iter->old_spte if cmpxchg fails David Matlack
2022-01-04 10:13   ` Peter Xu
2022-01-04 17:29     ` Ben Gardon
2022-01-06  0:54   ` Sean Christopherson
2022-01-06 18:04     ` David Matlack
2021-12-13 22:59 ` [PATCH v1 04/13] KVM: x86/mmu: Factor out logic to atomically install a new page table David Matlack
2022-01-04 10:32   ` Peter Xu
2022-01-04 18:26     ` David Matlack
2022-01-05  1:00       ` Peter Xu
2022-01-06 20:12   ` Sean Christopherson
2022-01-06 22:56     ` David Matlack
2022-01-07 18:24       ` David Matlack
2022-01-07 21:39         ` Sean Christopherson
2021-12-13 22:59 ` [PATCH v1 05/13] KVM: x86/mmu: Move restore_acc_track_spte to spte.c David Matlack
2022-01-04 10:33   ` Peter Xu
2022-01-06 20:27   ` Sean Christopherson [this message]
2022-01-06 22:58     ` David Matlack
2021-12-13 22:59 ` [PATCH v1 06/13] KVM: x86/mmu: Refactor tdp_mmu iterators to take kvm_mmu_page root David Matlack
2022-01-04 10:35   ` Peter Xu
2022-01-06 20:34   ` Sean Christopherson
2022-01-06 22:57     ` David Matlack
2021-12-13 22:59 ` [PATCH v1 07/13] KVM: x86/mmu: Derive page role from parent David Matlack
2022-01-05  7:51   ` Peter Xu
2022-01-06 20:45   ` Sean Christopherson
2022-01-06 23:00     ` David Matlack
2021-12-13 22:59 ` [PATCH v1 08/13] KVM: x86/mmu: Refactor TDP MMU child page initialization David Matlack
2022-01-05  7:51   ` Peter Xu
2022-01-06 20:59   ` Sean Christopherson
2022-01-06 22:08     ` David Matlack
2022-01-06 23:02       ` Sean Christopherson
2021-12-13 22:59 ` [PATCH v1 09/13] KVM: x86/mmu: Split huge pages when dirty logging is enabled David Matlack
2022-01-05  7:54   ` Peter Xu
2022-01-05 17:49     ` David Matlack
2022-01-06 22:48       ` Sean Christopherson
2022-01-06 21:28   ` Sean Christopherson
2022-01-06 22:20     ` David Matlack
2022-01-06 22:56       ` Sean Christopherson
2022-01-07  2:02       ` Peter Xu
2022-01-07  2:06   ` Peter Xu
2021-12-13 22:59 ` [PATCH v1 10/13] KVM: Push MMU locking down into kvm_arch_mmu_enable_log_dirty_pt_masked David Matlack
2021-12-13 22:59 ` [PATCH v1 11/13] KVM: x86/mmu: Split huge pages during CLEAR_DIRTY_LOG David Matlack
2022-01-05  9:02   ` Peter Xu
2022-01-05 17:55     ` David Matlack
2022-01-05 17:57       ` David Matlack
2021-12-13 22:59 ` [PATCH v1 12/13] KVM: x86/mmu: Add tracepoint for splitting huge pages David Matlack
2022-01-05  8:38   ` Peter Xu
2022-01-06 23:14   ` Sean Christopherson
2022-01-07  0:54     ` David Matlack
2021-12-13 22:59 ` [PATCH v1 13/13] KVM: selftests: Add an option to disable MANUAL_PROTECT_ENABLE and INITIALLY_SET David Matlack
2022-01-05  8:38   ` Peter Xu

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=YddQutP4wnCylJwn@google.com \
    --to=seanjc@google.com \
    --cc=bgardon@google.com \
    --cc=dmatlack@google.com \
    --cc=hbarath@google.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=junaids@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=nikunj@amd.com \
    --cc=oupton@google.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=pshier@google.com \
    --cc=scgl@linux.vnet.ibm.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).