..so that it can be re-used. Signed-off-by: Krish Sadhukhan <krish.sadhukhan@xxxxxxxxxx> Reviewed-by: Karl Heubaum <karl.heubaum@xxxxxxxxxx> --- lib/x86/desc.c | 8 ++++++++ lib/x86/desc.h | 1 + x86/access.c | 8 -------- x86/pcid.c | 8 -------- x86/vmx_tests.c | 8 -------- x86/xsave.c | 8 -------- 6 files changed, 9 insertions(+), 32 deletions(-) diff --git a/lib/x86/desc.c b/lib/x86/desc.c index 0108555..5f37cef 100644 --- a/lib/x86/desc.c +++ b/lib/x86/desc.c @@ -251,6 +251,14 @@ unsigned exception_vector(void) return vector; } +int write_cr4_checking(unsigned long val) +{ + asm volatile(ASM_TRY("1f") + "mov %0,%%cr4\n\t" + "1:": : "r" (val)); + return exception_vector(); +} + unsigned exception_error_code(void) { unsigned short error_code; diff --git a/lib/x86/desc.h b/lib/x86/desc.h index 7a7358a..9cf823a 100644 --- a/lib/x86/desc.h +++ b/lib/x86/desc.h @@ -207,6 +207,7 @@ extern tss64_t tss; #endif unsigned exception_vector(void); +int write_cr4_checking(unsigned long val); unsigned exception_error_code(void); bool exception_rflags_rf(void); void set_idt_entry(int vec, void *addr, int dpl); diff --git a/x86/access.c b/x86/access.c index 9412300..f0d1879 100644 --- a/x86/access.c +++ b/x86/access.c @@ -171,14 +171,6 @@ typedef struct { static void ac_test_show(ac_test_t *at); -static int write_cr4_checking(unsigned long val) -{ - asm volatile(ASM_TRY("1f") - "mov %0,%%cr4\n\t" - "1:": : "r" (val)); - return exception_vector(); -} - static void set_cr0_wp(int wp) { unsigned long cr0 = read_cr0(); diff --git a/x86/pcid.c b/x86/pcid.c index c04fd09..dfabe0e 100644 --- a/x86/pcid.c +++ b/x86/pcid.c @@ -21,14 +21,6 @@ static int write_cr0_checking(unsigned long val) return exception_vector(); } -static int write_cr4_checking(unsigned long val) -{ - asm volatile(ASM_TRY("1f") - "mov %0, %%cr4\n\t" - "1:": : "r" (val)); - return exception_vector(); -} - static int invpcid_checking(unsigned long type, void *desc) { asm volatile (ASM_TRY("1f") diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index c48e7fc..7184b06 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -7090,14 +7090,6 @@ static void vmentry_movss_shadow_test(void) vmcs_write(GUEST_RFLAGS, X86_EFLAGS_FIXED); } -static int write_cr4_checking(unsigned long val) -{ - asm volatile(ASM_TRY("1f") - "mov %0, %%cr4\n\t" - "1:": : "r" (val)); - return exception_vector(); -} - static void vmx_cr_load_test(void) { struct cpuid _cpuid = cpuid(1); diff --git a/x86/xsave.c b/x86/xsave.c index 00787bb..ca41bbf 100644 --- a/x86/xsave.c +++ b/x86/xsave.c @@ -33,14 +33,6 @@ static int xsetbv_checking(u32 index, u64 value) return exception_vector(); } -static int write_cr4_checking(unsigned long val) -{ - asm volatile(ASM_TRY("1f") - "mov %0,%%cr4\n\t" - "1:": : "r" (val)); - return exception_vector(); -} - #define CPUID_1_ECX_XSAVE (1 << 26) #define CPUID_1_ECX_OSXSAVE (1 << 27) static int check_cpuid_1_ecx(unsigned int bit) -- 2.20.1