From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4AE23336885 for ; Wed, 10 Jun 2026 23:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781133674; cv=none; b=S6PejyT8kNtHPw4ofNZNRa/DDXL0GEVxPZi17njwr3uxeMdZafwhZuN/0mfjKY24rr7ReK6Jm7W2x01f6Q33E2Kmnnq5o4F+m9MoSvi9gpkC9Gld5B0VAjXJUvbI5KE78aDZKc/WqKKdSGTEstXrgUe4OaoCVGO54SLF85pHWps= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781133674; c=relaxed/simple; bh=jdOxwUHwz6ZEX9aNkv6/BCVOoqwyPIrf1gqv/gHHMGI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ZfV/aatprI6Dx2Gw1nmhGcj7kf1FeO0fyUe3CP31EECM9I1lrNMUSNXZ1B1US69/2+xn6DoNsFm79aDHYiC46HJc+4ExG9r2pjrADb5J1T/k/0gPQtc+ZOwt3AXtf3PTBLLkhoutzr37tXLJS5pwX7jUUqyn+BO6dnUBroSZQ+Y= 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=KxhTTE1R; arc=none smtp.client-ip=91.218.175.178 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="KxhTTE1R" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1781133669; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ZKdrW8MSyYpUdE/yN9cJchnfw0mivcsg5Esu2sk15iE=; b=KxhTTE1R84GXIzfi4AjA0QLkq2hACD5bG8AXTiValPDgZx4utDK4WqZFdSxRWhDoCo4ePW 4bCMi1guYsCXdEiHJX8D79uE04PxfTQwPCF9oiyK++rzdKYOiQXS99nxam2krxIS/jBS3E yLMj+lGFa1MDkzN2hJTaBfktTRoP5XU= From: Shakeel Butt To: Andrew Morton Cc: Dave Chinner , Roman Gushchin , Muchun Song , Qi Zheng , Meta kernel team , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zenghui Yu , Nhat Pham Subject: [PATCH] mm/shrinker: do not hold RCU lock in shrinker_debugfs_count_show() Date: Wed, 10 Jun 2026 16:20:48 -0700 Message-ID: <20260610232048.62930-1-shakeel.butt@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: 8bit X-Migadu-Flow: FLOW_OUT Reading the debugfs "count" file of a memcg-aware shrinker can sleep inside an RCU read-side critical section: BUG: sleeping function called from invalid context at kernel/cgroup/rstat.c:421 RCU nest depth: 1, expected: 0 css_rstat_flush mem_cgroup_flush_stats zswap_shrinker_count shrinker_debugfs_count_show shrinker_debugfs_count_show() invokes the ->count_objects() callback under rcu_read_lock(). The zswap callback flushes memcg stats via css_rstat_flush(), which may sleep, so it must not run under RCU. The RCU lock is not needed here. mem_cgroup_iter() takes RCU internally and returns a memcg holding a css reference (dropped on the next iteration or by mem_cgroup_iter_break()), so the memcg stays alive without it. The shrinker is kept alive by the open debugfs file: shrinker_free() removes the debugfs entries via debugfs_remove_recursive(), which waits for in-flight readers to drain, before call_rcu(..., shrinker_free_rcu_cb). The sibling "scan" handler already invokes the sleeping ->scan_objects() callback with no RCU section. Drop the rcu_read_lock()/rcu_read_unlock(). Fixes: 5035ebc644ae ("mm: shrinkers: introduce debugfs interface for memory shrinkers") Reported-by: Zenghui Yu Closes: https://lore.kernel.org/all/c052a064-cddb-494f-a0d8-f8a10b4b1c4d@linux.dev/ Suggested-by: Nhat Pham Signed-off-by: Shakeel Butt --- mm/shrinker_debug.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c index affa64437302..cda4e86428c8 100644 --- a/mm/shrinker_debug.c +++ b/mm/shrinker_debug.c @@ -57,8 +57,6 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) if (!count_per_node) return -ENOMEM; - rcu_read_lock(); - memcg_aware = shrinker->flags & SHRINKER_MEMCG_AWARE; memcg = mem_cgroup_iter(NULL, NULL, NULL); @@ -88,8 +86,6 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) } } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); - rcu_read_unlock(); - kfree(count_per_node); return ret; } -- 2.53.0-Meta