From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) (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 01C0D2367CF for ; Thu, 11 Jun 2026 03:30:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781148654; cv=none; b=Tb1CKK8zT0w+Ci9HIyqwc6o0yneuWGnMNmz+4+87ffBNrxa2gEVnLSCRwHluhuPe/C59lABsSYJvLhFByps84w8GefYq5igeXWDiu9gkfnyLaplh2m0QoKADEAN6R9vEDhm3PuxEFoYEw/avPQu9v3sqN7fumxB2H7c2GZFmUX4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781148654; c=relaxed/simple; bh=jAJdEoFelqVAh6ODo9L5x67rF6paewSeeYDHws++788=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=MGF1y291R9wYPGOUKIq+uyema8b5o2YU68QPHHt7H7sqa6i63DAJtPPaovLx9gShfkppvUuG1cpZqRe+9qH4oIIRozksVQEf0P2fkqps7OKxMIWy3UIIRVj2DBucCHd96dMvEbImPafcaa1gQqUzCbPioa3vxlbBpjrla9ClrYA= 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=T0e3A5jt; arc=none smtp.client-ip=95.215.58.176 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="T0e3A5jt" Message-ID: <5426c88f-0c4a-459f-b9f6-f0677508d4af@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1781148651; 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=f9SeiToel+JcVkBJgaJtw5RlW+she1/Q3FYqXZbcv14=; b=T0e3A5jt2c1L1T+ln+V5jQZGkVp4n1FMK9QZi2JKXVrPUPCnqS/5e9EJ9R1059mESIxoOM 0CbMR+LA5dPe+Kd81W299AHs6nRWSGgQonMrDx5VTgnXKdr9lepBDcBqdv2wS529g8JJV5 nxNiJPfOHqOx1HQrgjgaKAk7GRc9gt8= Date: Thu, 11 Jun 2026 11:30:17 +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 , Andrew Morton Cc: Dave Chinner , Roman Gushchin , Muchun Song , Meta kernel team , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zenghui Yu , Nhat Pham References: <20260610232048.62930-1-shakeel.butt@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Qi Zheng In-Reply-To: <20260610232048.62930-1-shakeel.butt@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed 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(-) > LGTM, so: Reviewed-by: Qi Zheng Thanks!