Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1071143rdd; Wed, 10 Jan 2024 07:52:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IG+/t4qnDQrc6FPOcGrgOEIfb9mlZ2LcHPXTEpO7YqhQqd+1ht3BBY81xlv4uyTf57CvS3R X-Received: by 2002:a17:90b:4ac7:b0:28c:e434:2a0d with SMTP id mh7-20020a17090b4ac700b0028ce4342a0dmr674746pjb.23.1704901965079; Wed, 10 Jan 2024 07:52:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704901965; cv=none; d=google.com; s=arc-20160816; b=kRYam7zG7oRY7Fgcc8l7COZgi+y91Xd9QqQkerqe24EEokrQ02RVWlftV8Vbd49a67 avZXahNzwdhn0kkeFE7PCDT5ZKsiClAfeI1DyS9oq/BgenfFSPy4aPy7iXDPZEadLbbr y9ataueib9N+Jq31QoliV/3gCC+suIMWkeJKpxhHUq8pYbn6apVLICHPRTTX44PrfU+N Ndh2Cv0Pzj5jbJq47rvqcf8mGd5nhS7ajjzdqQ5XTAk0eRdP4sMm83YuzDuF4pirm9bZ a7uRnEALnMQgfeiCrTmB9SxuLrS22JuTDrpN5N83m+f6evqSOIgvIfu9YhHvUN17K1/a o+DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=A2++2iM2Vr/yA3h5aHgeI2sGhhdn7Ppv5vYed7JdVrk=; fh=eS7klLSFSsne5mKJXNPVqGJ3lldpJX0oa9q5+f8bHik=; b=ZjEkAABI0kOJ9ih27bndUgMjidsMidQNr/E8pg+Cn+OTrDg0TsKZ09O7B7bVFS+c9S bdIH3k+VwvQRQR8bU81P5Cib2f5Df81HJ5CuT2YMnHRZ3mY0CEzNpGO36Ve874hC5Z7d qCsY30qhHdDgsz+JQTo7mX6XRslZdDHOusYdavd5KO9brK3kgSh90UZnIpsJsrJ2rTtl qplMoC/IOEL1Lc1AJ692H6ospeT9WSR9wbRUMi/VdE1IlhNQ7PXWzFsRrQ7WwHvw8uhi hAW6F1ZSekqbBOIqoWXsWrwDXpbXJOpOocxE2XVrWuW8vG2uOb5RhR8gREt0Zekpk0em q1kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CXj99WHU; spf=pass (google.com: domain of linux-kernel+bounces-22457-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22457-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w6-20020a1709027b8600b001d3fc132760si3778301pll.545.2024.01.10.07.52.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 07:52:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22457-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CXj99WHU; spf=pass (google.com: domain of linux-kernel+bounces-22457-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22457-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C2F452851AB for ; Wed, 10 Jan 2024 15:52:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0EB524CDE8; Wed, 10 Jan 2024 15:52:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="CXj99WHU" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1965A4CB5E for ; Wed, 10 Jan 2024 15:52:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E99B7C43390; Wed, 10 Jan 2024 15:52:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1704901925; bh=XlltqPfa8Akiky7w8TdLIafVMR4SvWgI44ZmWOSsDio=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CXj99WHU/eYfD584OTSaFWnR04ME0zWX+oeIjgO67pzMAljFt3LQSs7xHQ7JBuUxi FYdMOHLvl1R8SpsPgPeoUAFHRaQNPyl00DbEwVdsga9zDhyh25f1i86Ja6Sbo5ZOmw lhWUyyCjw09dwPspC92tyffkjxp/vMhKm5R36Rwc= Date: Wed, 10 Jan 2024 16:52:02 +0100 From: Greg KH To: Tejun Heo Cc: andrea.righi@canonical.com, ast@kernel.org, linux-kernel@vger.kernel.org, geert@linux-m68k.org Subject: Re: [PATCHSET driver-core-next] kernfs: Protect kernfs_find_and_get_node_by_id() with RCU Message-ID: <2024011038-drainer-goofiness-9745@gregkh> References: <20240109214828.252092-1-tj@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: <20240109214828.252092-1-tj@kernel.org> On Tue, Jan 09, 2024 at 11:48:01AM -1000, Tejun Heo wrote: > The BPF helper bpf_cgroup_from_id() calls kernfs_find_and_get_node_by_id() > which acquires kernfs_idr_lock, which is an non-raw non-IRQ-safe lock. > kernfs_idr_lock used to be a non-irq-safe lock which could lead to deadlocks > as bpf_cgroup_from_id() can be called from any BPF programs including e.g. > the ones that attach to functions which are holding the scheduler rq lock. > > To resolve the situation dad3fb67ca1c ("kernfs: convert kernfs_idr_lock to > an irq safe raw spinlock") converted kernfs_idr_lock to an irq-safe raw > spinlock. However, this was also broken as we call idr_alloc*() while > holding the lock and idr itself uses an non-irq-safe lock and also calls > into memory allocator. > > Let's instead RCU protect kernfs_node and kernfs_root so that > kernfs_find_and_get_node_by_id() can use rcu_read_lock() instead of > kernfs_idr_lock. While this unfortunately increases the size of kernfs_node, > it's the most straightforward thing to do and there likely are other places > that can take advantage of RCU protection and improve scalability too. > > Please see the patch descriptions for more details. > > This patchset is on top of the current driver-core-next - dad3fb67ca1c > ("kernfs: convert kernfs_idr_lock to an irq safe raw spinlock"), and also > available in the following git branch. > > git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git kernfs-use-rcu Thanks, I'll take the first patch now, for -rc1, and then the other 2 after that to give some testing time. greg k-h