Re: [PATCH v4 1/2] rust: add static_key_false

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;




[Index of Archives]     [Linux Kernel]     [Kernel Newbies]     [x86 Platform Driver]     [Netdev]     [Linux Wireless]     [Netfilter]     [Bugtraq]     [Linux Filesystems]     [Yosemite Discussion]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]

  Powered by Linux