alpha: Add support for HAVE_ARCH_JUMP_LABEL
Subsystems (3)
Magnus Lindholm
maintainerv3 cover alpha: Add support for HAVE_ARCH_JUMP_LABEL
This revision addresses Matt Turner's review of v2.
Changes since v2:
- Rebase onto the current local alpha-devel branch.
- Place HAVE_ARCH_JUMP_LABEL beside the other HAVE_ARCH selections.
- Warn and return without patching an out-of-range branch target.
- Remove the unused mutex include. Retain JUMP_LABEL_NOP_SIZE: the current generic jump_entry_size() requires it on Alpha.
- Clean up the duplicate NOP comment and extra blank line.
- Document the writable kernel and module text requirement.
- Retain Matt's Reviewed-by.
Batching I-cache synchronization and relative jump table entries remain possible follow-ups.
The previous submission reported UP2000+ SMP tracepoint and stress checks. Those results do not establish validation of this revision. This revision cross-builds successfully with W=1 for Alpha SMP, with CONFIG_JUMP_LABEL=y, CONFIG_STATIC_KEYS_SELFTEST=y and CONFIG_TEST_STATIC_KEYS=m. On the ES40, the boot selftest passed and the static-key test modules completed 10 load/unload cycles on each of three CPUs (30 total), including cross-module keys. This used a combined kernel with CMA v2. no new kernel warnings or faults appeared during those tests.
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 | 63 +++++++++++++++ arch/alpha/kernel/Makefile | 2 + arch/alpha/kernel/jump_label.c | 79 +++++++++++++++++++ 5 files changed, 146 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
Signature · 1 line
2.43.0
Magnus Lindholm
maintainerPATCH v3 1/1 alpha: Add support for HAVE_ARCH_JUMP_LABEL
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.
--- .../core/jump-labels/arch-support.txt | 2 +- arch/alpha/Kconfig | 1 + arch/alpha/include/asm/jump_label.h | 65 +++++++++++++++ arch/alpha/kernel/Makefile | 2 + arch/alpha/kernel/jump_label.c | 79 +++++++++++++++++++ 5 files changed, 148 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
@@ -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
arch/alpha/include/asm/jump_label.h new file +65 -0
65 lines not on this page · raw message
arch/alpha/kernel/Makefile +2 -0
@@ -92,3 +92,5 @@ obj-$(CONFIG_ALPHA_TITAN) += err_ev6.o err_titan.o obj-$(CONFIG_ALPHA_TSUNAMI) += err_ev6.o err_tsunami.o endif # GENERIC + +obj-$(CONFIG_JUMP_LABEL) += jump_label.o
arch/alpha/kernel/jump_label.c new file +79 -0
79 lines not on this page · raw message
base-commit: 0b4cadbe7c39d830dec35c4a2655483de0dae568
Signature · 1 line
2.43.0
arch/alpha/kernel/Makefile obj-$(CONFIG_ALPHA_TITAN) += err_ev6.o err_titan.o · line 96
Quoted 10 lines · Magnus Lindholm
arch/alpha/kernel/Makefile +2
-0@@ -92,3 +92,5 @@ obj-$(CONFIG_ALPHA_TITAN) += err_ev6.o err_titan.o obj-$(CONFIG_ALPHA_TSUNAMI) += err_ev6.o err_tsunami.o endif # GENERIC + +obj-$(CONFIG_JUMP_LABEL) += jump_label.o
Nit: this would read better up with the other unconditional obj- lines near the top of the file rather than trailing the GENERIC block.
arch/alpha/kernel/Makefile
Quoted 3 lines
arch/alpha/kernel/Makefile +3
-0+#include <linux/jump_label.h> +#include <linux/kernel.h> +#include <asm/cacheflush.h>
Nit: checkpatch --strict suggests <linux/cacheflush.h> here.
arch/alpha/kernel/Makefile
Quoted 2 lines
arch/alpha/kernel/Makefile +2
-0+ if (WARN_ON_ONCE(disp < -(1L << 20) || disp > ((1L << 20) - 1))) + return false;
Thanks. The target is always within the same function and Alpha gcc doesn't do hot/cold partitioning, so I don't expect this to fire, but it's a cheap safety net.
arch/alpha/kernel/Makefile
Quoted 8 lines
arch/alpha/kernel/Makefile +8
-0+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)); +}
On SMP this is smp_imb(), so every key flip IPIs all CPUs once per site. That's correct, and fine as a starting point; batching via arch_jump_label_transform_queue()/_apply() would be the natural follow-up you mention in the cover letter.
I applied this on 0b4cadbe7c39 and cross-built an SMP defconfig with JUMP_LABEL and STATIC_KEYS_SELFTEST at W=1 with no new warnings. The patch sites in vmlinux are the expected 0x47ff041f nops with nearby targets.
The diffstat in the cover letter is stale (63/146 vs. 65/148 in the patch), but that doesn't matter for applying.
None of the above needs a respin from my side.
Magnus Lindholm
maintainerHi Matt,
Quoted 49 lines · Matt Turner
arch/alpha/kernel/Makefile obj-$(CONFIG_ALPHA_TITAN) += err_ev6.o err_titan.o · line 96
Quoted 10 lines · Magnus Lindholm
arch/alpha/kernel/Makefile +2
-0@@ -92,3 +92,5 @@ obj-$(CONFIG_ALPHA_TITAN) += err_ev6.o err_titan.o obj-$(CONFIG_ALPHA_TSUNAMI) += err_ev6.o err_tsunami.o endif # GENERIC + +obj-$(CONFIG_JUMP_LABEL) += jump_label.oNit: this would read better up with the other unconditional obj- lines near the top of the file rather than trailing the GENERIC block.
arch/alpha/kernel/Makefile
Quoted 3 lines
arch/alpha/kernel/Makefile +3
-0+#include <linux/jump_label.h> +#include <linux/kernel.h> +#include <asm/cacheflush.h>Nit: checkpatch --strict suggests <
linux/cacheflush.h> here.arch/alpha/kernel/Makefile
Quoted 2 lines
arch/alpha/kernel/Makefile +2
-0+ if (WARN_ON_ONCE(disp < -(1L << 20) || disp > ((1L << 20) - 1))) + return false;Thanks. The target is always within the same function and Alpha gcc doesn't do hot/cold partitioning, so I don't expect this to fire, but it's a cheap safety net.
arch/alpha/kernel/Makefile
Quoted 8 lines
arch/alpha/kernel/Makefile +8
-0+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)); +}On SMP this is
smp_imb(), so every key flip IPIs all CPUs once per site. That's correct, and fine as a starting point; batching via arch_jump_label_transform_queue()/_apply() would be the natural follow-up you mention in the cover letter.I applied this on
0b4cadbe7c39and cross-built an SMP defconfig withJUMP_LABELandSTATIC_KEYS_SELFTESTat W=1 with no new warnings. The patch sites in vmlinux are the expected0x47ff041fnops with nearby targets.
Quoted 6 lines
The diffstat in the cover letter is stale (63/146 vs. 65/148 in the patch), but that doesn't matter for applying.
None of the above needs a respin from my side.
Reviewed-by Matt Turner <[email protected]>
Thanks for reviewing and build-testing this. I'll fix the Makefile placement and cacheflush include when applying it, and refresh the cover-letter diffstat. Batching can remain a follow-up.
The boot selftest and 30 module load/unload cycles also passed on my three-CPU ES40, including cross-module static keys.
Thanks,
Magnus