Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp755811lqb; Wed, 29 May 2024 09:33:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVs3tLUAxiKiZxZZVQ+wDZkMGVQ+leKS0Gicl+T/8lnI5piDGyk7QHZTQoJN36v7ZOeJ1FkNuvEuRgd8ayXDGl/plTfjGH5N4Hh3HWKkQ== X-Google-Smtp-Source: AGHT+IH5yp/JWGqN+EnFHj5k5VeUZTI3h2aCPBbsWWtg5ooDpwWmO1bBrSGVgcRBFdMu+uw+jMdf X-Received: by 2002:a50:ab53:0:b0:578:6198:d6ff with SMTP id 4fb4d7f45d1cf-5786198d83amr8957892a12.33.1717000420033; Wed, 29 May 2024 09:33:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717000420; cv=pass; d=google.com; s=arc-20160816; b=TeY0ng85pvM9OZnsAQFhd0q8nZz/1T/jZHmGulc/2YpySlzwNO+ULjnFnYDtY3XNRX YIBP/xdRcIVmnrevA8Lpa5yvV/qUKhISp+izaEjaDJoMDb5/k5zD+2AdBomNYrU2hBP3 +qPMkT1dO+JjV5QT1iEOlrJvKV6milVcxeF/ek5DirgWABRr8whZ+p0NvZ+jlMwHB8lM qG+kpRLViH+M2Z/2BswzFNLtz39P/SYN13l3/Yc3k7lhHbEcHN6gbAqLIx+UkIwVI3WG xtlojBIXH4Zv2xpsKC8dGveR8Eohbho57DRoF+4ReOQfLkI85cY1QKKhSCUXVRee6k/T 8HDQ== 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=hJt9gmCzXKZq1/EDvJLFPCVcIT0BYHNB+LSrBaTimp0=; fh=W7Dca+T8MT+c4dhSkiblyzcjRLjbvPOaY9Ee2xwvkcs=; b=uqMJdGqXUpKsfEhQOAsjhlrb3Cp70EG1nGryMOvUfY3dS833B+DJM4N0jDQYtsj8gK pKQrBzqjCeVbukNm5/o/huCR3XGOcFvUSmrI8rX9gyR0fNjKmOEKC+8FvlWC4Lasb4ff ynl0KgXwJtp8+06kP+RmRN5LUXExFz0iYGJlx8+0WRcvq5J/5H3NwV626rE6FCGjytPG zHDJWst1rqzopowJnwITQ34JyQtU26HGED60A3sjQDfCRfoiUq6fBsgYHWZ6TQVuaKbU 1p01vI8clbm04NU3xE2DWGXJfqyCO35AcU8/bjlEbLCuF0dpjFE3qxCbRoLdglGY+F8Y XVeA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=TwEDAwx7; 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-194459-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194459-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-578524d2c7bsi6586100a12.675.2024.05.29.09.33.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 09:33:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194459-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=@linutronix.de header.s=2020 header.b=TwEDAwx7; 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-194459-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194459-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 5E5251F24AB0 for ; Wed, 29 May 2024 16:32:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 80DA71C0DE4; Wed, 29 May 2024 16:29:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="TwEDAwx7"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IbnYqrEe" 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 97F32199EA9; Wed, 29 May 2024 16:29:40 +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=1717000182; cv=none; b=UCP0NsamtZ0sD52Tv5Cn+Z9uyOaMFhtppsmAdizLSoQT0ONxMKu3eQXfKR+6n6qzuahZ8jzwRMKMcvwVCWJx9tOfwcMMBCnHCDQWagpe+WIhusd+0IeAX/1kO8jpKikyLOAsfEh+TPYOV7WGAVZAx7sgUF0e0JGxIJmVOBicUi0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717000182; c=relaxed/simple; bh=fxJVmdO1CTi7V8vAAKfth09PKKmQR961Uj2IUC0/xxM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ao0vWSAfUljwJd0CuhQmNRIWjlOHOAk2B6NBH4PPVf4MJ5/kj6sO7t7y+BVPxrPswm673ub+XfJlmQYz08G1Hgx6dpoJpSZoEPJkUtRoytka8DXr99sAVpWCPlRbzMnZPQPbALaMg+W3qMCVSihztYAIGc+yQSzKjUCjQRrcYHc= 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=TwEDAwx7; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=IbnYqrEe; 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=1717000179; 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=hJt9gmCzXKZq1/EDvJLFPCVcIT0BYHNB+LSrBaTimp0=; b=TwEDAwx7ARzPeMjReH8HhvWvqUfhfTXjvztXEF5dbScZcc0x62YozqRWO1yU5XK8RdZh1u y7/q5XpP0iFkYFyRVwEFg8ZuDjxWCN0fw8C2/3kiJEsLIpE52XQwgLQoKJ5ZOL3L1aEy6O GsEd6nIfWHBc55YzrrinIXpJC7M6Zzt/gYdMTIlZBwgSwU19BNYpdD5XkeTuvywzhC0NRo hrThz0X6Hvj6dJVAeV/iyOL1ToXZKqHbJIXhITRNHNzfd1plSJ+SdsXyjDXnG9Xo6b5xB8 HT6dOav8wokLQcAljmKKNaS7bRVOrxPgYku2ZTuKDCqeeUBuhAoXR6i/DCiVMQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1717000179; 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=hJt9gmCzXKZq1/EDvJLFPCVcIT0BYHNB+LSrBaTimp0=; b=IbnYqrEe2vJffzwqDYM3f8oH8QEk+orIrQVt16u2C6VGNlAChyFXLuxBTRX8zgaC7Tdqmr qPPO+jOweOb1M8CA== 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 v3 net-next 13/15] net: Use nested-BH locking for bpf_scratchpad. Date: Wed, 29 May 2024 18:02:36 +0200 Message-ID: <20240529162927.403425-14-bigeasy@linutronix.de> In-Reply-To: <20240529162927.403425-1-bigeasy@linutronix.de> References: <20240529162927.403425-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 ba1a739a9bedc..d6cf1a63c3f43 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.45.1