diff options
Diffstat (limited to 'include/linux/module.h')
| -rw-r--r-- | include/linux/module.h | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/include/linux/module.h b/include/linux/module.h index 6cb1a3cab5d3..515d53ae6a79 100644 --- a/include/linux/module.h +++ b/include/linux/module.h | |||
| @@ -17,7 +17,7 @@ | |||
| 17 | #include <linux/moduleparam.h> | 17 | #include <linux/moduleparam.h> |
| 18 | #include <linux/tracepoint.h> | 18 | #include <linux/tracepoint.h> |
| 19 | 19 | ||
| 20 | #include <asm/local.h> | 20 | #include <linux/percpu.h> |
| 21 | #include <asm/module.h> | 21 | #include <asm/module.h> |
| 22 | 22 | ||
| 23 | #include <trace/events/module.h> | 23 | #include <trace/events/module.h> |
| @@ -175,6 +175,7 @@ struct notifier_block; | |||
| 175 | 175 | ||
| 176 | #ifdef CONFIG_MODULES | 176 | #ifdef CONFIG_MODULES |
| 177 | 177 | ||
| 178 | extern int modules_disabled; /* for sysctl */ | ||
| 178 | /* Get/put a kernel symbol (calls must be symmetric) */ | 179 | /* Get/put a kernel symbol (calls must be symmetric) */ |
| 179 | void *__symbol_get(const char *symbol); | 180 | void *__symbol_get(const char *symbol); |
| 180 | void *__symbol_get_gpl(const char *symbol); | 181 | void *__symbol_get_gpl(const char *symbol); |
| @@ -329,8 +330,11 @@ struct module | |||
| 329 | struct module_notes_attrs *notes_attrs; | 330 | struct module_notes_attrs *notes_attrs; |
| 330 | #endif | 331 | #endif |
| 331 | 332 | ||
| 333 | #ifdef CONFIG_SMP | ||
| 332 | /* Per-cpu data. */ | 334 | /* Per-cpu data. */ |
| 333 | void *percpu; | 335 | void __percpu *percpu; |
| 336 | unsigned int percpu_size; | ||
| 337 | #endif | ||
| 334 | 338 | ||
| 335 | /* The command line arguments (may be mangled). People like | 339 | /* The command line arguments (may be mangled). People like |
| 336 | keeping pointers to this stuff */ | 340 | keeping pointers to this stuff */ |
| @@ -363,11 +367,10 @@ struct module | |||
| 363 | /* Destruction function. */ | 367 | /* Destruction function. */ |
| 364 | void (*exit)(void); | 368 | void (*exit)(void); |
| 365 | 369 | ||
| 366 | #ifdef CONFIG_SMP | 370 | struct module_ref { |
| 367 | char *refptr; | 371 | unsigned int incs; |
| 368 | #else | 372 | unsigned int decs; |
| 369 | local_t ref; | 373 | } __percpu *refptr; |
| 370 | #endif | ||
| 371 | #endif | 374 | #endif |
| 372 | 375 | ||
| 373 | #ifdef CONFIG_CONSTRUCTORS | 376 | #ifdef CONFIG_CONSTRUCTORS |
| @@ -393,6 +396,7 @@ static inline int module_is_live(struct module *mod) | |||
| 393 | struct module *__module_text_address(unsigned long addr); | 396 | struct module *__module_text_address(unsigned long addr); |
| 394 | struct module *__module_address(unsigned long addr); | 397 | struct module *__module_address(unsigned long addr); |
| 395 | bool is_module_address(unsigned long addr); | 398 | bool is_module_address(unsigned long addr); |
| 399 | bool is_module_percpu_address(unsigned long addr); | ||
| 396 | bool is_module_text_address(unsigned long addr); | 400 | bool is_module_text_address(unsigned long addr); |
| 397 | 401 | ||
| 398 | static inline int within_module_core(unsigned long addr, struct module *mod) | 402 | static inline int within_module_core(unsigned long addr, struct module *mod) |
| @@ -454,25 +458,16 @@ void __symbol_put(const char *symbol); | |||
| 454 | #define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x) | 458 | #define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x) |
| 455 | void symbol_put_addr(void *addr); | 459 | void symbol_put_addr(void *addr); |
| 456 | 460 | ||
| 457 | static inline local_t *__module_ref_addr(struct module *mod, int cpu) | ||
| 458 | { | ||
| 459 | #ifdef CONFIG_SMP | ||
| 460 | return (local_t *) (mod->refptr + per_cpu_offset(cpu)); | ||
| 461 | #else | ||
| 462 | return &mod->ref; | ||
| 463 | #endif | ||
| 464 | } | ||
| 465 | |||
| 466 | /* Sometimes we know we already have a refcount, and it's easier not | 461 | /* Sometimes we know we already have a refcount, and it's easier not |
| 467 | to handle the error case (which only happens with rmmod --wait). */ | 462 | to handle the error case (which only happens with rmmod --wait). */ |
| 468 | static inline void __module_get(struct module *module) | 463 | static inline void __module_get(struct module *module) |
| 469 | { | 464 | { |
| 470 | if (module) { | 465 | if (module) { |
| 471 | unsigned int cpu = get_cpu(); | 466 | preempt_disable(); |
| 472 | local_inc(__module_ref_addr(module, cpu)); | 467 | __this_cpu_inc(module->refptr->incs); |
| 473 | trace_module_get(module, _THIS_IP_, | 468 | trace_module_get(module, _THIS_IP_, |
| 474 | local_read(__module_ref_addr(module, cpu))); | 469 | __this_cpu_read(module->refptr->incs)); |
| 475 | put_cpu(); | 470 | preempt_enable(); |
| 476 | } | 471 | } |
| 477 | } | 472 | } |
| 478 | 473 | ||
| @@ -481,15 +476,16 @@ static inline int try_module_get(struct module *module) | |||
| 481 | int ret = 1; | 476 | int ret = 1; |
| 482 | 477 | ||
| 483 | if (module) { | 478 | if (module) { |
| 484 | unsigned int cpu = get_cpu(); | 479 | preempt_disable(); |
| 480 | |||
| 485 | if (likely(module_is_live(module))) { | 481 | if (likely(module_is_live(module))) { |
| 486 | local_inc(__module_ref_addr(module, cpu)); | 482 | __this_cpu_inc(module->refptr->incs); |
| 487 | trace_module_get(module, _THIS_IP_, | 483 | trace_module_get(module, _THIS_IP_, |
| 488 | local_read(__module_ref_addr(module, cpu))); | 484 | __this_cpu_read(module->refptr->incs)); |
| 489 | } | 485 | } else |
| 490 | else | ||
| 491 | ret = 0; | 486 | ret = 0; |
| 492 | put_cpu(); | 487 | |
| 488 | preempt_enable(); | ||
| 493 | } | 489 | } |
| 494 | return ret; | 490 | return ret; |
| 495 | } | 491 | } |
| @@ -571,6 +567,11 @@ static inline bool is_module_address(unsigned long addr) | |||
| 571 | return false; | 567 | return false; |
| 572 | } | 568 | } |
| 573 | 569 | ||
| 570 | static inline bool is_module_percpu_address(unsigned long addr) | ||
| 571 | { | ||
| 572 | return false; | ||
| 573 | } | ||
| 574 | |||
| 574 | static inline bool is_module_text_address(unsigned long addr) | 575 | static inline bool is_module_text_address(unsigned long addr) |
| 575 | { | 576 | { |
| 576 | return false; | 577 | return false; |
