From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796325238; b=dGXu5VPXQC3pONcQb5tVnxO9DlHrLo2TtqM0O3bgGMtQ8qTn8Kq8UI7uh1geD785/8rU NNEjdsv6Su54FsPIy6qC77zvKo2RXQy23NHimp0x4+Nzt/sA8P24HvpA7UiaIv02Uhes7 lidAXO3EvlCglmKnF7rM0HKl4nWU5debpq1TY5YdUcTsZJrWEdqE6d0EgcUo6k1aI5+cN 3G8rTBNqVPgUTVJwT4MLkeNJQw6PK46+PPEDNMwGud2GrnELp2u3k3pJ79Eyy2ph7Pyhg i9X2/clFaUm9nPieG+BLH+f0vJkjDyZ6Zhl7ZrvXrnETHKmjklk0kkN39fDi4IcEu2Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796325238; h=Received:DKIM-Signature:Date:Message-ID:From:To:Cc:Subject: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=CKnK6yVpFdPnKEebpy7s8jbhAGoC6UFJWcOBkVAIQiY=; b=xFpaCPLNFCqCgypNPCNMXYQKRcjrxK1hCprAMo9wkXFWUziFz6irXsHR9cz9SxNAXnzh 28oOHD4daeSlKALdqKLGDUQDyAPgbwkQb7ZFv54khjLxlTe6jFYlFUHUj3cIYYF0yhrm/ B72xi5kQwnHdmdSp7B5OZuwvvxRiPIk7kaOTps0ZSLWukFy3+TdI4DJPmjva4k80W8Zy6 Bi7KXfT/oMxZk/6jY2cg6nRqnTnWiz4C0y26WjGvJJSX/5qp2wQveiroVTsrL3Vn58VI7 4ghuObKqI/QADutCXbOKBsg0h7KKJJ+TlUiInDhm19+8BKYcG6b9l1Y71W9ujaysLQw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ou3jI4TD; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5075606A33C; Thu, 3 Dec 2026 19:13:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ou3jI4TD Received: by smtp.kernel.org (Postfix) with ESMTPSA id 610D71F0092C; Thu, 3 Dec 2026 19:13:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796325238; bh=CKnK6yVpFdPnKEebpy7s8jbhAGoC6UFJWcOBkVAIQiY=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=ou3jI4TDnl03d9m9wSW8jqLS3iHhVNJsf0yAWxslzH7V3hWP5sSkNTyfTFJLQ12Ky 1LW36Ooj7BqtqAOg9gxGzrwzvSf4+qWyPzC+xt712Pwuw37TLz6d8j+ylPjbMMtT70 Me3OFtipGSwa+4HpoXLiNON2Kd+vR+SzOg++DN2Q8SqlXy1D74nStfDNDHIJxlIHIy 2XOP1ZwGKgctYHEW1QVlx+iIjEEvo8XMgT/rjnd9TUMltlqLiRLshH3N5uuzg6Dd6t BgJYylIY+cO1BCIHsl+4s09crxplZAOE60nvCDWOJBrEAK14Lectmxptw5NOikZzCK liLR1LmBH+waA== Date: Thu, 03 Dec 2026 09:13:57 -1000 Message-ID: <2c277706a4a46a7540dbdfeef8a1d225@kernel.org> From: Tejun Heo To: Shakeel Butt Cc: Christian Brauner , Greg Kroah-Hartman , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Chengming Zhou , Johannes Weiner , Reinette Chatre , Babu Moger , driver-core@lists.linux.dev, linux-fsdevel@vger.kernel.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, stable@vger.kernel.org Subject: Re: [PATCH] kernfs: check the active count only before a node's first activation In-Reply-To: <20261203113949.1415267-1-shakeel.butt@linux.dev> References: <20261203113949.1415267-1-shakeel.butt@linux.dev> X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit On Thu, Dec 03, 2026 at 03:39:49AM -0800, Shakeel Butt wrote: > Writing 0 and then 1 to cgroup.pressure hides a cgroup's pressure files > and shows them again with kernfs_show(). If a PSI trigger is written to > one of these files at the same time, the show can hit this warning: > > WARNING: fs/kernfs/dir.c:1480 at kernfs_activate_one+0xe6/0xf0 > Call Trace: > kernfs_show+0xa8/0xe0 > cgroup_pressure_write+0x17c/0x220 > cgroup_file_write+0x17f/0x440 > kernfs_fop_write_iter+0x20c/0x2d0 > > The trigger writer breaks its active protection in cgroup_kn_lock_live() > and waits for cgroup_mutex. The hide cannot wait for the writer, because > it holds cgroup_mutex. The writer then takes its reference back with > kernfs_unbreak_active_protection(), so the hidden node has one active > reference. If the show runs before the writer drops it, > kernfs_activate_one() warns. The count is still correct: the writer > drops the reference when it finishes. > > Nothing can hold an active reference before a node's first activation, > so check the count only then, before the early return, which also > covers a node that is hidden at that point. resctrl can hit the same > warning since commit 2d77f9768850 ("fs/resctrl: Prevent deadlock and > use-after-free in info file handlers"): its info file handlers break > active protection on files it hides and shows. Commit 071d8e4c2a3b > ("kernfs: Relax constraint in draining guard") relaxed the same check in > kernfs_should_drain_open_files(). > > Tested in a VM with commit 8996b7c8174a ("kernfs: recheck of->released > after acquiring the active reference") applied, which fixes a separate > crash in the same test. Six threads write PSI triggers while another > thread writes 0 and 1 to cgroup.pressure for 15 seconds. Without this > change the warning fired in all 8 runs, also when an unprivileged user > does all of it in a delegated cgroup. With it, there was no warning in > 11 runs, though a debug counter showed the show still found the extra > reference. The kernfs and cgroup selftests pass. > > Fixes: 783bd07d095b ("kernfs: Implement kernfs_show()") > Cc: stable@vger.kernel.org > Signed-off-by: Shakeel Butt Acked-by: Tejun Heo Thanks. -- tejun