mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] x86/ibt: Fix some spurious ENDBR instances
@ 2023-08-02 10:55 Peter Zijlstra
  2023-08-02 10:55 ` [PATCH 1/2] x86/ibt: Suppress spurious ENDBR Peter Zijlstra
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Peter Zijlstra @ 2023-08-02 10:55 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, peterz, jpoimboe, andrew.cooper3, David.Kaplan

Hi,

David was staring at assembly output and noticed a few spurious ENDBR
instructions.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/2] x86/ibt: Suppress spurious ENDBR
  2023-08-02 10:55 [PATCH 0/2] x86/ibt: Fix some spurious ENDBR instances Peter Zijlstra
@ 2023-08-02 10:55 ` Peter Zijlstra
  2023-09-12 11:08   ` [tip: x86/urgent] " tip-bot2 for Peter Zijlstra
  2023-09-12 15:54   ` tip-bot2 for Peter Zijlstra
  2023-08-02 10:55 ` [PATCH 2/2] x86/ibt: Avoid duplicate ENDBR in __put_user_nocheck*() Peter Zijlstra
  2023-08-02 11:25 ` [PATCH 0/2] x86/ibt: Fix some spurious ENDBR instances andrew.cooper3
  2 siblings, 2 replies; 9+ messages in thread
From: Peter Zijlstra @ 2023-08-02 10:55 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, peterz, jpoimboe, andrew.cooper3, David.Kaplan

It was reported that under certain circumstances GCC emits ENDBR
instructions for _THIS_IP_ usage. Specifically, when it appears at the
start of a basic block -- but not elsewhere.

Since _THIS_IP_ is never used for control flow, these ENDBR
instructions are completely superfluous. Override the _THIS_IP_
definition for x86_64 to avoid this.

Less ENDBR instructions is better.

Fixes: 156ff4a544ae ("x86/ibt: Base IBT bits")
Reported-by: David Kaplan <David.Kaplan@amd.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 arch/x86/include/asm/linkage.h      |    8 ++++++++
 include/linux/instruction_pointer.h |    5 +++++
 2 files changed, 13 insertions(+)

--- a/arch/x86/include/asm/linkage.h
+++ b/arch/x86/include/asm/linkage.h
@@ -8,6 +8,14 @@
 #undef notrace
 #define notrace __attribute__((no_instrument_function))
 
+#ifdef CONFIG_64BIT
+/*
+ * The generic version tends to create spurious ENDBR instructions under
+ * certain conditions.
+ */
+#define _THIS_IP_ ({ unsigned long __here; asm ("lea 0(%%rip), %0" : "=r" (__here)); __here; })
+#endif
+
 #ifdef CONFIG_X86_32
 #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
 #endif /* CONFIG_X86_32 */
--- a/include/linux/instruction_pointer.h
+++ b/include/linux/instruction_pointer.h
@@ -2,7 +2,12 @@
 #ifndef _LINUX_INSTRUCTION_POINTER_H
 #define _LINUX_INSTRUCTION_POINTER_H
 
+#include <asm/linkage.h>
+
 #define _RET_IP_		(unsigned long)__builtin_return_address(0)
+
+#ifndef _THIS_IP_
 #define _THIS_IP_  ({ __label__ __here; __here: (unsigned long)&&__here; })
+#endif
 
 #endif /* _LINUX_INSTRUCTION_POINTER_H */



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/2] x86/ibt: Avoid duplicate ENDBR in __put_user_nocheck*()
  2023-08-02 10:55 [PATCH 0/2] x86/ibt: Fix some spurious ENDBR instances Peter Zijlstra
  2023-08-02 10:55 ` [PATCH 1/2] x86/ibt: Suppress spurious ENDBR Peter Zijlstra
@ 2023-08-02 10:55 ` Peter Zijlstra
  2023-08-02 20:33   ` Peter Zijlstra
                     ` (2 more replies)
  2023-08-02 11:25 ` [PATCH 0/2] x86/ibt: Fix some spurious ENDBR instances andrew.cooper3
  2 siblings, 3 replies; 9+ messages in thread
From: Peter Zijlstra @ 2023-08-02 10:55 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, peterz, jpoimboe, andrew.cooper3, David.Kaplan

Commit cb855971d717 ("x86/putuser: Provide room for padding") changed
__put_user_nocheck_*() into proper functions but failed to note that
SYM_FUNC_START() already provides ENDBR, rendering the explicit ENDBR
superfluous.

Fixes: cb855971d717 ("x86/putuser: Provide room for padding")
Reported-by: David Kaplan <David.Kaplan@amd.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 arch/x86/lib/putuser.S |    4 ----
 1 file changed, 4 deletions(-)

--- a/arch/x86/lib/putuser.S
+++ b/arch/x86/lib/putuser.S
@@ -56,7 +56,6 @@ SYM_FUNC_END(__put_user_1)
 EXPORT_SYMBOL(__put_user_1)
 
 SYM_FUNC_START(__put_user_nocheck_1)
-	ENDBR
 	ASM_STAC
 2:	movb %al,(%_ASM_CX)
 	xor %ecx,%ecx
@@ -76,7 +75,6 @@ SYM_FUNC_END(__put_user_2)
 EXPORT_SYMBOL(__put_user_2)
 
 SYM_FUNC_START(__put_user_nocheck_2)
-	ENDBR
 	ASM_STAC
 4:	movw %ax,(%_ASM_CX)
 	xor %ecx,%ecx
@@ -96,7 +94,6 @@ SYM_FUNC_END(__put_user_4)
 EXPORT_SYMBOL(__put_user_4)
 
 SYM_FUNC_START(__put_user_nocheck_4)
-	ENDBR
 	ASM_STAC
 6:	movl %eax,(%_ASM_CX)
 	xor %ecx,%ecx
@@ -119,7 +116,6 @@ SYM_FUNC_END(__put_user_8)
 EXPORT_SYMBOL(__put_user_8)
 
 SYM_FUNC_START(__put_user_nocheck_8)
-	ENDBR
 	ASM_STAC
 9:	mov %_ASM_AX,(%_ASM_CX)
 #ifdef CONFIG_X86_32



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/2] x86/ibt: Fix some spurious ENDBR instances
  2023-08-02 10:55 [PATCH 0/2] x86/ibt: Fix some spurious ENDBR instances Peter Zijlstra
  2023-08-02 10:55 ` [PATCH 1/2] x86/ibt: Suppress spurious ENDBR Peter Zijlstra
  2023-08-02 10:55 ` [PATCH 2/2] x86/ibt: Avoid duplicate ENDBR in __put_user_nocheck*() Peter Zijlstra
@ 2023-08-02 11:25 ` andrew.cooper3
  2 siblings, 0 replies; 9+ messages in thread
From: andrew.cooper3 @ 2023-08-02 11:25 UTC (permalink / raw)
  To: Peter Zijlstra, x86; +Cc: linux-kernel, jpoimboe, David.Kaplan

On 02/08/2023 11:55 am, Peter Zijlstra wrote:
> Hi,
>
> David was staring at assembly output and noticed a few spurious ENDBR
> instructions.
>

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] x86/ibt: Avoid duplicate ENDBR in __put_user_nocheck*()
  2023-08-02 10:55 ` [PATCH 2/2] x86/ibt: Avoid duplicate ENDBR in __put_user_nocheck*() Peter Zijlstra
@ 2023-08-02 20:33   ` Peter Zijlstra
  2023-09-12 11:08   ` [tip: x86/urgent] " tip-bot2 for Peter Zijlstra
  2023-09-12 15:54   ` tip-bot2 for Peter Zijlstra
  2 siblings, 0 replies; 9+ messages in thread
From: Peter Zijlstra @ 2023-08-02 20:33 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, jpoimboe, andrew.cooper3, David.Kaplan

On Wed, Aug 02, 2023 at 12:55:47PM +0200, Peter Zijlstra wrote:
> Commit cb855971d717 ("x86/putuser: Provide room for padding") changed
> __put_user_nocheck_*() into proper functions but failed to note that
> SYM_FUNC_START() already provides ENDBR, rendering the explicit ENDBR
> superfluous.

The below objtool thing reliably detects this pattern:

vmlinux.o: warning: objtool: __put_user_nocheck_1+0x4: duplicate ENDBR
vmlinux.o: warning: objtool: __put_user_nocheck_2+0x4: duplicate ENDBR
vmlinux.o: warning: objtool: __put_user_nocheck_4+0x4: duplicate ENDBR
vmlinux.o: warning: objtool: __put_user_nocheck_8+0x4: duplicate ENDBR

---
 tools/objtool/check.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 8936a05f0e5a..c6ba6e768b03 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -4254,13 +4254,30 @@ static bool noendbr_range(struct objtool_file *file, struct instruction *insn)
 	return insn->offset == sym->offset + sym->len;
 }
 
-static int validate_ibt_insn(struct objtool_file *file, struct instruction *insn)
+static int validate_ibt_insn(struct objtool_file *file,
+			     struct instruction *insn,
+			     struct instruction *prev)
 {
 	struct instruction *dest;
 	struct reloc *reloc;
 	unsigned long off;
 	int warnings = 0;
 
+	if (prev && prev->sym && prev->sym == insn->sym &&
+	    prev->type == INSN_ENDBR && insn->type == INSN_ENDBR) {
+		/*
+		 * ___bpf_prog_run() is a maze of 'label as value' and
+		 * 'computed goto' and GCC gets confused and emits back-to-back
+		 * ENDBR due to failing to merge two labels.
+		 *
+		 * Don't warn about this until GCC is fixed or verbose.
+		 */
+		if (strcmp(insn->sym->name, "___bpf_prog_run") != 0 || opts.verbose) {
+			WARN_INSN(insn, "duplicate ENDBR");
+			warnings++;
+		}
+	}
+
 	/*
 	 * Looking for function pointer load relocations.  Ignore
 	 * direct/indirect branches:
@@ -4382,11 +4399,13 @@ static int validate_ibt(struct objtool_file *file)
 {
 	struct section *sec;
 	struct reloc *reloc;
-	struct instruction *insn;
+	struct instruction *insn, *prev = NULL;
 	int warnings = 0;
 
-	for_each_insn(file, insn)
-		warnings += validate_ibt_insn(file, insn);
+	for_each_insn(file, insn) {
+		warnings += validate_ibt_insn(file, insn, prev);
+		prev = insn;
+	}
 
 	for_each_sec(file, sec) {
 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [tip: x86/urgent] x86/ibt: Avoid duplicate ENDBR in __put_user_nocheck*()
  2023-08-02 10:55 ` [PATCH 2/2] x86/ibt: Avoid duplicate ENDBR in __put_user_nocheck*() Peter Zijlstra
  2023-08-02 20:33   ` Peter Zijlstra
@ 2023-09-12 11:08   ` tip-bot2 for Peter Zijlstra
  2023-09-12 15:54   ` tip-bot2 for Peter Zijlstra
  2 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Peter Zijlstra @ 2023-09-12 11:08 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: David Kaplan, Peter Zijlstra (Intel), Andrew Cooper, x86, linux-kernel

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     1666863f28d7c490fa62ed5d1dfb1ba31453dc98
Gitweb:        https://git.kernel.org/tip/1666863f28d7c490fa62ed5d1dfb1ba31453dc98
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Wed, 02 Aug 2023 12:55:47 +02:00
Committer:     root <root@noisy.programming.kicks-ass.net>
CommitterDate: Tue, 12 Sep 2023 12:40:28 +02:00

x86/ibt: Avoid duplicate ENDBR in __put_user_nocheck*()

Commit cb855971d717 ("x86/putuser: Provide room for padding") changed
__put_user_nocheck_*() into proper functions but failed to note that
SYM_FUNC_START() already provides ENDBR, rendering the explicit ENDBR
superfluous.

Fixes: cb855971d717 ("x86/putuser: Provide room for padding")
Reported-by: David Kaplan <David.Kaplan@amd.com>
Signed-off-by: "Peter Zijlstra (Intel)" <peterz@infradead.org>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230802110323.086971726@infradead.org
---
 arch/x86/lib/putuser.S | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
index 1451e0c..235bbda 100644
--- a/arch/x86/lib/putuser.S
+++ b/arch/x86/lib/putuser.S
@@ -56,7 +56,6 @@ SYM_FUNC_END(__put_user_1)
 EXPORT_SYMBOL(__put_user_1)
 
 SYM_FUNC_START(__put_user_nocheck_1)
-	ENDBR
 	ASM_STAC
 2:	movb %al,(%_ASM_CX)
 	xor %ecx,%ecx
@@ -76,7 +75,6 @@ SYM_FUNC_END(__put_user_2)
 EXPORT_SYMBOL(__put_user_2)
 
 SYM_FUNC_START(__put_user_nocheck_2)
-	ENDBR
 	ASM_STAC
 4:	movw %ax,(%_ASM_CX)
 	xor %ecx,%ecx
@@ -96,7 +94,6 @@ SYM_FUNC_END(__put_user_4)
 EXPORT_SYMBOL(__put_user_4)
 
 SYM_FUNC_START(__put_user_nocheck_4)
-	ENDBR
 	ASM_STAC
 6:	movl %eax,(%_ASM_CX)
 	xor %ecx,%ecx
@@ -119,7 +116,6 @@ SYM_FUNC_END(__put_user_8)
 EXPORT_SYMBOL(__put_user_8)
 
 SYM_FUNC_START(__put_user_nocheck_8)
-	ENDBR
 	ASM_STAC
 9:	mov %_ASM_AX,(%_ASM_CX)
 #ifdef CONFIG_X86_32

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [tip: x86/urgent] x86/ibt: Suppress spurious ENDBR
  2023-08-02 10:55 ` [PATCH 1/2] x86/ibt: Suppress spurious ENDBR Peter Zijlstra
@ 2023-09-12 11:08   ` tip-bot2 for Peter Zijlstra
  2023-09-12 15:54   ` tip-bot2 for Peter Zijlstra
  1 sibling, 0 replies; 9+ messages in thread
From: tip-bot2 for Peter Zijlstra @ 2023-09-12 11:08 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: David Kaplan, Peter Zijlstra (Intel), Andrew Cooper, x86, linux-kernel

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     70524a25365bab3dfe968691aa436fff765a8dde
Gitweb:        https://git.kernel.org/tip/70524a25365bab3dfe968691aa436fff765a8dde
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Wed, 02 Aug 2023 12:55:46 +02:00
Committer:     root <root@noisy.programming.kicks-ass.net>
CommitterDate: Tue, 12 Sep 2023 12:40:28 +02:00

x86/ibt: Suppress spurious ENDBR

It was reported that under certain circumstances GCC emits ENDBR
instructions for _THIS_IP_ usage. Specifically, when it appears at the
start of a basic block -- but not elsewhere.

Since _THIS_IP_ is never used for control flow, these ENDBR
instructions are completely superfluous. Override the _THIS_IP_
definition for x86_64 to avoid this.

Less ENDBR instructions is better.

Fixes: 156ff4a544ae ("x86/ibt: Base IBT bits")
Reported-by: David Kaplan <David.Kaplan@amd.com>
Signed-off-by: "Peter Zijlstra (Intel)" <peterz@infradead.org>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230802110323.016197440@infradead.org
---
 arch/x86/include/asm/linkage.h      | 8 ++++++++
 include/linux/instruction_pointer.h | 5 +++++
 2 files changed, 13 insertions(+)

diff --git a/arch/x86/include/asm/linkage.h b/arch/x86/include/asm/linkage.h
index 97a3de7..5ff49fd 100644
--- a/arch/x86/include/asm/linkage.h
+++ b/arch/x86/include/asm/linkage.h
@@ -8,6 +8,14 @@
 #undef notrace
 #define notrace __attribute__((no_instrument_function))
 
+#ifdef CONFIG_64BIT
+/*
+ * The generic version tends to create spurious ENDBR instructions under
+ * certain conditions.
+ */
+#define _THIS_IP_ ({ unsigned long __here; asm ("lea 0(%%rip), %0" : "=r" (__here)); __here; })
+#endif
+
 #ifdef CONFIG_X86_32
 #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
 #endif /* CONFIG_X86_32 */
diff --git a/include/linux/instruction_pointer.h b/include/linux/instruction_pointer.h
index cda1f70..aa0b3ff 100644
--- a/include/linux/instruction_pointer.h
+++ b/include/linux/instruction_pointer.h
@@ -2,7 +2,12 @@
 #ifndef _LINUX_INSTRUCTION_POINTER_H
 #define _LINUX_INSTRUCTION_POINTER_H
 
+#include <asm/linkage.h>
+
 #define _RET_IP_		(unsigned long)__builtin_return_address(0)
+
+#ifndef _THIS_IP_
 #define _THIS_IP_  ({ __label__ __here; __here: (unsigned long)&&__here; })
+#endif
 
 #endif /* _LINUX_INSTRUCTION_POINTER_H */

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [tip: x86/urgent] x86/ibt: Avoid duplicate ENDBR in __put_user_nocheck*()
  2023-08-02 10:55 ` [PATCH 2/2] x86/ibt: Avoid duplicate ENDBR in __put_user_nocheck*() Peter Zijlstra
  2023-08-02 20:33   ` Peter Zijlstra
  2023-09-12 11:08   ` [tip: x86/urgent] " tip-bot2 for Peter Zijlstra
@ 2023-09-12 15:54   ` tip-bot2 for Peter Zijlstra
  2 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Peter Zijlstra @ 2023-09-12 15:54 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: David Kaplan, Andrew Cooper, Peter Zijlstra (Intel),
	Ingo Molnar, x86, linux-kernel

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     7575e5a35267983dcbeb1e0d3a49d21ae3cf0b82
Gitweb:        https://git.kernel.org/tip/7575e5a35267983dcbeb1e0d3a49d21ae3cf0b82
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Wed, 02 Aug 2023 12:55:47 +02:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 12 Sep 2023 17:51:24 +02:00

x86/ibt: Avoid duplicate ENDBR in __put_user_nocheck*()

Commit cb855971d717 ("x86/putuser: Provide room for padding") changed
__put_user_nocheck_*() into proper functions but failed to note that
SYM_FUNC_START() already provides ENDBR, rendering the explicit ENDBR
superfluous.

Fixes: cb855971d717 ("x86/putuser: Provide room for padding")
Reported-by: David Kaplan <David.Kaplan@amd.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20230802110323.086971726@infradead.org
---
 arch/x86/lib/putuser.S | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
index 1451e0c..235bbda 100644
--- a/arch/x86/lib/putuser.S
+++ b/arch/x86/lib/putuser.S
@@ -56,7 +56,6 @@ SYM_FUNC_END(__put_user_1)
 EXPORT_SYMBOL(__put_user_1)
 
 SYM_FUNC_START(__put_user_nocheck_1)
-	ENDBR
 	ASM_STAC
 2:	movb %al,(%_ASM_CX)
 	xor %ecx,%ecx
@@ -76,7 +75,6 @@ SYM_FUNC_END(__put_user_2)
 EXPORT_SYMBOL(__put_user_2)
 
 SYM_FUNC_START(__put_user_nocheck_2)
-	ENDBR
 	ASM_STAC
 4:	movw %ax,(%_ASM_CX)
 	xor %ecx,%ecx
@@ -96,7 +94,6 @@ SYM_FUNC_END(__put_user_4)
 EXPORT_SYMBOL(__put_user_4)
 
 SYM_FUNC_START(__put_user_nocheck_4)
-	ENDBR
 	ASM_STAC
 6:	movl %eax,(%_ASM_CX)
 	xor %ecx,%ecx
@@ -119,7 +116,6 @@ SYM_FUNC_END(__put_user_8)
 EXPORT_SYMBOL(__put_user_8)
 
 SYM_FUNC_START(__put_user_nocheck_8)
-	ENDBR
 	ASM_STAC
 9:	mov %_ASM_AX,(%_ASM_CX)
 #ifdef CONFIG_X86_32

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [tip: x86/urgent] x86/ibt: Suppress spurious ENDBR
  2023-08-02 10:55 ` [PATCH 1/2] x86/ibt: Suppress spurious ENDBR Peter Zijlstra
  2023-09-12 11:08   ` [tip: x86/urgent] " tip-bot2 for Peter Zijlstra
@ 2023-09-12 15:54   ` tip-bot2 for Peter Zijlstra
  1 sibling, 0 replies; 9+ messages in thread
From: tip-bot2 for Peter Zijlstra @ 2023-09-12 15:54 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: David Kaplan, Andrew Cooper, Peter Zijlstra (Intel),
	Ingo Molnar, x86, linux-kernel

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     25e73b7e3f72a25aa30cbb2eecb49036e0acf066
Gitweb:        https://git.kernel.org/tip/25e73b7e3f72a25aa30cbb2eecb49036e0acf066
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Wed, 02 Aug 2023 12:55:46 +02:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 12 Sep 2023 17:50:53 +02:00

x86/ibt: Suppress spurious ENDBR

It was reported that under certain circumstances GCC emits ENDBR
instructions for _THIS_IP_ usage. Specifically, when it appears at the
start of a basic block -- but not elsewhere.

Since _THIS_IP_ is never used for control flow, these ENDBR
instructions are completely superfluous. Override the _THIS_IP_
definition for x86_64 to avoid this.

Less ENDBR instructions is better.

Fixes: 156ff4a544ae ("x86/ibt: Base IBT bits")
Reported-by: David Kaplan <David.Kaplan@amd.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20230802110323.016197440@infradead.org
---
 arch/x86/include/asm/linkage.h      | 8 ++++++++
 include/linux/instruction_pointer.h | 5 +++++
 2 files changed, 13 insertions(+)

diff --git a/arch/x86/include/asm/linkage.h b/arch/x86/include/asm/linkage.h
index 97a3de7..5ff49fd 100644
--- a/arch/x86/include/asm/linkage.h
+++ b/arch/x86/include/asm/linkage.h
@@ -8,6 +8,14 @@
 #undef notrace
 #define notrace __attribute__((no_instrument_function))
 
+#ifdef CONFIG_64BIT
+/*
+ * The generic version tends to create spurious ENDBR instructions under
+ * certain conditions.
+ */
+#define _THIS_IP_ ({ unsigned long __here; asm ("lea 0(%%rip), %0" : "=r" (__here)); __here; })
+#endif
+
 #ifdef CONFIG_X86_32
 #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
 #endif /* CONFIG_X86_32 */
diff --git a/include/linux/instruction_pointer.h b/include/linux/instruction_pointer.h
index cda1f70..aa0b3ff 100644
--- a/include/linux/instruction_pointer.h
+++ b/include/linux/instruction_pointer.h
@@ -2,7 +2,12 @@
 #ifndef _LINUX_INSTRUCTION_POINTER_H
 #define _LINUX_INSTRUCTION_POINTER_H
 
+#include <asm/linkage.h>
+
 #define _RET_IP_		(unsigned long)__builtin_return_address(0)
+
+#ifndef _THIS_IP_
 #define _THIS_IP_  ({ __label__ __here; __here: (unsigned long)&&__here; })
+#endif
 
 #endif /* _LINUX_INSTRUCTION_POINTER_H */

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-09-12 15:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-02 10:55 [PATCH 0/2] x86/ibt: Fix some spurious ENDBR instances Peter Zijlstra
2023-08-02 10:55 ` [PATCH 1/2] x86/ibt: Suppress spurious ENDBR Peter Zijlstra
2023-09-12 11:08   ` [tip: x86/urgent] " tip-bot2 for Peter Zijlstra
2023-09-12 15:54   ` tip-bot2 for Peter Zijlstra
2023-08-02 10:55 ` [PATCH 2/2] x86/ibt: Avoid duplicate ENDBR in __put_user_nocheck*() Peter Zijlstra
2023-08-02 20:33   ` Peter Zijlstra
2023-09-12 11:08   ` [tip: x86/urgent] " tip-bot2 for Peter Zijlstra
2023-09-12 15:54   ` tip-bot2 for Peter Zijlstra
2023-08-02 11:25 ` [PATCH 0/2] x86/ibt: Fix some spurious ENDBR instances andrew.cooper3

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®