From: Steven Rostedt <rostedt@goodmis.org>
To: Alice Ryhl <aliceryhl@google.com>, Russell King <linux@armlinux.org.uk>
Cc: "Masami Hiramatsu" <mhiramat@kernel.org>,
"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Josh Poimboeuf" <jpoimboe@kernel.org>,
"Jason Baron" <jbaron@akamai.com>,
"Ard Biesheuvel" <ardb@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
linux-trace-kernel@vger.kernel.org,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
"Arnd Bergmann" <arnd@arndb.de>,
linux-arch@vger.kernel.org,
"Thomas Gleixner" <tglx@linutronix.de>,
"Ingo Molnar" <mingo@redhat.com>,
"Borislav Petkov" <bp@alien8.de>,
"Dave Hansen" <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
"Sean Christopherson" <seanjc@google.com>,
"Uros Bizjak" <ubizjak@gmail.com>,
"Catalin Marinas" <catalin.marinas@arm.com>,
"Will Deacon" <will@kernel.org>, "Marc Zyngier" <maz@kernel.org>,
"Oliver Upton" <oliver.upton@linux.dev>,
"Mark Rutland" <mark.rutland@arm.com>,
"Ryan Roberts" <ryan.roberts@arm.com>,
"Fuad Tabba" <tabba@google.com>,
linux-arm-kernel@lists.infradead.org,
"Paul Walmsley" <paul.walmsley@sifive.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
"Anup Patel" <apatel@ventanamicro.com>,
"Andrew Jones" <ajones@ventanamicro.com>,
"Alexandre Ghiti" <alexghiti@rivosinc.com>,
"Conor Dooley" <conor.dooley@microchip.com>,
"Samuel Holland" <samuel.holland@sifive.com>,
linux-riscv@lists.infradead.org,
"Huacai Chen" <chenhuacai@kernel.org>,
"WANG Xuerui" <kernel@xen0n.name>,
"Bibo Mao" <maobibo@loongson.cn>,
"Tiezhu Yang" <yangtiezhu@loongson.cn>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Tianrui Zhao" <zhaotianrui@loongson.cn>,
loongarch@lists.linux.dev, "Palmer Dabbelt" <palmer@rivosinc.com>
Subject: Re: [PATCH v12 4/5] jump_label: adjust inline asm to be consistent
Date: Wed, 30 Oct 2024 19:13:16 -0400 [thread overview]
Message-ID: <20241030191316.2a27ff1b@rorschach.local.home> (raw)
In-Reply-To: <20241030-tracepoint-v12-4-eec7f0f8ad22@google.com>
On Wed, 30 Oct 2024 16:04:27 +0000
Alice Ryhl <aliceryhl@google.com> wrote:
> 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.
>
> 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
Still missing an ack from the ARM maintainer (32 bit, just added) and loongarch.
I'll wait till Monday, if I don't hear anything against these patches
I'll pull them in.
-- Steve
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
> arch/arm/include/asm/jump_label.h | 14 +++++----
> arch/arm64/include/asm/jump_label.h | 20 ++++++++-----
> arch/loongarch/include/asm/jump_label.h | 16 +++++++----
> arch/riscv/include/asm/jump_label.h | 50 ++++++++++++++++++---------------
> arch/x86/include/asm/jump_label.h | 35 +++++++++--------------
> 5 files changed, 73 insertions(+), 62 deletions(-)
>
> diff --git a/arch/arm/include/asm/jump_label.h b/arch/arm/include/asm/jump_label.h
> index e4eb54f6cd9f..a35aba7f548c 100644
> --- a/arch/arm/include/asm/jump_label.h
> +++ b/arch/arm/include/asm/jump_label.h
> @@ -9,13 +9,17 @@
>
> #define JUMP_LABEL_NOP_SIZE 4
>
> +/* This macro is also expanded on the Rust side. */
> +#define ARCH_STATIC_BRANCH_ASM(key, label) \
> + "1:\n\t" \
> + WASM(nop) "\n\t" \
> + ".pushsection __jump_table, \"aw\"\n\t" \
> + ".word 1b, " label ", " key "\n\t" \
> + ".popsection\n\t" \
> +
> static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
> {
> - asm goto("1:\n\t"
> - WASM(nop) "\n\t"
> - ".pushsection __jump_table, \"aw\"\n\t"
> - ".word 1b, %l[l_yes], %c0\n\t"
> - ".popsection\n\t"
> + asm goto(ARCH_STATIC_BRANCH_ASM("%c0", "%l[l_yes]")
> : : "i" (&((char *)key)[branch]) : : l_yes);
>
> return false;
> diff --git a/arch/arm64/include/asm/jump_label.h b/arch/arm64/include/asm/jump_label.h
> index a0a5bbae7229..424ed421cd97 100644
> --- a/arch/arm64/include/asm/jump_label.h
> +++ b/arch/arm64/include/asm/jump_label.h
> @@ -19,10 +19,14 @@
> #define JUMP_TABLE_ENTRY(key, label) \
> ".pushsection __jump_table, \"aw\"\n\t" \
> ".align 3\n\t" \
> - ".long 1b - ., %l["#label"] - .\n\t" \
> - ".quad %c0 - .\n\t" \
> - ".popsection\n\t" \
> - : : "i"(key) : : label
> + ".long 1b - ., " label " - .\n\t" \
> + ".quad " key " - .\n\t" \
> + ".popsection\n\t"
> +
> +/* This macro is also expanded on the Rust side. */
> +#define ARCH_STATIC_BRANCH_ASM(key, label) \
> + "1: nop\n\t" \
> + JUMP_TABLE_ENTRY(key, label)
>
> static __always_inline bool arch_static_branch(struct static_key * const key,
> const bool branch)
> @@ -30,8 +34,8 @@ static __always_inline bool arch_static_branch(struct static_key * const key,
> char *k = &((char *)key)[branch];
>
> asm goto(
> - "1: nop \n\t"
> - JUMP_TABLE_ENTRY(k, l_yes)
> + ARCH_STATIC_BRANCH_ASM("%c0", "%l[l_yes]")
> + : : "i"(k) : : l_yes
> );
>
> return false;
> @@ -43,9 +47,11 @@ static __always_inline bool arch_static_branch_jump(struct static_key * const ke
> const bool branch)
> {
> char *k = &((char *)key)[branch];
> +
> asm goto(
> "1: b %l[l_yes] \n\t"
> - JUMP_TABLE_ENTRY(k, l_yes)
> + JUMP_TABLE_ENTRY("%c0", "%l[l_yes]")
> + : : "i"(k) : : l_yes
> );
> return false;
> l_yes:
> diff --git a/arch/loongarch/include/asm/jump_label.h b/arch/loongarch/include/asm/jump_label.h
> index 29acfe3de3fa..8a924bd69d19 100644
> --- a/arch/loongarch/include/asm/jump_label.h
> +++ b/arch/loongarch/include/asm/jump_label.h
> @@ -13,18 +13,22 @@
>
> #define JUMP_LABEL_NOP_SIZE 4
>
> -#define JUMP_TABLE_ENTRY \
> +/* This macro is also expanded on the Rust side. */
> +#define JUMP_TABLE_ENTRY(key, label) \
> ".pushsection __jump_table, \"aw\" \n\t" \
> ".align 3 \n\t" \
> - ".long 1b - ., %l[l_yes] - . \n\t" \
> - ".quad %0 - . \n\t" \
> + ".long 1b - ., " label " - . \n\t" \
> + ".quad " key " - . \n\t" \
> ".popsection \n\t"
>
> +#define ARCH_STATIC_BRANCH_ASM(key, label) \
> + "1: nop \n\t" \
> + JUMP_TABLE_ENTRY(key, label)
> +
> static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
> {
> asm goto(
> - "1: nop \n\t"
> - JUMP_TABLE_ENTRY
> + ARCH_STATIC_BRANCH_ASM("%0", "%l[l_yes]")
> : : "i"(&((char *)key)[branch]) : : l_yes);
>
> return false;
> @@ -37,7 +41,7 @@ static __always_inline bool arch_static_branch_jump(struct static_key * const ke
> {
> asm goto(
> "1: b %l[l_yes] \n\t"
> - JUMP_TABLE_ENTRY
> + JUMP_TABLE_ENTRY("%0", "%l[l_yes]")
> : : "i"(&((char *)key)[branch]) : : l_yes);
>
> return false;
> diff --git a/arch/riscv/include/asm/jump_label.h b/arch/riscv/include/asm/jump_label.h
> index 1c768d02bd0c..87a71cc6d146 100644
> --- a/arch/riscv/include/asm/jump_label.h
> +++ b/arch/riscv/include/asm/jump_label.h
> @@ -16,21 +16,28 @@
>
> #define JUMP_LABEL_NOP_SIZE 4
>
> +#define JUMP_TABLE_ENTRY(key, label) \
> + ".pushsection __jump_table, \"aw\" \n\t" \
> + ".align " RISCV_LGPTR " \n\t" \
> + ".long 1b - ., " label " - . \n\t" \
> + "" RISCV_PTR " " key " - . \n\t" \
> + ".popsection \n\t"
> +
> +/* This macro is also expanded on the Rust side. */
> +#define ARCH_STATIC_BRANCH_ASM(key, label) \
> + " .align 2 \n\t" \
> + " .option push \n\t" \
> + " .option norelax \n\t" \
> + " .option norvc \n\t" \
> + "1: nop \n\t" \
> + " .option pop \n\t" \
> + JUMP_TABLE_ENTRY(key, label)
> +
> static __always_inline bool arch_static_branch(struct static_key * const key,
> const bool branch)
> {
> asm goto(
> - " .align 2 \n\t"
> - " .option push \n\t"
> - " .option norelax \n\t"
> - " .option norvc \n\t"
> - "1: nop \n\t"
> - " .option pop \n\t"
> - " .pushsection __jump_table, \"aw\" \n\t"
> - " .align " RISCV_LGPTR " \n\t"
> - " .long 1b - ., %l[label] - . \n\t"
> - " " RISCV_PTR " %0 - . \n\t"
> - " .popsection \n\t"
> + ARCH_STATIC_BRANCH_ASM("%0", "%l[label]")
> : : "i"(&((char *)key)[branch]) : : label);
>
> return false;
> @@ -38,21 +45,20 @@ static __always_inline bool arch_static_branch(struct static_key * const key,
> return true;
> }
>
> +#define ARCH_STATIC_BRANCH_JUMP_ASM(key, label) \
> + " .align 2 \n\t" \
> + " .option push \n\t" \
> + " .option norelax \n\t" \
> + " .option norvc \n\t" \
> + "1: j " label " \n\t" \
> + " .option pop \n\t" \
> + JUMP_TABLE_ENTRY(key, label)
> +
> static __always_inline bool arch_static_branch_jump(struct static_key * const key,
> const bool branch)
> {
> asm goto(
> - " .align 2 \n\t"
> - " .option push \n\t"
> - " .option norelax \n\t"
> - " .option norvc \n\t"
> - "1: j %l[label] \n\t"
> - " .option pop \n\t"
> - " .pushsection __jump_table, \"aw\" \n\t"
> - " .align " RISCV_LGPTR " \n\t"
> - " .long 1b - ., %l[label] - . \n\t"
> - " " RISCV_PTR " %0 - . \n\t"
> - " .popsection \n\t"
> + ARCH_STATIC_BRANCH_JUMP_ASM("%0", "%l[label]")
> : : "i"(&((char *)key)[branch]) : : label);
>
> return false;
> diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_label.h
> index cbbef32517f0..3f1c1d6c0da1 100644
> --- a/arch/x86/include/asm/jump_label.h
> +++ b/arch/x86/include/asm/jump_label.h
> @@ -12,35 +12,28 @@
> #include <linux/stringify.h>
> #include <linux/types.h>
>
> -#define JUMP_TABLE_ENTRY \
> +#define JUMP_TABLE_ENTRY(key, label) \
> ".pushsection __jump_table, \"aw\" \n\t" \
> _ASM_ALIGN "\n\t" \
> ".long 1b - . \n\t" \
> - ".long %l[l_yes] - . \n\t" \
> - _ASM_PTR "%c0 + %c1 - .\n\t" \
> + ".long " label " - . \n\t" \
> + _ASM_PTR " " key " - . \n\t" \
> ".popsection \n\t"
>
> +/* This macro is also expanded on the Rust side. */
> #ifdef CONFIG_HAVE_JUMP_LABEL_HACK
> -
> -static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
> -{
> - asm goto("1:"
> - "jmp %l[l_yes] # objtool NOPs this \n\t"
> - JUMP_TABLE_ENTRY
> - : : "i" (key), "i" (2 | branch) : : l_yes);
> -
> - return false;
> -l_yes:
> - return true;
> -}
> -
> +#define ARCH_STATIC_BRANCH_ASM(key, label) \
> + "1: jmp " label " # objtool NOPs this \n\t" \
> + JUMP_TABLE_ENTRY(key " + 2", label)
> #else /* !CONFIG_HAVE_JUMP_LABEL_HACK */
> +#define ARCH_STATIC_BRANCH_ASM(key, label) \
> + "1: .byte " __stringify(BYTES_NOP5) "\n\t" \
> + JUMP_TABLE_ENTRY(key, label)
> +#endif /* CONFIG_HAVE_JUMP_LABEL_HACK */
>
> static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
> {
> - asm goto("1:"
> - ".byte " __stringify(BYTES_NOP5) "\n\t"
> - JUMP_TABLE_ENTRY
> + asm goto(ARCH_STATIC_BRANCH_ASM("%c0 + %c1", "%l[l_yes]")
> : : "i" (key), "i" (branch) : : l_yes);
>
> return false;
> @@ -48,13 +41,11 @@ static __always_inline bool arch_static_branch(struct static_key * const key, co
> return true;
> }
>
> -#endif /* CONFIG_HAVE_JUMP_LABEL_HACK */
> -
> static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch)
> {
> asm goto("1:"
> "jmp %l[l_yes]\n\t"
> - JUMP_TABLE_ENTRY
> + JUMP_TABLE_ENTRY("%c0 + %c1", "%l[l_yes]")
> : : "i" (key), "i" (branch) : : l_yes);
>
> return false;
>
next prev parent reply other threads:[~2024-10-30 23:13 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-30 16:04 [PATCH v12 0/5] Tracepoints and static branch in Rust Alice Ryhl
2024-10-30 16:04 ` [PATCH v12 1/5] rust: add static_branch_unlikely for static_key_false Alice Ryhl
2024-10-30 16:04 ` [PATCH v12 2/5] rust: add tracepoint support Alice Ryhl
2024-10-30 16:04 ` [PATCH v12 3/5] rust: samples: add tracepoint to Rust sample Alice Ryhl
2024-11-02 7:07 ` kernel test robot
2024-11-04 10:13 ` Alice Ryhl
2024-10-30 16:04 ` [PATCH v12 4/5] jump_label: adjust inline asm to be consistent Alice Ryhl
2024-10-30 23:13 ` Steven Rostedt [this message]
2024-10-31 0:10 ` Russell King (Oracle)
2024-10-31 0:14 ` Steven Rostedt
2024-10-30 16:04 ` [PATCH v12 5/5] rust: add arch_static_branch Alice Ryhl
2024-12-11 22:32 ` [PATCH v12 0/5] Tracepoints and static branch in Rust patchwork-bot+linux-riscv
2024-12-12 12:40 ` Miguel Ojeda
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=20241030191316.2a27ff1b@rorschach.local.home \
--to=rostedt@goodmis.org \
--cc=a.hindborg@kernel.org \
--cc=ajones@ventanamicro.com \
--cc=akpm@linux-foundation.org \
--cc=alex.gaynor@gmail.com \
--cc=alexghiti@rivosinc.com \
--cc=aliceryhl@google.com \
--cc=aou@eecs.berkeley.edu \
--cc=apatel@ventanamicro.com \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=bp@alien8.de \
--cc=catalin.marinas@arm.com \
--cc=chenhuacai@kernel.org \
--cc=conor.dooley@microchip.com \
--cc=dave.hansen@linux.intel.com \
--cc=gary@garyguo.net \
--cc=hpa@zytor.com \
--cc=jbaron@akamai.com \
--cc=jpoimboe@kernel.org \
--cc=kernel@xen0n.name \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=loongarch@lists.linux.dev \
--cc=maobibo@loongson.cn \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=maz@kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=ojeda@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=palmer@dabbelt.com \
--cc=palmer@rivosinc.com \
--cc=paul.walmsley@sifive.com \
--cc=peterz@infradead.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=ryan.roberts@arm.com \
--cc=samuel.holland@sifive.com \
--cc=seanjc@google.com \
--cc=tabba@google.com \
--cc=tglx@linutronix.de \
--cc=ubizjak@gmail.com \
--cc=wedsonaf@gmail.com \
--cc=will@kernel.org \
--cc=x86@kernel.org \
--cc=yangtiezhu@loongson.cn \
--cc=zhaotianrui@loongson.cn \
/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).