[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <mhng-0614da52-c420-4be1-a5b9-64dacae91d0e@palmer-ri-x1c9a>
Date: Thu, 17 Oct 2024 12:32:13 -0700 (PDT)
From: Palmer Dabbelt <palmer@...belt.com>
To: aliceryhl@...gle.com
CC: rostedt@...dmis.org, mhiramat@...nel.org, mathieu.desnoyers@...icios.com,
peterz@...radead.org, jpoimboe@...nel.org, jbaron@...mai.com, Ard Biesheuvel <ardb@...nel.org>,
ojeda@...nel.org, alex.gaynor@...il.com, wedsonaf@...il.com, boqun.feng@...il.com,
gary@...yguo.net, bjorn3_gh@...tonmail.com, benno.lossin@...ton.me, a.hindborg@...nel.org,
linux-trace-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
Arnd Bergmann <arnd@...db.de>, linux-arch@...r.kernel.org, tglx@...utronix.de, mingo@...hat.com, bp@...en8.de,
dave.hansen@...ux.intel.com, x86@...nel.org, hpa@...or.com, seanjc@...gle.com, ubizjak@...il.com,
Catalin Marinas <catalin.marinas@....com>, Will Deacon <will@...nel.org>, Marc Zyngier <maz@...nel.org>,
oliver.upton@...ux.dev, Mark Rutland <mark.rutland@....com>, ryan.roberts@....com, tabba@...gle.com,
linux-arm-kernel@...ts.infradead.org, Paul Walmsley <paul.walmsley@...ive.com>, aou@...s.berkeley.edu,
apatel@...tanamicro.com, ajones@...tanamicro.com, alexghiti@...osinc.com,
Conor Dooley <conor.dooley@...rochip.com>, samuel.holland@...ive.com, linux-riscv@...ts.infradead.org,
chenhuacai@...nel.org, kernel@...0n.name, maobibo@...ngson.cn, yangtiezhu@...ngson.cn,
akpm@...ux-foundation.org, zhaotianrui@...ngson.cn, loongarch@...ts.linux.dev, aliceryhl@...gle.com
Subject: Re: [PATCH v11 4/5] jump_label: adjust inline asm to be consistent
On Tue, 15 Oct 2024 06:14:58 PDT (-0700), aliceryhl@...gle.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@...radead.org>
> Co-developed-by: Miguel Ojeda <ojeda@...nel.org>
> Signed-off-by: Miguel Ojeda <ojeda@...nel.org>
> Acked-by: Peter Zijlstra (Intel) <peterz@...radead.org>
> Acked-by: Catalin Marinas <catalin.marinas@....com>
> Signed-off-by: Alice Ryhl <aliceryhl@...gle.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/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;
Acked-by: Palmer Dabbelt <palmer@...osinc.com> # RISC-V
Powered by blists - more mailing lists