Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp4432725rdb; Fri, 29 Dec 2023 01:14:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGGELDiPTv6uM9yrLHSx8ynU2iYD6RDfFl10ECOCFIUVU9Pg8GqmAUPx4eQL3kqAVwIvWWf X-Received: by 2002:a05:622a:13d3:b0:425:f0e0:adb3 with SMTP id p19-20020a05622a13d300b00425f0e0adb3mr18476835qtk.63.1703841276150; Fri, 29 Dec 2023 01:14:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703841276; cv=none; d=google.com; s=arc-20160816; b=fCctORZs1WZhz2BSKqROgzl5/LRKSFcnELvRLXJddsYrMVkQjcEAn1ulpfwmLL6aGj QMtxsHxJPFqBtMFV0NBcK2l2wSv34B6ygdosG778MSh3+uovnfTOnlXLS6M3lB7jU3pn 7fRFJeW4WY2GhnoXA9jF6fVKIKh4ZaYu3tAo0JQ5KgY9N2WXGBmLqf6tbJtvdbU5fKo3 6XwsExX1oOEYkV+hpknvELbaNY9t6sFQfMIMdz8Cdt0ZT75tIl3dgmElw37YiaekA1B8 XiEA6jr3IQin0m97xXPW0AInxApguhqJNT/U1KgjnNCGF8APeati0PrfGyY0e77F4v/v yE4Q== 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:sender:dkim-signature; bh=tt8D9UgoK3KzeqONo14OqSpjYQOH1MQ3gtZAY7SE4tg=; fh=IRbmDXpL76W3FzjliHVZEe2nQTsj2kq65LjIIOid6zY=; b=M2yNlP16/elIzbu0g6WUTcHP3+kwxPHpHu1AXolY/C8MIEXh0ZZQIGQ32OcSBHtHI/ VFLK8nr7BVUt/z77WqNLqHyOL+mGQLHHvDWEMk3mpb+bS4TejsRGuYPcc+95qlWHvf7G DjYaR6oh+7IdBNsDNsITHKuWUD/cikBrguMhx4Xb7DPmLpvdgv2Qf5dl81RlaefjXuns smJRLuh/UDEVTzGOaeP8c89giahh5920dw9LkqWCbw/o1R80V2DXIcb/vnjNCsN/Vj0Z Uoun8jvpfu1oU3gKeKhBZkUk0oTFtchE5Q5zw6XpDXJmLSW/1VlLE9p5EHzQ9lnGtGvU vNXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=JuN15BmV; spf=pass (google.com: domain of linux-kernel+bounces-13020-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13020-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t29-20020a05622a181d00b00425e942f110si18376518qtc.325.2023.12.29.01.14.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Dec 2023 01:14:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-13020-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=JuN15BmV; spf=pass (google.com: domain of linux-kernel+bounces-13020-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13020-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id AFB5A1C22D80 for ; Fri, 29 Dec 2023 09:14:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96F2B10A1D; Fri, 29 Dec 2023 09:14:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JuN15BmV" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F35B10A00 for ; Fri, 29 Dec 2023 09:14:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-28c467446f0so2570361a91.0 for ; Fri, 29 Dec 2023 01:14:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703841267; x=1704446067; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=tt8D9UgoK3KzeqONo14OqSpjYQOH1MQ3gtZAY7SE4tg=; b=JuN15BmVmJGNGTnF6KfEzNiwXTG/v7MkshieT+9nmpVZlLyRy/Agg0zEeLzPhDW04m hD0JNmRKjFri7StU4Sxwe8PLXibl2snRudFmYVg6fho0yD5hv8eP415M2m2oiqusnTt9 VScKgf/rNu3hwIld/7kK1jf0dUuFVvcXfOP+iQDvlLup1HS872JmZWJOuEnm3GwoDc1M J+h+HBW1IP7cFQkX7M9HazvDU4RK7w1WK7v52nNOVu/OT11TpYm19VP97JOv4NpD9x6A VDWvqaosolB/GN6BhFPa+4Ii64TmMUejqbYKIOceqWerI+WW7dmNzkQB3eOz+LVzsNep tAHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703841267; x=1704446067; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tt8D9UgoK3KzeqONo14OqSpjYQOH1MQ3gtZAY7SE4tg=; b=u7Te6CWrvrb4EjYepTLtXCzAZv+ugdPFSEXxwaSr89ea1cYbi9o51r2h4BuSHrrmzF xHrugTl7LmlUyp3eLl0BjOEBIawTScSVFLhgyQHhQkBxTPpfpvJo7HW4a8ucYkV4SllE p/VXHl+Gsh3otCVHRyakD3pExTv8bycSjmT5u/cuULyZroL/xuLFcvgHlFOTyAz9aMyu hDoE7HFkH2wOvJ5zd5/zn3GpOr2C+CYp5VNoZfZzsOtsx5qpFmnjkgXcyj8iIEkZ7go3 op6glp5mILd46qmLYRilXfnGf2lurtbd8hUi/ULqdwvKjTWdybuCGk72kLdh4KLPhPc4 xvpg== X-Gm-Message-State: AOJu0YzQF280WzLHT4OONXMDrZfLePx8DZ7IOzAHf+JY7qinvi74aHNZ O3aEOsJkr2Y//Po7yEcpt0E= X-Received: by 2002:a17:90b:3781:b0:28b:d31d:bca5 with SMTP id mz1-20020a17090b378100b0028bd31dbca5mr14941702pjb.32.1703841266690; Fri, 29 Dec 2023 01:14:26 -0800 (PST) Received: from localhost ([121.167.227.144]) by smtp.gmail.com with ESMTPSA id f4-20020a17090aec8400b0028bdc73edfcsm16806029pjy.12.2023.12.29.01.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Dec 2023 01:14:26 -0800 (PST) Sender: Tejun Heo Date: Fri, 29 Dec 2023 18:14:22 +0900 From: Tejun Heo To: Andrea Righi Cc: Greg Kroah-Hartman , Alexei Starovoitov , linux-kernel@vger.kernel.org Subject: Re: [PATCH] kernfs: convert kernfs_idr_lock to an irq safe raw spinlock Message-ID: References: <20231229074916.53547-1-andrea.righi@canonical.com> 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: <20231229074916.53547-1-andrea.righi@canonical.com> On Fri, Dec 29, 2023 at 08:49:16AM +0100, Andrea Righi wrote: > bpf_cgroup_from_id() is basically a wrapper to cgroup_get_from_id(), > that is relying on kernfs to determine the right cgroup associated to > the target id. > > As a kfunc, it has the potential to be attached to any function through > BPF, particularly in contexts where certain locks are held. > > However, kernfs is not using an irq safe spinlock for kernfs_idr_lock, > that means any kernfs function that is acquiring this lock can be > interrupted and potentially hit bpf_cgroup_from_id() in the process, > triggering a deadlock. > > For example, it is really easy to trigger a lockdep splat between > kernfs_idr_lock and rq->_lock, attaching a small BPF program to > __set_cpus_allowed_ptr_locked() that just calls bpf_cgroup_from_id(): ... > Fixes: 332ea1f697be ("bpf: Add bpf_cgroup_from_id() kfunc") > Signed-off-by: Andrea Righi Acked-by: Tejun Heo As an immediate fix, this looks great. In the longer term, it probably would make sense to make that idr RCU protected so that lookup path doesn't have to worry about locking order. Thanks. -- tejun