Skip to content

Commit 82b542e

Browse files
committed
KVM: selftests: Precisely limit the number of guest loops in mmu_stress_test
Run the exact number of guest loops required in mmu_stress_test instead of looping indefinitely in anticipation of adding more stages that run different code (e.g. reads instead of writes). Reviewed-by: James Houghton <jthoughton@google.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Link: https://lore.kernel.org/r/20241128005547.4077116-12-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 3a04225 commit 82b542e

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

tools/testing/selftests/kvm/mmu_stress_test.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
static void guest_code(uint64_t start_gpa, uint64_t end_gpa, uint64_t stride)
2121
{
2222
uint64_t gpa;
23+
int i;
2324

24-
for (;;) {
25+
for (i = 0; i < 2; i++) {
2526
for (gpa = start_gpa; gpa < end_gpa; gpa += stride)
2627
vcpu_arch_put_guest(*((volatile uint64_t *)gpa), gpa);
27-
GUEST_SYNC(0);
28+
GUEST_SYNC(i);
2829
}
30+
31+
GUEST_ASSERT(0);
2932
}
3033

3134
struct vcpu_info {
@@ -52,10 +55,18 @@ static void rendezvous_with_boss(void)
5255
}
5356
}
5457

55-
static void run_vcpu(struct kvm_vcpu *vcpu)
58+
static void assert_sync_stage(struct kvm_vcpu *vcpu, int stage)
59+
{
60+
struct ucall uc;
61+
62+
TEST_ASSERT_EQ(get_ucall(vcpu, &uc), UCALL_SYNC);
63+
TEST_ASSERT_EQ(uc.args[1], stage);
64+
}
65+
66+
static void run_vcpu(struct kvm_vcpu *vcpu, int stage)
5667
{
5768
vcpu_run(vcpu);
58-
TEST_ASSERT_EQ(get_ucall(vcpu, NULL), UCALL_SYNC);
69+
assert_sync_stage(vcpu, stage);
5970
}
6071

6172
static void *vcpu_worker(void *data)
@@ -69,7 +80,8 @@ static void *vcpu_worker(void *data)
6980

7081
rendezvous_with_boss();
7182

72-
run_vcpu(vcpu);
83+
/* Stage 0, write all of guest memory. */
84+
run_vcpu(vcpu, 0);
7385
rendezvous_with_boss();
7486
#ifdef __x86_64__
7587
vcpu_sregs_get(vcpu, &sregs);
@@ -79,7 +91,8 @@ static void *vcpu_worker(void *data)
7991
#endif
8092
rendezvous_with_boss();
8193

82-
run_vcpu(vcpu);
94+
/* Stage 1, re-write all of guest memory. */
95+
run_vcpu(vcpu, 1);
8396
rendezvous_with_boss();
8497

8598
return NULL;

0 commit comments

Comments
 (0)