Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6825304rdb; Fri, 15 Dec 2023 09:13:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbQ0YzkXRU3jOdNJemNVddm6FGqyY5Hd188dZj1i0VigjOQ59nhXoTyZRAyS2LhjCIWWdc X-Received: by 2002:a0d:d585:0:b0:5e3:72d:76f3 with SMTP id x127-20020a0dd585000000b005e3072d76f3mr4643243ywd.40.1702660421363; Fri, 15 Dec 2023 09:13:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702660421; cv=none; d=google.com; s=arc-20160816; b=iNjXueXx8kZREPcWQMsJG8VdyBDOSwBQMNBgeiz6xWJidwMUl57d0yEdNbOJdN1uAh GjGH+pCUMOqV7cbMrEqsnZ0d7UeY1oUYdNd0aToNbG4Yj/s1qqjBIKO6oX6m0il0CPTv tSqw+83L3ywwgwM35rb/ZzkJOM2aGreLLmLZ/mSegksn0A2mj+z96Etr/28g/LyGnQ2d K/jmymHQYtIcog16xAYI06Ndh6yBpO2KmPA5ttJ7DjgGmrTWdj360lr1vx7lBleaivC2 6ou23dQrVlpc7RP1DDjSovzGsTlmclx7fGAGQdKY8/cQjbS7hBn/7sTfp5GAw+03mvou Q9aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=ttIXeZ1ovHzP3s4F4dQhi8p1AikC0DzBNJEl/q3oOFU=; fh=W7Dca+T8MT+c4dhSkiblyzcjRLjbvPOaY9Ee2xwvkcs=; b=eL7pmXnXeCMlf4l1H/jhn5lW4uxs5ZMvfwYoThgYtNGysmDoGNyfftMUzciauwEa3T +9irXBY2zTmh7rgp1NNLLbTG3l+N39xnx79D3KI+95R8yDet9pWUP/nfmEKgax0kimgu POacNCx4OXWuauQb6yicd4CIZ2gF3CGKp7uGBz2NzMy2qbe/t/ZL6V00w/LLmS1eSjBH E07ugDIFGIt0649nY4MleQOzWi0btBMbl2zNkdH5ab7qIS1dHEr7J+CZCQPZclE8fyup AyZhmPXDL2QoryocJ+GKn0auYv7+p1/qm4wep1KKUGaC0/JySNcfR81UVMaswBzfzEGt pLPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=i1txzjU2; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-1371-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1371-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id n203-20020a0dcbd4000000b005e2834e8be2si4399969ywd.12.2023.12.15.09.13.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 09:13:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1371-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=i1txzjU2; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-1371-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1371-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 1CE191C23FC4 for ; Fri, 15 Dec 2023 17:13:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D91D44B14F; Fri, 15 Dec 2023 17:10:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="i1txzjU2"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qpiqOMh1" X-Original-To: linux-kernel@vger.kernel.org Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 E658246459; Fri, 15 Dec 2023 17:10:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1702660237; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ttIXeZ1ovHzP3s4F4dQhi8p1AikC0DzBNJEl/q3oOFU=; b=i1txzjU2KalZCJ8xYOeccEgh79T53JDMXo6hg9E0Mau+4g4nEzUiD/CU8QtNlcyNoMioNh TxMQ6lCO2yFp+l4aRR42CeLo7AtXdM42ZZzsnfMKblwNsySw00E19iXVw2u5HXIlKMh1od 0Llrgx3TK8reem3ivDEKJy2UXYWWALyMSBMFYs9+zxL/HlBtrzIcUXm5m8ZZ/5YImNN7lO cAGnMTMRhHeXvmYWjgB14T5Fcz6Y7eQAgy4ZqjE08SOVUO1jI2u1fAy/aFqNaScVh8B9jc QCHYZ1d78L1SzqyNvK0hY0llM5vR2g43iaL1X+2sVIpumHkKDsIyh1k5X25prQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702660237; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ttIXeZ1ovHzP3s4F4dQhi8p1AikC0DzBNJEl/q3oOFU=; b=qpiqOMh1zBcnXXLLLCyeEFb2GN33yYgr8NRbg0Pr11SJ8OU7LfkwcblN3sg2bH4nUYN3Sc jk7theU4aQBFwpBA== To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: "David S. Miller" , Boqun Feng , Daniel Borkmann , Eric Dumazet , Frederic Weisbecker , Ingo Molnar , Jakub Kicinski , Paolo Abeni , Peter Zijlstra , Thomas Gleixner , Waiman Long , Will Deacon , Sebastian Andrzej Siewior , Alexei Starovoitov , Andrii Nakryiko , Hao Luo , Jiri Olsa , John Fastabend , KP Singh , Martin KaFai Lau , Song Liu , Stanislav Fomichev , Yonghong Song , bpf@vger.kernel.org Subject: [PATCH net-next 13/24] net: Use nested-BH locking for bpf_scratchpad. Date: Fri, 15 Dec 2023 18:07:32 +0100 Message-ID: <20231215171020.687342-14-bigeasy@linutronix.de> In-Reply-To: <20231215171020.687342-1-bigeasy@linutronix.de> References: <20231215171020.687342-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable bpf_scratchpad is a per-CPU variable and relies on disabled BH for its locking. Without per-CPU locking in local_bh_disable() on PREEMPT_RT this data structure requires explicit locking. Add a local_lock_t to the data structure and use local_lock_nested_bh() for locking. This change adds only lockdep coverage and does not alter the functional behaviour for !PREEMPT_RT. Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Hao Luo Cc: Jiri Olsa Cc: John Fastabend Cc: KP Singh Cc: Martin KaFai Lau Cc: Song Liu Cc: Stanislav Fomichev Cc: Yonghong Song Cc: bpf@vger.kernel.org Signed-off-by: Sebastian Andrzej Siewior --- net/core/filter.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/core/filter.c b/net/core/filter.c index c8013f762524b..896aa3fa699f9 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -1652,9 +1652,12 @@ struct bpf_scratchpad { __be32 diff[MAX_BPF_STACK / sizeof(__be32)]; u8 buff[MAX_BPF_STACK]; }; + local_lock_t lock; }; =20 -static DEFINE_PER_CPU(struct bpf_scratchpad, bpf_sp); +static DEFINE_PER_CPU(struct bpf_scratchpad, bpf_sp) =3D { + .lock =3D INIT_LOCAL_LOCK(lock), +}; =20 static inline int __bpf_try_make_writable(struct sk_buff *skb, unsigned int write_len) @@ -2023,6 +2026,7 @@ BPF_CALL_5(bpf_csum_diff, __be32 *, from, u32, from_s= ize, diff_size > sizeof(sp->diff))) return -EINVAL; =20 + guard(local_lock_nested_bh)(&bpf_sp.lock); for (i =3D 0; i < from_size / sizeof(__be32); i++, j++) sp->diff[j] =3D ~from[i]; for (i =3D 0; i < to_size / sizeof(__be32); i++, j++) --=20 2.43.0