From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFB042512E6 for ; Thu, 4 Dec 2025 22:10:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764886202; cv=none; b=g5KMiBiA/if1vgDmL7j2BV5M0PJq51Mj6tsJbnQM14sEb+ag1dnXyt1N3fl6QO/J3h8fFAPGTeawxv81K/Rb6eGyNK+7PfexhwzbflyI+MVMNfDrPrVBVU4xELv7ssVq/5Zoki0ksJbpTJ39/jO/do0AXWMDRZaqGZwjXMzHoeM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764886202; c=relaxed/simple; bh=31BipMe1eVbI3HyN4EQ7FUyp3lEwPy1N/c2QrPqvN6U=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=MG+OVUa1FkLY0H87IVC9h0yw7FESg87GLIdfCLzUwnfhZYEB97540G5uPbgrHBlc7Pr2U9Rz8OhSyo6loKw7KPIRuoh/hfbjjZbYcHSf9vR+gzeYs+98wR8xqiDEPGNbvEppHWF0Q2ZeMGWGPryO5SF+/giaO/VaazIVjvlskFY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=y6iRdwV3; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="y6iRdwV3" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b630b4d8d52so1438361a12.3 for ; Thu, 04 Dec 2025 14:10:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764886200; x=1765491000; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=54oIStPr/s4vJcJKPPdjRiweYi2k8HSZohU+IbZP+5k=; b=y6iRdwV3BzS2LKxmHdlCM0ABCguKQCvcPJwlf0UhqLID87rAbrpjxzpwDxoWNfyXWi wdDHBSH7cP8X47ZS0DzMK+KyWRohHdjiSu0YNgXqPrONpHT190SCzKRvyGFlC5qyYgWT D8cXk/aRBLLJB+pHU8RkvipXVu5HLmcffzWdIjEtt20OTNFkUPsmwKt8t6SgWulR1mV/ 94XhHN5tr1ttnPRhR0HFWO5Z4gFPEk/FjHHWLIs+jpNR4Cgrs6BmdVsKcI4AsJfgWfdP cduW+X8B4p7VbPIt0e9zkeLZPbVIg0B9pcog88q9xKpCbv4fOCwOS1PZminqMjnX29JO HyKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764886200; x=1765491000; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=54oIStPr/s4vJcJKPPdjRiweYi2k8HSZohU+IbZP+5k=; b=wK86WfXHvWS+TbFFGUsEKg8y/QrmG+h045XPRmKiHN+QpcJ8x65ljJFhnkDDZg+T8T U+VnZsmyYgLn1wH7W0Q5BUh/tc/VllVZlBRzylf1jGE3S0zC0v2Ni7HiHzSjPPJEUm8h Dk6aJu0Y3MFGRZGxCJck13kqZG1Iwch/dSgrWEWHukEpE9qQjqPD4P2Kb4KDxNX3inon HDZ25Gd+xww1RYr3y/XTdn3IlvDtRes7dlhKaUUOwhwmvrlqe7f+nHECyw073ajJRJk+ hFmQmRc0yoPlZXAhXPSbJe3iiixOSPW3KJly1xGxHsY1Bj7gjZVWevLVcFjM+TIaiqrH XjJw== X-Forwarded-Encrypted: i=1; AJvYcCXbZCH9nx0pY1lKjVqEyqZPjNaLlJft7hfx6JdcvPD4aB7lag8QRUJfNIgjYphoxYe5C5WzjpHl7XYAXwI=@vger.kernel.org X-Gm-Message-State: AOJu0YwaYWfmUfnsTiuiahpsCgJo5nIb+cJwysNOTnRH7m1W6ED0Dnsi KBO0w4NRHkYYNdKBNkhhSSJxQdXVTMI4rFEb8+VSoqz1yxHYZBxYpEkrX20QDjRtQHqhd+KY5q2 cpEzZDA== X-Google-Smtp-Source: AGHT+IHLhrKsU7MdJp99+KvZZ/xCoXmF9qcszyx5DJq3SSgN+PpZivt51xKlhmqSsW0XWVKbU/tASHuysvs= X-Received: from dynm33.prod.google.com ([2002:a05:7300:2aa1:b0:2a4:664f:e91d]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:4d10:b0:2a4:3593:ddf2 with SMTP id 5a478bee46e88-2ab92e671a4mr4465065eec.31.1764886200002; Thu, 04 Dec 2025 14:10:00 -0800 (PST) Date: Thu, 4 Dec 2025 14:09:56 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.52.0.223.gf5cc29aaa4-goog Message-ID: <20251204220957.360838-1-surenb@google.com> Subject: [PATCH 1/1] alloc_tag: skip rcu barrier on module unload if profiling was not enabled From: Suren Baghdasaryan 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 Content-Type: text/plain; charset="UTF-8" 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 Signed-off-by: Suren Baghdasaryan --- 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