Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6824560rdb; Fri, 15 Dec 2023 09:12:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IGyg4NQTcuXMozEkk0N2iY+Ph3XOIU827Op04CLacJK8YYXkkZ3Mm6nol9xQgaV3oi+f8Rh X-Received: by 2002:a17:903:234e:b0:1d0:9201:5340 with SMTP id c14-20020a170903234e00b001d092015340mr14781770plh.33.1702660361556; Fri, 15 Dec 2023 09:12:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702660361; cv=none; d=google.com; s=arc-20160816; b=VNQtTl73HrGC7ND9/dtiKjHPmUl1C5JlfvosVpZVwZqxbWstKuEPcNTWS7PNMu13TN eBdLVgLLhb7xbRsdbQnJvMXnWtQDhhBVmZaDOHwuMuewQ/lF3MD/2IrtV9l/HS5mbMg7 FdUg/lwyVou7Jfi+lDf2wbXAXjA4SGEI2BBvMpOSxG8cXyq/XOaZ3vlv6UwIYLNke9xG 0cszd90h7XBTyoKREh1D1EPBD8EtHFics58jstbqFnMKqnABnafuilrwbGIvhnEYnj2J CWWdvJMWHCZAyq/RHhZ5nYfbERxNVN3LqefxDc8y5bFu4gtXQKC6HdOmiN/H4Ta/4SlU k73A== 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=Hic3KLXSw0kZLER1121n1f6ruOUri+R8eS2p0xEpoTw=; fh=7jqZq/ZYbMftFjhlWz03uMgixboqG3R2DyU/OfHTv0Q=; b=hlCUERLRe5sbK/iUE1K05KzafbwlSppCQf0uhgVTtzJVAn9T9+WFnstU7ON5Ao6euh qpzHDnkn4SlwEzmOI/Ef4TQctbKr/tpMtXG4tFzPJol/0VJyn+U+Cf+XlVdEc0eF5zme B7lk7fCbzukvVEAsOINmhJYvEtmhBqz/NLS0G2ZmgIALlhKi0BN8jb0tk78EHrV4KNX4 c1zmLssikruwbpcXwkOYZ8DmWGkIddmRKwuNutkgNvThqCvCZ7d2fJx64QspmZUHTuwo +r76O2uSgpiCRCrpl9dRbvN6wIh/3aBjmGJKpD6fdBJmIvPg+T0mdOT8ZL0teVTCF9Bo N1uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=nATz6yvK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=KYeTGHJc; spf=pass (google.com: domain of linux-kernel+bounces-1367-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1367-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 o2-20020a170902d4c200b001cc3527145bsi13677148plg.29.2023.12.15.09.12.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 09:12:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1367-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=nATz6yvK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=KYeTGHJc; spf=pass (google.com: domain of linux-kernel+bounces-1367-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1367-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 3AC82285F7B for ; Fri, 15 Dec 2023 17:12:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D40247F56; Fri, 15 Dec 2023 17:10:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="nATz6yvK"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="KYeTGHJc" 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 3DA9A4186E; Fri, 15 Dec 2023 17:10:36 +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=1702660233; 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=Hic3KLXSw0kZLER1121n1f6ruOUri+R8eS2p0xEpoTw=; b=nATz6yvKuLRWZq0Eq+aCX6uBuqNuBm6nccZ6FCvWPUzJPpmeO0DUZXmOdkKfNKVMkI/7WW KM346DHUpBF6toFRMq8TvYdsoHBD3NkGRQT96S12T8xIEcUVNorEzKSjHS6xjGiI0k/xeI pgWoOMYHV9ZZQ8qEZA4+DRbRLaQatC9+J+2atbwcBANgjP/jGG5sb89tZVSMIqQdSKJb4j dbZRxkxZOyt+mnbCDphCKQz3Yakklyo3Zhpre2lidqdQKk9HwCTQg7SCEFZ7VGjsPeGhch /1tV/DJTbkuDjB+JJHuwPy6W+JgixXNQKdAy49xLafU46GhdbtXvioXzZdfqdA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702660233; 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=Hic3KLXSw0kZLER1121n1f6ruOUri+R8eS2p0xEpoTw=; b=KYeTGHJchiUjRWIVo+kg+HQJVmmf7kR3Nv6Tnfk0U8hVYQ+oRm46QBWuqjYocOtbxQbPPS yWAD9JN/ErMA3OCQ== 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 , David Ahern Subject: [PATCH net-next 05/24] net/tcp_sigpool: Use nested-BH locking for sigpool_scratch. Date: Fri, 15 Dec 2023 18:07:24 +0100 Message-ID: <20231215171020.687342-6-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 sigpool_scratch 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. Make a struct with a pad member (original sigpool_scratch) and a local_lock_t 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: David Ahern Signed-off-by: Sebastian Andrzej Siewior --- net/ipv4/tcp_sigpool.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/net/ipv4/tcp_sigpool.c b/net/ipv4/tcp_sigpool.c index 55b310a722c7d..0046d1a0dd796 100644 --- a/net/ipv4/tcp_sigpool.c +++ b/net/ipv4/tcp_sigpool.c @@ -10,7 +10,14 @@ #include =20 static size_t __scratch_size; -static DEFINE_PER_CPU(void __rcu *, sigpool_scratch); +struct sigpool_scratch { + local_lock_t bh_lock; + void __rcu *pad; +}; + +static DEFINE_PER_CPU(struct sigpool_scratch, sigpool_scratch) =3D { + .bh_lock =3D INIT_LOCAL_LOCK(bh_lock), +}; =20 struct sigpool_entry { struct crypto_ahash *hash; @@ -72,7 +79,7 @@ static int sigpool_reserve_scratch(size_t size) break; } =20 - old_scratch =3D rcu_replace_pointer(per_cpu(sigpool_scratch, cpu), + old_scratch =3D rcu_replace_pointer(per_cpu(sigpool_scratch.pad, cpu), scratch, lockdep_is_held(&cpool_mutex)); if (!cpu_online(cpu) || !old_scratch) { kfree(old_scratch); @@ -93,7 +100,7 @@ static void sigpool_scratch_free(void) int cpu; =20 for_each_possible_cpu(cpu) - kfree(rcu_replace_pointer(per_cpu(sigpool_scratch, cpu), + kfree(rcu_replace_pointer(per_cpu(sigpool_scratch.pad, cpu), NULL, lockdep_is_held(&cpool_mutex))); __scratch_size =3D 0; } @@ -278,7 +285,8 @@ int tcp_sigpool_start(unsigned int id, struct tcp_sigpo= ol *c) __cond_acquires(RC /* Pairs with tcp_sigpool_reserve_scratch(), scratch area is * valid (allocated) until tcp_sigpool_end(). */ - c->scratch =3D rcu_dereference_bh(*this_cpu_ptr(&sigpool_scratch)); + local_lock_nested_bh(&sigpool_scratch.bh_lock); + c->scratch =3D rcu_dereference_bh(*this_cpu_ptr(&sigpool_scratch.pad)); return 0; } EXPORT_SYMBOL_GPL(tcp_sigpool_start); @@ -287,6 +295,7 @@ void tcp_sigpool_end(struct tcp_sigpool *c) __releases(= RCU_BH) { struct crypto_ahash *hash =3D crypto_ahash_reqtfm(c->req); =20 + local_unlock_nested_bh(&sigpool_scratch.bh_lock); rcu_read_unlock_bh(); ahash_request_free(c->req); crypto_free_ahash(hash); --=20 2.43.0