From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) (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 EDD1835893 for ; Thu, 11 Jun 2026 00:43:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781138602; cv=none; b=OFklgMKXkEGGy/XiwNy22043+lkykiwww92obCpDXxQEfPXZgXLkTcW+8Fqz6GKYPunNX9NYMwZ7EDwRKqWXGWoxVVJlvCZoHWXeeyF3k6mV/D/6izuTEGT/vmyxoPhiUuL16TjI3w/Gyap+H8qhFh45ZTKNJnXDLqHlYYUl+Dw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781138602; c=relaxed/simple; bh=0de5F5nrSF82bj9Q6IIK51kOhhys73TNetsau0ewNq4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fZ0zHqJ4H5b43hzybH3m/9Ov3+qAcQOuAXhvr7Cj0Ckjr6ePslfEYax9KHiLwBjyl4DofJunPhO+81pUECqyS/ZA+ImlqCYRxBFQAvTb08iH8UDG5syU8VoTVrHuOuYx+Xt/lTGN8BzTXrghgW5SlBRSxuVMWJ0khkLBkATH7No= 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=n1JOmPm4; arc=none smtp.client-ip=91.218.175.174 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="n1JOmPm4" Date: Wed, 10 Jun 2026 17:43:13 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1781138597; 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: in-reply-to:in-reply-to:references:references; bh=PxXYed74ADL8caJKJdGToQwcuACBpIehdiJ6ipQ6Epc=; b=n1JOmPm4sr6V71uCwYZTEeUGiMFTdzivPvGu/nr6gU6xUIK59EZPQfqlql8MqjU8juVKQV KN7SBZFy8OI5VIyr05j9NPWO1HlZH9rq0rJVit4LfqSWm8KRDaRibN1lmJaX9843erpfto 7OjPDzW/hEwh5PpJuBmoCbBmyrgHPX8= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: SeongJae Park Cc: Andrew Morton , 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: Re: [PATCH] mm/shrinker: do not hold RCU lock in shrinker_debugfs_count_show() Message-ID: References: <20260611002236.69207-1-sj@kernel.org> <20260611002651.69383-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260611002651.69383-1-sj@kernel.org> X-Migadu-Flow: FLOW_OUT On Wed, Jun 10, 2026 at 05:26:47PM -0700, SeongJae Park wrote: > On Wed, 10 Jun 2026 17:22:51 -0700 SeongJae Park wrote: > > > On Wed, 10 Jun 2026 16:20:48 -0700 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(). > > > > All make sense to me, thank you for the nice description and the fix! > > > > > > > > Fixes: 5035ebc644ae ("mm: shrinkers: introduce debugfs interface for memory shrinkers") > > Forgot asking this, sorry. Are you intentionally not adding Cc: stable@ here? > I think the user impact is arguably minor enough to not Cc-ing stable@, but > just thought it would be good to make the intention clear. > Haha I was just being lazy to think through if this should be CCed to stable or not and letting others/reviewers do that for me :P > > > 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 > > > > Reviewed-by: SeongJae Park Thanks.