Skip to content

Commit e3c92e8

Browse files
committed
runtime constants: add x86 architecture support
This implements the runtime constant infrastructure for x86, allowing the dcache d_hash() function to be generated using as a constant for hash table address followed by shift by a constant of the hash index. Signed-off-by: Linus Torvalds <[email protected]>
1 parent e782985 commit e3c92e8

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _ASM_RUNTIME_CONST_H
3+
#define _ASM_RUNTIME_CONST_H
4+
5+
#define runtime_const_ptr(sym) ({ \
6+
typeof(sym) __ret; \
7+
asm_inline("mov %1,%0\n1:\n" \
8+
".pushsection runtime_ptr_" #sym ",\"a\"\n\t" \
9+
".long 1b - %c2 - .\n\t" \
10+
".popsection" \
11+
:"=r" (__ret) \
12+
:"i" ((unsigned long)0x0123456789abcdefull), \
13+
"i" (sizeof(long))); \
14+
__ret; })
15+
16+
// The 'typeof' will create at _least_ a 32-bit type, but
17+
// will happily also take a bigger type and the 'shrl' will
18+
// clear the upper bits
19+
#define runtime_const_shift_right_32(val, sym) ({ \
20+
typeof(0u+(val)) __ret = (val); \
21+
asm_inline("shrl $12,%k0\n1:\n" \
22+
".pushsection runtime_shift_" #sym ",\"a\"\n\t" \
23+
".long 1b - 1 - .\n\t" \
24+
".popsection" \
25+
:"+r" (__ret)); \
26+
__ret; })
27+
28+
#define runtime_const_init(type, sym) do { \
29+
extern s32 __start_runtime_##type##_##sym[]; \
30+
extern s32 __stop_runtime_##type##_##sym[]; \
31+
runtime_const_fixup(__runtime_fixup_##type, \
32+
(unsigned long)(sym), \
33+
__start_runtime_##type##_##sym, \
34+
__stop_runtime_##type##_##sym); \
35+
} while (0)
36+
37+
/*
38+
* The text patching is trivial - you can only do this at init time,
39+
* when the text section hasn't been marked RO, and before the text
40+
* has ever been executed.
41+
*/
42+
static inline void __runtime_fixup_ptr(void *where, unsigned long val)
43+
{
44+
*(unsigned long *)where = val;
45+
}
46+
47+
static inline void __runtime_fixup_shift(void *where, unsigned long val)
48+
{
49+
*(unsigned char *)where = val;
50+
}
51+
52+
static inline void runtime_const_fixup(void (*fn)(void *, unsigned long),
53+
unsigned long val, s32 *start, s32 *end)
54+
{
55+
while (start < end) {
56+
fn(*start + (void *)start, val);
57+
start++;
58+
}
59+
}
60+
61+
#endif

arch/x86/kernel/vmlinux.lds.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ SECTIONS
357357
PERCPU_SECTION(INTERNODE_CACHE_BYTES)
358358
#endif
359359

360+
RUNTIME_CONST(shift, d_hash_shift)
361+
RUNTIME_CONST(ptr, dentry_hashtable)
362+
360363
. = ALIGN(PAGE_SIZE);
361364

362365
/* freed after init ends here */

0 commit comments

Comments
 (0)