* [PATCH] arm: Add runtime constant support for armv7 and !THUMB2_KERNEL
@ 2026-02-21 14:18 Jisheng Zhang
2026-02-21 16:03 ` Russell King (Oracle)
0 siblings, 1 reply; 3+ messages in thread
From: Jisheng Zhang @ 2026-02-21 14:18 UTC (permalink / raw)
To: Russell King; +Cc: linux-arm-kernel, linux-kernel
Implement the runtime constant infrastructure for
armv7 && !THUMB2_KERNEL. So that armv7 can use this infrastructure
to generate constants to be used by the d_hash(), dentry_cache(),
names_cache() and so on.
This is the armv7 variant of commit 94a2bc0f611c ("arm64: add 'runtime
constant' support") and commit e3c92e81711d ("runtime constants: add
x86 architecture support").
As for < armv7 or THUMB2_KERNEL, we fall back to the generic
runtime-constant.h, no functionality changes.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
arch/arm/include/asm/runtime-const.h | 102 +++++++++++++++++++++++++++
arch/arm/kernel/vmlinux.lds.S | 2 +
2 files changed, 104 insertions(+)
create mode 100644 arch/arm/include/asm/runtime-const.h
diff --git a/arch/arm/include/asm/runtime-const.h b/arch/arm/include/asm/runtime-const.h
new file mode 100644
index 000000000000..c1a14f71dd5e
--- /dev/null
+++ b/arch/arm/include/asm/runtime-const.h
@@ -0,0 +1,102 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_ARM_RUNTIME_CONST_H
+#define _ASM_ARM_RUNTIME_CONST_H
+
+#ifdef MODULE
+ #error "Cannot use runtime-const infrastructure from modules"
+#endif
+
+#if __LINUX_ARM_ARCH__ >= 7 && !defined(CONFIG_THUMB2_KERNEL)
+#include <asm/cacheflush.h>
+
+/* Sigh. You can still run arm in BE mode */
+#include <asm/byteorder.h>
+
+#define runtime_const_ptr(sym) ({ \
+ typeof(sym) __ret; \
+ asm_inline("1:\n" \
+ "movw %0, #0x4567\n" \
+ "movt %0, #0x0123\n" \
+ ".pushsection runtime_ptr_" #sym ",\"a\"\n\t" \
+ ".long 1b - .\n" \
+ ".popsection" \
+ : "=r" (__ret)); \
+ __ret; })
+
+#define runtime_const_shift_right_32(val, sym) ({ \
+ unsigned long __ret; \
+ asm_inline("1:\n" \
+ "lsr %0,%1,#12\n" \
+ ".pushsection runtime_shift_" #sym ",\"a\"\n\t" \
+ ".long 1b - .\n" \
+ ".popsection" \
+ : "=r" (__ret) \
+ : "r" (0u+(val))); \
+ __ret; })
+
+#define runtime_const_init(type, sym) do { \
+ extern s32 __start_runtime_##type##_##sym[]; \
+ extern s32 __stop_runtime_##type##_##sym[]; \
+ \
+ runtime_const_fixup(__runtime_fixup_##type, \
+ (unsigned long)(sym), \
+ __start_runtime_##type##_##sym, \
+ __stop_runtime_##type##_##sym); \
+} while (0)
+
+/*
+ * 16-bit immediate for wide move (movw and movt) is encoded in
+ * bits 19:16, 11:0
+ */
+static inline void __runtime_fixup_16(__le32 *p, unsigned int val)
+{
+ u32 insn = le32_to_cpu(*p);
+
+ insn &= 0xfff0f000;
+ insn |= val & 0xfff;
+ insn |= ((val & 0xf000) >> 12) << 16;
+ *p = cpu_to_le32(insn);
+}
+
+static inline void __runtime_fixup_caches(void *where, unsigned int insns)
+{
+ unsigned long va = (unsigned long)where;
+
+ flush_icache_range(va, va + 4 * insns);
+}
+
+static inline void __runtime_fixup_ptr(void *where, unsigned long val)
+{
+ __le32 *p = where;
+
+ __runtime_fixup_16(p, val);
+ __runtime_fixup_16(p + 1, val >> 16);
+ __runtime_fixup_caches(where, 2);
+}
+
+/* Immediate value is 5 bits starting at bit #7 */
+static inline void __runtime_fixup_shift(void *where, unsigned long val)
+{
+ __le32 *p = where;
+ u32 insn = le32_to_cpu(*p);
+
+ insn &= 0xfffff07f;
+ insn |= (val & 0x1f) << 7;
+ *p = cpu_to_le32(insn);
+ __runtime_fixup_caches(where, 1);
+}
+
+static inline void runtime_const_fixup(void (*fn)(void *, unsigned long),
+ unsigned long val, s32 *start, s32 *end)
+{
+ while (start < end) {
+ fn(*start + (void *)start, val);
+ start++;
+ }
+}
+
+#else
+#include <asm-generic/runtime-const.h>
+#endif /* __LINUX_ARM_ARCH__ >= 7 && !defined(CONFIG_THUMB2_KERNEL) */
+
+#endif /* _ASM_ARM_RUNTIME_CONST_H */
diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
index d592a203f9c6..5d90cd16e538 100644
--- a/arch/arm/kernel/vmlinux.lds.S
+++ b/arch/arm/kernel/vmlinux.lds.S
@@ -126,6 +126,8 @@ SECTIONS
ARM_EXIT_KEEP(EXIT_DATA)
}
+ RUNTIME_CONST_VARIABLES
+
#ifdef CONFIG_SMP
PERCPU_SECTION(L1_CACHE_BYTES)
#endif
--
2.51.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] arm: Add runtime constant support for armv7 and !THUMB2_KERNEL
2026-02-21 14:18 [PATCH] arm: Add runtime constant support for armv7 and !THUMB2_KERNEL Jisheng Zhang
@ 2026-02-21 16:03 ` Russell King (Oracle)
2026-02-23 12:19 ` Jisheng Zhang
0 siblings, 1 reply; 3+ messages in thread
From: Russell King (Oracle) @ 2026-02-21 16:03 UTC (permalink / raw)
To: Jisheng Zhang; +Cc: linux-arm-kernel, linux-kernel
On Sat, Feb 21, 2026 at 10:18:31PM +0800, Jisheng Zhang wrote:
> Implement the runtime constant infrastructure for
> armv7 && !THUMB2_KERNEL. So that armv7 can use this infrastructure
> to generate constants to be used by the d_hash(), dentry_cache(),
> names_cache() and so on.
>
> This is the armv7 variant of commit 94a2bc0f611c ("arm64: add 'runtime
> constant' support") and commit e3c92e81711d ("runtime constants: add
> x86 architecture support").
>
> As for < armv7 or THUMB2_KERNEL, we fall back to the generic
> runtime-constant.h, no functionality changes.
>
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
This looks fine to me, but it will need to appear in the patch system
for me to apply it. Details linked via my signature below.
Thanks.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] arm: Add runtime constant support for armv7 and !THUMB2_KERNEL
2026-02-21 16:03 ` Russell King (Oracle)
@ 2026-02-23 12:19 ` Jisheng Zhang
0 siblings, 0 replies; 3+ messages in thread
From: Jisheng Zhang @ 2026-02-23 12:19 UTC (permalink / raw)
To: Russell King (Oracle); +Cc: linux-arm-kernel, linux-kernel
On Sat, Feb 21, 2026 at 04:03:16PM +0000, Russell King (Oracle) wrote:
> On Sat, Feb 21, 2026 at 10:18:31PM +0800, Jisheng Zhang wrote:
> > Implement the runtime constant infrastructure for
> > armv7 && !THUMB2_KERNEL. So that armv7 can use this infrastructure
> > to generate constants to be used by the d_hash(), dentry_cache(),
> > names_cache() and so on.
> >
> > This is the armv7 variant of commit 94a2bc0f611c ("arm64: add 'runtime
> > constant' support") and commit e3c92e81711d ("runtime constants: add
> > x86 architecture support").
> >
> > As for < armv7 or THUMB2_KERNEL, we fall back to the generic
> > runtime-constant.h, no functionality changes.
> >
> > Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
>
> This looks fine to me, but it will need to appear in the patch system
> for me to apply it. Details linked via my signature below.
Thanks for the code review. Will put it into the patch system.
>
> Thanks.
>
> --
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-23 12:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-21 14:18 [PATCH] arm: Add runtime constant support for armv7 and !THUMB2_KERNEL Jisheng Zhang
2026-02-21 16:03 ` Russell King (Oracle)
2026-02-23 12:19 ` Jisheng Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox