linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] alloc_tag: skip rcu barrier on module unload if profiling was not enabled
@ 2025-12-04 22:09 Suren Baghdasaryan
  2025-12-06  4:45 ` kernel test robot
  2025-12-06  5:08 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Suren Baghdasaryan @ 2025-12-04 22:09 UTC (permalink / raw)
  To: akpm
  Cc: kent.overstreet, vbabka, harry.yoo, da.gomez, jonathanh,
	linux-kernel, linux-mm, Suren Baghdasaryan

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.

Suggested-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
---
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(-)

diff --git a/include/linux/codetag.h b/include/linux/codetag.h
index 8ea2a5f7c98a..8a07a83cabdd 100644
--- a/include/linux/codetag.h
+++ b/include/linux/codetag.h
@@ -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) */
 
diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c
index 27fee57a5c91..173eebfacb1e 100644
--- a/lib/alloc_tag.c
+++ b/lib/alloc_tag.c
@@ -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);
diff --git a/lib/codetag.c b/lib/codetag.c
index 545911cebd25..ed6d6425b62a 100644
--- a/lib/codetag.c
+++ b/lib/codetag.c
@@ -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
-- 
2.52.0.223.gf5cc29aaa4-goog



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] alloc_tag: skip rcu barrier on module unload if profiling was not enabled
  2025-12-04 22:09 [PATCH 1/1] alloc_tag: skip rcu barrier on module unload if profiling was not enabled Suren Baghdasaryan
@ 2025-12-06  4:45 ` kernel test robot
  2025-12-06  5:08 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2025-12-06  4:45 UTC (permalink / raw)
  To: Suren Baghdasaryan, akpm
  Cc: llvm, oe-kbuild-all, kent.overstreet, vbabka, harry.yoo,
	da.gomez, jonathanh, linux-kernel, linux-mm, Suren Baghdasaryan

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/202512061204.aGmmZds2-lkp@intel.com/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/202512061204.aGmmZds2-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202512061204.aGmmZds2-lkp@intel.com/

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	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] alloc_tag: skip rcu barrier on module unload if profiling was not enabled
  2025-12-04 22:09 [PATCH 1/1] alloc_tag: skip rcu barrier on module unload if profiling was not enabled Suren Baghdasaryan
  2025-12-06  4:45 ` kernel test robot
@ 2025-12-06  5:08 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2025-12-06  5:08 UTC (permalink / raw)
  To: Suren Baghdasaryan, akpm
  Cc: oe-kbuild-all, kent.overstreet, vbabka, harry.yoo, da.gomez,
	jonathanh, linux-kernel, linux-mm, Suren Baghdasaryan

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/202512061207.7zufoIcC-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251206/202512061207.7zufoIcC-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202512061207.7zufoIcC-lkp@intel.com/

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	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-06  5:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-04 22:09 [PATCH 1/1] alloc_tag: skip rcu barrier on module unload if profiling was not enabled Suren Baghdasaryan
2025-12-06  4:45 ` kernel test robot
2025-12-06  5:08 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox