All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>,
	"David S . Miller" <davem@davemloft.net>,
	Paolo Abeni <pabeni@redhat.com>, David Ahern <dsahern@kernel.org>,
	netdev@vger.kernel.org, eric.dumazet@gmail.com,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH net-next 1/8] inet: preserve const qualifier in inet_sk()
Date: Wed, 15 Mar 2023 17:34:20 -0700	[thread overview]
Message-ID: <CAHk-=wijs3BOOnJ9chfhR9DEQ0LNL0krPfhi=d9_mUwSBhog1A@mail.gmail.com> (raw)
In-Reply-To: <CANn89i+uJwvGy6HRN4Ym8Q=jSDx=wDEU-5neo=b3C+xJf=pW-g@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1062 bytes --]

On Wed, Mar 15, 2023 at 5:23 PM Eric Dumazet <edumazet@google.com> wrote:
>
> Oh I might have been fooled, because of course we can not use sk for
> the macro parameter name.

Heh. Yeah, that will rename the 'sk' member name too, and cause some
*very* strange errors.

> Basically something like this should work just fine

Yup.

I'm testing it on the current git tree, and I'm finding a number of
random issues, but it looks manageable. Attached is what I ended up
with.

You have presumably already fixed these issues in your tree.

Btw, it's very much things like 'tcp_sk()' too, and doing that with

   #define tcp_sk(ptr) container_of_const(ptr, struct tcp_sock,
inet_conn.icsk_inet.sk)

actually shows some fundamental problems. For example, we have
tcp_synq_overflow() that takes a const sk pointer, but then it does

        WRITE_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp, now);

which is a big no-no and writes to that sock thing.

I didn't even try any of the other 'xyzzy_sk()' conversions.

                   Linus

[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 4133 bytes --]

 include/linux/tcp.h         | 5 +----
 include/net/inet_sock.h     | 5 +----
 include/trace/events/sock.h | 4 ++--
 include/trace/events/tcp.h  | 2 +-
 net/ipv4/ip_output.c        | 4 ++--
 net/mptcp/sockopt.c         | 2 +-
 security/lsm_audit.c        | 6 +++---
 7 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h
index 51857117ac09..caa20a905531 100644
--- a/include/net/inet_sock.h
+++ b/include/net/inet_sock.h
@@ -305,10 +305,7 @@ static inline struct sock *skb_to_full_sk(const struct sk_buff *skb)
 	return sk_to_full_sk(skb->sk);
 }
 
-static inline struct inet_sock *inet_sk(const struct sock *sk)
-{
-	return (struct inet_sock *)sk;
-}
+#define inet_sk(ptr) container_of_const(ptr, struct inet_sock, sk)
 
 static inline void __inet_sk_copy_descendant(struct sock *sk_to,
 					     const struct sock *sk_from,
diff --git a/include/trace/events/sock.h b/include/trace/events/sock.h
index 03d19fc562f8..fd206a6ab5b8 100644
--- a/include/trace/events/sock.h
+++ b/include/trace/events/sock.h
@@ -158,7 +158,7 @@ TRACE_EVENT(inet_sock_set_state,
 	),
 
 	TP_fast_assign(
-		struct inet_sock *inet = inet_sk(sk);
+		const struct inet_sock *inet = inet_sk(sk);
 		struct in6_addr *pin6;
 		__be32 *p32;
 
@@ -222,7 +222,7 @@ TRACE_EVENT(inet_sk_error_report,
 	),
 
 	TP_fast_assign(
-		struct inet_sock *inet = inet_sk(sk);
+		const struct inet_sock *inet = inet_sk(sk);
 		struct in6_addr *pin6;
 		__be32 *p32;
 
diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
index 901b440238d5..bf06db8d2046 100644
--- a/include/trace/events/tcp.h
+++ b/include/trace/events/tcp.h
@@ -67,7 +67,7 @@ DECLARE_EVENT_CLASS(tcp_event_sk_skb,
 	),
 
 	TP_fast_assign(
-		struct inet_sock *inet = inet_sk(sk);
+		const struct inet_sock *inet = inet_sk(sk);
 		__be32 *p32;
 
 		__entry->skbaddr = skb;
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 4e4e308c3230..64971054f0c5 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -129,7 +129,7 @@ int ip_local_out(struct net *net, struct sock *sk, struct sk_buff *skb)
 }
 EXPORT_SYMBOL_GPL(ip_local_out);
 
-static inline int ip_select_ttl(struct inet_sock *inet, struct dst_entry *dst)
+static inline int ip_select_ttl(const struct inet_sock *inet, struct dst_entry *dst)
 {
 	int ttl = inet->uc_ttl;
 
@@ -146,7 +146,7 @@ int ip_build_and_send_pkt(struct sk_buff *skb, const struct sock *sk,
 			  __be32 saddr, __be32 daddr, struct ip_options_rcu *opt,
 			  u8 tos)
 {
-	struct inet_sock *inet = inet_sk(sk);
+	const struct inet_sock *inet = inet_sk(sk);
 	struct rtable *rt = skb_rtable(skb);
 	struct net *net = sock_net(sk);
 	struct iphdr *iph;
diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
index 8a9656248b0f..5cef4d3d21ac 100644
--- a/net/mptcp/sockopt.c
+++ b/net/mptcp/sockopt.c
@@ -1046,7 +1046,7 @@ static int mptcp_getsockopt_tcpinfo(struct mptcp_sock *msk, char __user *optval,
 
 static void mptcp_get_sub_addrs(const struct sock *sk, struct mptcp_subflow_addrs *a)
 {
-	struct inet_sock *inet = inet_sk(sk);
+	const struct inet_sock *inet = inet_sk(sk);
 
 	memset(a, 0, sizeof(*a));
 
diff --git a/security/lsm_audit.c b/security/lsm_audit.c
index a7355b4b9bb8..368e77ca43c4 100644
--- a/security/lsm_audit.c
+++ b/security/lsm_audit.c
@@ -310,14 +310,14 @@ static void dump_common_audit_data(struct audit_buffer *ab,
 	case LSM_AUDIT_DATA_NET:
 		if (a->u.net->sk) {
 			const struct sock *sk = a->u.net->sk;
-			struct unix_sock *u;
+			const struct unix_sock *u;
 			struct unix_address *addr;
 			int len = 0;
 			char *p = NULL;
 
 			switch (sk->sk_family) {
 			case AF_INET: {
-				struct inet_sock *inet = inet_sk(sk);
+				const struct inet_sock *inet = inet_sk(sk);
 
 				print_ipv4_addr(ab, inet->inet_rcv_saddr,
 						inet->inet_sport,
@@ -329,7 +329,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
 			}
 #if IS_ENABLED(CONFIG_IPV6)
 			case AF_INET6: {
-				struct inet_sock *inet = inet_sk(sk);
+				const struct inet_sock *inet = inet_sk(sk);
 
 				print_ipv6_addr(ab, &sk->sk_v6_rcv_saddr,
 						inet->inet_sport,

  reply	other threads:[~2023-03-16  0:36 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-15 15:42 [PATCH net-next 0/8] inet: better const qualifier awareness Eric Dumazet
2023-03-15 15:42 ` [PATCH net-next 1/8] inet: preserve const qualifier in inet_sk() Eric Dumazet
2023-03-15 18:52   ` Simon Horman
2023-03-15 21:28   ` Jakub Kicinski
2023-03-15 22:37     ` Eric Dumazet
2023-03-15 23:08       ` Jakub Kicinski
2023-03-15 23:16         ` Eric Dumazet
2023-03-15 23:21       ` Linus Torvalds
2023-03-15 23:37         ` Eric Dumazet
2023-03-15 23:47           ` Linus Torvalds
2023-03-15 23:39         ` Linus Torvalds
2023-03-15 23:45           ` Eric Dumazet
2023-03-15 23:54             ` Linus Torvalds
2023-03-15 23:56               ` Eric Dumazet
2023-03-16  0:02                 ` Linus Torvalds
2023-03-16  0:11                   ` Eric Dumazet
2023-03-16  0:23                     ` Eric Dumazet
2023-03-16  0:34                       ` Linus Torvalds [this message]
2023-03-15 15:42 ` [PATCH net-next 2/8] ipv4: constify ip_mc_sf_allow() socket argument Eric Dumazet
2023-03-15 18:52   ` Simon Horman
2023-03-15 15:42 ` [PATCH net-next 3/8] udp: constify __udp_is_mcast_sock() " Eric Dumazet
2023-03-15 18:53   ` Simon Horman
2023-03-15 15:42 ` [PATCH net-next 4/8] ipv6: constify inet6_mc_check() Eric Dumazet
2023-03-15 18:53   ` Simon Horman
2023-03-15 15:42 ` [PATCH net-next 5/8] udp6: constify __udp_v6_is_mcast_sock() socket argument Eric Dumazet
2023-03-15 18:53   ` Simon Horman
2023-03-15 15:42 ` [PATCH net-next 6/8] ipv6: raw: constify raw_v6_match() " Eric Dumazet
2023-03-15 18:54   ` Simon Horman
2023-03-15 15:42 ` [PATCH net-next 7/8] ipv4: raw: constify raw_v4_match() " Eric Dumazet
2023-03-15 18:54   ` Simon Horman
2023-03-15 15:42 ` [PATCH net-next 8/8] inet_diag: constify raw_lookup() " Eric Dumazet
2023-03-15 18:54   ` Simon Horman

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='CAHk-=wijs3BOOnJ9chfhR9DEQ0LNL0krPfhi=d9_mUwSBhog1A@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.