From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (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 788D81DC1AB for ; Thu, 11 Jun 2026 06:20:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781158820; cv=none; b=ET/Sgl0SiQ7UNqDWTYAUq4U32w8sZK98zHJSqwlfwHJG4O75Pk5Yo/p8qgmmmbQwpByB2t4fLj6S/oOV3N1e1EHmIDcioNrKem69dw3XmloauyYNOiUcY+1yIIeANPCF6K1Oah1GFizMdh68a+xgy4ErUv5pzvBsa2L4nlXJx6E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781158820; c=relaxed/simple; bh=Nr78hPKZYsjeAKM4JVk8yc4+mfjad4MKDQgQCbFk0XA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=tTWHSYbpb9WEYt0KbeW2ivkrtcvDTdnNGi8xTBSlB5WJqfoyqH/oVgkYoRTelwNJSzrw2HqZQDT2rzHU/aVgr1QbE0MU8+XTM+/m5hp9rW9CrIWOPFlk89UH17ZpJn3jlwJi838ujHXV/kksn5YD0nb0Q+18EPBskwix0Bc5C7E= 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=RSz5M7+g; arc=none smtp.client-ip=91.218.175.171 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="RSz5M7+g" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1781158798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hzaS7luShZFVWIou6yNVr0W7N9RPMJYs1Wve8A/vwxo=; b=RSz5M7+gLjW12lsa/Oh+YvE/MIQ/eb6xpdv9RIAi+8KDHKehZR63ux+gmwS05doyBxVecz SNGmgedzWfCAEbXvNCwGnBr4wWwJEswHTSDuIASeFxKtmhBWb/wtUNx0Nt90Hxnd/pK+6U wyV2KOR37JGYGxdWG2XHUlxQQV3JRiY= Date: Thu, 11 Jun 2026 14:19:47 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] mm/shrinker: do not hold RCU lock in shrinker_debugfs_count_show() To: Shakeel Butt Cc: Andrew Morton , Dave Chinner , Roman Gushchin , Muchun Song , Qi Zheng , Meta kernel team , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Nhat Pham References: <20260610232048.62930-1-shakeel.butt@linux.dev> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Zenghui Yu In-Reply-To: <20260610232048.62930-1-shakeel.butt@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 6/11/26 7:20 AM, Shakeel Butt wrote: > 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; > } Tested-by: Zenghui Yu (Huawei) Thanks for the fix! Zenghui