Skip to content

Commit e782985

Browse files
committed
runtime constants: add default dummy infrastructure
This adds the initial dummy support for 'runtime constants' for when an architecture doesn't actually support an implementation of fixing up said runtime constants. This ends up being the fallback to just using the variables as regular __ro_after_init variables, and changes the dcache d_hash() function to use this model. Signed-off-by: Linus Torvalds <[email protected]>
1 parent e60cc61 commit e782985

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

fs/dcache.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "internal.h"
3636
#include "mount.h"
3737

38+
#include <asm/runtime-const.h>
39+
3840
/*
3941
* Usage:
4042
* dcache->d_inode->i_lock protects:
@@ -102,7 +104,8 @@ static struct hlist_bl_head *dentry_hashtable __ro_after_init;
102104

103105
static inline struct hlist_bl_head *d_hash(unsigned long hashlen)
104106
{
105-
return dentry_hashtable + ((u32)hashlen >> d_hash_shift);
107+
return runtime_const_ptr(dentry_hashtable) +
108+
runtime_const_shift_right_32(hashlen, d_hash_shift);
106109
}
107110

108111
#define IN_LOOKUP_SHIFT 10
@@ -3129,6 +3132,9 @@ static void __init dcache_init_early(void)
31293132
0,
31303133
0);
31313134
d_hash_shift = 32 - d_hash_shift;
3135+
3136+
runtime_const_init(shift, d_hash_shift);
3137+
runtime_const_init(ptr, dentry_hashtable);
31323138
}
31333139

31343140
static void __init dcache_init(void)
@@ -3157,6 +3163,9 @@ static void __init dcache_init(void)
31573163
0,
31583164
0);
31593165
d_hash_shift = 32 - d_hash_shift;
3166+
3167+
runtime_const_init(shift, d_hash_shift);
3168+
runtime_const_init(ptr, dentry_hashtable);
31603169
}
31613170

31623171
/* SLAB cache for __getname() consumers */

include/asm-generic/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ mandatory-y += pci.h
4646
mandatory-y += percpu.h
4747
mandatory-y += pgalloc.h
4848
mandatory-y += preempt.h
49+
mandatory-y += runtime-const.h
4950
mandatory-y += rwonce.h
5051
mandatory-y += sections.h
5152
mandatory-y += serial.h
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _ASM_RUNTIME_CONST_H
3+
#define _ASM_RUNTIME_CONST_H
4+
5+
/*
6+
* This is the fallback for when the architecture doesn't
7+
* support the runtime const operations.
8+
*
9+
* We just use the actual symbols as-is.
10+
*/
11+
#define runtime_const_ptr(sym) (sym)
12+
#define runtime_const_shift_right_32(val, sym) ((u32)(val)>>(sym))
13+
#define runtime_const_init(type,sym) do { } while (0)
14+
15+
#endif

include/asm-generic/vmlinux.lds.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,14 @@
944944
#define CON_INITCALL \
945945
BOUNDED_SECTION_POST_LABEL(.con_initcall.init, __con_initcall, _start, _end)
946946

947+
#define RUNTIME_NAME(t,x) runtime_##t##_##x
948+
949+
#define RUNTIME_CONST(t,x) \
950+
. = ALIGN(8); \
951+
RUNTIME_NAME(t,x) : AT(ADDR(RUNTIME_NAME(t,x)) - LOAD_OFFSET) { \
952+
*(RUNTIME_NAME(t,x)); \
953+
}
954+
947955
/* Alignment must be consistent with (kunit_suite *) in include/kunit/test.h */
948956
#define KUNIT_TABLE() \
949957
. = ALIGN(8); \

0 commit comments

Comments
 (0)