mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] KVM: selftests: Fixes for access tracking perf test
@ 2022-11-29 17:52 Sean Christopherson
  2022-11-29 17:52 ` [PATCH 1/2] KVM: selftests: Fix inverted "warning" in " Sean Christopherson
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sean Christopherson @ 2022-11-29 17:52 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, linux-kernel, Emanuele Giuseppe Esposito,
	Sean Christopherson, David Matlack

Fix an inverted check in the access tracking perf test, and restore the
assert that there aren't too many dangling idle pages when running the
test on x86-64 bare metal.

Sean Christopherson (2):
  KVM: selftests: Fix inverted "warning" in access tracking perf test
  KVM: selftests: Restore assert for non-nested VMs in access tracking
    test

 .../selftests/kvm/access_tracking_perf_test.c | 22 ++++++++++++-------
 .../selftests/kvm/include/x86_64/processor.h  |  1 +
 2 files changed, 15 insertions(+), 8 deletions(-)


base-commit: 3e04435fe60590a1c79ec94d60e9897c3ff7d73b
-- 
2.38.1.584.g0f3c55d4c2-goog


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

* [PATCH 1/2] KVM: selftests: Fix inverted "warning" in access tracking perf test
  2022-11-29 17:52 [PATCH 0/2] KVM: selftests: Fixes for access tracking perf test Sean Christopherson
@ 2022-11-29 17:52 ` Sean Christopherson
  2022-11-29 17:53 ` [PATCH 2/2] KVM: selftests: Restore assert for non-nested VMs in access tracking test Sean Christopherson
  2022-12-01 11:11 ` [PATCH 0/2] KVM: selftests: Fixes for access tracking perf test Emanuele Giuseppe Esposito
  2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2022-11-29 17:52 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, linux-kernel, Emanuele Giuseppe Esposito,
	Sean Christopherson, David Matlack

Warn if the number of idle pages is greater than or equal to 10% of the
total number of pages, not if the percentage of idle pages is less than
10%.  The original code asserted that less than 10% of pages were still
idle, but the check got inverted when the assert was converted to a
warning.

Opportunistically clean up the warning; selftests are 64-bit only, there
is no need to use "%PRIu64" instead of "%lu".

Fixes: 6336a810db5c ("KVM: selftests: replace assertion with warning in access_tracking_perf_test")
Cc: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 tools/testing/selftests/kvm/access_tracking_perf_test.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/kvm/access_tracking_perf_test.c b/tools/testing/selftests/kvm/access_tracking_perf_test.c
index 02d3587cab0a..d45ef319a68f 100644
--- a/tools/testing/selftests/kvm/access_tracking_perf_test.c
+++ b/tools/testing/selftests/kvm/access_tracking_perf_test.c
@@ -185,10 +185,9 @@ static void mark_vcpu_memory_idle(struct kvm_vm *vm,
 	 * happens, much more pages are cached there and guest won't see the
 	 * "idle" bit cleared.
 	 */
-	if (still_idle < pages / 10)
-		printf("WARNING: vCPU%d: Too many pages still idle (%" PRIu64
-		       "out of %" PRIu64 "), this will affect performance results"
-		       ".\n",
+	if (still_idle >= pages / 10)
+		printf("WARNING: vCPU%d: Too many pages still idle (%lu out of %lu), "
+		       "this will affect performance results.\n",
 		       vcpu_idx, still_idle, pages);
 
 	close(page_idle_fd);
-- 
2.38.1.584.g0f3c55d4c2-goog


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

* [PATCH 2/2] KVM: selftests: Restore assert for non-nested VMs in access tracking test
  2022-11-29 17:52 [PATCH 0/2] KVM: selftests: Fixes for access tracking perf test Sean Christopherson
  2022-11-29 17:52 ` [PATCH 1/2] KVM: selftests: Fix inverted "warning" in " Sean Christopherson
@ 2022-11-29 17:53 ` Sean Christopherson
  2022-12-01 11:11 ` [PATCH 0/2] KVM: selftests: Fixes for access tracking perf test Emanuele Giuseppe Esposito
  2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2022-11-29 17:53 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, linux-kernel, Emanuele Giuseppe Esposito,
	Sean Christopherson, David Matlack

Restore the assert (on x86-64) that <10% of pages are still idle when NOT
running as a nested VM in the access tracking test.  The original assert
was converted to a "warning" to avoid false failures when running the
test in a VM, but the non-nested case does not suffer from the same
"infinite TLB size" issue.

Using the HYPERVISOR flag isn't infallible as VMMs aren't strictly
required to enumerate the "feature" in CPUID, but practically speaking
anyone that is running KVM selftests in VMs is going to be using a VMM
and hypervisor that sets the HYPERVISOR flag.

Cc: David Matlack <dmatlack@google.com>
Cc: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 .../selftests/kvm/access_tracking_perf_test.c   | 17 ++++++++++++-----
 .../selftests/kvm/include/x86_64/processor.h    |  1 +
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/kvm/access_tracking_perf_test.c b/tools/testing/selftests/kvm/access_tracking_perf_test.c
index d45ef319a68f..9f9503e40ca5 100644
--- a/tools/testing/selftests/kvm/access_tracking_perf_test.c
+++ b/tools/testing/selftests/kvm/access_tracking_perf_test.c
@@ -46,6 +46,7 @@
 #include "test_util.h"
 #include "memstress.h"
 #include "guest_modes.h"
+#include "processor.h"
 
 /* Global variable used to synchronize all of the vCPU threads. */
 static int iteration;
@@ -180,15 +181,21 @@ static void mark_vcpu_memory_idle(struct kvm_vm *vm,
 	 * access tracking but low enough as to not make the test too brittle
 	 * over time and across architectures.
 	 *
-	 * Note that when run in nested virtualization, this check will trigger
-	 * much more frequently because TLB size is unlimited and since no flush
-	 * happens, much more pages are cached there and guest won't see the
-	 * "idle" bit cleared.
+	 * When running the guest as a nested VM, "warn" instead of asserting
+	 * as the TLB size is effectively unlimited and the KVM doesn't
+	 * explicitly flush the TLB when aging SPTEs.  As a result, more pages
+	 * are cached and the guest won't see the "idle" bit cleared.
 	 */
-	if (still_idle >= pages / 10)
+	if (still_idle >= pages / 10) {
+#ifdef __x86_64__
+		TEST_ASSERT(this_cpu_has(X86_FEATURE_HYPERVISOR),
+			    "vCPU%d: Too many pages still idle (%lu out of %lu)",
+			    vcpu_idx, still_idle, pages);
+#endif
 		printf("WARNING: vCPU%d: Too many pages still idle (%lu out of %lu), "
 		       "this will affect performance results.\n",
 		       vcpu_idx, still_idle, pages);
+	}
 
 	close(page_idle_fd);
 	close(pagemap_fd);
diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h
index 5d310abe6c3f..22852bd32d7b 100644
--- a/tools/testing/selftests/kvm/include/x86_64/processor.h
+++ b/tools/testing/selftests/kvm/include/x86_64/processor.h
@@ -94,6 +94,7 @@ struct kvm_x86_cpu_feature {
 #define	X86_FEATURE_XSAVE		KVM_X86_CPU_FEATURE(0x1, 0, ECX, 26)
 #define	X86_FEATURE_OSXSAVE		KVM_X86_CPU_FEATURE(0x1, 0, ECX, 27)
 #define	X86_FEATURE_RDRAND		KVM_X86_CPU_FEATURE(0x1, 0, ECX, 30)
+#define	X86_FEATURE_HYPERVISOR		KVM_X86_CPU_FEATURE(0x1, 0, ECX, 31)
 #define X86_FEATURE_PAE			KVM_X86_CPU_FEATURE(0x1, 0, EDX, 6)
 #define	X86_FEATURE_MCE			KVM_X86_CPU_FEATURE(0x1, 0, EDX, 7)
 #define	X86_FEATURE_APIC		KVM_X86_CPU_FEATURE(0x1, 0, EDX, 9)
-- 
2.38.1.584.g0f3c55d4c2-goog


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

* Re: [PATCH 0/2] KVM: selftests: Fixes for access tracking perf test
  2022-11-29 17:52 [PATCH 0/2] KVM: selftests: Fixes for access tracking perf test Sean Christopherson
  2022-11-29 17:52 ` [PATCH 1/2] KVM: selftests: Fix inverted "warning" in " Sean Christopherson
  2022-11-29 17:53 ` [PATCH 2/2] KVM: selftests: Restore assert for non-nested VMs in access tracking test Sean Christopherson
@ 2022-12-01 11:11 ` Emanuele Giuseppe Esposito
  2 siblings, 0 replies; 4+ messages in thread
From: Emanuele Giuseppe Esposito @ 2022-12-01 11:11 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel, David Matlack



Am 29/11/2022 um 18:52 schrieb Sean Christopherson:
> Fix an inverted check in the access tracking perf test, and restore the
> assert that there aren't too many dangling idle pages when running the
> test on x86-64 bare metal.
> 
> Sean Christopherson (2):
>   KVM: selftests: Fix inverted "warning" in access tracking perf test
>   KVM: selftests: Restore assert for non-nested VMs in access tracking
>     test
> 
>  .../selftests/kvm/access_tracking_perf_test.c | 22 ++++++++++++-------
>  .../selftests/kvm/include/x86_64/processor.h  |  1 +
>  2 files changed, 15 insertions(+), 8 deletions(-)
> 
> 
> base-commit: 3e04435fe60590a1c79ec94d60e9897c3ff7d73b
> 

Makes sense, apologies for inverting the check.

Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>


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

end of thread, other threads:[~2022-12-01 11:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-29 17:52 [PATCH 0/2] KVM: selftests: Fixes for access tracking perf test Sean Christopherson
2022-11-29 17:52 ` [PATCH 1/2] KVM: selftests: Fix inverted "warning" in " Sean Christopherson
2022-11-29 17:53 ` [PATCH 2/2] KVM: selftests: Restore assert for non-nested VMs in access tracking test Sean Christopherson
2022-12-01 11:11 ` [PATCH 0/2] KVM: selftests: Fixes for access tracking perf test Emanuele Giuseppe Esposito

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®