On Thu, Mar 16, 2023 at 02:50:55PM -0700, Luis Chamberlain wrote: > The comment for "Update sh_addr to point to copy in image." seems pretty > misleading to me, what we are doing there is actually ensuring that we update > the copy's ELF section address to point to our newly allocated memory. > Do folks agree? > > And how about the size on the memcpy()? That's a shd->sh_size. No matter > how much I increase my struct module in include/linux/module.h I see > thes same sh_size. Do folks see same? > > nm --print-size --size-sort fs/xfs/xfs.ko | grep __this_module > 0000000000000000 0000000000000500 D __this_module > > This is what is supposed to make the final part of layout_and_allocate() work: > > mod = (void *)info->sechdrs[info->index.mod].sh_addr; > > This works off of the copy of the module. Let's recall that > setup_load_info() sets the copy mod to: > > info->mod = (void *)info->hdr + info->sechdrs[info->index.mod].sh_offset; > > The memcpy() in move_module() is what *should* be copying over the entire > mod stuff properly over, that includes the mod->klp for live patching > but also any new data we muck with in-kernel as the new mod->mem stuff > in layout_sections(). In short, anything in struct module should be > shoved into an ELF section. But I'm not quite sure this is all right. I dug into that code years ago, and the above sounds right. The .ko file has a .gnu.linkonce.this_module section whose data is just the original "struct module __this_module" which is created by the module build (from foo.mod.c). At the beginning of the finit_module() syscall, the .ko file's ELF sections get copied (and optionally decompressed) into kernel memory. Then 'mod' just points to the copied __this_module struct. Then mod->klp (and possibly mod->taint) get set. Then in layout_and_allocate(), that 'mod' gets memcpy'd into the second (and final) in-kernel copy of 'struct module': if (shdr->sh_type != SHT_NOBITS) memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size); /* Update sh_addr to point to copy in image. */ shdr->sh_addr = (unsigned long)dest; I suspect you don't see the size changing when you add to 'struct module' because it's ____cacheline_aligned. It's all rather obtuse, but working as designed as far as I can tell. -- Josh