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.h37
1 files changed, 14 insertions, 23 deletions
diff --git a/include/linux/module.h b/include/linux/module.h
index 6cb1a3cab5d3..dd618eb026aa 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>
@@ -363,11 +363,9 @@ struct module
363 /* Destruction function. */ 363 /* Destruction function. */
364 void (*exit)(void); 364 void (*exit)(void);
365 365
366#ifdef CONFIG_SMP 366 struct module_ref {
367 char *refptr; 367 int count;
368#else 368 } __percpu *refptr;
369 local_t ref;
370#endif
371#endif 369#endif
372 370
373#ifdef CONFIG_CONSTRUCTORS 371#ifdef CONFIG_CONSTRUCTORS
@@ -454,25 +452,16 @@ void __symbol_put(const char *symbol);
454#define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x) 452#define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x)
455void symbol_put_addr(void *addr); 453void symbol_put_addr(void *addr);
456 454
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 455/* 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). */ 456 to handle the error case (which only happens with rmmod --wait). */
468static inline void __module_get(struct module *module) 457static inline void __module_get(struct module *module)
469{ 458{
470 if (module) { 459 if (module) {
471 unsigned int cpu = get_cpu(); 460 preempt_disable();
472 local_inc(__module_ref_addr(module, cpu)); 461 __this_cpu_inc(module->refptr->count);
473 trace_module_get(module, _THIS_IP_, 462 trace_module_get(module, _THIS_IP_,
474 local_read(__module_ref_addr(module, cpu))); 463 __this_cpu_read(module->refptr->count));
475 put_cpu(); 464 preempt_enable();
476 } 465 }
477} 466}
478 467
@@ -481,15 +470,17 @@ static inline int try_module_get(struct module *module)
481 int ret = 1; 470 int ret = 1;
482 471
483 if (module) { 472 if (module) {
484 unsigned int cpu = get_cpu(); 473 preempt_disable();
474
485 if (likely(module_is_live(module))) { 475 if (likely(module_is_live(module))) {
486 local_inc(__module_ref_addr(module, cpu)); 476 __this_cpu_inc(module->refptr->count);
487 trace_module_get(module, _THIS_IP_, 477 trace_module_get(module, _THIS_IP_,
488 local_read(__module_ref_addr(module, cpu))); 478 __this_cpu_read(module->refptr->count));
489 } 479 }
490 else 480 else
491 ret = 0; 481 ret = 0;
492 put_cpu(); 482
483 preempt_enable();
493 } 484 }
494 return ret; 485 return ret;
495} 486}