aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/module.h
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2015-11-25 18:14:08 -0500
committerJiri Kosina <jkosina@suse.cz>2015-12-04 16:46:25 -0500
commit7523e4dc5057e157212b4741abd6256e03404cf1 (patch)
tree034014d98dea3f675e8e138bc34bd4e0a860b12b /include/linux/module.h
parentc65abf358f211c3f88c8ed714dff25775ab49fc1 (diff)
module: use a structure to encapsulate layout.
Makes it easier to handle init vs core cleanly, though the change is fairly invasive across random architectures. It simplifies the rbtree code immediately, however, while keeping the core data together in the same cachline (now iff the rbtree code is enabled). Acked-by: Peter Zijlstra <peterz@infradead.org> Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'include/linux/module.h')
-rw-r--r--include/linux/module.h64
1 files changed, 29 insertions, 35 deletions
diff --git a/include/linux/module.h b/include/linux/module.h
index 3a19c79918e0..6e68e8cf4d0d 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -302,6 +302,28 @@ struct mod_tree_node {
302 struct latch_tree_node node; 302 struct latch_tree_node node;
303}; 303};
304 304
305struct module_layout {
306 /* The actual code + data. */
307 void *base;
308 /* Total size. */
309 unsigned int size;
310 /* The size of the executable code. */
311 unsigned int text_size;
312 /* Size of RO section of the module (text+rodata) */
313 unsigned int ro_size;
314
315#ifdef CONFIG_MODULES_TREE_LOOKUP
316 struct mod_tree_node mtn;
317#endif
318};
319
320#ifdef CONFIG_MODULES_TREE_LOOKUP
321/* Only touch one cacheline for common rbtree-for-core-layout case. */
322#define __module_layout_align ____cacheline_aligned
323#else
324#define __module_layout_align
325#endif
326
305struct module { 327struct module {
306 enum module_state state; 328 enum module_state state;
307 329
@@ -366,37 +388,9 @@ struct module {
366 /* Startup function. */ 388 /* Startup function. */
367 int (*init)(void); 389 int (*init)(void);
368 390
369 /* 391 /* Core layout: rbtree is accessed frequently, so keep together. */
370 * If this is non-NULL, vfree() after init() returns. 392 struct module_layout core_layout __module_layout_align;
371 * 393 struct module_layout init_layout;
372 * Cacheline align here, such that:
373 * module_init, module_core, init_size, core_size,
374 * init_text_size, core_text_size and mtn_core::{mod,node[0]}
375 * are on the same cacheline.
376 */
377 void *module_init ____cacheline_aligned;
378
379 /* Here is the actual code + data, vfree'd on unload. */
380 void *module_core;
381
382 /* Here are the sizes of the init and core sections */
383 unsigned int init_size, core_size;
384
385 /* The size of the executable code in each section. */
386 unsigned int init_text_size, core_text_size;
387
388#ifdef CONFIG_MODULES_TREE_LOOKUP
389 /*
390 * We want mtn_core::{mod,node[0]} to be in the same cacheline as the
391 * above entries such that a regular lookup will only touch one
392 * cacheline.
393 */
394 struct mod_tree_node mtn_core;
395 struct mod_tree_node mtn_init;
396#endif
397
398 /* Size of RO sections of the module (text+rodata) */
399 unsigned int init_ro_size, core_ro_size;
400 394
401 /* Arch-specific module values */ 395 /* Arch-specific module values */
402 struct mod_arch_specific arch; 396 struct mod_arch_specific arch;
@@ -505,15 +499,15 @@ bool is_module_text_address(unsigned long addr);
505static inline bool within_module_core(unsigned long addr, 499static inline bool within_module_core(unsigned long addr,
506 const struct module *mod) 500 const struct module *mod)
507{ 501{
508 return (unsigned long)mod->module_core <= addr && 502 return (unsigned long)mod->core_layout.base <= addr &&
509 addr < (unsigned long)mod->module_core + mod->core_size; 503 addr < (unsigned long)mod->core_layout.base + mod->core_layout.size;
510} 504}
511 505
512static inline bool within_module_init(unsigned long addr, 506static inline bool within_module_init(unsigned long addr,
513 const struct module *mod) 507 const struct module *mod)
514{ 508{
515 return (unsigned long)mod->module_init <= addr && 509 return (unsigned long)mod->init_layout.base <= addr &&
516 addr < (unsigned long)mod->module_init + mod->init_size; 510 addr < (unsigned long)mod->init_layout.base + mod->init_layout.size;
517} 511}
518 512
519static inline bool within_module(unsigned long addr, const struct module *mod) 513static inline bool within_module(unsigned long addr, const struct module *mod)