alloc_tag: skip rcu barrier on module unload if profiling was not enabled
Subsystems (3)
Suren Baghdasaryan
maintainerPATCH 1/1 alloc_tag: skip rcu barrier on module unload if profiling was not enabled
RCU barrier in the module unload path is needed to ensure all kfree_rcu operations which modify tag counters are complete before we free the tags. However this is not necessary if memory allocation profiling was never enabled on the system. Introduce a sticky flag that records whether memory profiling was ever enabled and make the RCU barrier conditional.
---
Applies over mm-new
include/linux/codetag.h | 2 ++ lib/alloc_tag.c | 11 ++++++++++- lib/codetag.c | 14 ++++++++++++-- 3 files changed, 24 insertions(+), 3 deletions(-)
include/linux/codetag.h +2 -0
@@ -95,6 +95,7 @@ void codetag_free_module_sections(struct module *mod);void codetag_module_replaced (struct module *mod,struct module *new_mod);int codetag_load_module (struct module *mod);void codetag_unload_module (struct module *mod); +void codetag_flush_rcu_on_module_unload (void );#else /* defined(CONFIG_CODE_TAGGING) && defined(CONFIG_MODULES) */
@@ -109,6 +110,7 @@ static inline void codetag_free_module_sections(struct module *mod) {}static inline void codetag_module_replaced (struct module *mod,struct module *new_mod) {}static inline int codetag_load_module (struct module *mod) {return 0 ; }static inline void codetag_unload_module (struct module *mod) {} +static inline void codetag_flush_rcu_on_module_unload (void ) {}#endif /* defined(CONFIG_CODE_TAGGING) && defined(CONFIG_MODULES) */
lib/alloc_tag.c +10 -1
@@ -776,10 +776,16 @@ EXPORT_SYMBOL(page_alloc_tagging_ops);static int proc_mem_profiling_handler (const struct ctl_table *table,int write,void *buffer,size_t *lenp,loff_t *ppos) { +int ret; +if (!mem_profiling_support && write)return -EINVAL ; -return proc_do_static_key (table, write, buffer, lenp, ppos); + ret =proc_do_static_key (table, write, buffer, lenp, ppos); +if (!ret && write &&mem_alloc_profiling_enabled ()) +codetag_flush_rcu_on_module_unload (); + +return ret; }
@@ -829,6 +835,9 @@ static int __init alloc_tag_init(void)return 0 ; } +if (mem_alloc_profiling_enabled ()) +codetag_flush_rcu_on_module_unload (); +if (!proc_create_seq_private (ALLOCINFO_FILE_NAME ,0400 ,NULL , &allocinfo_seq_op,sizeof (struct allocinfo_private ),NULL )) {pr_err ("Failed to create %s file\n" ,ALLOCINFO_FILE_NAME );
lib/codetag.c +12 -2
@@ -34,6 +34,7 @@ struct codetag_module {static DEFINE_MUTEX (codetag_lock);static LIST_HEAD (codetag_types); +static bool flush_rcu_on_module_unload;void codetag_lock_module_list (struct codetag_type *cttype,bool lock) {
@@ -335,6 +336,11 @@ int codetag_load_module(struct module *mod)return ret; } +void codetag_flush_rcu_on_module_unload (void ) +{ + flush_rcu_on_module_unload = true; +} +void codetag_unload_module (struct module *mod) {struct codetag_type *cttype;
@@ -342,8 +348,12 @@ void codetag_unload_module(struct module *mod)if (!mod)return ; -/* await any module's kfree_rcu() operations to complete */ -kvfree_rcu_barrier (); +/* +* Await any module's kfree_rcu() operations to complete +* if profiling was ever enabled. +*/ +if (flush_rcu_on_module_unload) +kvfree_rcu_barrier ();mutex_lock (&codetag_lock);list_for_each_entry (cttype, &codetag_types, link) {
base-commit: 3f43be96f919cc611dcb2a4e38dd464831f4513e
Signature · 1 line
2.52.0.223.gf5cc29aaa4-goog
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Suren,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 3f43be96f919cc611dcb2a4e38dd464831f4513e]
url: https://github.com/intel-lab-lkp/linux/commits/Suren-Baghdasaryan/alloc_tag-skip-rcu-barrier-on-module-unload-if-profiling-was-not-enabled/20251205-061310 base: 3f43be96f919cc611dcb2a4e38dd464831f4513e patch link: https://lore.kernel.org/r/20251204220957.360838-1-surenb%40google.com patch subject: [PATCH 1/1] alloc_tag: skip rcu barrier on module unload if profiling was not enabled config: riscv-randconfig-001-20251206 (https://download.01.org/0day-ci/archive/20251206/[email protected]/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 14bf95b06a18b9b59c89601cbc0e5a6f2176b118) rustc: rustc 1.88.0 (6b00bc388 2025-06-23) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251206/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> lib/codetag.c:37:13: warning: unused variable 'flush_rcu_on_module_unload' [-Wunused-variable]
37 | static bool flush_rcu_on_module_unload;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~1 warning generated.
vim +/flush_rcu_on_module_unload +37 lib/codetag.c
34
35 static DEFINE_MUTEX(codetag_lock);
36 static LIST_HEAD(codetag_types);
> 37 static bool flush_rcu_on_module_unload;
38 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Suren,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 3f43be96f919cc611dcb2a4e38dd464831f4513e]
url: https://github.com/intel-lab-lkp/linux/commits/Suren-Baghdasaryan/alloc_tag-skip-rcu-barrier-on-module-unload-if-profiling-was-not-enabled/20251205-061310 base: 3f43be96f919cc611dcb2a4e38dd464831f4513e patch link: https://lore.kernel.org/r/20251204220957.360838-1-surenb%40google.com patch subject: [PATCH 1/1] alloc_tag: skip rcu barrier on module unload if profiling was not enabled config: parisc-randconfig-002-20251206 (https://download.01.org/0day-ci/archive/20251206/[email protected]/config) compiler: hppa-linux-gcc (GCC) 15.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251206/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> lib/codetag.c:37:13: warning: 'flush_rcu_on_module_unload' defined but not used [-Wunused-variable]
37 | static bool flush_rcu_on_module_unload;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~vim +/flush_rcu_on_module_unload +37 lib/codetag.c
34
35 static DEFINE_MUTEX(codetag_lock);
36 static LIST_HEAD(codetag_types);
> 37 static bool flush_rcu_on_module_unload;
38 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Suren Baghdasaryan
maintainerQuoted 20 lines · kernel test robot
Hi Suren,
kernel test robot noticed the following build warnings:
[auto build test WARNING on
3f43be96f919cc611dcb2a4e38dd464831f4513e]url: https://github.com/intel-lab-lkp/linux/commits/Suren-Baghdasaryan/alloc_tag-skip-rcu-barrier-on-module-unload-if-profiling-was-not-enabled/20251205-061310 base: 3f43be96f919cc611dcb2a4e38dd464831f4513e patch link: https://lore.kernel.org/r/20251204220957.360838-1-surenb%40google.com patch subject: [PATCH 1/1] alloc_tag: skip rcu barrier on module unload if profiling was not enabled config: parisc-randconfig-002-20251206 (https://download.01.org/0day-ci/archive/20251206/[email protected]/config) compiler: hppa-linux-gcc (GCC) 15.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251206/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Quoted 5 lines
All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
lib/codetag.c:37:13: warning: 'flush_rcu_on_module_unload' defined but not used [-Wunused-variable]37 | static bool flush_rcu_on_module_unload; | ^~~~~~~~~~~~~~~~~~~~~~~~~~
Thanks! I'll fix it and repost after Plumbers as the original issue seems to be resolved by Harry's patches and this optimization is not urgent anymore.
Quoted 13 lines
vim +/flush_rcu_on_module_unload +37
lib/codetag.c34 35 static DEFINE_MUTEX(codetag_lock); 36 static LIST_HEAD(codetag_types);Quoted 1 line
37 static bool
flush_rcu_on_module_unload;38--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki