kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Matlack <dmatlack@google.com>
To: Vipin Sharma <vipinsh@google.com>
Cc: seanjc@google.com, pbonzini@redhat.com, bgardon@google.com,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [Patch v3 7/7] KVM: x86/mmu: Merge all handle_changed_pte* functions.
Date: Wed, 22 Feb 2023 11:42:55 -0800	[thread overview]
Message-ID: <Y/ZwP18nw/PIHGsK@google.com> (raw)
In-Reply-To: <20230211014626.3659152-8-vipinsh@google.com>

On Fri, Feb 10, 2023 at 05:46:26PM -0800, Vipin Sharma wrote:
> __handle_changed_pte() and handle_changed_spte_acc_track() are always
> used together. Merge these two functions and name the new function

nit: State what the patch does first.

> handle_changed_pte(). Remove the existing handle_changed_pte() function
> which just calls __handle_changed_pte and
> handle_changed_spte_acc_track().

s/_pte/_spte/

> 
> This converges SPTEs change handling code to a single place.
> 
> Signed-off-by: Vipin Sharma <vipinsh@google.com>
> Reviewed-by: Ben Gardon <bgardon@google.com>

Nice cleanup! Commit message nits aside,

Reviewed-by: David Matlack <dmatlack@google.com>

> ---
>  arch/x86/kvm/mmu/tdp_mmu.c | 42 +++++++++++---------------------------
>  1 file changed, 12 insertions(+), 30 deletions(-)
> 
> diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
> index 0c031319e901..67538ec48ce5 100644
> --- a/arch/x86/kvm/mmu/tdp_mmu.c
> +++ b/arch/x86/kvm/mmu/tdp_mmu.c
> @@ -334,17 +334,6 @@ static void handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn,
>  				u64 old_spte, u64 new_spte, int level,
>  				bool shared);
>  
> -static void handle_changed_spte_acc_track(u64 old_spte, u64 new_spte, int level)
> -{
> -	if (!is_shadow_present_pte(old_spte) || !is_last_spte(old_spte, level))
> -		return;
> -
> -	if (is_accessed_spte(old_spte) &&
> -	    (!is_shadow_present_pte(new_spte) || !is_accessed_spte(new_spte) ||
> -	     spte_to_pfn(old_spte) != spte_to_pfn(new_spte)))
> -		kvm_set_pfn_accessed(spte_to_pfn(old_spte));
> -}
> -
>  static void tdp_account_mmu_page(struct kvm *kvm, struct kvm_mmu_page *sp)
>  {
>  	kvm_account_pgtable_pages((void *)sp->spt, +1);
> @@ -487,7 +476,7 @@ static void handle_removed_pt(struct kvm *kvm, tdp_ptep_t pt, bool shared)
>  }
>  
>  /**
> - * __handle_changed_spte - handle bookkeeping associated with an SPTE change
> + * handle_changed_spte - handle bookkeeping associated with an SPTE change
>   * @kvm: kvm instance
>   * @as_id: the address space of the paging structure the SPTE was a part of
>   * @gfn: the base GFN that was mapped by the SPTE
> @@ -501,9 +490,9 @@ static void handle_removed_pt(struct kvm *kvm, tdp_ptep_t pt, bool shared)
>   * Handle bookkeeping that might result from the modification of a SPTE.
>   * This function must be called for all TDP SPTE modifications.
>   */
> -static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn,
> -				  u64 old_spte, u64 new_spte, int level,
> -				  bool shared)
> +static void handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn,
> +				u64 old_spte, u64 new_spte, int level,
> +				bool shared)
>  {
>  	bool was_present = is_shadow_present_pte(old_spte);
>  	bool is_present = is_shadow_present_pte(new_spte);
> @@ -587,15 +576,10 @@ static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn,
>  	if (was_present && !was_leaf &&
>  	    (is_leaf || !is_present || WARN_ON_ONCE(pfn_changed)))
>  		handle_removed_pt(kvm, spte_to_child_pt(old_spte, level), shared);
> -}
>  
> -static void handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn,
> -				u64 old_spte, u64 new_spte, int level,
> -				bool shared)
> -{
> -	__handle_changed_spte(kvm, as_id, gfn, old_spte, new_spte, level,
> -			      shared);
> -	handle_changed_spte_acc_track(old_spte, new_spte, level);
> +	if (was_leaf && is_accessed_spte(old_spte) &&
> +	    (!is_present || !is_accessed_spte(new_spte) || pfn_changed))
> +		kvm_set_pfn_accessed(spte_to_pfn(old_spte));
>  }
>  
>  /*
> @@ -638,9 +622,8 @@ static inline int tdp_mmu_set_spte_atomic(struct kvm *kvm,
>  	if (!try_cmpxchg64(sptep, &iter->old_spte, new_spte))
>  		return -EBUSY;
>  
> -	__handle_changed_spte(kvm, iter->as_id, iter->gfn, iter->old_spte,
> -			      new_spte, iter->level, true);
> -	handle_changed_spte_acc_track(iter->old_spte, new_spte, iter->level);
> +	handle_changed_spte(kvm, iter->as_id, iter->gfn, iter->old_spte,
> +			    new_spte, iter->level, true);
>  
>  	return 0;
>  }
> @@ -705,8 +688,7 @@ static u64 tdp_mmu_set_spte(struct kvm *kvm, int as_id, tdp_ptep_t sptep,
>  
>  	old_spte = kvm_tdp_mmu_write_spte(sptep, old_spte, new_spte, level);
>  
> -	__handle_changed_spte(kvm, as_id, gfn, old_spte, new_spte, level, false);
> -	handle_changed_spte_acc_track(old_spte, new_spte, level);
> +	handle_changed_spte(kvm, as_id, gfn, old_spte, new_spte, level, false);
>  	return old_spte;
>  }
>  
> @@ -1276,7 +1258,7 @@ static bool set_spte_gfn(struct kvm *kvm, struct tdp_iter *iter,
>  	 * Note, when changing a read-only SPTE, it's not strictly necessary to
>  	 * zero the SPTE before setting the new PFN, but doing so preserves the
>  	 * invariant that the PFN of a present * leaf SPTE can never change.
> -	 * See __handle_changed_spte().
> +	 * See handle_changed_spte().
>  	 */
>  	tdp_mmu_iter_set_spte(kvm, iter, 0);
>  
> @@ -1301,7 +1283,7 @@ bool kvm_tdp_mmu_set_spte_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
>  	/*
>  	 * No need to handle the remote TLB flush under RCU protection, the
>  	 * target SPTE _must_ be a leaf SPTE, i.e. cannot result in freeing a
> -	 * shadow page.  See the WARN on pfn_changed in __handle_changed_spte().
> +	 * shadow page. See the WARN on pfn_changed in handle_changed_spte().
>  	 */
>  	return kvm_tdp_mmu_handle_gfn(kvm, range, set_spte_gfn);
>  }
> -- 
> 2.39.1.581.gbfd45094c4-goog
> 

  reply	other threads:[~2023-02-22 19:43 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-11  1:46 [Patch v3 0/7] Optimize clear dirty log Vipin Sharma
2023-02-11  1:46 ` [Patch v3 1/7] KVM: x86/mmu: Add a helper function to check if an SPTE needs atomic write Vipin Sharma
2023-02-11  1:46 ` [Patch v3 2/7] KVM: x86/mmu: Atomically clear SPTE dirty state in the clear-dirty-log flow Vipin Sharma
2023-02-15 21:12   ` David Matlack
2023-03-17 22:59   ` Sean Christopherson
2023-03-17 23:50     ` Vipin Sharma
2023-02-11  1:46 ` [Patch v3 3/7] KVM: x86/mmu: Remove "record_dirty_log" in __tdp_mmu_set_spte() Vipin Sharma
2023-02-15 21:10   ` David Matlack
2023-02-11  1:46 ` [Patch v3 4/7] KVM: x86/mmu: Optimize SPTE change for aging gfn range Vipin Sharma
2023-02-15 21:15   ` David Matlack
2023-03-21  0:51   ` Sean Christopherson
2023-02-11  1:46 ` [Patch v3 5/7] KVM: x86/mmu: Remove "record_acc_track" in __tdp_mmu_set_spte() Vipin Sharma
2023-02-22 19:31   ` David Matlack
2023-02-11  1:46 ` [Patch v3 6/7] KVM: x86/mmu: Remove handle_changed_spte_dirty_log() Vipin Sharma
2023-02-22 19:36   ` David Matlack
2023-02-11  1:46 ` [Patch v3 7/7] KVM: x86/mmu: Merge all handle_changed_pte* functions Vipin Sharma
2023-02-22 19:42   ` David Matlack [this message]
2023-03-17 22:51   ` Sean Christopherson
2023-03-17 23:48     ` Vipin Sharma
2023-03-17 22:57 ` [Patch v3 0/7] Optimize clear dirty log Sean Christopherson
2023-03-17 23:51   ` Vipin Sharma
2023-03-21  0:41   ` Sean Christopherson
2023-03-21 18:11     ` Vipin Sharma
2023-03-21 19:57       ` Sean Christopherson
2023-03-21 20:40         ` Sean Christopherson
2023-03-21 21:38         ` 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=Y/ZwP18nw/PIHGsK@google.com \
    --to=dmatlack@google.com \
    --cc=bgardon@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=vipinsh@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 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).