[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241011152312.r5sy7k7hsunmmbfo@treble>
Date: Fri, 11 Oct 2024 08:23:12 -0700
From: Josh Poimboeuf <jpoimboe@...nel.org>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: Steven Rostedt <rostedt@...dmis.org>,
Masami Hiramatsu <mhiramat@...nel.org>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
Peter Zijlstra <peterz@...radead.org>,
Jason Baron <jbaron@...mai.com>, Ard Biesheuvel <ardb@...nel.org>,
Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Wedson Almeida Filho <wedsonaf@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <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, Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
"H. Peter Anvin" <hpa@...or.com>,
Sean Christopherson <seanjc@...gle.com>,
Uros Bizjak <ubizjak@...il.com>,
Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will@...nel.org>, Marc Zyngier <maz@...nel.org>,
Oliver Upton <oliver.upton@...ux.dev>,
Mark Rutland <mark.rutland@....com>,
Ryan Roberts <ryan.roberts@....com>, Fuad Tabba <tabba@...gle.com>,
linux-arm-kernel@...ts.infradead.org,
Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>,
Albert Ou <aou@...s.berkeley.edu>,
Anup Patel <apatel@...tanamicro.com>,
Andrew Jones <ajones@...tanamicro.com>,
Alexandre Ghiti <alexghiti@...osinc.com>,
Conor Dooley <conor.dooley@...rochip.com>,
Samuel Holland <samuel.holland@...ive.com>,
linux-riscv@...ts.infradead.org,
Huacai Chen <chenhuacai@...nel.org>,
WANG Xuerui <kernel@...0n.name>, Bibo Mao <maobibo@...ngson.cn>,
Tiezhu Yang <yangtiezhu@...ngson.cn>,
Andrew Morton <akpm@...ux-foundation.org>,
Tianrui Zhao <zhaotianrui@...ngson.cn>, loongarch@...ts.linux.dev
Subject: Re: [PATCH v10 5/5] rust: add arch_static_branch
On Fri, Oct 11, 2024 at 10:13:38AM +0000, Alice Ryhl wrote:
> +#[cfg(CONFIG_JUMP_LABEL)]
> +#[cfg(not(CONFIG_HAVE_JUMP_LABEL_HACK))]
> +macro_rules! arch_static_branch {
> + ($key:path, $keytyp:ty, $field:ident, $branch:expr) => {'my_label: {
> + $crate::asm!(
> + include!(concat!(env!("OBJTREE"), "/rust/kernel/arch_static_branch_asm.rs"));
> + l_yes = label {
> + break 'my_label true;
> + },
> + symb = sym $key,
> + off = const ::core::mem::offset_of!($keytyp, $field),
> + branch = const $crate::jump_label::bool_to_int($branch),
> + );
> +
> + break 'my_label false;
> + }};
> +}
> +
> +#[macro_export]
> +#[doc(hidden)]
> +#[cfg(CONFIG_JUMP_LABEL)]
> +#[cfg(CONFIG_HAVE_JUMP_LABEL_HACK)]
> +macro_rules! arch_static_branch {
> + ($key:path, $keytyp:ty, $field:ident, $branch:expr) => {'my_label: {
> + $crate::asm!(
> + include!(concat!(env!("OBJTREE"), "/rust/kernel/arch_static_branch_asm.rs"));
> + l_yes = label {
> + break 'my_label true;
> + },
> + symb = sym $key,
> + off = const ::core::mem::offset_of!($keytyp, $field),
> + branch = const 2 | $crate::jump_label::bool_to_int($branch),
> + );
> +
> + break 'my_label false;
> + }};
Ouch... could we get rid of all this duplication by containing the hack
bit to ARCH_STATIC_BRANCH_ASM() like so?
diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_label.h
index ffd0d1a1a4af..3f1c1d6c0da1 100644
--- a/arch/x86/include/asm/jump_label.h
+++ b/arch/x86/include/asm/jump_label.h
@@ -24,7 +24,7 @@
#ifdef CONFIG_HAVE_JUMP_LABEL_HACK
#define ARCH_STATIC_BRANCH_ASM(key, label) \
"1: jmp " label " # objtool NOPs this \n\t" \
- JUMP_TABLE_ENTRY(key, label)
+ 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" \
@@ -33,10 +33,8 @@
static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
{
- int hack_bit = IS_ENABLED(CONFIG_HAVE_JUMP_LABEL_HACK) ? 2 : 0;
-
asm goto(ARCH_STATIC_BRANCH_ASM("%c0 + %c1", "%l[l_yes]")
- : : "i" (key), "i" (hack_bit | branch) : : l_yes);
+ : : "i" (key), "i" (branch) : : l_yes);
return false;
l_yes:
Powered by blists - more mailing lists