aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/module.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/module.h')
-rw-r--r--include/linux/module.h55
1 files changed, 27 insertions, 28 deletions
diff --git a/include/linux/module.h b/include/linux/module.h
index 6cb1a3cab5d3..6914fcad4673 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
178extern 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) */
179void *__symbol_get(const char *symbol); 180void *__symbol_get(const char *symbol);
180void *__symbol_get_gpl(const char *symbol); 181void *__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)
393struct module *__module_text_address(unsigned long addr); 396struct module *__module_text_address(unsigned long addr);
394struct module *__module_address(unsigned long addr); 397struct module *__module_address(unsigned long addr);
395bool is_module_address(unsigned long addr); 398bool is_module_address(unsigned long addr);
399bool is_module_percpu_address(unsigned long addr);
396bool is_module_text_address(unsigned long addr); 400bool is_module_text_address(unsigned long addr);
397 401
398static inline int within_module_core(unsigned long addr, struct module *mod) 402static inline int within_module_core(unsigned long addr, struct module *mod)
@@ -454,25 +458,15 @@ 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)
455void symbol_put_addr(void *addr); 459void symbol_put_addr(void *addr);
456 460
457static 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). */
468static inline void __module_get(struct module *module) 463static 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 preempt_enable();
475 put_cpu();
476 } 470 }
477} 471}
478 472
@@ -481,15 +475,15 @@ static inline int try_module_get(struct module *module)
481 int ret = 1; 475 int ret = 1;
482 476
483 if (module) { 477 if (module) {
484 unsigned int cpu = get_cpu(); 478 preempt_disable();
479
485 if (likely(module_is_live(module))) { 480 if (likely(module_is_live(module))) {
486 local_inc(__module_ref_addr(module, cpu)); 481 __this_cpu_inc(module->refptr->incs);
487 trace_module_get(module, _THIS_IP_, 482 trace_module_get(module, _THIS_IP_);
488 local_read(__module_ref_addr(module, cpu))); 483 } else
489 }
490 else
491 ret = 0; 484 ret = 0;
492 put_cpu(); 485
486 preempt_enable();
493 } 487 }
494 return ret; 488 return ret;
495} 489}
@@ -571,6 +565,11 @@ static inline bool is_module_address(unsigned long addr)
571 return false; 565 return false;
572} 566}
573 567
568static inline bool is_module_percpu_address(unsigned long addr)
569{
570 return false;
571}
572
574static inline bool is_module_text_address(unsigned long addr) 573static inline bool is_module_text_address(unsigned long addr)
575{ 574{
576 return false; 575 return false;