Skip to content

Commit 4e3c09e

Browse files
committed
Merge tag 'v6.5-rc1-modules-next' of git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux
Pull module updates from Luis Chamberlain: "The changes queued up for modules are pretty tame, mostly code removal of moving of code. Only two minor functional changes are made, the only one which stands out is Sebastian Andrzej Siewior's simplification of module reference counting by removing preempt_disable() and that has been tested on linux-next for well over a month without no regressions. I'm now, I guess, also a kitchen sink for some kallsyms changes" [ There was a mis-communication about the concurrent module load changes that I had expected to come through Luis despite me authoring the patch. So some of the module updates were left hanging in the email ether, and I just committed them separately. It's my bad - I should have made it more clear that I expected my own patches to come through the module tree too. Now they missed linux-next, but hopefully that won't cause any issues - Linus ] * tag 'v6.5-rc1-modules-next' of git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux: kallsyms: make kallsyms_show_value() as generic function kallsyms: move kallsyms_show_value() out of kallsyms.c kallsyms: remove unsed API lookup_symbol_attrs kallsyms: remove unused arch_get_kallsym() helper module: Remove preempt_disable() from module reference counting.
2 parents 9b9879f + 0eeaf1e commit 4e3c09e

File tree

8 files changed

+49
-152
lines changed

8 files changed

+49
-152
lines changed

include/linux/kallsyms.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ static inline void *dereference_symbol_descriptor(void *ptr)
6565
return ptr;
6666
}
6767

68+
/* How and when do we show kallsyms values? */
69+
extern bool kallsyms_show_value(const struct cred *cred);
70+
6871
#ifdef CONFIG_KALLSYMS
6972
unsigned long kallsyms_sym_address(int idx);
7073
int kallsyms_on_each_symbol(int (*fn)(void *, const char *, unsigned long),
@@ -93,10 +96,6 @@ extern int sprint_backtrace(char *buffer, unsigned long address);
9396
extern int sprint_backtrace_build_id(char *buffer, unsigned long address);
9497

9598
int lookup_symbol_name(unsigned long addr, char *symname);
96-
int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
97-
98-
/* How and when do we show kallsyms values? */
99-
extern bool kallsyms_show_value(const struct cred *cred);
10099

101100
#else /* !CONFIG_KALLSYMS */
102101

@@ -155,16 +154,6 @@ static inline int lookup_symbol_name(unsigned long addr, char *symname)
155154
return -ERANGE;
156155
}
157156

158-
static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
159-
{
160-
return -ERANGE;
161-
}
162-
163-
static inline bool kallsyms_show_value(const struct cred *cred)
164-
{
165-
return false;
166-
}
167-
168157
static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *, unsigned long),
169158
void *data)
170159
{

include/linux/module.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -968,15 +968,6 @@ static inline int lookup_module_symbol_name(unsigned long addr, char *symname)
968968
return -ERANGE;
969969
}
970970

971-
static inline int lookup_module_symbol_attrs(unsigned long addr,
972-
unsigned long *size,
973-
unsigned long *offset,
974-
char *modname,
975-
char *name)
976-
{
977-
return -ERANGE;
978-
}
979-
980971
static inline int module_get_kallsym(unsigned int symnum, unsigned long *value,
981972
char *type, char *name,
982973
char *module_name, int *exported)

kernel/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ obj-y = fork.o exec_domain.o panic.o \
1010
extable.o params.o \
1111
kthread.o sys_ni.o nsproxy.o \
1212
notifier.o ksysfs.o cred.o reboot.o \
13-
async.o range.o smpboot.o ucount.o regset.o
13+
async.o range.o smpboot.o ucount.o regset.o ksyms_common.o
1414

1515
obj-$(CONFIG_USERMODE_DRIVER) += usermode_driver.o
1616
obj-$(CONFIG_MULTIUSER) += groups.o

kernel/kallsyms.c

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -484,34 +484,6 @@ int lookup_symbol_name(unsigned long addr, char *symname)
484484
return 0;
485485
}
486486

487-
int lookup_symbol_attrs(unsigned long addr, unsigned long *size,
488-
unsigned long *offset, char *modname, char *name)
489-
{
490-
int res;
491-
492-
name[0] = '\0';
493-
name[KSYM_NAME_LEN - 1] = '\0';
494-
495-
if (is_ksym_addr(addr)) {
496-
unsigned long pos;
497-
498-
pos = get_symbol_pos(addr, size, offset);
499-
/* Grab name */
500-
kallsyms_expand_symbol(get_symbol_offset(pos),
501-
name, KSYM_NAME_LEN);
502-
modname[0] = '\0';
503-
goto found;
504-
}
505-
/* See if it's in a module. */
506-
res = lookup_module_symbol_attrs(addr, size, offset, modname, name);
507-
if (res)
508-
return res;
509-
510-
found:
511-
cleanup_symbol_name(name);
512-
return 0;
513-
}
514-
515487
/* Look up a kernel symbol and return it in a text buffer. */
516488
static int __sprint_symbol(char *buffer, unsigned long address,
517489
int symbol_offset, int add_offset, int add_buildid)
@@ -646,7 +618,6 @@ int sprint_backtrace_build_id(char *buffer, unsigned long address)
646618
/* To avoid using get_symbol_offset for every symbol, we carry prefix along. */
647619
struct kallsym_iter {
648620
loff_t pos;
649-
loff_t pos_arch_end;
650621
loff_t pos_mod_end;
651622
loff_t pos_ftrace_mod_end;
652623
loff_t pos_bpf_end;
@@ -659,29 +630,9 @@ struct kallsym_iter {
659630
int show_value;
660631
};
661632

662-
int __weak arch_get_kallsym(unsigned int symnum, unsigned long *value,
663-
char *type, char *name)
664-
{
665-
return -EINVAL;
666-
}
667-
668-
static int get_ksymbol_arch(struct kallsym_iter *iter)
669-
{
670-
int ret = arch_get_kallsym(iter->pos - kallsyms_num_syms,
671-
&iter->value, &iter->type,
672-
iter->name);
673-
674-
if (ret < 0) {
675-
iter->pos_arch_end = iter->pos;
676-
return 0;
677-
}
678-
679-
return 1;
680-
}
681-
682633
static int get_ksymbol_mod(struct kallsym_iter *iter)
683634
{
684-
int ret = module_get_kallsym(iter->pos - iter->pos_arch_end,
635+
int ret = module_get_kallsym(iter->pos - kallsyms_num_syms,
685636
&iter->value, &iter->type,
686637
iter->name, iter->module_name,
687638
&iter->exported);
@@ -764,7 +715,6 @@ static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
764715
iter->nameoff = get_symbol_offset(new_pos);
765716
iter->pos = new_pos;
766717
if (new_pos == 0) {
767-
iter->pos_arch_end = 0;
768718
iter->pos_mod_end = 0;
769719
iter->pos_ftrace_mod_end = 0;
770720
iter->pos_bpf_end = 0;
@@ -780,10 +730,6 @@ static int update_iter_mod(struct kallsym_iter *iter, loff_t pos)
780730
{
781731
iter->pos = pos;
782732

783-
if ((!iter->pos_arch_end || iter->pos_arch_end > pos) &&
784-
get_ksymbol_arch(iter))
785-
return 1;
786-
787733
if ((!iter->pos_mod_end || iter->pos_mod_end > pos) &&
788734
get_ksymbol_mod(iter))
789735
return 1;
@@ -961,41 +907,6 @@ late_initcall(bpf_ksym_iter_register);
961907

962908
#endif /* CONFIG_BPF_SYSCALL */
963909

964-
static inline int kallsyms_for_perf(void)
965-
{
966-
#ifdef CONFIG_PERF_EVENTS
967-
extern int sysctl_perf_event_paranoid;
968-
if (sysctl_perf_event_paranoid <= 1)
969-
return 1;
970-
#endif
971-
return 0;
972-
}
973-
974-
/*
975-
* We show kallsyms information even to normal users if we've enabled
976-
* kernel profiling and are explicitly not paranoid (so kptr_restrict
977-
* is clear, and sysctl_perf_event_paranoid isn't set).
978-
*
979-
* Otherwise, require CAP_SYSLOG (assuming kptr_restrict isn't set to
980-
* block even that).
981-
*/
982-
bool kallsyms_show_value(const struct cred *cred)
983-
{
984-
switch (kptr_restrict) {
985-
case 0:
986-
if (kallsyms_for_perf())
987-
return true;
988-
fallthrough;
989-
case 1:
990-
if (security_capable(cred, &init_user_ns, CAP_SYSLOG,
991-
CAP_OPT_NOAUDIT) == 0)
992-
return true;
993-
fallthrough;
994-
default:
995-
return false;
996-
}
997-
}
998-
999910
static int kallsyms_open(struct inode *inode, struct file *file)
1000911
{
1001912
/*

kernel/ksyms_common.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* ksyms_common.c: A split of kernel/kallsyms.c
4+
* Contains a few generic function definations independent of config KALLSYMS.
5+
*/
6+
#include <linux/kallsyms.h>
7+
#include <linux/security.h>
8+
9+
static inline int kallsyms_for_perf(void)
10+
{
11+
#ifdef CONFIG_PERF_EVENTS
12+
extern int sysctl_perf_event_paranoid;
13+
14+
if (sysctl_perf_event_paranoid <= 1)
15+
return 1;
16+
#endif
17+
return 0;
18+
}
19+
20+
/*
21+
* We show kallsyms information even to normal users if we've enabled
22+
* kernel profiling and are explicitly not paranoid (so kptr_restrict
23+
* is clear, and sysctl_perf_event_paranoid isn't set).
24+
*
25+
* Otherwise, require CAP_SYSLOG (assuming kptr_restrict isn't set to
26+
* block even that).
27+
*/
28+
bool kallsyms_show_value(const struct cred *cred)
29+
{
30+
switch (kptr_restrict) {
31+
case 0:
32+
if (kallsyms_for_perf())
33+
return true;
34+
fallthrough;
35+
case 1:
36+
if (security_capable(cred, &init_user_ns, CAP_SYSLOG,
37+
CAP_OPT_NOAUDIT) == 0)
38+
return true;
39+
fallthrough;
40+
default:
41+
return false;
42+
}
43+
}

kernel/module/kallsyms.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -381,34 +381,6 @@ int lookup_module_symbol_name(unsigned long addr, char *symname)
381381
return -ERANGE;
382382
}
383383

384-
int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size,
385-
unsigned long *offset, char *modname, char *name)
386-
{
387-
struct module *mod;
388-
389-
preempt_disable();
390-
list_for_each_entry_rcu(mod, &modules, list) {
391-
if (mod->state == MODULE_STATE_UNFORMED)
392-
continue;
393-
if (within_module(addr, mod)) {
394-
const char *sym;
395-
396-
sym = find_kallsyms_symbol(mod, addr, size, offset);
397-
if (!sym)
398-
goto out;
399-
if (modname)
400-
strscpy(modname, mod->name, MODULE_NAME_LEN);
401-
if (name)
402-
strscpy(name, sym, KSYM_NAME_LEN);
403-
preempt_enable();
404-
return 0;
405-
}
406-
}
407-
out:
408-
preempt_enable();
409-
return -ERANGE;
410-
}
411-
412384
int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
413385
char *name, char *module_name, int *exported)
414386
{

kernel/module/main.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -820,10 +820,8 @@ static struct module_attribute modinfo_refcnt =
820820
void __module_get(struct module *module)
821821
{
822822
if (module) {
823-
preempt_disable();
824823
atomic_inc(&module->refcnt);
825824
trace_module_get(module, _RET_IP_);
826-
preempt_enable();
827825
}
828826
}
829827
EXPORT_SYMBOL(__module_get);
@@ -833,15 +831,12 @@ bool try_module_get(struct module *module)
833831
bool ret = true;
834832

835833
if (module) {
836-
preempt_disable();
837834
/* Note: here, we can fail to get a reference */
838835
if (likely(module_is_live(module) &&
839836
atomic_inc_not_zero(&module->refcnt) != 0))
840837
trace_module_get(module, _RET_IP_);
841838
else
842839
ret = false;
843-
844-
preempt_enable();
845840
}
846841
return ret;
847842
}
@@ -852,11 +847,9 @@ void module_put(struct module *module)
852847
int ret;
853848

854849
if (module) {
855-
preempt_disable();
856850
ret = atomic_dec_if_positive(&module->refcnt);
857851
WARN_ON(ret < 0); /* Failed to put refcount */
858852
trace_module_put(module, _RET_IP_);
859-
preempt_enable();
860853
}
861854
}
862855
EXPORT_SYMBOL(module_put);

tools/testing/selftests/bpf/progs/bpf_iter_ksym.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ int dump_ksym(struct bpf_iter__ksym *ctx)
5959
} else {
6060
BPF_SEQ_PRINTF(seq, "0x%llx %c %s ", value, type, iter->name);
6161
}
62-
if (!iter->pos_arch_end || iter->pos_arch_end > iter->pos)
63-
BPF_SEQ_PRINTF(seq, "CORE ");
64-
else if (!iter->pos_mod_end || iter->pos_mod_end > iter->pos)
62+
if (!iter->pos_mod_end || iter->pos_mod_end > iter->pos)
6563
BPF_SEQ_PRINTF(seq, "MOD ");
6664
else if (!iter->pos_ftrace_mod_end || iter->pos_ftrace_mod_end > iter->pos)
6765
BPF_SEQ_PRINTF(seq, "FTRACE_MOD ");

0 commit comments

Comments
 (0)