Skip to content

Commit 71a93c2

Browse files
committed
x86/alternatives: Add an ALTERNATIVE_3() macro
Similar to ALTERNATIVE_2(), ALTERNATIVE_3() selects between 3 possible variants. Will be used for adding RDTSCP to the rdtsc_ordered() alternatives. Signed-off-by: Borislav Petkov <bp@suse.de> Cc: Andy Lutomirski <luto@amacapital.net> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Tom Lendacky <thomas.lendacky@amd.com> Cc: X86 ML <x86@kernel.org> Link: https://lkml.kernel.org/r/20181211222326.14581-4-bp@alien8.de
1 parent c1d4e41 commit 71a93c2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

arch/x86/include/asm/alternative.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ static inline int alternatives_text_reserved(void *start, void *end)
122122
"(" alt_max_short(alt_rlen(num1), alt_rlen(num2)) " - (" alt_slen ")), 0x90\n" \
123123
alt_end_marker ":\n"
124124

125+
#define OLDINSTR_3(oldinsn, n1, n2, n3) \
126+
"# ALT: oldinstr3\n" \
127+
"661:\n\t" oldinsn "\n662:\n" \
128+
"# ALT: padding3\n" \
129+
".skip -((" alt_max_short(alt_max_short(alt_rlen(n1), alt_rlen(n2)), alt_rlen(n3)) \
130+
" - (" alt_slen ")) > 0) * " \
131+
"(" alt_max_short(alt_max_short(alt_rlen(n1), alt_rlen(n2)), alt_rlen(n3)) \
132+
" - (" alt_slen ")), 0x90\n" \
133+
alt_end_marker ":\n"
134+
125135
#define ALTINSTR_ENTRY(feature, num) \
126136
" .long 661b - .\n" /* label */ \
127137
" .long " b_replacement(num)"f - .\n" /* new instruction */ \
@@ -155,6 +165,19 @@ static inline int alternatives_text_reserved(void *start, void *end)
155165
ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
156166
".popsection\n"
157167

168+
#define ALTERNATIVE_3(oldinsn, newinsn1, feat1, newinsn2, feat2, newinsn3, feat3) \
169+
OLDINSTR_3(oldinsn, 1, 2, 3) \
170+
".pushsection .altinstructions,\"a\"\n" \
171+
ALTINSTR_ENTRY(feat1, 1) \
172+
ALTINSTR_ENTRY(feat2, 2) \
173+
ALTINSTR_ENTRY(feat3, 3) \
174+
".popsection\n" \
175+
".pushsection .altinstr_replacement, \"ax\"\n" \
176+
ALTINSTR_REPLACEMENT(newinsn1, feat1, 1) \
177+
ALTINSTR_REPLACEMENT(newinsn2, feat2, 2) \
178+
ALTINSTR_REPLACEMENT(newinsn3, feat3, 3) \
179+
".popsection\n"
180+
158181
/*
159182
* Alternative instructions for different CPU types or capabilities.
160183
*

0 commit comments

Comments
 (0)