From: Borislav Petkov <bp@kernel.org>
To: X86 ML <x86@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
"Borislav Petkov (AMD)" <bp@alien8.de>
Subject: [PATCH v1 14/14] x86/alternative: Replace the old macros
Date: Fri, 7 Jun 2024 13:17:01 +0200 [thread overview]
Message-ID: <20240607111701.8366-15-bp@kernel.org> (raw)
In-Reply-To: <20240607111701.8366-1-bp@kernel.org>
From: "Borislav Petkov (AMD)" <bp@alien8.de>
Now that the new macros have been gradually put in place, replace the
old ones. Leave the new label numbers starting at 7xx as a hint that the
new nested alternatives are being used now.
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
---
arch/x86/include/asm/alternative.h | 144 +++++++----------------------
1 file changed, 32 insertions(+), 112 deletions(-)
diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
index 5278cfb1f745..4973edbe9289 100644
--- a/arch/x86/include/asm/alternative.h
+++ b/arch/x86/include/asm/alternative.h
@@ -156,131 +156,51 @@ static inline int alternatives_text_reserved(void *start, void *end)
#define ALT_CALL_INSTR "call BUG_func"
-#define b_replacement(num) "664"#num
-#define e_replacement(num) "665"#num
+#define alt_slen "772b-771b"
+#define alt_total_slen "773b-771b"
+#define alt_rlen "775f-774f"
-#define alt_end_marker "663"
-#define alt_slen "662b-661b"
-#define n_alt_slen "772b-771b"
-
-#define alt_total_slen alt_end_marker"b-661b"
-#define n_alt_total_slen "773b-771b"
-
-#define alt_rlen(num) e_replacement(num)"f-"b_replacement(num)"f"
-#define n_alt_rlen "775f-774f"
-
-#define OLDINSTR(oldinstr, num) \
- "# ALT: oldnstr\n" \
- "661:\n\t" oldinstr "\n662:\n" \
- "# ALT: padding\n" \
- ".skip -(((" alt_rlen(num) ")-(" alt_slen ")) > 0) * " \
- "((" alt_rlen(num) ")-(" alt_slen ")),0x90\n" \
- alt_end_marker ":\n"
-
-#define N_OLDINSTR(oldinstr) \
- "# N_ALT: oldinstr\n" \
+#define OLDINSTR(oldinstr) \
+ "# ALT: oldinstr\n" \
"771:\n\t" oldinstr "\n772:\n" \
- "# N_ALT: padding\n" \
- ".skip -(((" n_alt_rlen ")-(" n_alt_slen ")) > 0) * " \
- "((" n_alt_rlen ")-(" n_alt_slen ")),0x90\n" \
+ "# ALT: padding\n" \
+ ".skip -(((" alt_rlen ")-(" alt_slen ")) > 0) * " \
+ "((" alt_rlen ")-(" alt_slen ")),0x90\n" \
"773:\n"
-/*
- * gas compatible max based on the idea from:
- * http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
- *
- * The additional "-" is needed because gas uses a "true" value of -1.
- */
-#define alt_max_short(a, b) "((" a ") ^ (((" a ") ^ (" b ")) & -(-((" a ") < (" b ")))))"
-
-/*
- * Pad the second replacement alternative with additional NOPs if it is
- * additionally longer than the first replacement alternative.
- */
-#define OLDINSTR_2(oldinstr, num1, num2) \
- "# ALT: oldinstr2\n" \
- "661:\n\t" oldinstr "\n662:\n" \
- "# ALT: padding2\n" \
- ".skip -((" alt_max_short(alt_rlen(num1), alt_rlen(num2)) " - (" alt_slen ")) > 0) * " \
- "(" alt_max_short(alt_rlen(num1), alt_rlen(num2)) " - (" alt_slen ")), 0x90\n" \
- alt_end_marker ":\n"
-
-#define OLDINSTR_3(oldinsn, n1, n2, n3) \
- "# ALT: oldinstr3\n" \
- "661:\n\t" oldinsn "\n662:\n" \
- "# ALT: padding3\n" \
- ".skip -((" alt_max_short(alt_max_short(alt_rlen(n1), alt_rlen(n2)), alt_rlen(n3)) \
- " - (" alt_slen ")) > 0) * " \
- "(" alt_max_short(alt_max_short(alt_rlen(n1), alt_rlen(n2)), alt_rlen(n3)) \
- " - (" alt_slen ")), 0x90\n" \
- alt_end_marker ":\n"
-
-#define ALTINSTR_ENTRY(ft_flags, num) \
- " .long 661b - .\n" /* label */ \
- " .long " b_replacement(num)"f - .\n" /* new instruction */ \
- " .4byte " __stringify(ft_flags) "\n" /* feature + flags */ \
- " .byte " alt_total_slen "\n" /* source len */ \
- " .byte " alt_rlen(num) "\n" /* replacement len */
-
-#define N_ALTINSTR_ENTRY(ft_flags) \
+#define ALTINSTR_ENTRY(ft_flags) \
".pushsection .altinstructions,\"a\"\n" \
" .long 771b - .\n" /* label */ \
" .long 774f - .\n" /* new instruction */ \
" .4byte " __stringify(ft_flags) "\n" /* feature + flags */ \
- " .byte " n_alt_total_slen "\n" /* source len */ \
- " .byte " n_alt_rlen "\n" /* replacement len */ \
+ " .byte " alt_total_slen "\n" /* source len */ \
+ " .byte " alt_rlen "\n" /* replacement len */ \
".popsection\n"
-#define ALTINSTR_REPLACEMENT(newinstr, num) /* replacement */ \
- "# ALT: replacement " #num "\n" \
- b_replacement(num)":\n\t" newinstr "\n" e_replacement(num) ":\n"
-
-#define N_ALTINSTR_REPLACEMENT(newinstr) /* replacement */ \
- ".pushsection .altinstr_replacement, \"ax\"\n" \
- "# N_ALT: replacement\n" \
- "774:\n\t" newinstr "\n775:\n" \
+#define ALTINSTR_REPLACEMENT(newinstr) /* replacement */ \
+ ".pushsection .altinstr_replacement, \"ax\"\n" \
+ "# ALT: replacement\n" \
+ "774:\n\t" newinstr "\n775:\n" \
".popsection\n"
/* alternative assembly primitive: */
#define ALTERNATIVE(oldinstr, newinstr, ft_flags) \
- OLDINSTR(oldinstr, 1) \
- ".pushsection .altinstructions,\"a\"\n" \
- ALTINSTR_ENTRY(ft_flags, 1) \
- ".popsection\n" \
- ".pushsection .altinstr_replacement, \"ax\"\n" \
- ALTINSTR_REPLACEMENT(newinstr, 1) \
- ".popsection\n"
-
-/* Nested alternatives macro variant */
-#define N_ALTERNATIVE(oldinstr, newinstr, ft_flags) \
- N_OLDINSTR(oldinstr) \
- N_ALTINSTR_ENTRY(ft_flags) \
- N_ALTINSTR_REPLACEMENT(newinstr)
+ OLDINSTR(oldinstr) \
+ ALTINSTR_ENTRY(ft_flags) \
+ ALTINSTR_REPLACEMENT(newinstr)
#define ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2) \
- OLDINSTR_2(oldinstr, 1, 2) \
- ".pushsection .altinstructions,\"a\"\n" \
- ALTINSTR_ENTRY(ft_flags1, 1) \
- ALTINSTR_ENTRY(ft_flags2, 2) \
- ".popsection\n" \
- ".pushsection .altinstr_replacement, \"ax\"\n" \
- ALTINSTR_REPLACEMENT(newinstr1, 1) \
- ALTINSTR_REPLACEMENT(newinstr2, 2) \
- ".popsection\n"
-
-#define N_ALTERNATIVE_2(oldinst, newinst1, flag1, newinst2, flag2) \
- N_ALTERNATIVE(N_ALTERNATIVE(oldinst, newinst1, flag1), \
- newinst2, flag2)
+ ALTERNATIVE(ALTERNATIVE(oldinstr, newinstr1, ft_flags1), newinstr2, ft_flags2)
/* If @feature is set, patch in @newinstr_yes, otherwise @newinstr_no. */
#define ALTERNATIVE_TERNARY(oldinstr, ft_flags, newinstr_yes, newinstr_no) \
- N_ALTERNATIVE_2(oldinstr, newinstr_no, X86_FEATURE_ALWAYS, \
- newinstr_yes, ft_flags)
+ ALTERNATIVE_2(oldinstr, newinstr_no, X86_FEATURE_ALWAYS, newinstr_yes, ft_flags)
#define ALTERNATIVE_3(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2, \
newinstr3, ft_flags3) \
- N_ALTERNATIVE(N_ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2), \
+ ALTERNATIVE(ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2), \
newinstr3, ft_flags3)
+
/*
* Alternative instructions for different CPU types or capabilities.
*
@@ -294,10 +214,10 @@ static inline int alternatives_text_reserved(void *start, void *end)
* without volatile and memory clobber.
*/
#define alternative(oldinstr, newinstr, ft_flags) \
- asm_inline volatile(N_ALTERNATIVE(oldinstr, newinstr, ft_flags) : : : "memory")
+ asm_inline volatile(ALTERNATIVE(oldinstr, newinstr, ft_flags) : : : "memory")
#define alternative_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2) \
- asm_inline volatile(N_ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2) ::: "memory")
+ asm_inline volatile(ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2) ::: "memory")
/*
* Alternative inline assembly with input.
@@ -308,12 +228,12 @@ static inline int alternatives_text_reserved(void *start, void *end)
* Leaving an unused argument 0 to keep API compatibility.
*/
#define alternative_input(oldinstr, newinstr, ft_flags, input...) \
- asm_inline volatile(N_ALTERNATIVE(oldinstr, newinstr, ft_flags) \
+ asm_inline volatile(ALTERNATIVE(oldinstr, newinstr, ft_flags) \
: : "i" (0), ## input)
/* Like alternative_input, but with a single output argument */
#define alternative_io(oldinstr, newinstr, ft_flags, output, input...) \
- asm_inline volatile(N_ALTERNATIVE(oldinstr, newinstr, ft_flags) \
+ asm_inline volatile(ALTERNATIVE(oldinstr, newinstr, ft_flags) \
: output : "i" (0), ## input)
/*
@@ -327,7 +247,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
* suffix.
*/
#define alternative_call(oldfunc, newfunc, ft_flags, output, input...) \
- asm_inline volatile(N_ALTERNATIVE("call %c[old]", "call %c[new]", ft_flags) \
+ asm_inline volatile(ALTERNATIVE("call %c[old]", "call %c[new]", ft_flags) \
: output : [old] "i" (oldfunc), [new] "i" (newfunc), ## input)
/*
@@ -338,7 +258,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
*/
#define alternative_call_2(oldfunc, newfunc1, ft_flags1, newfunc2, ft_flags2, \
output, input...) \
- asm_inline volatile(N_ALTERNATIVE_2("call %c[old]", "call %c[new1]", ft_flags1, \
+ asm_inline volatile(ALTERNATIVE_2("call %c[old]", "call %c[new1]", ft_flags1, \
"call %c[new2]", ft_flags2) \
: output, ASM_CALL_CONSTRAINT \
: [old] "i" (oldfunc), [new1] "i" (newfunc1), \
@@ -422,7 +342,7 @@ void nop_func(void);
* @newinstr. ".skip" directive takes care of proper instruction padding
* in case @newinstr is longer than @oldinstr.
*/
-#define __N_ALTERNATIVE(oldinst, newinst, flag) \
+#define __ALTERNATIVE(oldinst, newinst, flag) \
740: \
oldinst ; \
741: \
@@ -438,7 +358,7 @@ void nop_func(void);
.popsection ;
.macro ALTERNATIVE oldinstr, newinstr, ft_flags
- __N_ALTERNATIVE(\oldinstr, \newinstr, \ft_flags)
+ __ALTERNATIVE(\oldinstr, \newinstr, \ft_flags)
.endm
#define old_len 141b-140b
@@ -461,12 +381,12 @@ void nop_func(void);
* @feature2, it replaces @oldinstr with @feature2.
*/
.macro ALTERNATIVE_2 oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2
- __N_ALTERNATIVE(__N_ALTERNATIVE(\oldinstr, \newinstr1, \ft_flags1),
+ __ALTERNATIVE(__ALTERNATIVE(\oldinstr, \newinstr1, \ft_flags1),
\newinstr2, \ft_flags2)
.endm
.macro ALTERNATIVE_3 oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2, newinstr3, ft_flags3
- __N_ALTERNATIVE(N_ALTERNATIVE_2(\oldinstr, \newinstr1, \ft_flags1, \newinstr2, \ft_flags2),
+ __ALTERNATIVE(ALTERNATIVE_2(\oldinstr, \newinstr1, \ft_flags1, \newinstr2, \ft_flags2),
\newinstr3, \ft_flags3)
.endm
--
2.43.0
next prev parent reply other threads:[~2024-06-07 11:17 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-07 11:16 [PATCH v1 00/14] x86/alternatives: Nest them Borislav Petkov
2024-06-07 11:16 ` [PATCH v1 01/14] x86/alternative: Zap alternative_ternary() Borislav Petkov
2024-06-11 16:53 ` [tip: x86/alternatives] " tip-bot2 for Borislav Petkov (AMD)
2024-06-07 11:16 ` [PATCH v1 02/14] x86/alternatives: Add nested alternatives macros Borislav Petkov
2024-06-07 11:16 ` [PATCH v1 03/14] x86/alternative: Convert alternative() Borislav Petkov
2024-06-11 16:53 ` [tip: x86/alternatives] " tip-bot2 for Borislav Petkov (AMD)
2024-06-07 11:16 ` [PATCH v1 04/14] x86/alternative: Convert alternative_2() Borislav Petkov
2024-06-11 16:53 ` [tip: x86/alternatives] " tip-bot2 for Borislav Petkov (AMD)
2024-06-07 11:16 ` [PATCH v1 05/14] x86/alternative: Convert alternative_input() Borislav Petkov
2024-06-11 16:53 ` [tip: x86/alternatives] " tip-bot2 for Borislav Petkov (AMD)
2024-06-07 11:16 ` [PATCH v1 06/14] x86/alternative: Convert alternative_io() Borislav Petkov
2024-06-11 16:53 ` [tip: x86/alternatives] " tip-bot2 for Borislav Petkov (AMD)
2024-06-07 11:16 ` [PATCH v1 07/14] x86/alternative: Convert alternative_call() Borislav Petkov
2024-06-11 16:53 ` [tip: x86/alternatives] " tip-bot2 for Borislav Petkov (AMD)
2024-06-07 11:16 ` [PATCH v1 08/14] x86/alternative: Convert alternative_call_2() Borislav Petkov
2024-06-11 16:53 ` [tip: x86/alternatives] " tip-bot2 for Borislav Petkov (AMD)
2024-06-07 11:16 ` [PATCH v1 09/14] x86/alternative: Convert ALTERNATIVE_TERNARY() Borislav Petkov
2024-06-11 16:53 ` [tip: x86/alternatives] " tip-bot2 for Borislav Petkov (AMD)
2024-06-07 11:16 ` [PATCH v1 10/14] x86/alternative: Convert ALTERNATIVE_3() Borislav Petkov
2024-06-11 16:53 ` [tip: x86/alternatives] " tip-bot2 for Borislav Petkov (AMD)
2024-06-07 11:16 ` [PATCH v1 11/14] x86/alternative: Convert the asm ALTERNATIVE() macro Borislav Petkov
2024-06-11 16:53 ` [tip: x86/alternatives] " tip-bot2 for Borislav Petkov (AMD)
2024-06-07 11:16 ` [PATCH v1 12/14] x86/alternative: Convert the asm ALTERNATIVE_2() macro Borislav Petkov
2024-06-11 16:53 ` [tip: x86/alternatives] " tip-bot2 for Borislav Petkov (AMD)
2024-06-07 11:17 ` [PATCH v1 13/14] x86/alternative: Convert the asm ALTERNATIVE_3() macro Borislav Petkov
2024-06-11 16:53 ` [tip: x86/alternatives] " tip-bot2 for Borislav Petkov (AMD)
2024-06-07 11:17 ` Borislav Petkov [this message]
2024-06-11 13:25 ` [PATCH v1 14/14] x86/alternative: Replace the old macros Peter Zijlstra
2024-06-11 16:53 ` [tip: x86/alternatives] " tip-bot2 for Borislav Petkov (AMD)
2024-06-11 13:26 ` [PATCH v1 00/14] x86/alternatives: Nest them Peter Zijlstra
2024-06-11 14:05 ` Borislav Petkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240607111701.8366-15-bp@kernel.org \
--to=bp@kernel.org \
--cc=bp@alien8.de \
--cc=linux-kernel@vger.kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.