Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp863269lqt; Fri, 7 Jun 2024 00:16:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUMue6r90D0Zhe1c3s6ssa/KCzPo3LVJJA9fU2B7olPtX31E9wMvTo8DUMmcFdTebQ6S4rzlpPQKrbVQ/HGEmWd4oUW9PBT9vvcJGT/Gg== X-Google-Smtp-Source: AGHT+IHSzaIbxRXqdxHD0sSyG66fTC64kYlRbIUcvtPS30HQfzllDkb/ovUkyhl0EZ5iqhq80jFI X-Received: by 2002:a05:6358:716:b0:19c:4478:59a3 with SMTP id e5c5f4694b2df-19f1feaecacmr243747755d.17.1717744597031; Fri, 07 Jun 2024 00:16:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717744596; cv=pass; d=google.com; s=arc-20160816; b=JyD+/rgYxN52frEqla8RgNSy6L6n3X9ACm3ZWNtrcZHPpCFOR78lZCkavhPPzMPdMM hCFgyBsdcnHbmqMkcNRQdcOY3LqJmUAJ4wl+BPuqQjBOinWv4OFqGyu/xye/JfRL8rqu y/60eiA2DxS/u443ovGPiEJvX1xTcnJt4BrgywH3qQbhEp2Vf3S2oSSkTRoC4KLsQng6 L7H87UVtPIq6LIYDUG9fcljm5mC5KEKe6vnha4AQ1dNLJR//bkvQu+Tab1rwnAwt+Epy WZQFVx/n//T4wTCfnf2gTOCf8e2s1d7YTcCXXzTROb61ppxGkqElE28Of4EmCe16T6/K NEgg== 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=vNvzn6YBgh3SLeUaRC7IMEJndOAuZol5cL2OUwmCNkc=; fh=2CLNAjJ7fyudZGVopJHp/YeVj31ODH68AmVGsFDuQas=; b=BhiFzSchiA+8jxGJJytnsFFQFuBa1d8d7+k/qY+K/+V9sMsR17cMrhFW7p5CUFUcAD l2sMF6mSzKWIio6QyoGcshoDHs6YN7nuEHGJBoCOlt6MgcWDa+G+NhvLt3jaUvE6JgJ7 +7bTA0umepwTQRKQ2mv4drGlmAXyPgR7nHIu4uMeNi/uX5a9J08rsf7UBU23WJy/snJw RB9Jq6GaBDpTep40AHT7STpEuImlq6sO0tzkCNRXQBI8LbiMmMMhza1cVncafw46hCML c9UVfYzq1THmWoK/F11M+Ot3+7e8Fj1ty5qRCSBs4HUBrxu814RZ4en9xDXlSugYLyT5 /Luw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="YxSm4j/3"; 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-205487-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205487-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6e4532507ecsi150683a12.401.2024.06.07.00.16.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 00:16:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205487-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="YxSm4j/3"; 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-205487-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205487-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 1FD18B22E8A for ; Fri, 7 Jun 2024 07:07:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 70E9B1586F5; Fri, 7 Jun 2024 07:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YxSm4j/3"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ZiBunsmN" 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 7B08015572D; Fri, 7 Jun 2024 07:04:38 +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=1717743880; cv=none; b=TcydCpDfH0Qb4mXmQKFvKhJoeHhr/J/JtBlouiWK/itnVRk4AcMMvTB5Hk5mLveG/3jG60yVXXN3lQpovY8U+WUfGze2afwQADb5PVDz3chUw7FmRY4oxpQLgkAJ55pGiSKJxXvBhR6txphSgXsc7XxIFHgn/KJ6dpt1A7irX6Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717743880; c=relaxed/simple; bh=f2JsaRGu7vA7hA1bGsZGvZuKQkyhegS/xCLgmJwB4bI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Yqb8XVB4j8+C0P7+eq3T6Ce+Ccxd/DRbQjVFOJ7zN2L9Y/141xfpCFNWL05Ugl0e8VGD1asLWqicoxmEN5k/wLycDr2qe1aW16aP4IbD4/y9VPEtvh61FS43Eebwy+uxo/gZ2wjLXEKVDCgVV2iTIcq1Kfga+BLO2QHbIoegtKE= 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=YxSm4j/3; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ZiBunsmN; 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=1717743876; 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=vNvzn6YBgh3SLeUaRC7IMEJndOAuZol5cL2OUwmCNkc=; b=YxSm4j/3Z6rAm2z6KlfyIJ8tpltNgFidrNPFMlm9SqH1aucgow69kEBzS6TWmXN1k6boQE IttDiA0O1nNlc80zDOGj4px+8Rsvqz31T4oYZw7PFNC9NA9YhNW7o4hQUwKd/PwHudOBbW Gut24GFY3kZiQSEqnHqH1wkEhSc2MkgK828WMulfSQmzXdb5b80eZPHQouT6QtF5GDjDQj +L1FETNDivEBpxqkb1N/k6t0RcpD99NLkt7JLqvpqUUeBI1lyatcy/lDOf4TLcLyumWkUK qBGLBEEGFPCejsGHL2u74AmcrmIJoBMlYNPXejqiucKb1nAXPocpBJp6cKNRmA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1717743876; 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=vNvzn6YBgh3SLeUaRC7IMEJndOAuZol5cL2OUwmCNkc=; b=ZiBunsmNajMGNi0hE04HZL51KRJmAVphbLILUjbK7vfMB9hTldlxtR56EvHpTrmir09Lfc SLEyvHfTf3SQ6jDQ== To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: "David S. Miller" , Daniel Bristot de Oliveira , 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 v5 net-next 13/15] net: Use nested-BH locking for bpf_scratchpad. Date: Fri, 7 Jun 2024 08:53:16 +0200 Message-ID: <20240607070427.1379327-14-bigeasy@linutronix.de> In-Reply-To: <20240607070427.1379327-1-bigeasy@linutronix.de> References: <20240607070427.1379327-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 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index ba1a739a9bedc..fbcfd563dccfd 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) @@ -2016,6 +2019,7 @@ BPF_CALL_5(bpf_csum_diff, __be32 *, from, u32, from_s= ize, struct bpf_scratchpad *sp =3D this_cpu_ptr(&bpf_sp); u32 diff_size =3D from_size + to_size; int i, j =3D 0; + __wsum ret; =20 /* This is quite flexible, some examples: * @@ -2029,12 +2033,15 @@ BPF_CALL_5(bpf_csum_diff, __be32 *, from, u32, from= _size, diff_size > sizeof(sp->diff))) return -EINVAL; =20 + 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++) sp->diff[j] =3D to[i]; =20 - return csum_partial(sp->diff, diff_size, seed); + ret =3D csum_partial(sp->diff, diff_size, seed); + local_unlock_nested_bh(&bpf_sp.bh_lock); + return ret; } =20 static const struct bpf_func_proto bpf_csum_diff_proto =3D { --=20 2.45.1