Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit aecaf18

Browse files
Darksonnrostedt
authored andcommitted
jump_label: adjust inline asm to be consistent
To avoid duplication of inline asm between C and Rust, we need to import the inline asm from the relevant `jump_label.h` header into Rust. To make that easier, this patch updates the header files to expose the inline asm via a new ARCH_STATIC_BRANCH_ASM macro. The header files are all updated to define a ARCH_STATIC_BRANCH_ASM that takes the same arguments in a consistent order so that Rust can use the same logic for every architecture. Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Josh Poimboeuf <jpoimboe@kernel.org> Cc: Jason Baron <jbaron@akamai.com> Cc: Ard Biesheuvel <ardb@kernel.org> Cc: Alex Gaynor <alex.gaynor@gmail.com> Cc: Wedson Almeida Filho <wedsonaf@gmail.com> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Gary Guo <gary@garyguo.net> Cc: " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " <bjorn3_gh@protonmail.com> Cc: Benno Lossin <benno.lossin@proton.me> Cc: Andreas Hindborg <a.hindborg@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Sean Christopherson <seanjc@google.com> Cc: Uros Bizjak <ubizjak@gmail.com> Cc: Will Deacon <will@kernel.org> Cc: Marc Zyngier <maz@kernel.org> Cc: Oliver Upton <oliver.upton@linux.dev> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Fuad Tabba <tabba@google.com> Cc: Paul Walmsley <paul.walmsley@sifive.com> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Albert Ou <aou@eecs.berkeley.edu> Cc: Anup Patel <apatel@ventanamicro.com> Cc: Andrew Jones <ajones@ventanamicro.com> Cc: Alexandre Ghiti <alexghiti@rivosinc.com> Cc: Conor Dooley <conor.dooley@microchip.com> Cc: Samuel Holland <samuel.holland@sifive.com> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: WANG Xuerui <kernel@xen0n.name> Cc: Bibo Mao <maobibo@loongson.cn> Cc: Tiezhu Yang <yangtiezhu@loongson.cn> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Tianrui Zhao <zhaotianrui@loongson.cn> Cc: Palmer Dabbelt <palmer@rivosinc.com> Link: https://lore.kernel.org/20241030-tracepoint-v12-4-eec7f0f8ad22@google.com Suggested-by: Peter Zijlstra (Intel) <peterz@infradead.org> Co-developed-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Miguel Ojeda <ojeda@kernel.org> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Acked-by: Palmer Dabbelt <palmer@rivosinc.com> # RISC-V Signed-off-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 91d3902 commit aecaf18

File tree

5 files changed

+73
-62
lines changed

5 files changed

+73
-62
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/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;

0 commit comments

Comments
 (0)