* [PATCH 6.1 0/3] ITS fixes
@ 2025-05-14 5:35 Pawan Gupta
2025-05-14 5:35 ` [PATCH 6.1 1/3] x86/alternative: Optimize returns patching Pawan Gupta
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Pawan Gupta @ 2025-05-14 5:35 UTC (permalink / raw)
To: stable
Cc: Greg Kroah-Hartman, Sasha Levin, Josh Poimboeuf, Borislav Petkov,
Alexandre Chartre, Peter Zijlstra (Intel)
Two of the patches are older rethunk fixes and one is a build fix for
CONFIG_MODULES=n.
---
Borislav Petkov (AMD) (1):
x86/alternative: Optimize returns patching
Eric Biggers (1):
x86/its: Fix build errors when CONFIG_MODULES=n
Josh Poimboeuf (1):
x86/alternatives: Remove faulty optimization
arch/x86/kernel/alternative.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
---
change-id: 20250513-its-fixes-6-1-d21ce20b0d1d
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 6.1 1/3] x86/alternative: Optimize returns patching
2025-05-14 5:35 [PATCH 6.1 0/3] ITS fixes Pawan Gupta
@ 2025-05-14 5:35 ` Pawan Gupta
2025-05-14 20:13 ` Sasha Levin
2025-05-14 5:36 ` [PATCH 6.1 2/3] x86/alternatives: Remove faulty optimization Pawan Gupta
2025-05-14 5:36 ` [PATCH 6.1 3/3] x86/its: Fix build errors when CONFIG_MODULES=n Pawan Gupta
2 siblings, 1 reply; 7+ messages in thread
From: Pawan Gupta @ 2025-05-14 5:35 UTC (permalink / raw)
To: stable
Cc: Greg Kroah-Hartman, Sasha Levin, Josh Poimboeuf, Borislav Petkov,
Alexandre Chartre
From: "Borislav Petkov (AMD)" <bp@alien8.de>
commit d2408e043e7296017420aa5929b3bba4d5e61013 upstream.
Instead of decoding each instruction in the return sites range only to
realize that that return site is a jump to the default return thunk
which is needed - X86_FEATURE_RETHUNK is enabled - lift that check
before the loop and get rid of that loop overhead.
Add comments about what gets patched, while at it.
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230512120952.7924-1-bp@alien8.de
Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
---
arch/x86/kernel/alternative.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index 44bff34f7d10cb6868ad079ca1cb87e458d3f91b..dfd5490df0af9e55d1a6ab185ad7cb03bdda4a91 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -769,13 +769,12 @@ static int patch_return(void *addr, struct insn *insn, u8 *bytes)
{
int i = 0;
+ /* Patch the custom return thunks... */
if (cpu_wants_rethunk_at(addr)) {
- if (x86_return_thunk == __x86_return_thunk)
- return -1;
-
i = JMP32_INSN_SIZE;
__text_gen_insn(bytes, JMP32_INSN_OPCODE, addr, x86_return_thunk, i);
} else {
+ /* ... or patch them out if not needed. */
bytes[i++] = RET_INSN_OPCODE;
}
@@ -788,6 +787,14 @@ void __init_or_module noinline apply_returns(s32 *start, s32 *end)
{
s32 *s;
+ /*
+ * Do not patch out the default return thunks if those needed are the
+ * ones generated by the compiler.
+ */
+ if (cpu_feature_enabled(X86_FEATURE_RETHUNK) &&
+ (x86_return_thunk == __x86_return_thunk))
+ return;
+
for (s = start; s < end; s++) {
void *dest = NULL, *addr = (void *)s + *s;
struct insn insn;
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 6.1 2/3] x86/alternatives: Remove faulty optimization
2025-05-14 5:35 [PATCH 6.1 0/3] ITS fixes Pawan Gupta
2025-05-14 5:35 ` [PATCH 6.1 1/3] x86/alternative: Optimize returns patching Pawan Gupta
@ 2025-05-14 5:36 ` Pawan Gupta
2025-05-14 20:14 ` Sasha Levin
2025-05-14 5:36 ` [PATCH 6.1 3/3] x86/its: Fix build errors when CONFIG_MODULES=n Pawan Gupta
2 siblings, 1 reply; 7+ messages in thread
From: Pawan Gupta @ 2025-05-14 5:36 UTC (permalink / raw)
To: stable
Cc: Greg Kroah-Hartman, Sasha Levin, Josh Poimboeuf, Borislav Petkov,
Alexandre Chartre
From: Josh Poimboeuf <jpoimboe@kernel.org>
commit 4ba89dd6ddeca2a733bdaed7c9a5cbe4e19d9124 upstream.
The following commit
095b8303f383 ("x86/alternative: Make custom return thunk unconditional")
made '__x86_return_thunk' a placeholder value. All code setting
X86_FEATURE_RETHUNK also changes the value of 'x86_return_thunk'. So
the optimization at the beginning of apply_returns() is dead code.
Also, before the above-mentioned commit, the optimization actually had a
bug It bypassed __static_call_fixup(), causing some raw returns to
remain unpatched in static call trampolines. Thus the 'Fixes' tag.
Fixes: d2408e043e72 ("x86/alternative: Optimize returns patching")
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Acked-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/16d19d2249d4485d8380fb215ffaae81e6b8119e.1693889988.git.jpoimboe@kernel.org
Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
---
arch/x86/kernel/alternative.c | 8 --------
1 file changed, 8 deletions(-)
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index dfd5490df0af9e55d1a6ab185ad7cb03bdda4a91..023899e9ebd16ba223a1de91da9bcb43666788f9 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -787,14 +787,6 @@ void __init_or_module noinline apply_returns(s32 *start, s32 *end)
{
s32 *s;
- /*
- * Do not patch out the default return thunks if those needed are the
- * ones generated by the compiler.
- */
- if (cpu_feature_enabled(X86_FEATURE_RETHUNK) &&
- (x86_return_thunk == __x86_return_thunk))
- return;
-
for (s = start; s < end; s++) {
void *dest = NULL, *addr = (void *)s + *s;
struct insn insn;
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 6.1 3/3] x86/its: Fix build errors when CONFIG_MODULES=n
2025-05-14 5:35 [PATCH 6.1 0/3] ITS fixes Pawan Gupta
2025-05-14 5:35 ` [PATCH 6.1 1/3] x86/alternative: Optimize returns patching Pawan Gupta
2025-05-14 5:36 ` [PATCH 6.1 2/3] x86/alternatives: Remove faulty optimization Pawan Gupta
@ 2025-05-14 5:36 ` Pawan Gupta
2025-05-14 20:13 ` Sasha Levin
2 siblings, 1 reply; 7+ messages in thread
From: Pawan Gupta @ 2025-05-14 5:36 UTC (permalink / raw)
To: stable
Cc: Greg Kroah-Hartman, Sasha Levin, Josh Poimboeuf, Borislav Petkov,
Alexandre Chartre
From: Eric Biggers <ebiggers@google.com>
commit 9f35e33144ae5377d6a8de86dd3bd4d995c6ac65 upstream.
Fix several build errors when CONFIG_MODULES=n, including the following:
../arch/x86/kernel/alternative.c:195:25: error: incomplete definition of type 'struct module'
195 | for (int i = 0; i < mod->its_num_pages; i++) {
Fixes: 872df34d7c51 ("x86/its: Use dynamic thunks for indirect branches")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
Acked-by: Dave Hansen <dave.hansen@intel.com>
Tested-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Reviewed-by: Alexandre Chartre <alexandre.chartre@oracle.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
---
arch/x86/kernel/alternative.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index 023899e9ebd16ba223a1de91da9bcb43666788f9..843bda0cb5d09a091a06ac7c3b30d5545880e905 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -402,7 +402,9 @@ static int emit_indirect(int op, int reg, u8 *bytes)
#ifdef CONFIG_MITIGATION_ITS
+#ifdef CONFIG_MODULES
static struct module *its_mod;
+#endif
static void *its_page;
static unsigned int its_offset;
@@ -423,6 +425,7 @@ static void *its_init_thunk(void *thunk, int reg)
return thunk;
}
+#ifdef CONFIG_MODULES
void its_init_mod(struct module *mod)
{
if (!cpu_feature_enabled(X86_FEATURE_INDIRECT_THUNK_ITS))
@@ -462,6 +465,7 @@ void its_free_mod(struct module *mod)
}
kfree(mod->its_page_array);
}
+#endif /* CONFIG_MODULES */
DEFINE_FREE(its_execmem, void *, if (_T) module_memfree(_T));
@@ -472,6 +476,7 @@ static void *its_alloc(void)
if (!page)
return NULL;
+#ifdef CONFIG_MODULES
if (its_mod) {
void *tmp = krealloc(its_mod->its_page_array,
(its_mod->its_num_pages+1) * sizeof(void *),
@@ -482,6 +487,7 @@ static void *its_alloc(void)
its_mod->its_page_array = tmp;
its_mod->its_page_array[its_mod->its_num_pages++] = page;
}
+#endif /* CONFIG_MODULES */
return no_free_ptr(page);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 6.1 1/3] x86/alternative: Optimize returns patching
2025-05-14 5:35 ` [PATCH 6.1 1/3] x86/alternative: Optimize returns patching Pawan Gupta
@ 2025-05-14 20:13 ` Sasha Levin
0 siblings, 0 replies; 7+ messages in thread
From: Sasha Levin @ 2025-05-14 20:13 UTC (permalink / raw)
To: stable, pawan.kumar.gupta; +Cc: Sasha Levin
[ Sasha's backport helper bot ]
Hi,
Summary of potential issues:
⚠️ Found follow-up fixes in mainline
The upstream commit SHA1 provided is correct: d2408e043e7296017420aa5929b3bba4d5e61013
WARNING: Author mismatch between patch and upstream commit:
Backport author: Pawan Gupta<pawan.kumar.gupta@linux.intel.com>
Commit author: Borislav Petkov (AMD)<bp@alien8.de>
Status in newer kernel trees:
6.14.y | Present (exact SHA1)
6.12.y | Present (exact SHA1)
6.6.y | Present (exact SHA1)
Found fixes commits:
4ba89dd6ddec x86/alternatives: Remove faulty optimization
Note: The patch differs from the upstream commit:
---
1: d2408e043e729 < -: ------------- x86/alternative: Optimize returns patching
-: ------------- > 1: 02b72ccb5f9df Linux 6.1.138
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.1.y | Success | Success |
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 6.1 3/3] x86/its: Fix build errors when CONFIG_MODULES=n
2025-05-14 5:36 ` [PATCH 6.1 3/3] x86/its: Fix build errors when CONFIG_MODULES=n Pawan Gupta
@ 2025-05-14 20:13 ` Sasha Levin
0 siblings, 0 replies; 7+ messages in thread
From: Sasha Levin @ 2025-05-14 20:13 UTC (permalink / raw)
To: stable; +Cc: Pawan Gupta, Sasha Levin
[ Sasha's backport helper bot ]
Hi,
✅ All tests passed successfully. No issues detected.
No action required from the submitter.
The upstream commit SHA1 provided is correct: 9f35e33144ae5377d6a8de86dd3bd4d995c6ac65
WARNING: Author mismatch between patch and upstream commit:
Backport author: Pawan Gupta<pawan.kumar.gupta@linux.intel.com>
Commit author: Eric Biggers<ebiggers@google.com>
Status in newer kernel trees:
6.14.y | Not found
6.12.y | Not found
6.6.y | Not found
Note: The patch differs from the upstream commit:
---
1: 9f35e33144ae5 < -: ------------- x86/its: Fix build errors when CONFIG_MODULES=n
-: ------------- > 1: 02b72ccb5f9df Linux 6.1.138
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.6.y | Success | Success |
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 6.1 2/3] x86/alternatives: Remove faulty optimization
2025-05-14 5:36 ` [PATCH 6.1 2/3] x86/alternatives: Remove faulty optimization Pawan Gupta
@ 2025-05-14 20:14 ` Sasha Levin
0 siblings, 0 replies; 7+ messages in thread
From: Sasha Levin @ 2025-05-14 20:14 UTC (permalink / raw)
To: stable; +Cc: Pawan Gupta, Sasha Levin
[ Sasha's backport helper bot ]
Hi,
✅ All tests passed successfully. No issues detected.
No action required from the submitter.
The upstream commit SHA1 provided is correct: 4ba89dd6ddeca2a733bdaed7c9a5cbe4e19d9124
WARNING: Author mismatch between patch and upstream commit:
Backport author: Pawan Gupta<pawan.kumar.gupta@linux.intel.com>
Commit author: Josh Poimboeuf<jpoimboe@kernel.org>
Status in newer kernel trees:
6.14.y | Present (exact SHA1)
6.12.y | Present (exact SHA1)
6.6.y | Present (exact SHA1)
Note: The patch differs from the upstream commit:
---
1: 4ba89dd6ddeca < -: ------------- x86/alternatives: Remove faulty optimization
-: ------------- > 1: 02b72ccb5f9df Linux 6.1.138
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.6.y | Success | Success |
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-05-14 20:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-14 5:35 [PATCH 6.1 0/3] ITS fixes Pawan Gupta
2025-05-14 5:35 ` [PATCH 6.1 1/3] x86/alternative: Optimize returns patching Pawan Gupta
2025-05-14 20:13 ` Sasha Levin
2025-05-14 5:36 ` [PATCH 6.1 2/3] x86/alternatives: Remove faulty optimization Pawan Gupta
2025-05-14 20:14 ` Sasha Levin
2025-05-14 5:36 ` [PATCH 6.1 3/3] x86/its: Fix build errors when CONFIG_MODULES=n Pawan Gupta
2025-05-14 20:13 ` Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox