All of lore.kernel.org
 help / color / mirror / Atom feed
From: Suren Baghdasaryan <surenb@google.com>
To: akpm@linux-foundation.org
Cc: kent.overstreet@linux.dev, vbabka@suse.cz, harry.yoo@oracle.com,
	 da.gomez@kernel.org, jonathanh@nvidia.com,
	linux-kernel@vger.kernel.org,  linux-mm@kvack.org,
	Suren Baghdasaryan <surenb@google.com>
Subject: [PATCH 1/1] alloc_tag: skip rcu barrier on module unload if profiling was not enabled
Date: Thu,  4 Dec 2025 14:09:56 -0800	[thread overview]
Message-ID: <20251204220957.360838-1-surenb@google.com> (raw)

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



             reply	other threads:[~2025-12-04 22:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-04 22:09 Suren Baghdasaryan [this message]
2025-12-06  4:45 ` [PATCH 1/1] alloc_tag: skip rcu barrier on module unload if profiling was not enabled kernel test robot
2025-12-06  5:08 ` kernel test robot
2025-12-08 21:30   ` Suren Baghdasaryan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251204220957.360838-1-surenb@google.com \
    --to=surenb@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=da.gomez@kernel.org \
    --cc=harry.yoo@oracle.com \
    --cc=jonathanh@nvidia.com \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.