From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 03FB9E56A for ; Thu, 11 Jun 2026 00:27:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781137622; cv=none; b=qdgy93DsaA/lKueL7vvdibzQ/nS5LpTEcuL87UPlluZRDJ3i06R0yQHyDJ1EZVCmcI+p7LVnC8Ei1bxdVA6VifIRCPbybX6CzWrKjvC7POl7iIedds9+sJ7pw21X77ceSMANb/eKRAfP8ZwvzsuOubLEmRD4TXO2fbcJEnxC2LE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781137622; c=relaxed/simple; bh=8W9c4GHkhyKEwEiwXpq2d4Ue1T9vqCDjew9pNQbOcDQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q/EXuAGMDfTH9zouOmcPnwYreAZ1oUKDpBOPByWgKMO9U4dB5h9+bhyREIj0LEnv/Ur5nZNIamB6xaaOh1NBiJoNQWRoeXKBpHDumDf0EHRdcL91dI8AEUm5/HYV+6OHVlyfHPfARVKvXdFG6EqDXLT7d+1HwfU4BmPGGIWf2g8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P2pAqV9z; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="P2pAqV9z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 469051F00898; Thu, 11 Jun 2026 00:27:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781137620; bh=sWl60uBMj2xbDWQfoHVwCjMYGBGOuR1rbjq8PkUIT3g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=P2pAqV9zNsybjktSvwbLvyRzqDcg64Whh6aePSx2mVgbHQscgHImYvCPhQUwvV9L9 jHffcv+bzo2ODhAbTKUXJJemL5ZepdW0ViWlAK2Cw/bazdz4P+GBz/9zWpF67vFr6S YHjTC6xuz6j474PcFeHwSo9v5ITmlej+z3MYz+KsHBaTfSKp08Sv/jjSQTb7zAYC7p NSSZNXZMn88nz25aNc454UX8QnvyTF9CS1h3VHdGRCVRw0YjhxRt7DXxGhLxeOdvcD hgKacUH+e6i1aboK6FOLu4DVGGfaPjAvMeiNmQFpY9Zmy6pQxJgibd0uG4ijlU3HxC bbZHkWG1e0BMA== From: SeongJae Park To: SeongJae Park Cc: Shakeel Butt , 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() Date: Wed, 10 Jun 2026 17:26:47 -0700 Message-ID: <20260611002651.69383-1-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260611002236.69207-1-sj@kernel.org> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. > > 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, SJ [...]