lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240801102804.GQ33588@noisy.programming.kicks-ass.net>
Date: Thu, 1 Aug 2024 12:28:04 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: Steven Rostedt <rostedt@...dmis.org>,
	Masami Hiramatsu <mhiramat@...nel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
	Josh Poimboeuf <jpoimboe@...nel.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@...sung.com>,
	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>,
	"Peter Zijlstra (Intel)" <peterz@...radaed.org>,
	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 v4 1/2] rust: add static_key_false

On Wed, Jul 31, 2024 at 11:34:13PM +0200, Alice Ryhl wrote:

> > Please work harder to not have to duplicate stuff like this.
> 
> I really didn't want to duplicate it, but it's very hard to find a
> performant alternative. Is there any way we could accept duplication
> only in the cases where an 'i' parameter is used? I don't have the
> choice of using a Rust helper for 'i' parameters.
> 
> Perhaps one option could be to put the Rust code inside jump_label.h
> and have the header file evaluate to either C or Rust depending on the
> value of some #ifdefs?
> 
> #ifndef RUST_ASM
> /* existing C code goes here */
> #endif
> #ifdef RUST_ASM
> // rust code goes here
> #endif
> 
> That way the duplication is all in a single file. It would also avoid
> the need for duplicating the nop5 string, as the Rust case is still
> going through the C preprocessor and can use the existing #define.

I suppose that is slightly better, but ideally you generate the whole of
the Rust thing from the C version. After all, Clang can already parse
this.

That said, with the below patch, I think you should be able to reuse the
JUMP_TABLE_ENTRY macro like:

	JUMP_TABLE_ENTRY({0}, {1}, {2} + {3})

> I'm also open to other alternatives. But I don't have infinite
> resources to drive major language changes.

Yes, well, you all picked this terrible language full well knowing it
hated C/C++ and had not a single effort put into integration with
existing code bases.

I find it very hard to care for the problems you've created for
yourself.


---
diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_label.h
index cbbef32517f0..6cff7bf5e779 100644
--- a/arch/x86/include/asm/jump_label.h
+++ b/arch/x86/include/asm/jump_label.h
@@ -12,12 +12,12 @@
 #include <linux/stringify.h>
 #include <linux/types.h>
 
-#define JUMP_TABLE_ENTRY				\
-	".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"			\
+#define JUMP_TABLE_ENTRY(l_yes, key, branch)				\
+	".pushsection __jump_table,  \"aw\" \n\t"			\
+	_ASM_ALIGN "\n\t"						\
+	".long 1b - . \n\t"						\
+	".long " __stringify(l_yes) "- . \n\t"				\
+	_ASM_PTR " " __stringify(key) " + " __stringify(branch) " - . \n\t" \
 	".popsection \n\t"
 
 #ifdef CONFIG_HAVE_JUMP_LABEL_HACK
@@ -26,7 +26,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
 {
 	asm goto("1:"
 		"jmp %l[l_yes] # objtool NOPs this \n\t"
-		JUMP_TABLE_ENTRY
+		JUMP_TABLE_ENTRY(%[l_yes], %c0, %c1)
 		: :  "i" (key), "i" (2 | branch) : : l_yes);
 
 	return false;
@@ -40,7 +40,7 @@ static __always_inline bool arch_static_branch(struct static_key * const key, co
 {
 	asm goto("1:"
 		".byte " __stringify(BYTES_NOP5) "\n\t"
-		JUMP_TABLE_ENTRY
+		JUMP_TABLE_ENTRY(%[l_yes], %c0, %c1)
 		: :  "i" (key), "i" (branch) : : l_yes);
 
 	return false;
@@ -54,7 +54,7 @@ static __always_inline bool arch_static_branch_jump(struct static_key * const ke
 {
 	asm goto("1:"
 		"jmp %l[l_yes]\n\t"
-		JUMP_TABLE_ENTRY
+		JUMP_TABLE_ENTRY(%[l_yes], %c0, %c1)
 		: :  "i" (key), "i" (branch) : : l_yes);
 
 	return false;

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ