Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp13344lqh; Fri, 3 May 2024 11:46:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX9fWiMa2jBIylFWNSTREaKyf0h1yarqYsmT1dcwpkVboX10gXCzeR8soDIYihZboVZVqNv6IDeid1k+KBamox/Ve/nSgurZfB3EQ7E9g== X-Google-Smtp-Source: AGHT+IFqCMqkG4XmHSraQRoj8emeYu0l0xHl2+57Q7AnO1j5eOyedrz7NwhZx2GrwYZhywRH8Ha2 X-Received: by 2002:a05:6a00:240e:b0:6ec:fe38:d94 with SMTP id z14-20020a056a00240e00b006ecfe380d94mr4105203pfh.33.1714761968067; Fri, 03 May 2024 11:46:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714761968; cv=pass; d=google.com; s=arc-20160816; b=r9triiwqNQrW8T+dx76rrzQ5mfYBuIlz2HOoGk1KL59OdLcyB6j37Y4f9rPNYvFQiJ xhNFymUaRKLr/DNOtpxGidiEQbcJR2LMzdkAvOxLLyFBZpy9z8MMhU/TdxacWa7qDcfJ 8388F7H+aEnJfdFsq3wpnUbRJMQmk8QKBuzul/IjhW9x93vuTJFyW0mf7cA0go5BbHto RctKdyn9wVNzjve603xAFBuWZSoammmHigoq/tU+R8n49rVwX+UVGhIhUvtoM7XQVq5S k3sMWTd2R62h3dw/GRPvxDPHxeOUe0YUjdbmrocy0JeGmWsjplD6o8vFqZK2U24Py8p7 krNA== ARC-Message-Signature: i=2; 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=0ybrNKVMPkZ4Ap31+Up4JCU5gLeDUDgUGDfpmjWAnCM=; fh=W7Dca+T8MT+c4dhSkiblyzcjRLjbvPOaY9Ee2xwvkcs=; b=j6dkhGwLWEB6LuwK60CryMgatwrM+rCQieCeHtzKu0dHWogPEQGDgNN2Gw/7Ov/AJr KaEzFGA084HZA1qplMrh71jkX6B52iLojcOVUefUNuhM+HYvLUJcCI4+rAdeA/faQUQi sa11h6CeiDAGxMVV8JZWT52Xuq7z89PEYUcFQqjdqDVmscME0NBwFNVMqRqy3jygnC+N 39nNMMfytfC28bZrmoPsRUR44dH1dle4b0k4e5IwpAo+XF8EIEHLW3qUGNEaoiYMOqwx E7xaeflHr2ySZJMzuRqh/J8Bp0g53UKlywIUh/8QbS5Q6jsDi5TUn/y5d+9Its1TYEwy +gEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=hpW97fX4; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-168065-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168065-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l190-20020a6388c7000000b0061b489b5345si2636006pgd.291.2024.05.03.11.46.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 11:46:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-168065-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=hpW97fX4; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-168065-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168065-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C44BB28813A for ; Fri, 3 May 2024 18:33:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A7C7815B0FC; Fri, 3 May 2024 18:30:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hpW97fX4"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ssmiv9hm" 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 CD63C1591F1; Fri, 3 May 2024 18:30:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714761014; cv=none; b=I+mFn6yyVje1Bguv9xqS2xgzMADEFWtS/MEafynthM4AEIIxJTB3z60z8aOyoxWRrnorsOMBr9N3B00e6rAvZ9sTg4NaaXXAehG7oPuWox1I4gV2HyblIndKk6yFd6u6KEBgMRUBD3DMCpR1mdFxzSkr1DtbcN59rcX5jVQmFxw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714761014; c=relaxed/simple; bh=6fVCWFsuEBR7nJV+h+rv294+QgH0Wy9inghRo5IE69k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jPQ37TuQFkOM/Y5JDnR5HNrjrR8pRmyt2G0TUjYAOMf/mofmu2iCvhsJ9ulWxuc+hkPUKnbv29m/KiGcL9N4wALC+qsPWfCj529+Wx2QWFSmhNl6h6emidcAU0Qba7fl8/h1Q3bCq4WcoqPjWX1kHvAcM3fn902ip6Uycr49vxY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hpW97fX4; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Ssmiv9hm; arc=none smtp.client-ip=193.142.43.55 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=1714761010; 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=0ybrNKVMPkZ4Ap31+Up4JCU5gLeDUDgUGDfpmjWAnCM=; b=hpW97fX4evbEt0tWQbOvOP61Uj5ksTD/64vN6UYwBwECNGgT89P7IQWlYezsnZ67Vymtsq tcpqYqRCHoHti+ZTXiAH6um/7o3j4E/Q9+4tZofYYGvCT+PXrmdizM0DXsQGjV9mRlASuv 6j1l6KxjNZfuZGxEcX4NgQX6tMfzfW5WW+0vLvDyLkEWmxuhuz9HxvQE8OdBFniSeZN1DN WGs3YnW8oe0vS+tt4hpZnFTNgWIgkbd4oamLnQm/kv5tTEZVjtTb7chdKRotAY+k0RKpiX UavJJ4P/QnD4G9qBVkAYCpc2hdpToj+O1lgSnoBEqGQD2QKyYMVuoVtFv6lwkA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1714761010; 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=0ybrNKVMPkZ4Ap31+Up4JCU5gLeDUDgUGDfpmjWAnCM=; b=Ssmiv9hmiUSp1iHRdezmkdqkkK3COLazKJDAi/W/DvYC0fZ3hOoM1UGn1Om40iRt7c5xvm RlcAOAQLtBV9HVCQ== 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/15] net: Use nested-BH locking for bpf_scratchpad. Date: Fri, 3 May 2024 20:25:17 +0200 Message-ID: <20240503182957.1042122-14-bigeasy@linutronix.de> In-Reply-To: <20240503182957.1042122-1-bigeasy@linutronix.de> References: <20240503182957.1042122-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 cfe8ea59fd9db..e95b235a1e4f4 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -1658,9 +1658,12 @@ struct bpf_scratchpad { __be32 diff[MAX_BPF_STACK / sizeof(__be32)]; u8 buff[MAX_BPF_STACK]; }; + local_lock_t bh_lock; }; =20 -static DEFINE_PER_CPU(struct bpf_scratchpad, bpf_sp); +static DEFINE_PER_CPU(struct bpf_scratchpad, bpf_sp) =3D { + .bh_lock =3D INIT_LOCAL_LOCK(bh_lock), +}; =20 static inline int __bpf_try_make_writable(struct sk_buff *skb, unsigned int write_len) @@ -2029,6 +2032,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.bh_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