kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] kvm/x86: Fix 'lpages' kvm stat for TDM MMU
@ 2021-04-30 11:52 Shahin, Md Shahadat Hossain
  2021-05-03 16:25 ` Ben Gardon
  0 siblings, 1 reply; 2+ messages in thread
From: Shahin, Md Shahadat Hossain @ 2021-04-30 11:52 UTC (permalink / raw)
  To: kvm; +Cc: Szczepanek, Bartosz, seanjc, bgardon, pbonzini

Large pages not being created properly may result in increased memory
access time. The 'lpages' kvm stat used to keep track of the current
number of large pages in the system, but with TDP MMU enabled the stat
is not showing the correct number.

This patch extends the lpages counter to cover the TDP case.

Signed-off-by: Md Shahadat Hossain Shahin <shahinmd@amazon.de>
Cc: Bartosz Szczepanek <bsz@amazon.de>
---
 arch/x86/kvm/mmu/tdp_mmu.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
index bc1283ed4db6..f89a140b8dea 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.c
+++ b/arch/x86/kvm/mmu/tdp_mmu.c
@@ -240,6 +240,13 @@ static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn,
 	if (old_spte == new_spte)
 		return;
 
+	if (is_large_pte(old_spte) != is_large_pte(new_spte)) {
+		if (is_large_pte(old_spte))
+			atomic64_sub(1, (atomic64_t*)&kvm->stat.lpages);
+		else
+			atomic64_add(1, (atomic64_t*)&kvm->stat.lpages);
+	}
+
 	/*
 	 * The only times a SPTE should be changed from a non-present to
 	 * non-present state is when an MMIO entry is installed/modified/
-- 
2.17.1



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] kvm/x86: Fix 'lpages' kvm stat for TDM MMU
  2021-04-30 11:52 [PATCH v2] kvm/x86: Fix 'lpages' kvm stat for TDM MMU Shahin, Md Shahadat Hossain
@ 2021-05-03 16:25 ` Ben Gardon
  0 siblings, 0 replies; 2+ messages in thread
From: Ben Gardon @ 2021-05-03 16:25 UTC (permalink / raw)
  To: Shahin, Md Shahadat Hossain; +Cc: kvm, Szczepanek, Bartosz, seanjc, pbonzini

On Fri, Apr 30, 2021 at 4:52 AM Shahin, Md Shahadat Hossain
<shahinmd@amazon.de> wrote:
>
> Large pages not being created properly may result in increased memory
> access time. The 'lpages' kvm stat used to keep track of the current
> number of large pages in the system, but with TDP MMU enabled the stat
> is not showing the correct number.
>
> This patch extends the lpages counter to cover the TDP case.
>
> Signed-off-by: Md Shahadat Hossain Shahin <shahinmd@amazon.de>
> Cc: Bartosz Szczepanek <bsz@amazon.de>

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

Thanks for fixing this!

> ---
>  arch/x86/kvm/mmu/tdp_mmu.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
> index bc1283ed4db6..f89a140b8dea 100644
> --- a/arch/x86/kvm/mmu/tdp_mmu.c
> +++ b/arch/x86/kvm/mmu/tdp_mmu.c
> @@ -240,6 +240,13 @@ static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn,
>         if (old_spte == new_spte)
>                 return;
>
> +       if (is_large_pte(old_spte) != is_large_pte(new_spte)) {
> +               if (is_large_pte(old_spte))
> +                       atomic64_sub(1, (atomic64_t*)&kvm->stat.lpages);
> +               else
> +                       atomic64_add(1, (atomic64_t*)&kvm->stat.lpages);
> +       }
> +
>         /*
>          * The only times a SPTE should be changed from a non-present to
>          * non-present state is when an MMIO entry is installed/modified/
> --
> 2.17.1
>
>
>
> Amazon Development Center Germany GmbH
> Krausenstr. 38
> 10117 Berlin
> Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
> Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
> Sitz: Berlin
> Ust-ID: DE 289 237 879
>
>
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-03 16:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-30 11:52 [PATCH v2] kvm/x86: Fix 'lpages' kvm stat for TDM MMU Shahin, Md Shahadat Hossain
2021-05-03 16:25 ` Ben Gardon

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).