alpha: Add support for HAVE_ARCH_JUMP_LABEL
Subsystems (3)
Magnus Lindholm
maintainerv2 cover alpha: Add support for HAVE_ARCH_JUMP_LABEL
This patch adds jump label (static key) support for Alpha. Testing and verification were performed on an UP2000+ system.
Verification steps:
- Confirmed __jump_table section is present at runtime via /proc/kallsyms and contains a non-zero number of entries.
- Instrumented arch_jump_label_transform() to log patch
operations and verified instruction sites toggle between:
NOP (bis $31,$31,$31, 0x47ff041f)
BR (br $31,target) - Added temporary instrumentation in arch_jump_label_transform() to log old/new instruction values at each patch site, and used a Python script to validate correct NOP/BR transitions and branch encoding, confirming functional runtime patching.
Instruction stream synchronization uses imb()/smp_imb() via flush_icache_range(), and runtime behavior confirms correct I-cache coherency.
The system remained stable throughout all testing.
---
Changes since v1:
- Update features documentation for features/core/jump-labels
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 | 66 +++++++++++++++ arch/alpha/kernel/Makefile | 1 + arch/alpha/kernel/jump_label.c | 81 +++++++++++++++++++ 5 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 arch/alpha/include/asm/jump_label.h create mode 100644 arch/alpha/kernel/jump_label.c
Signature · 1 line
2.52.0
Magnus Lindholm
maintainerPATCH v2 1/1 alpha: Add support for HAVE_ARCH_JUMP_LABEL
Implement static key (jump label) support for Alpha.
Provide arch_static_branch() helpers and implement arch_jump_label_transform() to patch a single instruction site between NOP and BR, with appropriate I-cache synchronization.
Tested on Alpha UP2000+ SMP. Static key sites toggle correctly under tracepoint enable/disable and repeated stress testing without faults.
--- .../core/jump-labels/arch-support.txt | 2 +- arch/alpha/Kconfig | 1 + arch/alpha/include/asm/jump_label.h | 66 +++++++++++++++ arch/alpha/kernel/Makefile | 1 + arch/alpha/kernel/jump_label.c | 81 +++++++++++++++++++ 5 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 arch/alpha/include/asm/jump_label.h create mode 100644 arch/alpha/kernel/jump_label.c
Documentation/features/core/jump-labels/arch-support.txt +1 -1
@@ -6,7 +6,7 @@ ----------------------- | arch |status| ----------------------- - | alpha: | TODO | + | alpha: | ok | | arc: | ok | | arm: | ok | | arm64: | ok |
arch/alpha/Kconfig +1 -0
@@ -41,6 +41,7 @@ config ALPHA select MMU_GATHER_RCU_TABLE_FREE select SPARSEMEM_EXTREME if SPARSEMEM select ZONE_DMA + select HAVE_ARCH_JUMP_LABEL help The Alpha is a 64-bit general-purpose processor designed and marketed by the Digital Equipment Corporation of blessed memory,
arch/alpha/include/asm/jump_label.h new file +66 -0
66 lines not on this page · raw message
arch/alpha/kernel/Makefile +1 -0
@@ -19,6 +19,7 @@ obj-$(CONFIG_MODULES) += module.o obj-$(CONFIG_PERF_EVENTS) += perf_event.o obj-$(CONFIG_RTC_DRV_ALPHA) += rtc.o obj-$(CONFIG_AUDIT) += audit.o +obj-$(CONFIG_JUMP_LABEL) += jump_label.o ifdef CONFIG_ALPHA_GENERIC
arch/alpha/kernel/jump_label.c new file +81 -0
81 lines not on this page · raw message
Signature · 1 line
2.52.0
Quoted 1 line · Magnus Lindholm
Implement static key (jump label) support for Alpha.
Sorry for the slow review. This looks correct to me. I applied it to your for-next (the arch/alpha/Kconfig hunk needs a trivial rebase) and it builds cleanly with W=1, CONFIG_JUMP_LABEL=y and CONFIG_STATIC_KEYS_SELFTEST=y. I have not booted it. A few comments, none of them blocking:
Quoted 1 line
+ select
HAVE_ARCH_JUMP_LABEL
Please keep the select list sorted.
arch/alpha/kernel/jump_label.c line 66
Quoted 4 lines
arch/alpha/kernel/jump_label.c new file +4
-0+static inline void alpha_patch_text (u32 *site,u32 insn) +{ +WRITE_ONCE (*site, insn); +flush_icache_range ((unsigned long )site, (unsigned long )site +sizeof (*site));
On SMP flush_icache_range() is smp_imb(), so this is one on_each_cpu() IPI round per patched site. A key with many sites, or a module load, turns into that many broadcasts. That is fine as a first version, but it would be worth a follow-up that implements arch_jump_label_transform_queue()/_apply() (HAVE_JUMP_LABEL_BATCH) so that a key update does a single imb at the end.
arch/alpha/kernel/jump_label.c line 53
Quoted 4 lines
arch/alpha/kernel/jump_label.c new file +4
-0+if (disp < -(1L <<20 ) || disp > ((1L <<20 ) -1 )) { +WARN_ON_ONCE (1 ); + disp =0 ; + }
With disp = 0 we write a branch to the next instruction, so the site silently behaves as a NOP. I would rather return without patching (or BUG) than install something that looks valid. The comment about what other architectures do can go.
arch/alpha/include/asm/jump_label.h line 27
Quoted 5 lines
arch/alpha/include/asm/jump_label.h new file +5
-0+struct jump_entry { +jump_label_t code; +jump_label_t target; +jump_label_t key; +};
Optional: HAVE_ARCH_JUMP_LABEL_RELATIVE would shrink this from 24 to 16 bytes per entry, and the module loader already handles R_ALPHA_SREL32 and R_ALPHA_SREL64. Fine to leave for later.
Small things:
- <linux/mutex.h> is unused in jump_label.c.
- JUMP_LABEL_NOP_SIZE is unused.
- ALPHA_INSN_NOP has two trailing comments.
- There is a stray double blank line before the include guard.
- The commit message could note that this relies on kernel and module text being writable (no STRICT_KERNEL_RWX on alpha).
Did you run CONFIG_STATIC_KEYS_SELFTEST, and load and unload a module that carries static keys?