[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241210073829.62520-4-kuniyu@amazon.com>
Date: Tue, 10 Dec 2024 16:38:17 +0900
From: Kuniyuki Iwashima <kuniyu@...zon.com>
To: "David S. Miller" <davem@...emloft.net>, Eric Dumazet
<edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>, Paolo Abeni
<pabeni@...hat.com>, Simon Horman <horms@...nel.org>
CC: Kuniyuki Iwashima <kuniyu@...zon.com>, Kuniyuki Iwashima
<kuni1840@...il.com>, <netdev@...r.kernel.org>
Subject: [PATCH v2 net-next 03/15] smc: Pass kern to smc_sock_alloc().
AF_SMC was introduced in commit ac7138746e14 ("smc: establish
new socket family").
Since then, smc_create() ignores the kern argument and calls
smc_sock_alloc(), which calls sk_alloc() with hard-coded arguments.
sk = sk_alloc(net, PF_SMC, GFP_KERNEL, prot, 0);
This means sock_create_kern(AF_SMC) always creates a userspace
socket.
Later, commit d7cd421da9da ("net/smc: Introduce TCP ULP support")
added another confusing call site.
smc_ulp_init() calls __smc_create() with kern=1, but again,
smc_sock_alloc() allocates a userspace socket by calling
sk_alloc() with kern=0.
To fix up the weird paths, let's pass kern down to smc_sock_alloc()
and sk_alloc().
This commit does not introduce functional change because we have
no in-tree users calling sock_create_kern(AF_SMC) and we change
kern from 1 to 0 in smc_ulp_init().
Signed-off-by: Kuniyuki Iwashima <kuniyu@...zon.com>
---
net/smc/af_smc.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 9e6c69d18581..a9679c37202d 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -387,13 +387,13 @@ void smc_sk_init(struct net *net, struct sock *sk, int protocol)
}
static struct sock *smc_sock_alloc(struct net *net, struct socket *sock,
- int protocol)
+ int protocol, int kern)
{
struct proto *prot;
struct sock *sk;
prot = (protocol == SMCPROTO_SMC6) ? &smc_proto6 : &smc_proto;
- sk = sk_alloc(net, PF_SMC, GFP_KERNEL, prot, 0);
+ sk = sk_alloc(net, PF_SMC, GFP_KERNEL, prot, kern);
if (!sk)
return NULL;
@@ -1712,7 +1712,7 @@ static int smc_clcsock_accept(struct smc_sock *lsmc, struct smc_sock **new_smc)
int rc = -EINVAL;
release_sock(lsk);
- new_sk = smc_sock_alloc(sock_net(lsk), NULL, lsk->sk_protocol);
+ new_sk = smc_sock_alloc(sock_net(lsk), NULL, lsk->sk_protocol, 0);
if (!new_sk) {
rc = -ENOMEM;
lsk->sk_err = ENOMEM;
@@ -3346,7 +3346,7 @@ static int __smc_create(struct net *net, struct socket *sock, int protocol,
rc = -ENOBUFS;
sock->ops = &smc_sock_ops;
sock->state = SS_UNCONNECTED;
- sk = smc_sock_alloc(net, sock, protocol);
+ sk = smc_sock_alloc(net, sock, protocol, kern);
if (!sk)
goto out;
@@ -3405,7 +3405,7 @@ static int smc_ulp_init(struct sock *sk)
smcsock->type = SOCK_STREAM;
__module_get(THIS_MODULE); /* tried in __tcp_ulp_find_autoload */
- ret = __smc_create(net, smcsock, protocol, 1, tcp);
+ ret = __smc_create(net, smcsock, protocol, 0, tcp);
if (ret) {
sock_release(smcsock); /* module_put() which ops won't be NULL */
return ret;
--
2.39.5 (Apple Git-154)
Powered by blists - more mailing lists