linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "tip-bot2 for Peter Zijlstra" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Josh Poimboeuf <jpoimboe@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	linux@weissschuh.net, x86@kernel.org,
	linux-kernel@vger.kernel.org
Subject: [tip: objtool/core] x86: Fix FILL_RETURN_BUFFER
Date: Mon, 13 Feb 2023 11:10:28 -0000	[thread overview]
Message-ID: <167628662816.4906.5931554689698286479.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20230208172245.783099843@infradead.org>

The following commit has been merged into the objtool/core branch of tip:

Commit-ID:     2db38eca62cb9e893e7c0bfe0f6c5d327d990680
Gitweb:        https://git.kernel.org/tip/2db38eca62cb9e893e7c0bfe0f6c5d327d990680
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Wed, 08 Feb 2023 18:18:04 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Mon, 13 Feb 2023 11:26:09 +01:00

x86: Fix FILL_RETURN_BUFFER

With overlapping alternative validation fixed, objtool promptly
complains:

vmlinux.o: warning: objtool: __switch_to_asm+0x2c: stack layout conflict in alternatives: .altinstr_replacement+0x47

.rela.altinstructions:

000000000000009c  0000000200000002 R_X86_64_PC32          0000000000000000 .text + 16dc
00000000000000a0  0000000600000002 R_X86_64_PC32          0000000000000000 .altinstr_replacement + 3a
00000000000000a8  0000000200000002 R_X86_64_PC32          0000000000000000 .text + 16dc
00000000000000ac  0000000600000002 R_X86_64_PC32          0000000000000000 .altinstr_replacement + 66

.text:

00000000000016b0 <__switch_to_asm>:
    16b0:       f3 0f 1e fa             endbr64
    16b4:       55                      push   %rbp
    16b5:       53                      push   %rbx
    16b6:       41 54                   push   %r12
    16b8:       41 55                   push   %r13
    16ba:       41 56                   push   %r14
    16bc:       41 57                   push   %r15
    16be:       48 89 a7 18 0b 00 00    mov    %rsp,0xb18(%rdi)
    16c5:       48 8b a6 18 0b 00 00    mov    0xb18(%rsi),%rsp
    16cc:       48 8b 9e 28 05 00 00    mov    0x528(%rsi),%rbx
    16d3:       65 48 89 1c 25 00 00 00 00      mov    %rbx,%gs:0x0     16d8: R_X86_64_32S      fixed_percpu_data+0x28
    16dc:       eb 2a                   jmp    1708 <__switch_to_asm+0x58>
    16de:       90                      nop
    16df:       90                      nop
    16e0:       90                      nop
    16e1:       90                      nop
    16e2:       90                      nop
    16e3:       90                      nop
    16e4:       90                      nop
    16e5:       90                      nop
    16e6:       90                      nop
    16e7:       90                      nop
    16e8:       90                      nop
    16e9:       90                      nop
    16ea:       90                      nop
    16eb:       90                      nop
    16ec:       90                      nop
    16ed:       90                      nop
    16ee:       90                      nop
    16ef:       90                      nop
    16f0:       90                      nop
    16f1:       90                      nop
    16f2:       90                      nop
    16f3:       90                      nop
    16f4:       90                      nop
    16f5:       90                      nop
    16f6:       90                      nop
    16f7:       90                      nop
    16f8:       90                      nop
    16f9:       90                      nop
    16fa:       90                      nop
    16fb:       90                      nop
    16fc:       90                      nop
    16fd:       90                      nop
    16fe:       90                      nop
    16ff:       90                      nop
    1700:       90                      nop
    1701:       90                      nop
    1702:       90                      nop
    1703:       90                      nop
    1704:       90                      nop
    1705:       90                      nop
    1706:       90                      nop
    1707:       90                      nop
    1708:       41 5f                   pop    %r15
    170a:       41 5e                   pop    %r14
    170c:       41 5d                   pop    %r13
    170e:       41 5c                   pop    %r12
    1710:       5b                      pop    %rbx
    1711:       5d                      pop    %rbp
    1712:       e9 00 00 00 00          jmp    1717 <__switch_to_asm+0x67>      1713: R_X86_64_PLT32    __switch_to-0x4

.altinstr_replacement:

      3a:       49 c7 c4 10 00 00 00    mov    $0x10,%r12
      41:       e8 01 00 00 00          call   47 <.altinstr_replacement+0x47>
      46:       cc                      int3
      47:       e8 01 00 00 00          call   4d <.altinstr_replacement+0x4d>
      4c:       cc                      int3
      4d:       48 83 c4 10             add    $0x10,%rsp
      51:       49 ff cc                dec    %r12
      54:       75 eb                   jne    41 <.altinstr_replacement+0x41>
      56:       0f ae e8                lfence
      59:       65 48 c7 04 25 00 00 00 00 ff ff ff ff  movq   $0xffffffffffffffff,%gs:0x0      5e: R_X86_64_32S        pcpu_hot+0x10

      66:       e8 01 00 00 00          call   6c <.altinstr_replacement+0x6c>
      6b:       cc                      int3
      6c:       48 83 c4 08             add    $0x8,%rsp
      70:       0f ae e8                lfence

As can be seen from the two alternatives, when overlaid, the NOP after
the shorter (starting at 66) coinsides with the call at 47, leading to
conflicting CFI state for that instruction.

By offsetting the shorter alternative by 2 bytes, this alignment is
undone.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org> # build only
Tested-by: Thomas Weißschuh <linux@weissschuh.net> # compile and run
Link: https://lore.kernel.org/r/20230208172245.783099843@infradead.org
---
 arch/x86/include/asm/nospec-branch.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
index e04313e..3ef70e5 100644
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -261,7 +261,7 @@
 .macro FILL_RETURN_BUFFER reg:req nr:req ftr:req ftr2=ALT_NOT(X86_FEATURE_ALWAYS)
 	ALTERNATIVE_2 "jmp .Lskip_rsb_\@", \
 		__stringify(__FILL_RETURN_BUFFER(\reg,\nr)), \ftr, \
-		__stringify(__FILL_ONE_RETURN), \ftr2
+		__stringify(nop;nop;__FILL_ONE_RETURN), \ftr2
 
 .Lskip_rsb_\@:
 .endm

  reply	other threads:[~2023-02-13 11:10 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-08 17:17 [PATCH 00/10] objtool: Honey, I shrunk the instruction Peter Zijlstra
2023-02-08 17:17 ` [PATCH 01/10] objtool: Change arch_decode_instruction() signature Peter Zijlstra
2023-02-13 11:10   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2023-02-23  8:32   ` tip-bot2 for Peter Zijlstra
2023-02-08 17:17 ` [PATCH 02/10] objtool: Make instruction::stack_ops a single-linked list Peter Zijlstra
2023-02-13 11:10   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2023-02-23  8:32   ` tip-bot2 for Peter Zijlstra
2023-02-08 17:17 ` [PATCH 03/10] objtool: Make instruction::alts " Peter Zijlstra
2023-02-13 11:10   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2023-02-23  8:32   ` tip-bot2 for Peter Zijlstra
2023-02-08 17:18 ` [PATCH 04/10] objtool: Shrink instruction::{type,visited} Peter Zijlstra
2023-02-13 11:10   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2023-02-23  8:32   ` tip-bot2 for Peter Zijlstra
2023-02-08 17:18 ` [PATCH 05/10] objtool: Remove instruction::reloc Peter Zijlstra
2023-02-13 11:10   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2023-02-23  8:32   ` tip-bot2 for Peter Zijlstra
2023-02-08 17:18 ` [PATCH 06/10] objtool: Union instruction::{call_dest,jump_table} Peter Zijlstra
2023-02-13 11:10   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2023-02-23  8:32   ` tip-bot2 for Peter Zijlstra
2023-02-08 17:18 ` [PATCH 07/10] objtool: Fix overlapping alternatives Peter Zijlstra
2023-02-13 11:10   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2023-02-23  8:32   ` tip-bot2 for Peter Zijlstra
2023-02-08 17:18 ` [PATCH 08/10] x86: Fix FILL_RETURN_BUFFER Peter Zijlstra
2023-02-13 11:10   ` tip-bot2 for Peter Zijlstra [this message]
2023-02-23  8:32   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2023-02-08 17:18 ` [PATCH 09/10] objtool: Remove instruction::list Peter Zijlstra
2023-02-13 11:10   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2023-02-23  8:32   ` tip-bot2 for Peter Zijlstra
2023-02-08 17:18 ` [PATCH 10/10][HACK] objtool: Shrink reloc Peter Zijlstra
2023-02-08 18:35 ` [PATCH 00/10] objtool: Honey, I shrunk the instruction Nathan Chancellor
2023-02-08 20:22 ` Damian Tometzki
2023-02-09 10:22   ` Peter Zijlstra
2023-02-09 10:56     ` Damian Tometzki
2023-02-09 19:57 ` Josh Poimboeuf
2023-02-10  8:59   ` Peter Zijlstra
2023-02-10 13:47     ` [PATCH 00/10] objtool: Honey, I shrunk the instruction^Wreloc Peter Zijlstra
2023-02-10  1:50 ` [PATCH 00/10] objtool: Honey, I shrunk the instruction Thomas Weißschuh

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=167628662816.4906.5931554689698286479.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=nathan@kernel.org \
    --cc=peterz@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).