diff mbox series

[net-next,v2,1/2] net: introduce and use custom sockopt socket flag

Message ID dc549a4d5c1d2031c64794c8e12bed55afb85c3e.1666287924.git.pabeni@redhat.com (mailing list archive)
State Accepted
Commit a5ef058dc4d9a3e60d1808a0700e18e0e37e408e
Delegated to: Netdev Maintainers
Headers show
Series udp: avoid false sharing on receive | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5338 this patch: 5338
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 1125 this patch: 1125
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 5520 this patch: 5520
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 37 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Paolo Abeni Oct. 20, 2022, 5:48 p.m. UTC
We will soon introduce custom setsockopt for UDP sockets, too.
Instead of doing even more complex arbitrary checks inside
sock_use_custom_sol_socket(), add a new socket flag and set it
for the relevant socket types (currently only MPTCP).

Reviewed-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
 include/linux/net.h  | 1 +
 net/mptcp/protocol.c | 4 ++++
 net/socket.c         | 8 +-------
 3 files changed, 6 insertions(+), 7 deletions(-)

Comments

Eric Dumazet Oct. 20, 2022, 6:11 p.m. UTC | #1
On Thu, Oct 20, 2022 at 10:49 AM Paolo Abeni <pabeni@redhat.com> wrote:
>
> We will soon introduce custom setsockopt for UDP sockets, too.
> Instead of doing even more complex arbitrary checks inside
> sock_use_custom_sol_socket(), add a new socket flag and set it
> for the relevant socket types (currently only MPTCP).
>
> Reviewed-by: Matthieu Baerts <matthieu.baerts@tessares.net>
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> ---
>

Reviewed-by: Eric Dumazet <edumazet@google.com>
Kuniyuki Iwashima Oct. 20, 2022, 6:19 p.m. UTC | #2
From:   Paolo Abeni <pabeni@redhat.com>
Date:   Thu, 20 Oct 2022 19:48:51 +0200
> We will soon introduce custom setsockopt for UDP sockets, too.
> Instead of doing even more complex arbitrary checks inside
> sock_use_custom_sol_socket(), add a new socket flag and set it
> for the relevant socket types (currently only MPTCP).
> 
> Reviewed-by: Matthieu Baerts <matthieu.baerts@tessares.net>
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>

Acked-by: Kuniyuki Iwashima <kuniyu@amazon.com>


> ---
>  include/linux/net.h  | 1 +
>  net/mptcp/protocol.c | 4 ++++
>  net/socket.c         | 8 +-------
>  3 files changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/include/linux/net.h b/include/linux/net.h
> index 711c3593c3b8..59350fd85823 100644
> --- a/include/linux/net.h
> +++ b/include/linux/net.h
> @@ -41,6 +41,7 @@ struct net;
>  #define SOCK_NOSPACE		2
>  #define SOCK_PASSCRED		3
>  #define SOCK_PASSSEC		4
> +#define SOCK_CUSTOM_SOCKOPT	5
>  
>  #ifndef ARCH_HAS_SOCKET_TYPES
>  /**
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index f599ad44ed24..0448a5c3da3c 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -2708,6 +2708,8 @@ static int mptcp_init_sock(struct sock *sk)
>  	if (ret)
>  		return ret;
>  
> +	set_bit(SOCK_CUSTOM_SOCKOPT, &sk->sk_socket->flags);
> +
>  	/* fetch the ca name; do it outside __mptcp_init_sock(), so that clone will
>  	 * propagate the correct value
>  	 */
> @@ -3684,6 +3686,8 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
>  		struct mptcp_subflow_context *subflow;
>  		struct sock *newsk = newsock->sk;
>  
> +		set_bit(SOCK_CUSTOM_SOCKOPT, &newsock->flags);
> +
>  		lock_sock(newsk);
>  
>  		/* PM/worker can now acquire the first subflow socket
> diff --git a/net/socket.c b/net/socket.c
> index 00da9ce3dba0..55c5d536e5f6 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -2199,13 +2199,7 @@ SYSCALL_DEFINE4(recv, int, fd, void __user *, ubuf, size_t, size,
>  
>  static bool sock_use_custom_sol_socket(const struct socket *sock)
>  {
> -	const struct sock *sk = sock->sk;
> -
> -	/* Use sock->ops->setsockopt() for MPTCP */
> -	return IS_ENABLED(CONFIG_MPTCP) &&
> -	       sk->sk_protocol == IPPROTO_MPTCP &&
> -	       sk->sk_type == SOCK_STREAM &&
> -	       (sk->sk_family == AF_INET || sk->sk_family == AF_INET6);
> +	return test_bit(SOCK_CUSTOM_SOCKOPT, &sock->flags);
>  }
>  
>  /*
> -- 
> 2.37.3
diff mbox series

Patch

diff --git a/include/linux/net.h b/include/linux/net.h
index 711c3593c3b8..59350fd85823 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -41,6 +41,7 @@  struct net;
 #define SOCK_NOSPACE		2
 #define SOCK_PASSCRED		3
 #define SOCK_PASSSEC		4
+#define SOCK_CUSTOM_SOCKOPT	5
 
 #ifndef ARCH_HAS_SOCKET_TYPES
 /**
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index f599ad44ed24..0448a5c3da3c 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2708,6 +2708,8 @@  static int mptcp_init_sock(struct sock *sk)
 	if (ret)
 		return ret;
 
+	set_bit(SOCK_CUSTOM_SOCKOPT, &sk->sk_socket->flags);
+
 	/* fetch the ca name; do it outside __mptcp_init_sock(), so that clone will
 	 * propagate the correct value
 	 */
@@ -3684,6 +3686,8 @@  static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
 		struct mptcp_subflow_context *subflow;
 		struct sock *newsk = newsock->sk;
 
+		set_bit(SOCK_CUSTOM_SOCKOPT, &newsock->flags);
+
 		lock_sock(newsk);
 
 		/* PM/worker can now acquire the first subflow socket
diff --git a/net/socket.c b/net/socket.c
index 00da9ce3dba0..55c5d536e5f6 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -2199,13 +2199,7 @@  SYSCALL_DEFINE4(recv, int, fd, void __user *, ubuf, size_t, size,
 
 static bool sock_use_custom_sol_socket(const struct socket *sock)
 {
-	const struct sock *sk = sock->sk;
-
-	/* Use sock->ops->setsockopt() for MPTCP */
-	return IS_ENABLED(CONFIG_MPTCP) &&
-	       sk->sk_protocol == IPPROTO_MPTCP &&
-	       sk->sk_type == SOCK_STREAM &&
-	       (sk->sk_family == AF_INET || sk->sk_family == AF_INET6);
+	return test_bit(SOCK_CUSTOM_SOCKOPT, &sock->flags);
 }
 
 /*