From nobody Mon Sep 28 21:52:11 2026 Received: from mta0.migadu.com (out-117.mta0.migadu.com [91.218.175.117]) (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 F37AA2D877A for ; Mon, 17 Aug 2026 06:26:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.117 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786948021; cv=none; b=ULWqF9lLOc6F47KZMSDb/SHp7OkGqA6AsNs/3AIzxyG66A3TcWV+Ya5ElZywd8ddfsE/iI4N4mILZP0YRAg1Naigu3LRY1PHyWpasys/PsHzMKPfhSizBehX1lJar4JRPAuEgRXBGUBSt0Efk9nxJDgKTdhu6ytxddJMRAdRYVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786948021; c=relaxed/simple; bh=Nrl5tHbT9eQhQhzooTC92+qQ11qduWmutBe6i3Oleeo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oQETDCDYRu5BXfYk8OBxfIrYGc7cULoUQ1WAXJaqtmwDuna2Xyh47IOPbsjlAVTy4w42IdhLmX3+tdqtCZvwH7gSCSN3mg1YMztjNuxNIvYJVM8y9PO8LHvKYUU7QO6jqn6ho+pGLOtuet5+5197V0nNb8H9BvdFNqhov/WVlSY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=f6LbZYdJ; arc=none smtp.client-ip=91.218.175.117 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="f6LbZYdJ" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=Nrl5tHbT9eQhQhzooTC92+qQ11qduWmutBe6i3Oleeo=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786948017; v=1; x=1787552817; b=f6LbZYdJbh+RYFONAlNMXgMCY6QH0m73I0gQkFwtcV5vUoPEq1W0rJI/BDaJSUr6yKX2kkcP 57tl03izkRjx3CJv6Cr3Qab9i8hMy4S612po1osOSA0X/X60Qn+N0O8O50qNuWvFRbuRC2R7WrE e+HDGPSYtiVd7lQZ0fgYrbaE= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost.localdomain (116.128.244.169) by smtp.migadu.com with ESMTPS id 411436bb243080ca; Mon, 17 Aug 2026 06:26:57 +0000 X-Migadu-Flow: FLOW_OUT From: Hao Ge To: Suren Baghdasaryan , Kent Overstreet , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Hao Ge , Sashiko , stable@vger.kernel.org Subject: [PATCH 1/2] alloc_tag: skip percpu counter allocation when profiling is disabled Date: Mon, 17 Aug 2026 14:27:25 +0800 Message-Id: <20260817062726.106511-2-hao.ge@linux.dev> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260817062726.106511-1-hao.ge@linux.dev> References: <20260817062726.106511-1-hao.ge@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" After shutdown_mem_profiling() clears mem_profiling_support, needs_section_mem() returns false, so later modules have their codetag section placed as regular data and never enter the alloc_tag maple tree. codetag_load_module() still called load_module(), which allocated a percpu counter for every tag; release_module_tags() could not find these modules on unload, so the counters leaked. Return -EOPNOTSUPP from load_module() when profiling is off: codetag_module_init() drops the module's cmod, no counters are allocated and the module loads without its tags. codetag_unload_module() now always calls free_section_mem(), since a module whose module_load() returned -EOPNOTSUPP is not in the idr but may still hold a reserved section. Reported-by: Sashiko Fixes: 4835f747d3ed ("alloc_tag: support for page allocation tag compressio= n") Cc: stable@vger.kernel.org Suggested-by: Suren Baghdasaryan Signed-off-by: Hao Ge Acked-by: Suren Baghdasaryan --- lib/codetag.c | 10 ++++++++-- mm/alloc_tag.c | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/codetag.c b/lib/codetag.c index a9cda4c962a3..a0b600720afc 100644 --- a/lib/codetag.c +++ b/lib/codetag.c @@ -240,7 +240,9 @@ static int codetag_module_init(struct codetag_type *ctt= ype, struct module *mod) =20 if (err < 0) { kfree(cmod); - return err; + /* -EOPNOTSUPP means we can load the module without its tag. */ + if (err !=3D -EOPNOTSUPP) + return err; } =20 return 0; @@ -388,7 +390,11 @@ void codetag_unload_module(struct module *mod) ++cttype->content_id; } up_write(&cttype->mod_lock); - if (found && cttype->desc.free_section_mem) + /* + * A module whose module_load() returned -EOPNOTSUPP is not + * in the idr but may still hold reserved section memory. + */ + if (cttype->desc.free_section_mem) cttype->desc.free_section_mem(mod, true); } mutex_unlock(&codetag_lock); diff --git a/mm/alloc_tag.c b/mm/alloc_tag.c index 52aece27b00e..80eccaca665a 100644 --- a/mm/alloc_tag.c +++ b/mm/alloc_tag.c @@ -975,6 +975,10 @@ static int load_module(struct module *mod, struct code= tag *start, struct codetag struct alloc_tag *stop_tag; struct alloc_tag *tag; =20 + /* Profiling disabled: load the module without its tags. */ + if (!mem_profiling_support) + return -EOPNOTSUPP; + /* percpu counters for core allocations are already statically allocated = */ if (!mod) return 0; --=20 2.25.1 From nobody Mon Sep 28 21:52:11 2026 Received: from mta0.migadu.com (out-121.mta0.migadu.com [91.218.175.121]) (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 B18A914EC73 for ; Mon, 17 Aug 2026 06:27:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.121 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786948031; cv=none; b=E19T9Ob9wM7lnBOsdmcvUyEfEVDUA/FPKXWo3H0BDdxhddP5cBZeIXKjeINTB5Ir9utDOXiZJa1jAuvarZ13AVsSW/Keee0b80jEDbZ1F4qbzweujxrZf6vQNpSWTq5pE+GX19yII6bXgMaQ1mdAEq8XKECBIVmSUKBlFJiF3q8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786948031; c=relaxed/simple; bh=GCy+WguWNDQlk/N3Wy1cyqoO2byfKnIj9nX7d8+026w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lJhoSFolDiSD+YLJLH2Tvj3G6OwHWceI83lYSUp1BtSk3BkM0cvIi4bB4L03VotS9Bk9BNt9B9XpcPPFzS+CvtOGyVhVZQtuLoMqnM81O6IxP3tMNbXodnLOjliff6Cs8cVotexgroyFQuNSIilfzWk+yjzNOILldw48EbgMf4E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=kFbNfxaJ; arc=none smtp.client-ip=91.218.175.121 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="kFbNfxaJ" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=GCy+WguWNDQlk/N3Wy1cyqoO2byfKnIj9nX7d8+026w=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786948027; v=1; x=1787552827; b=kFbNfxaJSQd+teceRATDLlPSixZxjsV8yAQQTFTaMNe/YvC9puCwBjg/ettFEm6/+fUoaNbb 7MJJxnolOK4L7K4Dggjgc45fFCIIlCWx7ogYTjXWmjiLaaleurv36c2Zf/w0ohsYoqzFQ9Y07Pl tkd57W5y/eedfZCdfiZwQUbg= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost.localdomain (116.128.244.169) by smtp.migadu.com with ESMTPS id b5ed0a00273cb5ad; Mon, 17 Aug 2026 06:27:07 +0000 X-Migadu-Flow: FLOW_OUT From: Hao Ge To: Suren Baghdasaryan , Kent Overstreet , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Hao Ge , Sashiko , stable@vger.kernel.org Subject: [PATCH 2/2] alloc_tag: remove /proc/allocinfo outside of mod_lock Date: Mon, 17 Aug 2026 14:27:26 +0800 Message-Id: <20260817062726.106511-3-hao.ge@linux.dev> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260817062726.106511-1-hao.ge@linux.dev> References: <20260817062726.106511-1-hao.ge@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" shutdown_mem_profiling() calls remove_proc_entry() from reserve_module_tags(), which runs under mod_lock held for write. remove_proc_entry() waits for readers, and a reader takes mod_lock for read in allocinfo_start(): CPU0 (insmod) CPU1 (read /proc/allocinfo) ---------------- ---------------------------- reserve_module_tags() down_write(&mod_lock) [held] use_pde() [in_use++] allocinfo_start() down_read(&mod_lock) <- blocks shutdown_mem_profiling() remove_proc_entry() wait for in_use =3D=3D 0 <- blocks Move remove_proc_entry() to a workqueue. Reported-by: Sashiko Fixes: 4835f747d3ed ("alloc_tag: support for page allocation tag compressio= n") Cc: stable@vger.kernel.org Signed-off-by: Hao Ge Acked-by: Suren Baghdasaryan --- mm/alloc_tag.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mm/alloc_tag.c b/mm/alloc_tag.c index 80eccaca665a..b1d48532a25a 100644 --- a/mm/alloc_tag.c +++ b/mm/alloc_tag.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include =20 @@ -591,6 +592,13 @@ void pgalloc_tag_swap(struct folio *new, struct folio = *old) put_page_tag_ref(handle_new); } =20 +static void remove_allocinfo_file(struct work_struct *work) +{ + remove_proc_entry(ALLOCINFO_FILE_NAME, NULL); +} + +static DECLARE_WORK(remove_allocinfo_work, remove_allocinfo_file); + static void shutdown_mem_profiling(bool remove_file) { if (mem_alloc_profiling_enabled()) @@ -600,7 +608,7 @@ static void shutdown_mem_profiling(bool remove_file) return; =20 if (remove_file) - remove_proc_entry(ALLOCINFO_FILE_NAME, NULL); + schedule_work(&remove_allocinfo_work); mem_profiling_support =3D false; } =20 --=20 2.25.1