Commit 4e9427ae authored by Ivan Orlov's avatar Ivan Orlov Committed by Sean Christopherson
Browse files

KVM: selftests: Add and use a helper function for x86's LIDT



Implement a function for setting the IDT descriptor from the guest
code. Replace the existing lidt occurrences with calls to this function
as `lidt` is used in multiple places.

Signed-off-by: default avatarIvan Orlov <iorlov@amazon.com>
Link: https://lore.kernel.org/r/20241217181458.68690-7-iorlov@amazon.com


Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
parent 7bd7ff99
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -569,6 +569,11 @@ static inline void set_cr4(uint64_t val)
	__asm__ __volatile__("mov %0, %%cr4" : : "r" (val) : "memory");
}

static inline void set_idt(const struct desc_ptr *idt_desc)
{
	__asm__ __volatile__("lidt %0"::"m"(*idt_desc));
}

static inline u64 xgetbv(u32 index)
{
	u32 eax, edx;
+1 −1
Original line number Diff line number Diff line
@@ -235,7 +235,7 @@ static void guest_code_delete_memory_region(void)
	 * in the guest will never succeed, and so isn't an option.
	 */
	memset(&idt, 0, sizeof(idt));
	__asm__ __volatile__("lidt %0" :: "m"(idt));
	set_idt(&idt);

	GUEST_SYNC(0);

+1 −1
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ static void guest_shutdown_code(void)

	/* Clobber the IDT so that #UD is guaranteed to trigger SHUTDOWN. */
	memset(&idt, 0, sizeof(idt));
	__asm__ __volatile__("lidt %0" :: "m"(idt));
	set_idt(&idt);

	__asm__ __volatile__("ud2");
}