Skip to content

Commit 8fcee04

Browse files
committed
KVM: selftests: Restore assert for non-nested VMs in access tracking test
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 <[email protected]> Reviewed-by: Emanuele Giuseppe Esposito <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a33004e commit 8fcee04

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

tools/testing/selftests/kvm/access_tracking_perf_test.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "test_util.h"
4747
#include "memstress.h"
4848
#include "guest_modes.h"
49+
#include "processor.h"
4950

5051
/* Global variable used to synchronize all of the vCPU threads. */
5152
static int iteration;
@@ -180,15 +181,21 @@ static void mark_vcpu_memory_idle(struct kvm_vm *vm,
180181
* access tracking but low enough as to not make the test too brittle
181182
* over time and across architectures.
182183
*
183-
* Note that when run in nested virtualization, this check will trigger
184-
* much more frequently because TLB size is unlimited and since no flush
185-
* happens, much more pages are cached there and guest won't see the
186-
* "idle" bit cleared.
184+
* When running the guest as a nested VM, "warn" instead of asserting
185+
* as the TLB size is effectively unlimited and the KVM doesn't
186+
* explicitly flush the TLB when aging SPTEs. As a result, more pages
187+
* are cached and the guest won't see the "idle" bit cleared.
187188
*/
188-
if (still_idle >= pages / 10)
189+
if (still_idle >= pages / 10) {
190+
#ifdef __x86_64__
191+
TEST_ASSERT(this_cpu_has(X86_FEATURE_HYPERVISOR),
192+
"vCPU%d: Too many pages still idle (%lu out of %lu)",
193+
vcpu_idx, still_idle, pages);
194+
#endif
189195
printf("WARNING: vCPU%d: Too many pages still idle (%lu out of %lu), "
190196
"this will affect performance results.\n",
191197
vcpu_idx, still_idle, pages);
198+
}
192199

193200
close(page_idle_fd);
194201
close(pagemap_fd);

tools/testing/selftests/kvm/include/x86_64/processor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct kvm_x86_cpu_feature {
9494
#define X86_FEATURE_XSAVE KVM_X86_CPU_FEATURE(0x1, 0, ECX, 26)
9595
#define X86_FEATURE_OSXSAVE KVM_X86_CPU_FEATURE(0x1, 0, ECX, 27)
9696
#define X86_FEATURE_RDRAND KVM_X86_CPU_FEATURE(0x1, 0, ECX, 30)
97+
#define X86_FEATURE_HYPERVISOR KVM_X86_CPU_FEATURE(0x1, 0, ECX, 31)
9798
#define X86_FEATURE_PAE KVM_X86_CPU_FEATURE(0x1, 0, EDX, 6)
9899
#define X86_FEATURE_MCE KVM_X86_CPU_FEATURE(0x1, 0, EDX, 7)
99100
#define X86_FEATURE_APIC KVM_X86_CPU_FEATURE(0x1, 0, EDX, 9)

0 commit comments

Comments
 (0)