x86/xstate: Rework xsetbv() to use asm goto()
PATCH 1/1 x86/xstate: Rework xsetbv() to use asm goto()
Switch to using a mnemonic, and asm_inline as there's EXTABLE metadata.
Update the types, and adjust parameter names. The name xfeatures is specific to xcr0, so rename to val to be more generic, even if there isn't another writeable xcr yet.
No functional change.
Resolves: https://gitlab.com/xen-project/xen/-/work_items/212
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/arch/x86/xstate.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
xen/arch/x86/xstate.c +15 -14
@@ -40,21 +40,22 @@ static DEFINE_PER_CPU(uint64_t, xcr0);/* Because XCR0 is cached for each CPU, xsetbv() is not exposed. Users should * use set_xcr0() instead. */ -static inline bool xsetbv (u32 index,u64 xfeatures) +static inline bool xsetbv (uint32_t xcr,uint64_t val) { -u32 hi = xfeatures >>32 ; -u32 lo = (u32 )xfeatures; - - asmvolatile ("1: .byte 0x0f,0x01,0xd1\n" -"3: \n" -".section .fixup,\"ax\" \n" -"2: xor %0,%0 \n" -" jmp 3b \n" -".previous \n" - _ASM_EXTABLE(1b, 2b) - : "+a" (lo) - : "c" (index), "d" (hi)); - return lo !=0 ; +uint32_t hi = val >>32 , lo = val; + + asm_inline goto ( + "1: xsetbv\n\t" + _ASM_EXTABLE(1b, %l[fault]) + : + : "a" (lo), "c" (xcr), "d" (hi) + : + : fault ); + +return true; + + fault: +return false; }bool set_xcr0 (u64 xfeatures)
Signature · 1 line
2.39.5
Quoted 10 lines · Andrew Cooper
Switch to using a mnemonic, and
asm_inlineas there's EXTABLE metadata.Update the types, and adjust parameter names. The name xfeatures is specific to xcr0, so rename to val to be more generic, even if there isn't another writeable xcr yet.
No functional change.
Resolves: https://gitlab.com/xen-project/xen/-/work_items/212
Signed-off-by Andrew Cooper <[email protected]>