Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6825981rdb; Fri, 15 Dec 2023 09:14:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IEskQNuA9kgdkg3fKCqhgcbahdq3IP+s5J4eBurnRhn5tT7kX543qaICPV7+HB9aXyNivWh X-Received: by 2002:a05:6a20:8e1f:b0:18f:97c:824a with SMTP id y31-20020a056a208e1f00b0018f097c824amr7234802pzj.84.1702660479925; Fri, 15 Dec 2023 09:14:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702660479; cv=none; d=google.com; s=arc-20160816; b=vF20ZzV8Uaa9Ty3VNpPu/vznd5lLdXnMsS7tT7R9nJyUmUbDm1rRejJYoz57kF55/X JMPpTpw+TuwG34hu2c6irXB64wh9wv/MOMOF5jKN+GhUv+PwKW9+B6Pmexn77gWYp57v XmeLs8LcokRJY5dzMWCXRWOEhxG32XF2uquCVg3EcMEMPiQ7tjo4Lfip021FAspg7AQu Kk24tHzrfkxdTUhibKq6MCtZ92mYre6Qy45T72Yv1EDtx4oWecNjhUSi5pu+YD1w5Tlt r/6PJZvIQNdNaJAxMrQ4lhE/b9nVHdCgstPulPk/6+rLMKI4Gss9Br5/jPgc4KbmMC2B rWqg== 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=daf5a4PohYYdeeZFpg6Z2CxAh8jUeo4C/K4Qpe4O64I=; fh=7jqZq/ZYbMftFjhlWz03uMgixboqG3R2DyU/OfHTv0Q=; b=BRYNj1qJQy/t5X7hi5WLaq+oTLpqqGQ1zRAEL16vXoZZvQXRK02ujbcxdVdwpx4oG6 Yjvz4RkRlQlvALa+1vKZOzOOHdKa7f/waSMVVJjCUQlfV22HbykOe4FuHwtrcsQVqJT3 h77ltqqpXE0wFn3W5pUdJTO17HFdgwj94zgrmrTl/JOkNA2+rjBscUg9CGP60RkbsBp3 Xh+0fzPnoxEmuFsCl3GGaT1vnKncFabmzfr7KR0qJRr+jAEeMrrz8/fnrmRf5DXHYKMa JfboCI5dW5lqMQAYCbDywwGapj4kzrl6HmmMhepb9iSdad9cj3PH99+GuT7wgu71u4tc 6ZNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Ayo+EDi5; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-1374-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1374-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. [139.178.88.99]) by mx.google.com with ESMTPS id g184-20020a636bc1000000b005c668a5a906si13216677pgc.282.2023.12.15.09.14.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 09:14:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1374-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Ayo+EDi5; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-1374-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1374-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 523862833CC for ; Fri, 15 Dec 2023 17:14:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 89BEA5644D; Fri, 15 Dec 2023 17:10:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ayo+EDi5"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2dLeTH8h" 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 684A64187F; Fri, 15 Dec 2023 17:10:37 +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=1702660234; 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=daf5a4PohYYdeeZFpg6Z2CxAh8jUeo4C/K4Qpe4O64I=; b=Ayo+EDi5WVEC2oLyPTNKAToccX83oPlWy8QWjqmt1EG27G3lOiITDJxXKIYmP8BtLTfk9g jDq3wQPeS03j80Vi5z9+OI9poqQZhDWDmm2V/xC4pOk7nPE6q+oTY25/ab/aFNr9EBSRzW +zXi8vVFNrEqdXNiOAabOe1kEIAOG75MfHCB6+0t5FlPSDg29BOi/OchHk/vpy6ucseuj+ 8HqTxMwy67MuWt8lPzas3DIh5IX9+I4sdNaUYgml2/Eh2EPBlQtICUwdZLyU40DImADiKX S9iTz6gxS95JYl1aMK2iBZgWIoQSi7HTaIpxTFyQqJYQbBSgQ0LqELnc3KI9Zw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702660234; 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=daf5a4PohYYdeeZFpg6Z2CxAh8jUeo4C/K4Qpe4O64I=; b=2dLeTH8hdXCnGl6QDlIBcjzuoQ63ePDXnfZOVmAarAgpnweapCi8GGwCs18KiklP6EVtVR Nn3BeaSw8j8G6ICg== 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 06/24] net/ipv4: Use nested-BH locking for ipv4_tcp_sk. Date: Fri, 15 Dec 2023 18:07:25 +0100 Message-ID: <20231215171020.687342-7-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 ipv4_tcp_sk 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 sock member (original ipv4_tcp_sk) 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 --- include/net/sock.h | 5 +++++ net/ipv4/tcp_ipv4.c | 15 +++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index 1d6931caf0c3c..cb407b7ae39f8 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -547,6 +547,11 @@ struct sock { struct hlist_node sk_bind2_node; }; =20 +struct sock_bh_locked { + struct sock *sock; + local_lock_t bh_lock; +}; + enum sk_pacing { SK_PACING_NONE =3D 0, SK_PACING_NEEDED =3D 1, diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 0c50c5a32b84a..e69dd19f39e02 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -92,7 +92,9 @@ static int tcp_v4_md5_hash_hdr(char *md5_hash, const stru= ct tcp_md5sig_key *key, struct inet_hashinfo tcp_hashinfo; EXPORT_SYMBOL(tcp_hashinfo); =20 -static DEFINE_PER_CPU(struct sock *, ipv4_tcp_sk); +static DEFINE_PER_CPU(struct sock_bh_locked, ipv4_tcp_sk) =3D { + .bh_lock =3D INIT_LOCAL_LOCK(bh_lock), +}; =20 static u32 tcp_v4_init_seq(const struct sk_buff *skb) { @@ -878,7 +880,9 @@ static void tcp_v4_send_reset(const struct sock *sk, st= ruct sk_buff *skb) arg.tos =3D ip_hdr(skb)->tos; arg.uid =3D sock_net_uid(net, sk && sk_fullsock(sk) ? sk : NULL); local_bh_disable(); - ctl_sk =3D this_cpu_read(ipv4_tcp_sk); + local_lock_nested_bh(&ipv4_tcp_sk.bh_lock); + ctl_sk =3D this_cpu_read(ipv4_tcp_sk.sock); + sock_net_set(ctl_sk, net); if (sk) { ctl_sk->sk_mark =3D (sk->sk_state =3D=3D TCP_TIME_WAIT) ? @@ -903,6 +907,7 @@ static void tcp_v4_send_reset(const struct sock *sk, st= ruct sk_buff *skb) sock_net_set(ctl_sk, &init_net); __TCP_INC_STATS(net, TCP_MIB_OUTSEGS); __TCP_INC_STATS(net, TCP_MIB_OUTRSTS); + local_unlock_nested_bh(&ipv4_tcp_sk.bh_lock); local_bh_enable(); =20 #ifdef CONFIG_TCP_MD5SIG @@ -998,7 +1003,8 @@ static void tcp_v4_send_ack(const struct sock *sk, arg.tos =3D tos; arg.uid =3D sock_net_uid(net, sk_fullsock(sk) ? sk : NULL); local_bh_disable(); - ctl_sk =3D this_cpu_read(ipv4_tcp_sk); + local_lock_nested_bh(&ipv4_tcp_sk.bh_lock); + ctl_sk =3D this_cpu_read(ipv4_tcp_sk.sock); sock_net_set(ctl_sk, net); ctl_sk->sk_mark =3D (sk->sk_state =3D=3D TCP_TIME_WAIT) ? inet_twsk(sk)->tw_mark : READ_ONCE(sk->sk_mark); @@ -1013,6 +1019,7 @@ static void tcp_v4_send_ack(const struct sock *sk, =20 sock_net_set(ctl_sk, &init_net); __TCP_INC_STATS(net, TCP_MIB_OUTSEGS); + local_unlock_nested_bh(&ipv4_tcp_sk.bh_lock); local_bh_enable(); } =20 @@ -3604,7 +3611,7 @@ void __init tcp_v4_init(void) */ inet_sk(sk)->pmtudisc =3D IP_PMTUDISC_DO; =20 - per_cpu(ipv4_tcp_sk, cpu) =3D sk; + per_cpu(ipv4_tcp_sk.sock, cpu) =3D sk; } if (register_pernet_subsys(&tcp_sk_ops)) panic("Failed to create the TCP control socket.\n"); --=20 2.43.0