Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp864642lqt; Fri, 7 Jun 2024 00:20:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV9x4n0a/6mAd80iUnB/E46Ell1JEN3LOcUHm4bfYlBvr70ntbV49VguB97WfcTeCtruPp0VzptWEktgq7OsZr4UQ192zn1LXWzhBDELA== X-Google-Smtp-Source: AGHT+IGLrd5kdQMdouXVKZhjddnuDCMB711OZ1OU+8mPGTgqEeVVGN8MPAfEeQnPzyv572FwObEU X-Received: by 2002:a05:6a20:1581:b0:1af:d44c:cfc4 with SMTP id adf61e73a8af0-1b2f96e1d72mr1912523637.17.1717744833686; Fri, 07 Jun 2024 00:20:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717744833; cv=pass; d=google.com; s=arc-20160816; b=epJIQODwgo1c2I9JuWZFg7FDDAhoDfBywo4SP9rDxJUgBGdWffXWHLLXR9HWo31Q12 YwN9TZlsyfX1Pgw6oO0CQaZ2cbdm8OQwQA8AHihS52PoAvAge6Fodx7xJMta+npbvkBx O+et0i7PZk2TWMALJOGW9Yq1u8P2CX/YGGNaF71rLwdQMRIylK68QqwtTDw3Fn8DNwkC ABijKT/WdalXQelqKRpJx6UYXaGYrxnK6WwnlC2Ef1TjNfqXuGpmC5lZSyrHjtv5CSuU hfW0uiXxi8PFm9phOXOt1V3cNMk7WL8M/BikzbPEp508ltOyxGyaC8tpGuyqopCYrGtA d0Bg== 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=DbjjMbdKLpfx1nfmPQgqOnCtQGvrpEV1bEpUIdjXdxg=; fh=qFRiKZhrwaEDqlLZZs8xjZtPa+g3K/alutsG3Qr7aF8=; b=PXr1F5YyGDrZ8KJGfHio0TK7RgBmB5jb0zB8dZPq8cwDpbUN/msG1HdZ9rSHPJoSZK 12qrXBUwSrnq+ur0n04pY48VGP2z7hx0O++9jIMyCMZzx5YtkV7Am1EkRZ2tI0x5QxAi AHnTCrlgptKanTm5AGnIZKwqA7Z/1/TcW/nIkobSvb5eIhpfPmr/SoJyDfNN6q4Z/LQo +xeNqTtYcWPcfA/RrX1nmSLPHMWAUUsw2OMc6MK/cEcJCyIH+k50Euz3KRmoplqNNA05 +gdF19aBRyNuqBY/PhnGay4MzQm1r2RqRlOp18cj8wCl4dZb4sIMrFs6uMgbEKl6L7Fe CXLg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=PrTAwh6u; dkim=neutral (no key) header.i=@linutronix.de; 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-205479-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205479-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 d9443c01a7336-1f6bd76d005si24568575ad.188.2024.06.07.00.20.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 00:20:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205479-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=PrTAwh6u; dkim=neutral (no key) header.i=@linutronix.de; 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-205479-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205479-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 2603D28DB98 for ; Fri, 7 Jun 2024 07:06:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 95C0C15665D; Fri, 7 Jun 2024 07:04:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="PrTAwh6u"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dNE/IZGa" 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 8389415530F; Fri, 7 Jun 2024 07:04:36 +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=1717743878; cv=none; b=Mq86HYBEVlKCD2Icp2aIKHTpLXBK1uYMPTYxlYuX6tmvSnV3QouVRXV5ETkI9VnTEN1eytfjcIr56Yn4FJp1To+bW/fRX+fYa4742BIey6d9kMz35BUOGFoS5XMJP9SS+u/ej+tZap2ROeZeF0uhL7/woJXYMbwagQG95UskSaM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717743878; c=relaxed/simple; bh=IGMeFZp/DDNHIR8mhUZJsU/LIxN53uMuK5eCO+COKYU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M0ED7dOR7cmZl07foEDQSLsKg74WxO9uhZj8Xz007P6Ll8Jbe6bdC3ElnA8kZ5E6FxspDM+K4p+4abQ6y8em8/2XxPfSTXUaDjLbmp2E0c3WtbBgB6DvlturevYP0PRgPuCfIIImtI2XDXtZSLOGgwzNu3xprGa/8zYDlk98VK4= 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=PrTAwh6u; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dNE/IZGa; 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=1717743873; 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=DbjjMbdKLpfx1nfmPQgqOnCtQGvrpEV1bEpUIdjXdxg=; b=PrTAwh6uhCydre3hkTec8aKTbslZzyyl3PtFn//M6LiwBujVXAgi7aBFPMC2p7Zs6VVtSP Lg83Xw7G5UgEqYrcaDb2UsrMsmN9YLpTyP16/4QAfzuAKv6SW05YZDL85xbcrHehR68400 aDDbNyX+Ks35NWqSdRJCwONSSup0D0PFWiAkNInuqRAJbn45yDucKZzcCSXJg40osR9Wpu eKoDfsxG+YKCW+J+mAv3ZLL8msPXP7jHcyMDt4kmRlm+vLTnyafc5PxxvpjY3YSxVdkl6O 9ZdyWq1Qed5GkAk2UdZudLjvzs/bmkgYl9oOIlBGwJ6G0kBhSHKxGgfFPBvQ/w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1717743873; 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=DbjjMbdKLpfx1nfmPQgqOnCtQGvrpEV1bEpUIdjXdxg=; b=dNE/IZGanhEcFgtCcRtZv9QG4t8gpUR+VXKjhGdQ1bKyMfksKeVOcr8sG14HBn+BgD6CR9 ZTVkMLai3UFRCTBQ== 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 , David Ahern Subject: [PATCH v5 net-next 06/15] net/ipv4: Use nested-BH locking for ipv4_tcp_sk. Date: Fri, 7 Jun 2024 08:53:09 +0200 Message-ID: <20240607070427.1379327-7-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 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 953c8dc4e259e..7d6784ebb26f5 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -544,6 +544,11 @@ struct sock { netns_tracker ns_tracker; }; =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 3613e08ca7949..58b21f5c333b2 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -93,7 +93,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) { @@ -882,7 +884,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) ? @@ -907,6 +911,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 @@ -1002,7 +1007,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); @@ -1017,6 +1023,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 @@ -3619,7 +3626,7 @@ void __init tcp_v4_init(void) =20 sk->sk_clockid =3D CLOCK_MONOTONIC; =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.45.1