netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>
Cc: David Ahern <dsahern@kernel.org>,
	netdev@vger.kernel.org, eric.dumazet@gmail.com,
	 Eric Dumazet <edumazet@google.com>
Subject: [PATCH net-next 5/8] inet: lockless getsockopt(IP_MTU)
Date: Thu, 21 Sep 2023 13:30:18 +0000	[thread overview]
Message-ID: <20230921133021.1995349-6-edumazet@google.com> (raw)
In-Reply-To: <20230921133021.1995349-1-edumazet@google.com>

sk_dst_get() does not require socket lock.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/ipv4/ip_sockglue.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 45d89487914a12061f05c192004ad79f0abbf756..04579e390ddd4dadb8a107ef0b5da15e7a60f1ff 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -1620,13 +1620,6 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
 			return -EFAULT;
 		return 0;
 	}
-	}
-
-	if (needs_rtnl)
-		rtnl_lock();
-	sockopt_lock_sock(sk);
-
-	switch (optname) {
 	case IP_MTU:
 	{
 		struct dst_entry *dst;
@@ -1636,12 +1629,17 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
 			val = dst_mtu(dst);
 			dst_release(dst);
 		}
-		if (!val) {
-			sockopt_release_sock(sk);
+		if (!val)
 			return -ENOTCONN;
-		}
-		break;
+		goto copyval;
+	}
 	}
+
+	if (needs_rtnl)
+		rtnl_lock();
+	sockopt_lock_sock(sk);
+
+	switch (optname) {
 	case IP_UNICAST_IF:
 		val = (__force int)htonl((__u32) inet->uc_index);
 		break;
-- 
2.42.0.459.ge4e396fd5e-goog


  parent reply	other threads:[~2023-09-21 17:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-21 13:30 [PATCH net-next 0/8] inet: more data-race fixes Eric Dumazet
2023-09-21 13:30 ` [PATCH net-next 1/8] inet: implement lockless IP_MULTICAST_TTL Eric Dumazet
2023-09-21 19:03   ` David Ahern
2023-09-21 13:30 ` [PATCH net-next 2/8] inet: implement lockless IP_MTU_DISCOVER Eric Dumazet
2023-09-21 19:03   ` David Ahern
2023-09-21 13:30 ` [PATCH net-next 3/8] inet: implement lockless IP_TOS Eric Dumazet
2023-09-21 19:10   ` David Ahern
2023-09-21 19:15     ` Eric Dumazet
2023-09-21 13:30 ` [PATCH net-next 4/8] inet: lockless getsockopt(IP_OPTIONS) Eric Dumazet
2023-09-21 19:12   ` David Ahern
2023-09-21 13:30 ` Eric Dumazet [this message]
2023-09-21 19:13   ` [PATCH net-next 5/8] inet: lockless getsockopt(IP_MTU) David Ahern
2023-09-21 13:30 ` [PATCH net-next 6/8] inet: implement lockless getsockopt(IP_UNICAST_IF) Eric Dumazet
2023-09-21 19:19   ` David Ahern
2023-09-21 13:30 ` [PATCH net-next 7/8] inet: lockless IP_PKTOPTIONS implementation Eric Dumazet
2023-09-21 19:23   ` David Ahern
2023-09-21 13:30 ` [PATCH net-next 8/8] inet: implement lockless getsockopt(IP_MULTICAST_IF) Eric Dumazet
2023-09-21 19:24   ` David Ahern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230921133021.1995349-6-edumazet@google.com \
    --to=edumazet@google.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=eric.dumazet@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).