Re: [PATCH/RFC] module: replace module_layout with module_memory

From: Song Liu
Date: Fri Jan 20 2023 - 12:42:49 EST


On Thu, Jan 19, 2023 at 12:29 AM Song Liu <song@xxxxxxxxxx> wrote:
>
> On Wed, Jan 18, 2023 at 9:35 PM Christoph Hellwig <hch@xxxxxx> wrote:
> >
> > On Wed, Jan 18, 2023 at 01:52:51PM -0800, Song Liu wrote:
> > > In this way we can use the array in the for loops, and use mod->core_text,
> > > etc. when we only need to access one of them.
> >
> > Just use the array please instead of making it too ugly. If that
> > is the only sensible way to iterate we have a good argument for the
> > array and can live with it.
>
> Hmm.. I think it won't be ugly outside of the struct definition...
> Alternatively, how about use something like
>
> #define core_text mod_mem[MOD_MEM_TYPE_TEXT]
> ...
>
> which is similar to
>
> struct sock {
> /*
> * Now struct inet_timewait_sock also uses sock_common, so please just
> * don't add nothing before this first member (__sk_common) --acme
> */
> struct sock_common __sk_common;
> #define sk_node __sk_common.skc_node
> #define sk_nulls_node __sk_common.skc_nulls_node
> ...
> };

So here are the two versions, both with secondary addr_[min|max] for
CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC.

v2. Just use mod_mem array:
https://git.kernel.org/pub/scm/linux/kernel/git/song/md.git/commit/?h=remotes/song-md/new_module_alloc_build_test_v2

v3. mod_mem array and the defines:
#define mod_core_text mod_mem[MOD_MEM_TYPE_TEXT]
#define mod_core_data mod_mem[MOD_MEM_TYPE_DATA]
etc.
https://git.kernel.org/pub/scm/linux/kernel/git/song/md.git/commit/?h=remotes/song-md/new_module_alloc_build_test_v3

I personally like the v3 better. Please share you
comments on this.

Thanks,
Song