Skip to content

Commit 9369412

Browse files
committed
x86/alternative: Convert ALTERNATIVE_3()
Zap the hack of using an ALTERNATIVE_3() internal label, as suggested by bgerst: https://lore.kernel.org/r/CAMzpN2i4oJ-Dv0qO46Fd-DxNv5z9=x%2BvO%2B8g=47NiiAf8QEJYA@mail.gmail.com in favor of a label local to this macro only, as it should be done. Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/r/20240607111701.8366-11-bp@kernel.org
1 parent d2d302b commit 9369412

2 files changed

Lines changed: 9 additions & 29 deletions

File tree

arch/x86/include/asm/alternative.h

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -277,26 +277,10 @@ static inline int alternatives_text_reserved(void *start, void *end)
277277
N_ALTERNATIVE_2(oldinstr, newinstr_no, X86_FEATURE_ALWAYS, \
278278
newinstr_yes, ft_flags)
279279

280-
#define ALTERNATIVE_3(oldinsn, newinsn1, ft_flags1, newinsn2, ft_flags2, \
281-
newinsn3, ft_flags3) \
282-
OLDINSTR_3(oldinsn, 1, 2, 3) \
283-
".pushsection .altinstructions,\"a\"\n" \
284-
ALTINSTR_ENTRY(ft_flags1, 1) \
285-
ALTINSTR_ENTRY(ft_flags2, 2) \
286-
ALTINSTR_ENTRY(ft_flags3, 3) \
287-
".popsection\n" \
288-
".pushsection .altinstr_replacement, \"ax\"\n" \
289-
ALTINSTR_REPLACEMENT(newinsn1, 1) \
290-
ALTINSTR_REPLACEMENT(newinsn2, 2) \
291-
ALTINSTR_REPLACEMENT(newinsn3, 3) \
292-
".popsection\n"
293-
294-
295-
#define N_ALTERNATIVE_3(oldinst, newinst1, flag1, newinst2, flag2, \
296-
newinst3, flag3) \
297-
N_ALTERNATIVE(N_ALTERNATIVE_2(oldinst, newinst1, flag1, newinst2, flag2), \
298-
newinst3, flag3)
299-
280+
#define ALTERNATIVE_3(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2, \
281+
newinstr3, ft_flags3) \
282+
N_ALTERNATIVE(N_ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2), \
283+
newinstr3, ft_flags3)
300284
/*
301285
* Alternative instructions for different CPU types or capabilities.
302286
*

arch/x86/kernel/fpu/xstate.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,17 @@ static inline u64 xfeatures_mask_independent(void)
106106
* Otherwise, if XSAVEOPT is enabled, XSAVEOPT replaces XSAVE because XSAVEOPT
107107
* supports modified optimization which is not supported by XSAVE.
108108
*
109-
* We use XSAVE as a fallback.
110-
*
111-
* The 661 label is defined in the ALTERNATIVE* macros as the address of the
112-
* original instruction which gets replaced. We need to use it here as the
113-
* address of the instruction where we might get an exception at.
109+
* Use XSAVE as a fallback.
114110
*/
115111
#define XSTATE_XSAVE(st, lmask, hmask, err) \
116-
asm volatile(ALTERNATIVE_3(XSAVE, \
112+
asm volatile("1: " ALTERNATIVE_3(XSAVE, \
117113
XSAVEOPT, X86_FEATURE_XSAVEOPT, \
118114
XSAVEC, X86_FEATURE_XSAVEC, \
119115
XSAVES, X86_FEATURE_XSAVES) \
120116
"\n" \
121117
"xor %[err], %[err]\n" \
122118
"3:\n" \
123-
_ASM_EXTABLE_TYPE_REG(661b, 3b, EX_TYPE_EFAULT_REG, %[err]) \
119+
_ASM_EXTABLE_TYPE_REG(1b, 3b, EX_TYPE_EFAULT_REG, %[err]) \
124120
: [err] "=r" (err) \
125121
: "D" (st), "m" (*st), "a" (lmask), "d" (hmask) \
126122
: "memory")
@@ -130,11 +126,11 @@ static inline u64 xfeatures_mask_independent(void)
130126
* XSAVE area format.
131127
*/
132128
#define XSTATE_XRESTORE(st, lmask, hmask) \
133-
asm volatile(ALTERNATIVE(XRSTOR, \
129+
asm volatile("1: " ALTERNATIVE(XRSTOR, \
134130
XRSTORS, X86_FEATURE_XSAVES) \
135131
"\n" \
136132
"3:\n" \
137-
_ASM_EXTABLE_TYPE(661b, 3b, EX_TYPE_FPU_RESTORE) \
133+
_ASM_EXTABLE_TYPE(1b, 3b, EX_TYPE_FPU_RESTORE) \
138134
: \
139135
: "D" (st), "m" (*st), "a" (lmask), "d" (hmask) \
140136
: "memory")

0 commit comments

Comments
 (0)