From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (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 C1C8E331EDA for ; Fri, 12 Jun 2026 04:00:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781236834; cv=none; b=DDMaugVqzexmoFvALH5rPEBpBO1MplgGW8GvuDLk9E4rqJE/l4ErUIgprgYPiEK09tyf5kjDUNn+UiDIROT4oNYge/jE6U0f/+nPq+96j8BrRb7y44lCYP1EjBxOnr/uJZYqJEU6QDezuxIoYkqnDo7BJ1HP7+1j3nT9dlt+jp0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781236834; c=relaxed/simple; bh=Tf7HmAOmadB+ZfSBpCPCB80cFoYChbWDYBTU3c/r7xg=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=HdNOKOSPVphNigWebgEa6N3D10+VnotejIF3giyWSKOmLd1rzHEBGCJazQlTNPUp5XCpcs6tED9DqDEwMqOAOuym5sMTYWZ0ZNQyQbZBWYyypXoIh1TQ/O9wrc3NE+wOyQZjJsr0ppBzhrP7JjQO0qFE9pFZKAYy2e1yO9mVGao= 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=G5EcDdQp; arc=none smtp.client-ip=91.218.175.172 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="G5EcDdQp" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1781236830; 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=Kb9XhzHn/hQKeTGOyjGfHnMrWyxQdJZuAbxjI5R5xbo=; b=G5EcDdQpHo2eHjWBTqxZMmRBT/I9pw3ptbS2GYZEoYTNAWQ0Ke/jktVzTYdCrIR7U34HR8 XyQmjwvUdpJiCuRK1yO8YElKSgXnzACGMW3lCEN37Wm8+vZow58TLloRZsQv6AztvdLkLa FHar+0HFVajewrsqhstI0C1m6FxM6m4= From: Roman Gushchin To: Shakeel Butt Cc: Andrew Morton , Dave Chinner , 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() In-Reply-To: <20260610232048.62930-1-shakeel.butt@linux.dev> (Shakeel Butt's message of "Wed, 10 Jun 2026 16:20:48 -0700") References: <20260610232048.62930-1-shakeel.butt@linux.dev> Date: Thu, 11 Jun 2026 21:00:24 -0700 Message-ID: <87cxxwz9uv.fsf@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Flow: FLOW_OUT Shakeel Butt writes: > 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 Reviewed-by: Roman Gushchin