Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp754741lqb; Wed, 29 May 2024 09:32:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV8UkdXC3dpZKwNPmZ9QSeWJVMHcmSGlAgjHmac9daXG0jKDup07bEYgQ2qaO0/MCP+KD/rWpzVtk5jb7qXq/YF4WuoJxlW6SQjwAxN4w== X-Google-Smtp-Source: AGHT+IH26fVOxQjzoYkqtzRa6rlmZ51s/JazSjUKe0iYLTmJYPFcCHJM/VAkE6rktDuJr4gf5uyQ X-Received: by 2002:a05:6a00:6c87:b0:6f8:bae3:37b4 with SMTP id d2e1a72fcca58-6f8f2c7041emr17325776b3a.5.1717000329165; Wed, 29 May 2024 09:32:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717000329; cv=pass; d=google.com; s=arc-20160816; b=WaUaullxPxIqGB2mFmZHwuadmEQMqumDt946Dtia5hfHLh9ADcEAnyi6yYhrvi/AgH ySpJMFZtxi79coqyXxYZzYjXiXttaEbkFU+F3oAmOX+fC5zK4VgYHrVeaUiwwWg1ROhW F4HkgwN2FEzQDbbXMU+q29y4lQe0KNpDKXW2VZfdixehRgGlahKDf224rb7mayg3tqwo IKfJGD8wdPCFxVw+wUmZl9JUHec/y+lkdh2AJVUXtMsBC52KhlPL8D+J9z4/cnIZV8Ds BABHYdGdF4k5ZdZoifaq2SGFRkDjKP/oJ/ILN3o6LfU+Fox5ty9CBrPUSO1FG3/ubLJy NuvQ== 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=4qaNAKLFhAtWg8AIcUa7hYCunt+INJ3A0lAqwiwMQAI=; fh=7jqZq/ZYbMftFjhlWz03uMgixboqG3R2DyU/OfHTv0Q=; b=KWMOQpj7nhjhc2wlF+vDjECKNY5TU0JcEZbRKFYTeQ9W3xn3JVakTC9qfPEufUSavp VKjvX3pkeHb194fq1jlC+6HpsO0OVLJGIHHklc/6WGgJUIQw5uL4c+pWnhXJcGuLY3yE o8zjlOJ8zeqeopRUl1f5y1clEHsACkhnU3+7LafQVKbZBGihYmjV9pBXD+BqpLHt0bcf UfMjKSCg4rMYzLJj9ZIDV+HW3V8pmIJrZ4NpVOkIirXl4UlseAOwxA5KPKYeJc/e1JS0 F+UYi6FE+1fxC6oD0Msry+7H1iiTzK90ULMEgHcBZ+pyLTvxw56M4CAPdkIv3cvs44uD SWOA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=MoX0PrgM; 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-194451-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194451-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 41be03b00d2f7-6822a98e50csi10949270a12.749.2024.05.29.09.32.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 09:32:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194451-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=MoX0PrgM; 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-194451-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194451-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 A6F50287DE2 for ; Wed, 29 May 2024 16:31:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA04619DF45; Wed, 29 May 2024 16:29:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="MoX0PrgM"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="RFMPwasG" 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 EE93119067E; Wed, 29 May 2024 16:29:37 +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=1717000179; cv=none; b=oJQF/QFAQjg8ios2o49+cUCI2Yht5OuFNvxujzUqO/cRxvFkujCG9huDbopiks3mtxGvzz6nnmJ2whTunzGmai0wRaASXfytDpL2ZneFtIucYC+kPj8iOKBt7F0pvgXsB93x2tKTl9mybZSdCAYST1HcIl+7C2URjoVOkAAim7k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717000179; c=relaxed/simple; bh=YiPmxaRADsJsN55xVT2BOQ/1LOJuKBNEnf9YIUI4CIQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nr+fmUnGVbYW7eg602KR2hB25Xte/usF0IEjK6FUbtFjQlCvnY53BjLFi8Cr/kB9rcaz8mgcIOixyaRSezotbDjR4hh3CdDdDguJAJqEtpfCDLXT+3tNV4mXYLsfnElzf1tV4QX95OClRARwSuAfFGsZ/jFBoVgLA3U75anNFMw= 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=MoX0PrgM; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=RFMPwasG; 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=1717000175; 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=4qaNAKLFhAtWg8AIcUa7hYCunt+INJ3A0lAqwiwMQAI=; b=MoX0PrgMySwt8a9X4K37cwUXrn1JljjLMEHhb+DGZA2YjMzr2Qq+/jE2rXzNnod7rq8I2h PCz8ev+TvMVaXKGHC5QqcIcD/SP44JmK95JTaDf2F+ha9/G9+i0nsGtXjrpUG3M53Dew4T IkraQpNNFVp/0/a0dJ0W+lC5TUZL5qUPPey3ILPyEeBP21Qg7+HsxEXECTOZL1bSkAf0D+ t/rI8lXzkG3aHjgnF3w77ibhwZu+XaQDurggqOr04M7FmosDtKyulZD1uigLAFhVb1N2Yf z/LvQhB5AO959GjK1cuWRjacAURCORSkRrMa3nqYaXmAdzAfOJM91dfyRy4/mg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1717000175; 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=4qaNAKLFhAtWg8AIcUa7hYCunt+INJ3A0lAqwiwMQAI=; b=RFMPwasGDiCqxdTHSxfxE2CvlmuLdWCalCTmzHg+WvkmgdKr3/wJ4J8Unl+xV7vae2MbeL OstWeedchK4IvKDg== 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 v3 net-next 06/15] net/ipv4: Use nested-BH locking for ipv4_tcp_sk. Date: Wed, 29 May 2024 18:02:29 +0200 Message-ID: <20240529162927.403425-7-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 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 5f4d0629348f3..365bf676023f8 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 8f70b8d1d1e56..34c852a4e202d 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) { @@ -885,7 +887,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) ? @@ -910,6 +914,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 @@ -1005,7 +1010,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); @@ -1020,6 +1026,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 @@ -3627,7 +3634,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