Skip to content

Commit 61c3cff

Browse files
committed
KVM: selftests: Explicitly clobber the IDT in the "delete memslot" testcase
Explicitly clobber the guest IDT in the "delete memslot" test, which expects the deleted memslot to result in either a KVM emulation error, or a triple fault shutdown. A future change to the core selftests library will configuring the guest IDT and exception handlers by default, i.e. will install a guest #PF handler and put the guest into an infinite #NPF loop (the guest hits a !PRESENT SPTE when trying to vector a #PF, and KVM reinjects the #PF without fixing the #NPF, because there is no memslot). Note, it's not clear whether or not KVM's behavior is reasonable in this case, e.g. arguably KVM should try (and fail) to emulate in response to the #NPF. But barring a goofy/broken userspace, this scenario will likely never happen in practice. Punt the KVM investigation to the future. Link: https://lore.kernel.org/r/20240314232637.2538648-8-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent dec79ea commit 61c3cff

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

tools/testing/selftests/kvm/set_memory_region_test.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,20 @@ static void test_move_memory_region(void)
220220

221221
static void guest_code_delete_memory_region(void)
222222
{
223+
struct desc_ptr idt;
223224
uint64_t val;
224225

226+
/*
227+
* Clobber the IDT so that a #PF due to the memory region being deleted
228+
* escalates to triple-fault shutdown. Because the memory region is
229+
* deleted, there will be no valid mappings. As a result, KVM will
230+
* repeatedly intercepts the state-2 page fault that occurs when trying
231+
* to vector the guest's #PF. I.e. trying to actually handle the #PF
232+
* in the guest will never succeed, and so isn't an option.
233+
*/
234+
memset(&idt, 0, sizeof(idt));
235+
__asm__ __volatile__("lidt %0" :: "m"(idt));
236+
225237
GUEST_SYNC(0);
226238

227239
/* Spin until the memory region is deleted. */

0 commit comments

Comments
 (0)