Skip to content

Commit c3be80f

Browse files
committed
Merge: objtool: rebase to 6.15 with supporting commits
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/995 JIRA: https://issues.redhat.com/browse/RHEL-94124 This MR backports recent v6.15 commits for objtool. Several additional commits (x86, vmlinux.lds and jump_label) help set context for this patchset and potential future backports of a klp-build livepatching tool [1] [1] [PATCH v2 00/62] objtool,livepatch: klp-build livepatch module generation https://lore.kernel.org/live-patching/cover.1746821544.git.jpoimboe@kernel.org/T/#t Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com> Approved-by: Lenny Szubowicz <lszubowi@redhat.com> Approved-by: Josh Poimboeuf <jpoimboe@redhat.com> Merged-by: Julio Faracco <jfaracco@redhat.com>
2 parents 01b5d14 + 27780af commit c3be80f

File tree

18 files changed

+218
-178
lines changed

18 files changed

+218
-178
lines changed

arch/arm/include/asm/jump_label.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99

1010
#define JUMP_LABEL_NOP_SIZE 4
1111

12+
/* This macro is also expanded on the Rust side. */
13+
#define ARCH_STATIC_BRANCH_ASM(key, label) \
14+
"1:\n\t" \
15+
WASM(nop) "\n\t" \
16+
".pushsection __jump_table, \"aw\"\n\t" \
17+
".word 1b, " label ", " key "\n\t" \
18+
".popsection\n\t" \
19+
1220
static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
1321
{
14-
asm goto("1:\n\t"
15-
WASM(nop) "\n\t"
16-
".pushsection __jump_table, \"aw\"\n\t"
17-
".word 1b, %l[l_yes], %c0\n\t"
18-
".popsection\n\t"
22+
asm goto(ARCH_STATIC_BRANCH_ASM("%c0", "%l[l_yes]")
1923
: : "i" (&((char *)key)[branch]) : : l_yes);
2024

2125
return false;

arch/arm64/include/asm/jump_label.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,23 @@
1919
#define JUMP_TABLE_ENTRY(key, label) \
2020
".pushsection __jump_table, \"aw\"\n\t" \
2121
".align 3\n\t" \
22-
".long 1b - ., %l["#label"] - .\n\t" \
23-
".quad %c0 - .\n\t" \
24-
".popsection\n\t" \
25-
: : "i"(key) : : label
22+
".long 1b - ., " label " - .\n\t" \
23+
".quad " key " - .\n\t" \
24+
".popsection\n\t"
25+
26+
/* This macro is also expanded on the Rust side. */
27+
#define ARCH_STATIC_BRANCH_ASM(key, label) \
28+
"1: nop\n\t" \
29+
JUMP_TABLE_ENTRY(key, label)
2630

2731
static __always_inline bool arch_static_branch(struct static_key * const key,
2832
const bool branch)
2933
{
3034
char *k = &((char *)key)[branch];
3135

3236
asm goto(
33-
"1: nop \n\t"
34-
JUMP_TABLE_ENTRY(k, l_yes)
37+
ARCH_STATIC_BRANCH_ASM("%c0", "%l[l_yes]")
38+
: : "i"(k) : : l_yes
3539
);
3640

3741
return false;
@@ -43,9 +47,11 @@ static __always_inline bool arch_static_branch_jump(struct static_key * const ke
4347
const bool branch)
4448
{
4549
char *k = &((char *)key)[branch];
50+
4651
asm goto(
4752
"1: b %l[l_yes] \n\t"
48-
JUMP_TABLE_ENTRY(k, l_yes)
53+
JUMP_TABLE_ENTRY("%c0", "%l[l_yes]")
54+
: : "i"(k) : : l_yes
4955
);
5056
return false;
5157
l_yes:

arch/loongarch/include/asm/jump_label.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@
1313

1414
#define JUMP_LABEL_NOP_SIZE 4
1515

16-
#define JUMP_TABLE_ENTRY \
16+
/* This macro is also expanded on the Rust side. */
17+
#define JUMP_TABLE_ENTRY(key, label) \
1718
".pushsection __jump_table, \"aw\" \n\t" \
1819
".align 3 \n\t" \
19-
".long 1b - ., %l[l_yes] - . \n\t" \
20-
".quad %0 - . \n\t" \
20+
".long 1b - ., " label " - . \n\t" \
21+
".quad " key " - . \n\t" \
2122
".popsection \n\t"
2223

24+
#define ARCH_STATIC_BRANCH_ASM(key, label) \
25+
"1: nop \n\t" \
26+
JUMP_TABLE_ENTRY(key, label)
27+
2328
static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
2429
{
2530
asm goto(
26-
"1: nop \n\t"
27-
JUMP_TABLE_ENTRY
31+
ARCH_STATIC_BRANCH_ASM("%0", "%l[l_yes]")
2832
: : "i"(&((char *)key)[branch]) : : l_yes);
2933

3034
return false;
@@ -37,7 +41,7 @@ static __always_inline bool arch_static_branch_jump(struct static_key * const ke
3741
{
3842
asm goto(
3943
"1: b %l[l_yes] \n\t"
40-
JUMP_TABLE_ENTRY
44+
JUMP_TABLE_ENTRY("%0", "%l[l_yes]")
4145
: : "i"(&((char *)key)[branch]) : : l_yes);
4246

4347
return false;

arch/riscv/include/asm/jump_label.h

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,49 @@
1616

1717
#define JUMP_LABEL_NOP_SIZE 4
1818

19+
#define JUMP_TABLE_ENTRY(key, label) \
20+
".pushsection __jump_table, \"aw\" \n\t" \
21+
".align " RISCV_LGPTR " \n\t" \
22+
".long 1b - ., " label " - . \n\t" \
23+
"" RISCV_PTR " " key " - . \n\t" \
24+
".popsection \n\t"
25+
26+
/* This macro is also expanded on the Rust side. */
27+
#define ARCH_STATIC_BRANCH_ASM(key, label) \
28+
" .align 2 \n\t" \
29+
" .option push \n\t" \
30+
" .option norelax \n\t" \
31+
" .option norvc \n\t" \
32+
"1: nop \n\t" \
33+
" .option pop \n\t" \
34+
JUMP_TABLE_ENTRY(key, label)
35+
1936
static __always_inline bool arch_static_branch(struct static_key * const key,
2037
const bool branch)
2138
{
2239
asm goto(
23-
" .align 2 \n\t"
24-
" .option push \n\t"
25-
" .option norelax \n\t"
26-
" .option norvc \n\t"
27-
"1: nop \n\t"
28-
" .option pop \n\t"
29-
" .pushsection __jump_table, \"aw\" \n\t"
30-
" .align " RISCV_LGPTR " \n\t"
31-
" .long 1b - ., %l[label] - . \n\t"
32-
" " RISCV_PTR " %0 - . \n\t"
33-
" .popsection \n\t"
40+
ARCH_STATIC_BRANCH_ASM("%0", "%l[label]")
3441
: : "i"(&((char *)key)[branch]) : : label);
3542

3643
return false;
3744
label:
3845
return true;
3946
}
4047

48+
#define ARCH_STATIC_BRANCH_JUMP_ASM(key, label) \
49+
" .align 2 \n\t" \
50+
" .option push \n\t" \
51+
" .option norelax \n\t" \
52+
" .option norvc \n\t" \
53+
"1: j " label " \n\t" \
54+
" .option pop \n\t" \
55+
JUMP_TABLE_ENTRY(key, label)
56+
4157
static __always_inline bool arch_static_branch_jump(struct static_key * const key,
4258
const bool branch)
4359
{
4460
asm goto(
45-
" .align 2 \n\t"
46-
" .option push \n\t"
47-
" .option norelax \n\t"
48-
" .option norvc \n\t"
49-
"1: j %l[label] \n\t"
50-
" .option pop \n\t"
51-
" .pushsection __jump_table, \"aw\" \n\t"
52-
" .align " RISCV_LGPTR " \n\t"
53-
" .long 1b - ., %l[label] - . \n\t"
54-
" " RISCV_PTR " %0 - . \n\t"
55-
" .popsection \n\t"
61+
ARCH_STATIC_BRANCH_JUMP_ASM("%0", "%l[label]")
5662
: : "i"(&((char *)key)[branch]) : : label);
5763

5864
return false;

arch/x86/include/asm/arch_hweight.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ static __always_inline unsigned int __arch_hweight32(unsigned int w)
1616
{
1717
unsigned int res;
1818

19-
asm (ALTERNATIVE("call __sw_hweight32", "popcntl %1, %0", X86_FEATURE_POPCNT)
20-
: "="REG_OUT (res)
21-
: REG_IN (w));
19+
asm_inline (ALTERNATIVE("call __sw_hweight32",
20+
"popcntl %[val], %[cnt]", X86_FEATURE_POPCNT)
21+
: [cnt] "=" REG_OUT (res), ASM_CALL_CONSTRAINT
22+
: [val] REG_IN (w));
2223

2324
return res;
2425
}
@@ -44,9 +45,10 @@ static __always_inline unsigned long __arch_hweight64(__u64 w)
4445
{
4546
unsigned long res;
4647

47-
asm (ALTERNATIVE("call __sw_hweight64", "popcntq %1, %0", X86_FEATURE_POPCNT)
48-
: "="REG_OUT (res)
49-
: REG_IN (w));
48+
asm_inline (ALTERNATIVE("call __sw_hweight64",
49+
"popcntq %[val], %[cnt]", X86_FEATURE_POPCNT)
50+
: [cnt] "=" REG_OUT (res), ASM_CALL_CONSTRAINT
51+
: [val] REG_IN (w));
5052

5153
return res;
5254
}

arch/x86/include/asm/jump_label.h

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,40 @@
1212
#include <linux/stringify.h>
1313
#include <linux/types.h>
1414

15-
#define JUMP_TABLE_ENTRY \
15+
#define JUMP_TABLE_ENTRY(key, label) \
1616
".pushsection __jump_table, \"aw\" \n\t" \
1717
_ASM_ALIGN "\n\t" \
1818
".long 1b - . \n\t" \
19-
".long %l[l_yes] - . \n\t" \
20-
_ASM_PTR "%c0 + %c1 - .\n\t" \
19+
".long " label " - . \n\t" \
20+
_ASM_PTR " " key " - . \n\t" \
2121
".popsection \n\t"
2222

23+
/* This macro is also expanded on the Rust side. */
2324
#ifdef CONFIG_HAVE_JUMP_LABEL_HACK
24-
25-
static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
26-
{
27-
asm goto("1:"
28-
"jmp %l[l_yes] # objtool NOPs this \n\t"
29-
JUMP_TABLE_ENTRY
30-
: : "i" (key), "i" (2 | branch) : : l_yes);
31-
32-
return false;
33-
l_yes:
34-
return true;
35-
}
36-
25+
#define ARCH_STATIC_BRANCH_ASM(key, label) \
26+
"1: jmp " label " # objtool NOPs this \n\t" \
27+
JUMP_TABLE_ENTRY(key " + 2", label)
3728
#else /* !CONFIG_HAVE_JUMP_LABEL_HACK */
29+
#define ARCH_STATIC_BRANCH_ASM(key, label) \
30+
"1: .byte " __stringify(BYTES_NOP5) "\n\t" \
31+
JUMP_TABLE_ENTRY(key, label)
32+
#endif /* CONFIG_HAVE_JUMP_LABEL_HACK */
3833

3934
static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
4035
{
41-
asm goto("1:"
42-
".byte " __stringify(BYTES_NOP5) "\n\t"
43-
JUMP_TABLE_ENTRY
36+
asm goto(ARCH_STATIC_BRANCH_ASM("%c0 + %c1", "%l[l_yes]")
4437
: : "i" (key), "i" (branch) : : l_yes);
4538

4639
return false;
4740
l_yes:
4841
return true;
4942
}
5043

51-
#endif /* CONFIG_HAVE_JUMP_LABEL_HACK */
52-
5344
static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch)
5445
{
5546
asm goto("1:"
5647
"jmp %l[l_yes]\n\t"
57-
JUMP_TABLE_ENTRY
48+
JUMP_TABLE_ENTRY("%c0 + %c1", "%l[l_yes]")
5849
: : "i" (key), "i" (branch) : : l_yes);
5950

6051
return false;

arch/x86/include/asm/smap.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,35 @@
1313
#include <asm/cpufeatures.h>
1414
#include <asm/alternative.h>
1515

16-
/* "Raw" instruction opcodes */
17-
#define __ASM_CLAC ".byte 0x0f,0x01,0xca"
18-
#define __ASM_STAC ".byte 0x0f,0x01,0xcb"
19-
2016
#ifdef __ASSEMBLY__
2117

2218
#define ASM_CLAC \
23-
ALTERNATIVE "", __ASM_CLAC, X86_FEATURE_SMAP
19+
ALTERNATIVE "", "clac", X86_FEATURE_SMAP
2420

2521
#define ASM_STAC \
26-
ALTERNATIVE "", __ASM_STAC, X86_FEATURE_SMAP
22+
ALTERNATIVE "", "stac", X86_FEATURE_SMAP
2723

2824
#else /* __ASSEMBLY__ */
2925

3026
static __always_inline void clac(void)
3127
{
3228
/* Note: a barrier is implicit in alternative() */
33-
alternative("", __ASM_CLAC, X86_FEATURE_SMAP);
29+
alternative("", "clac", X86_FEATURE_SMAP);
3430
}
3531

3632
static __always_inline void stac(void)
3733
{
3834
/* Note: a barrier is implicit in alternative() */
39-
alternative("", __ASM_STAC, X86_FEATURE_SMAP);
35+
alternative("", "stac", X86_FEATURE_SMAP);
4036
}
4137

4238
static __always_inline unsigned long smap_save(void)
4339
{
4440
unsigned long flags;
4541

4642
asm volatile ("# smap_save\n\t"
47-
ALTERNATIVE("", "pushf; pop %0; " __ASM_CLAC "\n\t",
43+
ALTERNATIVE(ANNOTATE_IGNORE_ALTERNATIVE
44+
"", "pushf; pop %0; clac",
4845
X86_FEATURE_SMAP)
4946
: "=rm" (flags) : : "memory", "cc");
5047

@@ -54,16 +51,22 @@ static __always_inline unsigned long smap_save(void)
5451
static __always_inline void smap_restore(unsigned long flags)
5552
{
5653
asm volatile ("# smap_restore\n\t"
57-
ALTERNATIVE("", "push %0; popf\n\t",
54+
ALTERNATIVE(ANNOTATE_IGNORE_ALTERNATIVE
55+
"", "push %0; popf",
5856
X86_FEATURE_SMAP)
5957
: : "g" (flags) : "memory", "cc");
6058
}
6159

6260
/* These macros can be used in asm() statements */
6361
#define ASM_CLAC \
64-
ALTERNATIVE("", __ASM_CLAC, X86_FEATURE_SMAP)
62+
ALTERNATIVE("", "clac", X86_FEATURE_SMAP)
6563
#define ASM_STAC \
66-
ALTERNATIVE("", __ASM_STAC, X86_FEATURE_SMAP)
64+
ALTERNATIVE("", "stac", X86_FEATURE_SMAP)
65+
66+
#define ASM_CLAC_UNSAFE \
67+
ALTERNATIVE("", ANNOTATE_IGNORE_ALTERNATIVE "clac", X86_FEATURE_SMAP)
68+
#define ASM_STAC_UNSAFE \
69+
ALTERNATIVE("", ANNOTATE_IGNORE_ALTERNATIVE "stac", X86_FEATURE_SMAP)
6770

6871
#endif /* __ASSEMBLY__ */
6972

arch/x86/include/asm/xen/hypercall.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,12 @@ static __always_inline void __xen_stac(void)
231231
* Suppress objtool seeing the STAC/CLAC and getting confused about it
232232
* calling random code with AC=1.
233233
*/
234-
asm volatile(ANNOTATE_IGNORE_ALTERNATIVE
235-
ASM_STAC ::: "memory", "flags");
234+
asm volatile(ASM_STAC_UNSAFE ::: "memory", "flags");
236235
}
237236

238237
static __always_inline void __xen_clac(void)
239238
{
240-
asm volatile(ANNOTATE_IGNORE_ALTERNATIVE
241-
ASM_CLAC ::: "memory", "flags");
239+
asm volatile(ASM_CLAC_UNSAFE ::: "memory", "flags");
242240
}
243241

244242
static inline long

arch/x86/xen/xen-asm.S

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,7 @@ SYM_CODE_END(xen_early_idt_handler_array)
221221
push %rax
222222
mov $__HYPERVISOR_iret, %eax
223223
syscall /* Do the IRET. */
224-
#ifdef CONFIG_MITIGATION_SLS
225-
int3
226-
#endif
224+
ud2 /* The SYSCALL should never return. */
227225
.endm
228226

229227
SYM_CODE_START(xen_iret)

0 commit comments

Comments
 (0)