From: Peter Zijlstra <peterz@infradead.org>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: linux-kernel@vger.kernel.org, Josh Poimboeuf <jpoimboe@redhat.com>
Subject: Re: [PATCH 3/4] module: use a structure to encapsulate layout.
Date: Mon, 9 Nov 2015 10:41:50 +0100 [thread overview]
Message-ID: <20151109094150.GF17308@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1447043037-10833-4-git-send-email-rusty@rustcorp.com.au>
On Mon, Nov 09, 2015 at 02:53:56PM +1030, Rusty Russell wrote:
> 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 {
> struct latch_tree_node node;
> };
>
> +struct module_layout {
> + /* The actual code + data. */
> + void *base;
> + /* Total size. */
> + unsigned int size;
> + /* The size of the executable code. */
> + unsigned int text_size;
> + /* Size of RO section of the module (text+rodata) */
> + unsigned int ro_size;
There's a 4 byte hole here, but I suppose that's OK, this arrangement
does simplify things.
> +
> +#ifdef CONFIG_MODULES_TREE_LOOKUP
> + struct mod_tree_node mtn;
> +#endif
> +};
> +
> +#ifdef CONFIG_MODULES_TREE_LOOKUP
> +/* Only touch one cacheline for common rbtree-for-core-layout case. */
> +#define __module_layout_align ____cacheline_aligned
> +#else
> +#define __module_layout_align
> +#endif
> +
> struct module {
> enum module_state state;
>
> diff --git a/kernel/module.c b/kernel/module.c
> index 14b224967e7b..a0a3d6d9d5e8 100644
> --- a/kernel/module.c
> +++ b/kernel/module.c
> @@ -108,13 +108,6 @@ static LIST_HEAD(modules);
> * Use a latched RB-tree for __module_address(); this allows us to use
> * RCU-sched lookups of the address from any context.
> *
> - * Because modules have two address ranges: init and core, we need two
> - * latch_tree_nodes entries. Therefore we need the back-pointer from
> - * mod_tree_node.
We still have the back-pointers, so removing all of that seems a little
excessive.
> - *
> - * Because init ranges are short lived we mark them unlikely and have placed
> - * them outside the critical cacheline in struct module.
This information also isn't preserved.
> * This is conditional on PERF_EVENTS || TRACING because those can really hit
> * __module_address() hard by doing a lot of stack unwinding; potentially from
> * NMI context.
> @@ -122,24 +115,16 @@ static LIST_HEAD(modules);
>
> static __always_inline unsigned long __mod_tree_val(struct latch_tree_node *n)
> {
> - struct mod_tree_node *mtn = container_of(n, struct mod_tree_node, node);
> - struct module *mod = mtn->mod;
> + struct module_layout *layout = container_of(n, struct module_layout, mtn.node);
>
> - if (unlikely(mtn == &mod->mtn_init))
> - return (unsigned long)mod->module_init;
> -
> - return (unsigned long)mod->module_core;
> + return (unsigned long)layout->base;
> }
>
> static __always_inline unsigned long __mod_tree_size(struct latch_tree_node *n)
> {
> - struct mod_tree_node *mtn = container_of(n, struct mod_tree_node, node);
> - struct module *mod = mtn->mod;
> -
> - if (unlikely(mtn == &mod->mtn_init))
> - return (unsigned long)mod->init_size;
> + struct module_layout *layout = container_of(n, struct module_layout, mtn.node);
>
> - return (unsigned long)mod->core_size;
> + return (unsigned long)layout->size;
> }
Nice!
> @@ -197,23 +182,23 @@ static void __mod_tree_remove(struct mod_tree_node *node)
> */
> static void mod_tree_insert(struct module *mod)
> {
> - mod->mtn_core.mod = mod;
> - mod->mtn_init.mod = mod;
> + mod->core_layout.mtn.mod = mod;
> + mod->init_layout.mtn.mod = mod;
^ back-pointers :-)
> - __mod_tree_insert(&mod->mtn_core);
> - if (mod->init_size)
> - __mod_tree_insert(&mod->mtn_init);
> + __mod_tree_insert(&mod->core_layout.mtn);
> + if (mod->init_layout.size)
> + __mod_tree_insert(&mod->init_layout.mtn);
> }
Aside from these minor nits,
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
next prev parent reply other threads:[~2015-11-09 9:41 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-09 4:23 [PATCH 0/4] module RO/NX cleanups Rusty Russell
2015-11-09 4:23 ` [PATCH 1/4] module: Use the same logic for setting and unsetting RO/NX Rusty Russell
2015-11-09 4:23 ` [PATCH 2/4] gcov: use within_module() helper Rusty Russell
2015-11-09 8:19 ` Peter Oberparleiter
2015-11-09 4:23 ` [PATCH 3/4] module: use a structure to encapsulate layout Rusty Russell
2015-11-09 9:41 ` Peter Zijlstra [this message]
2015-11-10 1:41 ` Rusty Russell
2015-11-09 16:54 ` Josh Poimboeuf
2015-11-09 4:23 ` [PATCH 4/4] module: clean up RO/NX handling Rusty Russell
2015-11-09 19:51 ` Josh Poimboeuf
2015-11-10 1:57 ` Rusty Russell
2015-11-10 4:27 ` Josh Poimboeuf
2015-11-12 1:28 ` Rusty Russell
2015-11-12 3:41 ` Josh Poimboeuf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151109094150.GF17308@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome