Re: [PATCH v5] module: Add CONFIG_MODULE_DISABLE_INIT_FREE option

From: Dan Carpenter
Date: Fri Oct 27 2023 - 08:27:32 EST


On Fri, Oct 27, 2023 at 03:00:00PM +0300, Dan Carpenter wrote:
> 607c543f939d8c kernel/module.c Andrii Nakryiko 2020-11-20 2579 #ifdef CONFIG_DEBUG_INFO_BTF_MODULES
> 607c543f939d8c kernel/module.c Andrii Nakryiko 2020-11-20 2580 /* .BTF is not SHF_ALLOC and will get removed, so sanitize pointer */
> 607c543f939d8c kernel/module.c Andrii Nakryiko 2020-11-20 2581 mod->btf_data = NULL;
> 607c543f939d8c kernel/module.c Andrii Nakryiko 2020-11-20 2582 #endif
> c749637909eea5 kernel/module.c Rusty Russell 2015-01-20 2583 /*
> c749637909eea5 kernel/module.c Rusty Russell 2015-01-20 2584 * We want to free module_init, but be aware that kallsyms may be
> 0be964be0d4508 kernel/module.c Peter Zijlstra 2015-05-27 2585 * walking this with preempt disabled. In all the failure paths, we
> cb2f55369d3a9e kernel/module.c Paul E. McKenney 2018-11-06 2586 * call synchronize_rcu(), but we don't want to slow down the success
> 1a7b7d9220819a kernel/module.c Rick Edgecombe 2019-04-25 2587 * path. module_memfree() cannot be called in an interrupt, so do the
> 1a7b7d9220819a kernel/module.c Rick Edgecombe 2019-04-25 2588 * work and call synchronize_rcu() in a work queue.
> 1a7b7d9220819a kernel/module.c Rick Edgecombe 2019-04-25 2589 *
> ae646f0b9ca135 kernel/module.c Jeffrey Hugo 2018-05-11 2590 * Note that module_alloc() on most architectures creates W+X page
> ae646f0b9ca135 kernel/module.c Jeffrey Hugo 2018-05-11 2591 * mappings which won't be cleaned up until do_free_init() runs. Any
> ae646f0b9ca135 kernel/module.c Jeffrey Hugo 2018-05-11 2592 * code such as mark_rodata_ro() which depends on those mappings to
> ae646f0b9ca135 kernel/module.c Jeffrey Hugo 2018-05-11 2593 * be cleaned up needs to sync with the queued work - ie
> cb2f55369d3a9e kernel/module.c Paul E. McKenney 2018-11-06 2594 * rcu_barrier()
> c749637909eea5 kernel/module.c Rusty Russell 2015-01-20 2595 */
> 36022a47582048 kernel/module/main.c Joey Jiao 2023-10-13 2596 if (!IS_ENABLED(CONFIG_MODULE_DISABLE_INIT_FREE) &&
> 36022a47582048 kernel/module/main.c Joey Jiao 2023-10-13 2597 llist_add(&freeinit->node, &init_free_list))
>
> Let's not allocate freeinit if CONFIG_MODULE_DISABLE_INIT_FREE is not
> enabled.

Wait. It's the other way around actually. freeinit isn't used if
CONFIG_MODULE_DISABLE_INIT_FREE is enabled.

regards,
dan carpenter