Skip to content

Commit cab4e4c

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-module-and-param
* git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-module-and-param: module: use strstarts() strstarts: helper function for !strncmp(str, prefix, strlen(prefix)) arm: allow usage of string functions in linux/string.h module: don't use stop_machine on module load module: create a request_module_nowait() module: include other structures in module version check module: remove the SHF_ALLOC flag on the __versions section. module: clarify the force-loading taint message. module: Export symbols needed for Ksplice Ksplice: Add functions for walking kallsyms symbols module: remove module_text_address() module: __module_address module: Make find_symbol return a struct kernel_symbol kernel/module.c: fix an unused goto label param: fix charp parameters set via sysfs Fix trivial conflicts in kernel/extable.c manually.
2 parents 5412b53 + 4950267 commit cab4e4c

13 files changed

Lines changed: 319 additions & 137 deletions

File tree

arch/arm/boot/compressed/misc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818

1919
unsigned int __machine_arch_type;
2020

21-
#include <linux/string.h>
21+
#include <linux/compiler.h> /* for inline */
22+
#include <linux/types.h> /* for size_t */
23+
#include <linux/stddef.h> /* for NULL */
24+
#include <asm/string.h>
2225

2326
#ifdef STANDALONE_DEBUG
2427
#define putstr printf

drivers/mtd/nand/nand_base.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,14 +2720,14 @@ int nand_scan_tail(struct mtd_info *mtd)
27202720
return chip->scan_bbt(mtd);
27212721
}
27222722

2723-
/* module_text_address() isn't exported, and it's mostly a pointless
2723+
/* is_module_text_address() isn't exported, and it's mostly a pointless
27242724
test if this is a module _anyway_ -- they'd have to try _really_ hard
27252725
to call us from in-kernel code if the core NAND support is modular. */
27262726
#ifdef MODULE
27272727
#define caller_is_module() (1)
27282728
#else
27292729
#define caller_is_module() \
2730-
module_text_address((unsigned long)__builtin_return_address(0))
2730+
is_module_text_address((unsigned long)__builtin_return_address(0))
27312731
#endif
27322732

27332733
/**

include/linux/kallsyms.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@
1313
#define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \
1414
2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1)
1515

16+
struct module;
17+
1618
#ifdef CONFIG_KALLSYMS
1719
/* Lookup the address for a symbol. Returns 0 if not found. */
1820
unsigned long kallsyms_lookup_name(const char *name);
1921

22+
/* Call a function on each kallsyms symbol in the core kernel */
23+
int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
24+
unsigned long),
25+
void *data);
26+
2027
extern int kallsyms_lookup_size_offset(unsigned long addr,
2128
unsigned long *symbolsize,
2229
unsigned long *offset);
@@ -43,6 +50,14 @@ static inline unsigned long kallsyms_lookup_name(const char *name)
4350
return 0;
4451
}
4552

53+
static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *,
54+
struct module *,
55+
unsigned long),
56+
void *data)
57+
{
58+
return 0;
59+
}
60+
4661
static inline int kallsyms_lookup_size_offset(unsigned long addr,
4762
unsigned long *symbolsize,
4863
unsigned long *offset)

include/linux/kmod.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@
2929
#ifdef CONFIG_MODULES
3030
/* modprobe exit status on success, -ve on error. Return value
3131
* usually useless though. */
32-
extern int request_module(const char * name, ...) __attribute__ ((format (printf, 1, 2)));
33-
#define try_then_request_module(x, mod...) ((x) ?: (request_module(mod), (x)))
32+
extern int __request_module(bool wait, const char *name, ...) \
33+
__attribute__((format(printf, 2, 3)));
34+
#define request_module(mod...) __request_module(true, mod)
35+
#define request_module_nowait(mod...) __request_module(false, mod)
36+
#define try_then_request_module(x, mod...) \
37+
((x) ?: (__request_module(false, mod), (x)))
3438
#else
35-
static inline int request_module(const char * name, ...) { return -ENOSYS; }
39+
static inline int request_module(const char *name, ...) { return -ENOSYS; }
40+
static inline int request_module_nowait(const char *name, ...) { return -ENOSYS; }
3641
#define try_then_request_module(x, mod...) (x)
3742
#endif
3843

include/linux/module.h

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ struct module
248248
const unsigned long *crcs;
249249
unsigned int num_syms;
250250

251+
/* Kernel parameters. */
252+
struct kernel_param *kp;
253+
unsigned int num_kp;
254+
251255
/* GPL-only exported symbols. */
252256
unsigned int num_gpl_syms;
253257
const struct kernel_symbol *gpl_syms;
@@ -350,6 +354,8 @@ struct module
350354
#define MODULE_ARCH_INIT {}
351355
#endif
352356

357+
extern struct mutex module_mutex;
358+
353359
/* FIXME: It'd be nice to isolate modules during init, too, so they
354360
aren't used before they (may) fail. But presently too much code
355361
(IDE & SCSI) require entry into the module during init.*/
@@ -358,10 +364,10 @@ static inline int module_is_live(struct module *mod)
358364
return mod->state != MODULE_STATE_GOING;
359365
}
360366

361-
/* Is this address in a module? (second is with no locks, for oops) */
362-
struct module *module_text_address(unsigned long addr);
363367
struct module *__module_text_address(unsigned long addr);
364-
int is_module_address(unsigned long addr);
368+
struct module *__module_address(unsigned long addr);
369+
bool is_module_address(unsigned long addr);
370+
bool is_module_text_address(unsigned long addr);
365371

366372
static inline int within_module_core(unsigned long addr, struct module *mod)
367373
{
@@ -375,6 +381,31 @@ static inline int within_module_init(unsigned long addr, struct module *mod)
375381
addr < (unsigned long)mod->module_init + mod->init_size;
376382
}
377383

384+
/* Search for module by name: must hold module_mutex. */
385+
struct module *find_module(const char *name);
386+
387+
struct symsearch {
388+
const struct kernel_symbol *start, *stop;
389+
const unsigned long *crcs;
390+
enum {
391+
NOT_GPL_ONLY,
392+
GPL_ONLY,
393+
WILL_BE_GPL_ONLY,
394+
} licence;
395+
bool unused;
396+
};
397+
398+
/* Search for an exported symbol by name. */
399+
const struct kernel_symbol *find_symbol(const char *name,
400+
struct module **owner,
401+
const unsigned long **crc,
402+
bool gplok,
403+
bool warn);
404+
405+
/* Walk the exported symbol table */
406+
bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
407+
unsigned int symnum, void *data), void *data);
408+
378409
/* Returns 0 and fills in value, defined and namebuf, or -ERANGE if
379410
symnum out of range. */
380411
int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
@@ -383,6 +414,10 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
383414
/* Look for this name: can be of form module:name. */
384415
unsigned long module_kallsyms_lookup_name(const char *name);
385416

417+
int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
418+
struct module *, unsigned long),
419+
void *data);
420+
386421
extern void __module_put_and_exit(struct module *mod, long code)
387422
__attribute__((noreturn));
388423
#define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code);
@@ -444,6 +479,7 @@ static inline void __module_get(struct module *module)
444479
#define symbol_put_addr(p) do { } while(0)
445480

446481
#endif /* CONFIG_MODULE_UNLOAD */
482+
int use_module(struct module *a, struct module *b);
447483

448484
/* This is a #define so the string doesn't get put in every .o file */
449485
#define module_name(mod) \
@@ -490,21 +526,24 @@ search_module_extables(unsigned long addr)
490526
return NULL;
491527
}
492528

493-
/* Is this address in a module? */
494-
static inline struct module *module_text_address(unsigned long addr)
529+
static inline struct module *__module_address(unsigned long addr)
495530
{
496531
return NULL;
497532
}
498533

499-
/* Is this address in a module? (don't take a lock, we're oopsing) */
500534
static inline struct module *__module_text_address(unsigned long addr)
501535
{
502536
return NULL;
503537
}
504538

505-
static inline int is_module_address(unsigned long addr)
539+
static inline bool is_module_address(unsigned long addr)
506540
{
507-
return 0;
541+
return false;
542+
}
543+
544+
static inline bool is_module_text_address(unsigned long addr)
545+
{
546+
return false;
508547
}
509548

510549
/* Get/put a kernel symbol (calls should be symmetric) */
@@ -559,6 +598,14 @@ static inline unsigned long module_kallsyms_lookup_name(const char *name)
559598
return 0;
560599
}
561600

601+
static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
602+
struct module *,
603+
unsigned long),
604+
void *data)
605+
{
606+
return 0;
607+
}
608+
562609
static inline int register_module_notifier(struct notifier_block * nb)
563610
{
564611
/* no events will happen anyway, so this can always succeed */

include/linux/moduleparam.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ extern int parse_args(const char *name,
138138
unsigned num,
139139
int (*unknown)(char *param, char *val));
140140

141+
/* Called by module remove. */
142+
#ifdef CONFIG_SYSFS
143+
extern void destroy_params(const struct kernel_param *params, unsigned num);
144+
#else
145+
static inline void destroy_params(const struct kernel_param *params,
146+
unsigned num)
147+
{
148+
}
149+
#endif /* !CONFIG_SYSFS */
150+
141151
/* All the helper functions */
142152
/* The macros to do compile-time type checking stolen from Jakub
143153
Jelinek, who IIRC came up with this idea for the 2.4 module init code. */

include/linux/string.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,14 @@ int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) __printf(3, 4);
122122
extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
123123
const void *from, size_t available);
124124

125+
/**
126+
* strstarts - does @str start with @prefix?
127+
* @str: string to examine
128+
* @prefix: prefix to look for.
129+
*/
130+
static inline bool strstarts(const char *str, const char *prefix)
131+
{
132+
return strncmp(str, prefix, strlen(prefix)) == 0;
133+
}
125134
#endif
126135
#endif /* _LINUX_STRING_H_ */

kernel/extable.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ __notrace_funcgraph int __kernel_text_address(unsigned long addr)
6565
{
6666
if (core_kernel_text(addr))
6767
return 1;
68-
if (__module_text_address(addr))
68+
if (is_module_text_address(addr))
6969
return 1;
7070
/*
7171
* There might be init symbols in saved stacktraces.
@@ -84,7 +84,7 @@ int kernel_text_address(unsigned long addr)
8484
{
8585
if (core_kernel_text(addr))
8686
return 1;
87-
return module_text_address(addr) != NULL;
87+
return is_module_text_address(addr);
8888
}
8989

9090
/*
@@ -100,5 +100,5 @@ int func_ptr_is_kernel_text(void *ptr)
100100
addr = (unsigned long) dereference_function_descriptor(ptr);
101101
if (core_kernel_text(addr))
102102
return 1;
103-
return module_text_address(addr) != NULL;
103+
return is_module_text_address(addr);
104104
}

kernel/kallsyms.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,25 @@ unsigned long kallsyms_lookup_name(const char *name)
161161
return module_kallsyms_lookup_name(name);
162162
}
163163

164+
int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
165+
unsigned long),
166+
void *data)
167+
{
168+
char namebuf[KSYM_NAME_LEN];
169+
unsigned long i;
170+
unsigned int off;
171+
int ret;
172+
173+
for (i = 0, off = 0; i < kallsyms_num_syms; i++) {
174+
off = kallsyms_expand_symbol(off, namebuf);
175+
ret = fn(data, namebuf, NULL, kallsyms_addresses[i]);
176+
if (ret != 0)
177+
return ret;
178+
}
179+
return module_kallsyms_on_each_symbol(fn, data);
180+
}
181+
EXPORT_SYMBOL_GPL(kallsyms_on_each_symbol);
182+
164183
static unsigned long get_symbol_pos(unsigned long addr,
165184
unsigned long *symbolsize,
166185
unsigned long *offset)

kernel/kmod.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ static struct workqueue_struct *khelper_wq;
5050
char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
5151

5252
/**
53-
* request_module - try to load a kernel module
53+
* __request_module - try to load a kernel module
54+
* @wait: wait (or not) for the operation to complete
5455
* @fmt: printf style format string for the name of the module
5556
* @...: arguments as specified in the format string
5657
*
@@ -63,7 +64,7 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
6364
* If module auto-loading support is disabled then this function
6465
* becomes a no-operation.
6566
*/
66-
int request_module(const char *fmt, ...)
67+
int __request_module(bool wait, const char *fmt, ...)
6768
{
6869
va_list args;
6970
char module_name[MODULE_NAME_LEN];
@@ -108,11 +109,12 @@ int request_module(const char *fmt, ...)
108109
return -ENOMEM;
109110
}
110111

111-
ret = call_usermodehelper(modprobe_path, argv, envp, 1);
112+
ret = call_usermodehelper(modprobe_path, argv, envp,
113+
wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
112114
atomic_dec(&kmod_concurrent);
113115
return ret;
114116
}
115-
EXPORT_SYMBOL(request_module);
117+
EXPORT_SYMBOL(__request_module);
116118
#endif /* CONFIG_MODULES */
117119

118120
struct subprocess_info {

0 commit comments

Comments
 (0)