From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) (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 43FED31064B for ; Fri, 12 Jun 2026 03:14:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781234073; cv=none; b=bzKCS01iSB0NzoPtuyCHzYVPmoNRDkJyp4Xh6upf8KIhPMmAXNO3GNolGJfS+EGId5u3QDACzPF6psaeuGmIDLSSKAOrWdbagwRLN2P4kcMtb7cutR22uXosjc9vTttO7vnMVs2LeAOOjoSkHDnUiq2EvJk91s088Yksw4KAtEc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781234073; c=relaxed/simple; bh=VAWcQIo4LFCR4g1n96XAyhGsxkHzOswwVjSVyyRsVhY=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=MFtXfiFgQNZ+/HgIxUw/8cbEivOo1kc2BhUa70+ip4V1DEFWKn8XxQ31iOHiaqch5znrZQKJksT6FX/zLqVWCRfMNk96eEEfaQC9d8oS1uAYavNrGCwSa3d0p952ggWYNnMxKy8xqI0w4wYY2/PMchEU/P7Bynv7ndavl20ayjk= 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=RM5K7Geg; arc=none smtp.client-ip=95.215.58.189 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="RM5K7Geg" Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1781234070; 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=Fx4XH+gdmaatynF2HbNiaRzulnURipVC2+u2CSHKWqc=; b=RM5K7Gegvr/qYlJsWmxEJwZmeqnLTvH6TNVM1SSVcpxqVAhgshMiZZF4s89zWg2IOdZ1ae onpdpWXQpIkdR8ln27AqCH1d7PgUo6hlTtSsjHjjiW/QWDitesOiJvprY7XipcfUJH+kiT ehJQGvy9oVQxM1wGnvbMmaD1rnFo5+s= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Re: [PATCH] mm/shrinker: do not hold RCU lock in shrinker_debugfs_count_show() X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <20260610232048.62930-1-shakeel.butt@linux.dev> Date: Fri, 12 Jun 2026 11:12:54 +0800 Cc: Andrew Morton , Dave Chinner , Roman Gushchin , Qi Zheng , Meta kernel team , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zenghui Yu , Nhat Pham Content-Transfer-Encoding: quoted-printable Message-Id: <0C56AFF0-61B4-4212-80D9-474D838C9498@linux.dev> References: <20260610232048.62930-1-shakeel.butt@linux.dev> To: Shakeel Butt X-Migadu-Flow: FLOW_OUT > On Jun 11, 2026, at 07:20, Shakeel Butt = wrote: >=20 > Reading the debugfs "count" file of a memcg-aware shrinker can sleep > inside an RCU read-side critical section: >=20 > 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 >=20 > 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. >=20 > 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. >=20 > Drop the rcu_read_lock()/rcu_read_unlock(). >=20 > 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 Acked-by: Muchun Song Thanks.