Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: selftests: fix max_guest_memory_test with more that 256 vCPUs

max_guest_memory_test uses ucalls to sync with the host, but
it also resets the guest RIP back to its initial value in between
tests stages.

This makes the guest never reach the code which frees the ucall struct
and since a fixed pool of 512 ucall structs is used, the test starts
to fail when more that 256 vCPUs are used.

Fix that by replacing the manual register reset with a loop in
the guest code.

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Link: https://lore.kernel.org/r/20240315143507.102629-1-mlevitsk@redhat.com
Signed-off-by: Sean Christopherson <seanjc@google.com>

authored by

Maxim Levitsky and committed by
Sean Christopherson
0ef2dd1f 08a82824

+6 -9
+6 -9
tools/testing/selftests/kvm/max_guest_memory_test.c
··· 22 22 { 23 23 uint64_t gpa; 24 24 25 - for (gpa = start_gpa; gpa < end_gpa; gpa += stride) 26 - *((volatile uint64_t *)gpa) = gpa; 27 - 28 - GUEST_DONE(); 25 + for (;;) { 26 + for (gpa = start_gpa; gpa < end_gpa; gpa += stride) 27 + *((volatile uint64_t *)gpa) = gpa; 28 + GUEST_SYNC(0); 29 + } 29 30 } 30 31 31 32 struct vcpu_info { ··· 56 55 static void run_vcpu(struct kvm_vcpu *vcpu) 57 56 { 58 57 vcpu_run(vcpu); 59 - TEST_ASSERT_EQ(get_ucall(vcpu, NULL), UCALL_DONE); 58 + TEST_ASSERT_EQ(get_ucall(vcpu, NULL), UCALL_SYNC); 60 59 } 61 60 62 61 static void *vcpu_worker(void *data) ··· 65 64 struct kvm_vcpu *vcpu = info->vcpu; 66 65 struct kvm_vm *vm = vcpu->vm; 67 66 struct kvm_sregs sregs; 68 - struct kvm_regs regs; 69 67 70 68 vcpu_args_set(vcpu, 3, info->start_gpa, info->end_gpa, vm->page_size); 71 69 72 - /* Snapshot regs before the first run. */ 73 - vcpu_regs_get(vcpu, &regs); 74 70 rendezvous_with_boss(); 75 71 76 72 run_vcpu(vcpu); 77 73 rendezvous_with_boss(); 78 - vcpu_regs_set(vcpu, &regs); 79 74 vcpu_sregs_get(vcpu, &sregs); 80 75 #ifdef __x86_64__ 81 76 /* Toggle CR0.WP to trigger a MMU context reset. */