]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: selftests: Add and use a helper function for x86's LIDT
authorIvan Orlov <iorlov@amazon.com>
Tue, 17 Dec 2024 18:14:57 +0000 (18:14 +0000)
committerSean Christopherson <seanjc@google.com>
Wed, 18 Dec 2024 23:14:46 +0000 (15:14 -0800)
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 <iorlov@amazon.com>
Link: https://lore.kernel.org/r/20241217181458.68690-7-iorlov@amazon.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/include/x86/processor.h
tools/testing/selftests/kvm/set_memory_region_test.c
tools/testing/selftests/kvm/x86/sev_smoke_test.c

index b6753e27dfb6f9aac694d131e2d5f5feac89d53e..daa02b85127353a2c783daf99c1ba95a6b1292a0 100644 (file)
@@ -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;
index 86ee3385e860be47bf37b7bd8ba7d11533751459..621a227e2bf2940e89eecf39cf0f779bef143dd0 100644 (file)
@@ -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);
 
index ae77698e6e9762a219c19ea9230e3f26fbb2990a..a1a688e752666cd06f10c97b7c10c906068b4711 100644 (file)
@@ -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");
 }