Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp196775lqb; Tue, 4 Jun 2024 08:47:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXTo5zCBqZLa7ptTWRDhYAyBPL+HTlBzjMXeJO2x2jyzGem7m2OZSGlyzW8/y43Dig4+XM8LLYCPmPicDFKQjly22f27bsmgFzsSIhKmg== X-Google-Smtp-Source: AGHT+IEUZcAy9HAM1ugdbgpGbnBvDJl4k1oxsiOiSnc/JuZW2XcU0GVSYJ8P5/ZQHtbYElvTxYA3 X-Received: by 2002:a9d:480b:0:b0:6f9:4164:1e17 with SMTP id 46e09a7af769-6f941642031mr628499a34.16.1717516070087; Tue, 04 Jun 2024 08:47:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717516070; cv=pass; d=google.com; s=arc-20160816; b=F5tddjSA6YZ6ZqdDEaGNvBHU2ZD8IxS9cLSMf57xj4Pz+hmROyynzal680fMF0jPHB M0t/z3K9gWCfWHjsWyNhhOK0+3MQHc1lz4TCsce+nKsLhX8oVI2HQFYDiMSu6+TGAwM9 z46LXD5WU1hvxs1hafB4fkyPopL/eu/cW81CxMDjOSSYfQy50MD6xGeGS1OgHxNtieql QGbNtfG4hdatGkJnT9zG0IuWIwG8UhrthhQV0JCwwB2bN1xuQfGnNVCzfI9PLTh7eJrK MAK9uxB7TJL+i0khsk79fxicWo784VBF1vYKzEFYMP9tNOzCQ6NIGcvSWPyzRN/5qRf4 6tiQ== 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=2CLNAjJ7fyudZGVopJHp/YeVj31ODH68AmVGsFDuQas=; b=rArOeHUzHoMeZuzhsCrxBwvx7kBWFNLswO/okQr4hltag4NQNSSsKiM81zomlXDJZa Lg/xX8UAZd+jHaUS+xusiUpH6qYT2ADIKzLFXf22zCIouKpLa71czZpYUGoHEsbWM+4i V1NvIRZ1iiUpO8vIU4zg/91qZ38knTge3rDw1myFZtCRRp6P94RqoQ09OV6TVTP07+b9 v/WyCNDZIE4Rw3r9ITmslxKMrfJO2vMZCyw+vwY0uOW8H1Ba+12DnB1X3JpJ/xthf0NQ 2KgsHY7rvKZwa43BNpJMUEymq097xDdR+u94l3I0GYArsLXCRA9NXaDnowR319vLJvr+ A66A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fe0VzxAc; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="e+fricD/"; 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-200993-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200993-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 d75a77b69052e-43ff259d2c0si10313201cf.622.2024.06.04.08.47.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 08:47:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-200993-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=fe0VzxAc; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="e+fricD/"; 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-200993-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200993-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 C79081C2230B for ; Tue, 4 Jun 2024 15:47:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7471014A634; Tue, 4 Jun 2024 15:44:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="fe0VzxAc"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="e+fricD/" 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 697BD149000; Tue, 4 Jun 2024 15:44:53 +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=1717515895; cv=none; b=h8PG4XcuAJK5QBXMouUrnMmDPR+Yx4YHcknzxmIl8txcP29opeWXuhmDSJt5FgIrCfbdWEQzYxvVmsX02DGi48IwbqlYtviH6u7TCscD0wBlgya1y0vlEZOacuPXumHVFBm95GapDAicdTt424QnCF4yYZJvFUDDI8Sfs+uL9As= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717515895; c=relaxed/simple; bh=fxJVmdO1CTi7V8vAAKfth09PKKmQR961Uj2IUC0/xxM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YEnd66wr/gY5SFN5tleYA2g9oL+hjR19gE6PDUh0IqB2CBwRQ9y53oNsT3DJVkjzQRMr31rBm0pywMrBIB8DxdVcmGdiwzeuPpBmcu38qksHsmt61OtF0HG9IiYrkBQTbTSJemGk9pF2JTwQU0ZAt/WuD8o89XuO0Lm1ZvWIRyI= 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=fe0VzxAc; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=e+fricD/; 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=1717515892; 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=fe0VzxAcTFVdsFkFJFpDL1+1n8nICuKctkRpBl0d4Aq6Bl0YIjd45JXYIKfzmOj1C+koOw A/+TnQ5NHNuWBEfICJlgAcBqQ4wBKeo90XO5GunDeH2lZMaxyiV5kDQw+aOJaRvDeoYV6L /z2/xDPflrzH1XhyR4URer7LqXzPj+VV1RcHYzAUgE0K/cCv6XcEne9l7F93Qw96hfhKNJ csRm2cGy5INANPkD5NnJSSOd/UlB6GsdCCxwe+4/VUzUnNHSw2KrfSRWc32R8enrTSk96J PHI8iGOlcybQKb/fPlVKGYQZgreLmRSEYK4MovMBcc4hzS3VM1I7rk56mHce0Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1717515892; 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=e+fricD/CinJLizzUzmU78peMB/LCy7pjpJVIGx2smV4esX+YofDxD4cdrQGpfPGZ0q/73 z6AmEim1Qjj7jmCQ== 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 v4 net-next 12/14] net: Use nested-BH locking for bpf_scratchpad. Date: Tue, 4 Jun 2024 17:24:19 +0200 Message-ID: <20240604154425.878636-13-bigeasy@linutronix.de> In-Reply-To: <20240604154425.878636-1-bigeasy@linutronix.de> References: <20240604154425.878636-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