* [PATCH v4 0/1] alpha: Add support for HAVE_ARCH_JUMP_LABEL
@ 2026-11-15 9:37 Magnus Lindholm
2026-11-15 9:37 ` [PATCH v4 1/1] " Magnus Lindholm
0 siblings, 1 reply; 2+ messages in thread
From: Magnus Lindholm @ 2026-11-15 9:37 UTC (permalink / raw)
To: richard.henderson, mattst88, linux-kernel, linux-alpha; +Cc: linmag7
Apply-time cleanups following Matt Turner's review of v3:
- Move jump_label.o beside the other object entries near the top of
arch/alpha/kernel/Makefile, outside the GENERIC block.
- Include linux/cacheflush.h instead of asm/cacheflush.h.
- Regenerate the cover-letter diffstat and retain Matt's Reviewed-by.
The jump-label implementation is otherwise unchanged from v3.
V3 was cross-built with W=1 and boot-tested on a three-CPU AlphaServer
ES40 with CMA v2. The static-key boot selftest and 30 module load/unload
cycles passed, including cross-module keys. This revised export has
not been rebuilt or boot-tested separately.
Batching I-cache synchronization and relative jump-table entries remain
follow-ups. The early jump_label_init() call needed before Alpha's new
early-parameter parsing is carried by the separate CMA v3 series.
This patch applies to for-next at 0b4cadbe7c39.
Magnus Lindholm (1):
alpha: Add support for HAVE_ARCH_JUMP_LABEL
.../core/jump-labels/arch-support.txt | 2 +-
arch/alpha/Kconfig | 1 +
arch/alpha/include/asm/jump_label.h | 65 +++++++++++++++
arch/alpha/kernel/Makefile | 1 +
arch/alpha/kernel/jump_label.c | 79 +++++++++++++++++++
5 files changed, 147 insertions(+), 1 deletion(-)
create mode 100644 arch/alpha/include/asm/jump_label.h
create mode 100644 arch/alpha/kernel/jump_label.c
base-commit: 0b4cadbe7c39d830dec35c4a2655483de0dae568
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH v4 1/1] alpha: Add support for HAVE_ARCH_JUMP_LABEL
2026-11-15 9:37 [PATCH v4 0/1] alpha: Add support for HAVE_ARCH_JUMP_LABEL Magnus Lindholm
@ 2026-11-15 9:37 ` Magnus Lindholm
0 siblings, 0 replies; 2+ messages in thread
From: Magnus Lindholm @ 2026-11-15 9:37 UTC (permalink / raw)
To: richard.henderson, mattst88, linux-kernel, linux-alpha; +Cc: linmag7
Implement static key (jump label) support for Alpha. Emit jump table
entries and patch instruction sites between NOP and BR, synchronizing
instruction caches after each update.
Warn and leave the instruction unchanged if the target is outside the
signed 21-bit branch displacement range.
This relies on kernel and module text being writable; Alpha does not
implement STRICT_KERNEL_RWX or STRICT_MODULE_RWX.
Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
---
.../core/jump-labels/arch-support.txt | 2 +-
arch/alpha/Kconfig | 1 +
arch/alpha/include/asm/jump_label.h | 65 +++++++++++++++
arch/alpha/kernel/Makefile | 1 +
arch/alpha/kernel/jump_label.c | 79 +++++++++++++++++++
5 files changed, 147 insertions(+), 1 deletion(-)
create mode 100644 arch/alpha/include/asm/jump_label.h
create mode 100644 arch/alpha/kernel/jump_label.c
diff --git a/Documentation/features/core/jump-labels/arch-support.txt b/Documentation/features/core/jump-labels/arch-support.txt
index 683de7c15058..119c71b7cec0 100644
--- a/Documentation/features/core/jump-labels/arch-support.txt
+++ b/Documentation/features/core/jump-labels/arch-support.txt
@@ -6,7 +6,7 @@
-----------------------
| arch |status|
-----------------------
- | alpha: | TODO |
+ | alpha: | ok |
| arc: | ok |
| arm: | ok |
| arm64: | ok |
diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
index 6ccb2d230326..e7e7cb37d670 100644
--- a/arch/alpha/Kconfig
+++ b/arch/alpha/Kconfig
@@ -28,6 +28,7 @@ config ALPHA
select PCI_DOMAINS if PCI
select PCI_SYSCALL if PCI
select HAVE_ARCH_COMPILER_H
+ select HAVE_ARCH_JUMP_LABEL
select HAVE_ASM_MODVERSIONS
select HAVE_DEBUG_KMEMLEAK
select HAVE_GUP_FAST
diff --git a/arch/alpha/include/asm/jump_label.h b/arch/alpha/include/asm/jump_label.h
new file mode 100644
index 000000000000..df0b59530c85
--- /dev/null
+++ b/arch/alpha/include/asm/jump_label.h
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Alpha architecture jump label (static key) definitions
+ *
+ * Defines patch site emission and jump table layout for
+ * Alpha static key support.
+ *
+ * Copyright (C) 2026 Magnus Lindholm <linmag7@gmail.com>
+ */
+
+#ifndef _ASM_ALPHA_JUMP_LABEL_H
+#define _ASM_ALPHA_JUMP_LABEL_H
+
+#ifndef __ASSEMBLER__
+
+#include <linux/types.h>
+
+#define JUMP_LABEL_NOP_SIZE 4
+
+typedef u64 jump_label_t;
+
+struct jump_entry {
+ jump_label_t code;
+ jump_label_t target;
+ jump_label_t key;
+};
+
+static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
+{
+ asm goto("1:\n\t"
+ "nop\n\t"
+ ".pushsection __jump_table, \"aw\"\n\t"
+ ".align 3\n\t"
+ ".quad 1b, %l[l_yes], %0\n\t"
+ ".popsection\n\t"
+ :
+ : "i"(&((char *)key)[branch])
+ :
+ : l_yes);
+
+ return false;
+l_yes:
+ return true;
+}
+
+static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
+{
+ asm goto("1:\n\t"
+ "br $31, %l[l_yes]\n\t"
+ ".pushsection __jump_table, \"aw\"\n\t"
+ ".align 3\n\t"
+ ".quad 1b, %l[l_yes], %0\n\t"
+ ".popsection\n\t"
+ :
+ : "i"(&((char *)key)[branch])
+ :
+ : l_yes);
+
+ return false;
+l_yes:
+ return true;
+}
+
+#endif /* __ASSEMBLER__ */
+#endif /* _ASM_ALPHA_JUMP_LABEL_H */
diff --git a/arch/alpha/kernel/Makefile b/arch/alpha/kernel/Makefile
index 850f1265cc55..279616993fb9 100644
--- a/arch/alpha/kernel/Makefile
+++ b/arch/alpha/kernel/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_SRM_ENV) += srm_env.o
obj-$(CONFIG_MODULES) += module.o
obj-$(CONFIG_PERF_EVENTS) += perf_event.o
obj-$(CONFIG_HAVE_PERF_REGS) += perf_regs.o
+obj-$(CONFIG_JUMP_LABEL) += jump_label.o
obj-$(CONFIG_RTC_DRV_ALPHA) += rtc.o
ifdef CONFIG_ALPHA_GENERIC
diff --git a/arch/alpha/kernel/jump_label.c b/arch/alpha/kernel/jump_label.c
new file mode 100644
index 000000000000..69475e840e46
--- /dev/null
+++ b/arch/alpha/kernel/jump_label.c
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Alpha architecture jump label (static key) support
+ *
+ * Implements runtime patching of static key sites by replacing
+ * a NOP instruction with an unconditional branch and vice versa.
+ *
+ * Copyright (C) 2026 Magnus Lindholm <linmag7@gmail.com>
+ */
+
+#include <linux/cacheflush.h>
+#include <linux/jump_label.h>
+#include <linux/kernel.h>
+
+/*
+ * Alpha instruction encoding helpers.
+ *
+ * Branch format:
+ * [31:26] opcode
+ * [25:21] Ra
+ * [20:0 ] disp (signed, in instructions; hardware multiplies by 4)
+ *
+ * Unconditional branch:
+ * BR opcode is 0x30. We use Ra=r31 so no link register is written.
+ *
+ * Updated PC semantics:
+ * Target = (pc + 4) + (disp << 2)
+ * so disp = (target - (pc + 4)) >> 2.
+ */
+#define ALPHA_OP_BR 0x30
+#define ALPHA_RA_R31 31
+#define ALPHA_BR_DISP_MASK ((1u << 21) - 1)
+
+#define ALPHA_INSN_NOP 0x47FF041Fu /* BIS r31,r31,r31 */
+
+static inline bool alpha_br_insn(unsigned long pc, unsigned long target,
+ u32 *insn)
+{
+ long off_bytes = (long)target - (long)(pc + 4);
+ long disp = off_bytes >> 2;
+
+ /*
+ * 21-bit signed displacement: range is [-2^20, 2^20-1] instructions.
+ * If this trips, the site/target are too far apart for a BR.
+ */
+ if (WARN_ON_ONCE(disp < -(1L << 20) || disp > ((1L << 20) - 1)))
+ return false;
+
+ *insn = (ALPHA_OP_BR << 26) |
+ (ALPHA_RA_R31 << 21) |
+ ((u32)disp & ALPHA_BR_DISP_MASK);
+ return true;
+}
+
+static inline void alpha_patch_text(u32 *site, u32 insn)
+{
+ WRITE_ONCE(*site, insn);
+ /*
+ * Alpha needs an I-cache sync after patching executable text.
+ */
+ flush_icache_range((unsigned long)site, (unsigned long)site + sizeof(*site));
+}
+
+void arch_jump_label_transform(struct jump_entry *entry,
+ enum jump_label_type type)
+{
+ u32 *site = (u32 *)jump_entry_code(entry);
+ u32 insn;
+
+ if (type == JUMP_LABEL_JMP) {
+ if (!alpha_br_insn((unsigned long)site, jump_entry_target(entry),
+ &insn))
+ return;
+ } else {
+ insn = ALPHA_INSN_NOP;
+ }
+
+ alpha_patch_text(site, insn);
+}
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-15 9:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-15 9:37 [PATCH v4 0/1] alpha: Add support for HAVE_ARCH_JUMP_LABEL Magnus Lindholm
2026-11-15 9:37 ` [PATCH v4 1/1] " Magnus Lindholm
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®