On Mon, 14 Oct 2024 13:36:43 -0700 Suren Baghdasaryan <surenb@xxxxxxxxxx> wrote: > When a module gets unloaded there is a possibility that some of the > allocations it made are still used and therefore the allocation tags > corresponding to these allocations are still referenced. As such, the > memory for these tags can't be freed. This is currently handled as an > abnormal situation and module's data section is not being unloaded. > To handle this situation without keeping module's data in memory, > allow codetags with longer lifespan than the module to be loaded into > their own separate memory. The in-use memory areas and gaps after > module unloading in this separate memory are tracked using maple trees. > Allocation tags arrange their separate memory so that it is virtually > contiguous and that will allow simple allocation tag indexing later on > in this patchset. The size of this virtually contiguous memory is set > to store up to 100000 allocation tags. > > ... > > --- a/kernel/module/main.c > +++ b/kernel/module/main.c > @@ -1254,22 +1254,17 @@ static int module_memory_alloc(struct module *mod, enum mod_mem_type type) > return 0; > } > > -static void module_memory_free(struct module *mod, enum mod_mem_type type, > - bool unload_codetags) > +static void module_memory_free(struct module *mod, enum mod_mem_type type) > { > struct module_memory *mem = &mod->mem[type]; > - void *ptr = mem->base; > > if (mem->is_rox) > vfree(mem->rw_copy); > > - if (!unload_codetags && mod_mem_type_is_core_data(type)) > - return; > - > - execmem_free(ptr); > + execmem_free(mem->base); > } The changes around here are dependent upon Mike's "module: make module_memory_{alloc,free} more self-contained", which is no longer in mm-unstable. I assume Mike is working on a v2 so I'll park this series for now.