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

KVM: selftests: Test slot move/delete with slot zap quirk enabled/disabled

Update set_memory_region_test to make sure memslot move and deletion
function correctly both when slot zap quirk KVM_X86_QUIRK_SLOT_ZAP_ALL is
enabled and disabled.

Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
Message-ID: <20240703021119.13904-1-yan.y.zhao@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Yan Zhao and committed by
Paolo Bonzini
b4ed2c67 aa8d1f48

+21 -8
+21 -8
tools/testing/selftests/kvm/set_memory_region_test.c
··· 175 175 GUEST_DONE(); 176 176 } 177 177 178 - static void test_move_memory_region(void) 178 + static void test_move_memory_region(bool disable_slot_zap_quirk) 179 179 { 180 180 pthread_t vcpu_thread; 181 181 struct kvm_vcpu *vcpu; ··· 183 183 uint64_t *hva; 184 184 185 185 vm = spawn_vm(&vcpu, &vcpu_thread, guest_code_move_memory_region); 186 + 187 + if (disable_slot_zap_quirk) 188 + vm_enable_cap(vm, KVM_CAP_DISABLE_QUIRKS2, KVM_X86_QUIRK_SLOT_ZAP_ALL); 186 189 187 190 hva = addr_gpa2hva(vm, MEM_REGION_GPA); 188 191 ··· 269 266 GUEST_ASSERT(0); 270 267 } 271 268 272 - static void test_delete_memory_region(void) 269 + static void test_delete_memory_region(bool disable_slot_zap_quirk) 273 270 { 274 271 pthread_t vcpu_thread; 275 272 struct kvm_vcpu *vcpu; ··· 278 275 struct kvm_vm *vm; 279 276 280 277 vm = spawn_vm(&vcpu, &vcpu_thread, guest_code_delete_memory_region); 278 + 279 + if (disable_slot_zap_quirk) 280 + vm_enable_cap(vm, KVM_CAP_DISABLE_QUIRKS2, KVM_X86_QUIRK_SLOT_ZAP_ALL); 281 281 282 282 /* Delete the memory region, the guest should not die. */ 283 283 vm_mem_region_delete(vm, MEM_REGION_SLOT); ··· 559 553 { 560 554 #ifdef __x86_64__ 561 555 int i, loops; 556 + int j, disable_slot_zap_quirk = 0; 562 557 558 + if (kvm_check_cap(KVM_CAP_DISABLE_QUIRKS2) & KVM_X86_QUIRK_SLOT_ZAP_ALL) 559 + disable_slot_zap_quirk = 1; 563 560 /* 564 561 * FIXME: the zero-memslot test fails on aarch64 and s390x because 565 562 * KVM_RUN fails with ENOEXEC or EFAULT. ··· 588 579 else 589 580 loops = 10; 590 581 591 - pr_info("Testing MOVE of in-use region, %d loops\n", loops); 592 - for (i = 0; i < loops; i++) 593 - test_move_memory_region(); 582 + for (j = 0; j <= disable_slot_zap_quirk; j++) { 583 + pr_info("Testing MOVE of in-use region, %d loops, slot zap quirk %s\n", 584 + loops, j ? "disabled" : "enabled"); 585 + for (i = 0; i < loops; i++) 586 + test_move_memory_region(!!j); 594 587 595 - pr_info("Testing DELETE of in-use region, %d loops\n", loops); 596 - for (i = 0; i < loops; i++) 597 - test_delete_memory_region(); 588 + pr_info("Testing DELETE of in-use region, %d loops, slot zap quirk %s\n", 589 + loops, j ? "disabled" : "enabled"); 590 + for (i = 0; i < loops; i++) 591 + test_delete_memory_region(!!j); 592 + } 598 593 #endif 599 594 600 595 return 0;