Skip to content

Commit 4e9427a

Browse files
iorlov-devsean-jc
authored andcommitted
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: Ivan Orlov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 7bd7ff9 commit 4e9427a

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

tools/testing/selftests/kvm/include/x86/processor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,11 @@ static inline void set_cr4(uint64_t val)
569569
__asm__ __volatile__("mov %0, %%cr4" : : "r" (val) : "memory");
570570
}
571571

572+
static inline void set_idt(const struct desc_ptr *idt_desc)
573+
{
574+
__asm__ __volatile__("lidt %0"::"m"(*idt_desc));
575+
}
576+
572577
static inline u64 xgetbv(u32 index)
573578
{
574579
u32 eax, edx;

tools/testing/selftests/kvm/set_memory_region_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ static void guest_code_delete_memory_region(void)
235235
* in the guest will never succeed, and so isn't an option.
236236
*/
237237
memset(&idt, 0, sizeof(idt));
238-
__asm__ __volatile__("lidt %0" :: "m"(idt));
238+
set_idt(&idt);
239239

240240
GUEST_SYNC(0);
241241

tools/testing/selftests/kvm/x86/sev_smoke_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static void guest_shutdown_code(void)
155155

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

160160
__asm__ __volatile__("ud2");
161161
}

0 commit comments

Comments
 (0)