Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp816986rdd; Tue, 9 Jan 2024 23:40:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHvs2/eGVU5WClVm76UbCUoc/SPKedCGARIr2NowCHj9QsSEWNt6nBrLQ5QwC7WP57X3wC+ X-Received: by 2002:a50:ee85:0:b0:557:153e:58cb with SMTP id f5-20020a50ee85000000b00557153e58cbmr306059edr.16.1704872438467; Tue, 09 Jan 2024 23:40:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704872438; cv=none; d=google.com; s=arc-20160816; b=MTg4+L1BzgXlOgYlN4xr14Fc8XhgTU0REEsp0eqH+qbEndxKCSjjBlO0BxwSFT+IMu sIGzS3aSBqojVT6o0xnXl3hV3LB6PEqKXKryhkv9guZa9Cl/iikTGELCr8EJGJxnXEgF wPkXiRwRw8jybWoixE1rsw+5GUUOlTG3FTGR35qMIIMaLnmD+p91nhbOJRn28Qd50d7u QZ9qHIS6VqMmkgt8HftA3O8TtWd3rUwW4/LYSzIsqlmsCKvc7vrxp6uWgvagK2Mez0OL BaF2DFkWhjMbeqCoykEb0MXPFQdoqz7JHkXtASJo871aRpdqvEeazkW2OZq6wn7LbMwX kafA== 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=gqWONg/RdAipmRUniv6l6rz28Dcm60IsseyPA4ghbII=; fh=yKZpIhKviYzTTi5DVJIoS23/pOx3GmfdXpqmhifee2g=; b=QL38KXEkkGA20WzjE3LbI/eqqozn/CV0I7VVeykWnipT4i2h0kEhLyUjykZy7bsMRQ CZ5pV5A79PZ679H0Xf8XkBjysmZBTBzuQr19cbnOntAiO0SniY65+sFHGB77oNN+Sl9+ iL1t1B+HbP9a17Zv0hHuY3YH5O/GxXHvWfJ52HvGJJZu3DjtNMRsfY40qj7W4ObuEPAI QqLnpqVh/FJj0t4++n1z5OyFh8dwH/BZu+JG+llRX+91CDIMYzNOX3Cm42jafVOKI/St DS8xRaENlxgoZ4MObIvCx8yAdbD4UqV/zF3iP71YKtTX7Yp0rizYZpRvwrkUUazMnbJd i46Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b="uqzi/qd6"; spf=pass (google.com: domain of linux-kernel+bounces-21798-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21798-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id c2-20020a50f602000000b005574ae398ecsi1474446edn.62.2024.01.09.23.40.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 23:40:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21798-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b="uqzi/qd6"; spf=pass (google.com: domain of linux-kernel+bounces-21798-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21798-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 0726C1F27641 for ; Wed, 10 Jan 2024 07:40:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 11B003DB85; Wed, 10 Jan 2024 07:40:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="uqzi/qd6" Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (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 99F363D964 for ; Wed, 10 Jan 2024 07:40:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id F2C563F2D3 for ; Wed, 10 Jan 2024 07:40:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1704872429; bh=gqWONg/RdAipmRUniv6l6rz28Dcm60IsseyPA4ghbII=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:In-Reply-To; b=uqzi/qd6CFcnm7AQp39X4tQdWXK6MDhkZau5kumOecuN6+F/vv+RP/su0O1k/SAun E8dhZe/lzIJXhcxrIqp6qJb+PQNVdOFJgwfxDIBXXsIY/kd2jl3bDh+W2J+7vXhx3M n0tZmVxZswv+Wu05Qgeo4uyEXzrtHtmgLksvF2faKBla6NFAgx9JPyvDBvYSpcyKZ0 MJUr6M1LYMBoJ+1f/uDZhaCZVuvWzKuNrazwa2A7cudJYTw/vIZg8fEYIbRktG8JAD RuLm8600PyviYmwfCtDlGUEVI9RScy9NZGwQn3c+qgDHh/IR+6oRA8Ce+brYlEGvD/ eb1xFAJTCKceA== Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a2b068401b4so233109166b.1 for ; Tue, 09 Jan 2024 23:40:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704872429; x=1705477229; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gqWONg/RdAipmRUniv6l6rz28Dcm60IsseyPA4ghbII=; b=mTsFTok6wx6gWbuaWbTRCnXuqoi2PLGk94BYsKgKQYhZ15wo/J+rtSy6cMmLYWJ3HL tam11FzVmxOdlm4/XqwxqBw3Ch//ZyRR4mD3URRLCwjhNKil3pDo7DDV7jcrxwNJAcUo tCDoCLTdAbwKdqthncRFP7sprvEIqJ87c4UqcgoyVNbx/A6loUhEMiSaZJZdoX6zxnxm de5NJQKYzUZIx93/4zmi3j6T8WNd0H4cHlpU6+M7G5U6a5bSIyNw7hebnH9oQ1JYS1BE nTAhlh/ApLA0k8ADI6M2hBm4l1pwDxqOY39S5vJxrBpnLyhDRs+AW6CwHZAaoXqGP/y1 20bw== X-Gm-Message-State: AOJu0YwIl0EVAbYPVEb31kmuUUo+vuqXCf+Md+KXpsBQ/yhhupjkNtFm QpxRbF1bCPrqju2aN8m/u5nz2a3dirxU/9hCmnIRhzGofiwlJ34+QlXsNpwbEVHJcwkCZkqnVmU n01BV4rJlaoYr2/+nPh8BCO90dZl7KbNvgiRKcHxOi6G9Jm41 X-Received: by 2002:a17:907:5c4:b0:a26:8c4d:b0b6 with SMTP id wg4-20020a17090705c400b00a268c4db0b6mr2356453ejb.9.1704872429681; Tue, 09 Jan 2024 23:40:29 -0800 (PST) X-Received: by 2002:a17:907:5c4:b0:a26:8c4d:b0b6 with SMTP id wg4-20020a17090705c400b00a268c4db0b6mr2356437ejb.9.1704872429384; Tue, 09 Jan 2024 23:40:29 -0800 (PST) Received: from localhost (host-87-18-244-72.retail.telecomitalia.it. [87.18.244.72]) by smtp.gmail.com with ESMTPSA id z4-20020a170906714400b00a26f63d16f6sm1814846ejj.25.2024.01.09.23.40.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 23:40:28 -0800 (PST) Date: Wed, 10 Jan 2024 08:40:26 +0100 From: Andrea Righi To: Tejun Heo Cc: gregkh@linuxfoundation.org, 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: 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. > > -- > tejun Everything looks good to me and I can't trigger any oops with this one applied. You can add my: Tested-by: Andrea Righi Thanks! -Andrea