From patchwork Fri Dec 13 09:21:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13906716 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-52004.amazon.com (smtp-fw-52004.amazon.com [52.119.213.154]) (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 92DFB74BE1 for ; Fri, 13 Dec 2024 09:26:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734082002; cv=none; b=XdXYd1kv8NQBPTaBtefKysvY/J3mv3fxM/7tiuRAHNVs9PhFTLNGSfeAGwzd3NqELWHJXCEM1B5DwavAymNSYWM+V6ApXYItlGx34B6TMzzvKN+pNYbstK2lMUr9RfAFeE9saodUQmpUhh0yIIm3qZXfegMBd4cq0w4oXutPYt0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734082002; c=relaxed/simple; bh=hFP8/26Cafqzl5yLKzS2/QOIimtkrjaNuxjAFkyzfPE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OeUMLNi3SeoVLZo+rNSYyifc0ds1d4UCAPRiUdVZN50ecp6sxfMnpTrbLowbgwZwdqef8Td+a5pOaOIxE/n8KwfOauvHNBNIXw54Ow84eUMKrGFGvx1rjf0t4ieWTHRWO4+RMmKpGFZIQaOQU1XNlgz9gZvX3DwKni3kJfTxwMQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=J03ieYv5; arc=none smtp.client-ip=52.119.213.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="J03ieYv5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1734082000; x=1765618000; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SPHEoETNo8xr6kU4J/NuzEy1jiB940OG1NT5AuXzxoQ=; b=J03ieYv5dEmCxOgHR3Qo2drEHlLhk8EfWQWd608zyzlHyBYuT4aqOh0C gY7gTPSmBoO7+G1S1gfSkr4ettnxSH1oTAetLy0Q1fGR3KaBAp6ODJtCU YPL8tSyDZEqhoGtJ4JkvaSra5W4Wce5JleAgVnzZapZtQLTezHYfxz+W7 w=; X-IronPort-AV: E=Sophos;i="6.12,230,1728950400"; d="scan'208";a="254688626" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.2]) by smtp-border-fw-52004.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2024 09:26:38 +0000 Received: from EX19MTAUWB001.ant.amazon.com [10.0.21.151:61226] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.41.254:2525] with esmtp (Farcaster) id da35bf3c-da49-4dca-a6de-5d59bb9cf9eb; Fri, 13 Dec 2024 09:26:37 +0000 (UTC) X-Farcaster-Flow-ID: da35bf3c-da49-4dca-a6de-5d59bb9cf9eb Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWB001.ant.amazon.com (10.250.64.248) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Fri, 13 Dec 2024 09:26:37 +0000 Received: from 6c7e67c6786f.amazon.com (10.119.14.208) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Fri, 13 Dec 2024 09:26:34 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v3 net-next 13/15] socket: Use sock_create_net() instead of sock_create(). Date: Fri, 13 Dec 2024 18:21:50 +0900 Message-ID: <20241213092152.14057-14-kuniyu@amazon.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241213092152.14057-1-kuniyu@amazon.com> References: <20241213092152.14057-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D033UWA003.ant.amazon.com (10.13.139.42) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org sock_create() is a bad name, and no one really cares about what it's for. In fact, except for only one user, sctp_do_peeloff(), all sockets created by drivers and fs are not tied to userspace processes nor exposed via file descriptors. Let's use sock_create_net() for such in-kernel use cases. Signed-off-by: Kuniyuki Iwashima --- drivers/infiniband/hw/erdma/erdma_cm.c | 6 ++++-- drivers/infiniband/sw/siw/siw_cm.c | 6 ++++-- drivers/isdn/mISDN/l1oip_core.c | 3 ++- drivers/nvme/host/tcp.c | 5 +++-- drivers/nvme/target/tcp.c | 5 +++-- drivers/target/iscsi/iscsi_target_login.c | 7 ++++--- drivers/xen/pvcalls-back.c | 6 ++++-- fs/ocfs2/cluster/tcp.c | 8 +++++--- fs/smb/server/transport_tcp.c | 7 ++++--- 9 files changed, 33 insertions(+), 20 deletions(-) diff --git a/drivers/infiniband/hw/erdma/erdma_cm.c b/drivers/infiniband/hw/erdma/erdma_cm.c index 771059a8eb7d..5014237127cb 100644 --- a/drivers/infiniband/hw/erdma/erdma_cm.c +++ b/drivers/infiniband/hw/erdma/erdma_cm.c @@ -1023,7 +1023,8 @@ int erdma_connect(struct iw_cm_id *id, struct iw_cm_conn_param *params) return -ENOENT; erdma_qp_get(qp); - ret = sock_create(AF_INET, SOCK_STREAM, IPPROTO_TCP, &s); + ret = sock_create_net(current->nsproxy->net_ns, + AF_INET, SOCK_STREAM, IPPROTO_TCP, &s); if (ret < 0) goto error_put_qp; @@ -1299,7 +1300,8 @@ int erdma_create_listen(struct iw_cm_id *id, int backlog) if (addr_family != AF_INET) return -EAFNOSUPPORT; - ret = sock_create(addr_family, SOCK_STREAM, IPPROTO_TCP, &s); + ret = sock_create_net(current->nsproxy->net_ns, + addr_family, SOCK_STREAM, IPPROTO_TCP, &s); if (ret < 0) return ret; diff --git a/drivers/infiniband/sw/siw/siw_cm.c b/drivers/infiniband/sw/siw/siw_cm.c index 86323918a570..4c8f0e3ec0ce 100644 --- a/drivers/infiniband/sw/siw/siw_cm.c +++ b/drivers/infiniband/sw/siw/siw_cm.c @@ -1391,7 +1391,8 @@ int siw_connect(struct iw_cm_id *id, struct iw_cm_conn_param *params) siw_dbg_qp(qp, "pd_len %d, laddr %pISp, raddr %pISp\n", pd_len, laddr, raddr); - rv = sock_create(v4 ? AF_INET : AF_INET6, SOCK_STREAM, IPPROTO_TCP, &s); + rv = sock_create_net(current->nsproxy->net_ns, + v4 ? AF_INET : AF_INET6, SOCK_STREAM, IPPROTO_TCP, &s); if (rv < 0) goto error; @@ -1766,7 +1767,8 @@ int siw_create_listen(struct iw_cm_id *id, int backlog) if (addr_family != AF_INET && addr_family != AF_INET6) return -EAFNOSUPPORT; - rv = sock_create(addr_family, SOCK_STREAM, IPPROTO_TCP, &s); + rv = sock_create_net(current->nsproxy->net_ns, + addr_family, SOCK_STREAM, IPPROTO_TCP, &s); if (rv < 0) return rv; diff --git a/drivers/isdn/mISDN/l1oip_core.c b/drivers/isdn/mISDN/l1oip_core.c index a5ad88a960d0..04733bcc8d07 100644 --- a/drivers/isdn/mISDN/l1oip_core.c +++ b/drivers/isdn/mISDN/l1oip_core.c @@ -659,7 +659,8 @@ l1oip_socket_thread(void *data) allow_signal(SIGTERM); /* create socket */ - if (sock_create(PF_INET, SOCK_DGRAM, IPPROTO_UDP, &socket)) { + if (sock_create_net(current->nsproxy->net_ns, + PF_INET, SOCK_DGRAM, IPPROTO_UDP, &socket)) { printk(KERN_ERR "%s: Failed to create socket.\n", __func__); ret = -EIO; goto fail; diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 28c76a3e1bd2..32af5fe66882 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -1682,8 +1682,9 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid, queue->cmnd_capsule_len = sizeof(struct nvme_command) + NVME_TCP_ADMIN_CCSZ; - ret = sock_create(ctrl->addr.ss_family, SOCK_STREAM, - IPPROTO_TCP, &queue->sock); + ret = sock_create_net(current->nsproxy->net_ns, + ctrl->addr.ss_family, SOCK_STREAM, + IPPROTO_TCP, &queue->sock); if (ret) { dev_err(nctrl->device, "failed to create socket: %d\n", ret); diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index 7c51c2a8c109..dff8c56d1783 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -2042,8 +2042,9 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport) if (port->nport->inline_data_size < 0) port->nport->inline_data_size = NVMET_TCP_DEF_INLINE_DATA_SIZE; - ret = sock_create(port->addr.ss_family, SOCK_STREAM, - IPPROTO_TCP, &port->sock); + ret = sock_create_net(current->nsproxy->net_ns, + port->addr.ss_family, SOCK_STREAM, + IPPROTO_TCP, &port->sock); if (ret) { pr_err("failed to create a socket\n"); goto err_port; diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/iscsi/iscsi_target_login.c index 90b870f234f0..b7135b6d96d7 100644 --- a/drivers/target/iscsi/iscsi_target_login.c +++ b/drivers/target/iscsi/iscsi_target_login.c @@ -837,10 +837,11 @@ int iscsit_setup_np( return -EINVAL; } - ret = sock_create(sockaddr->ss_family, np->np_sock_type, - np->np_ip_proto, &sock); + ret = sock_create_net(current->nsproxy->net_ns, + sockaddr->ss_family, np->np_sock_type, + np->np_ip_proto, &sock); if (ret < 0) { - pr_err("sock_create() failed.\n"); + pr_err("sock_create_net() failed.\n"); return ret; } np->np_socket = sock; diff --git a/drivers/xen/pvcalls-back.c b/drivers/xen/pvcalls-back.c index f0f8b4862983..83b6bfff5cd4 100644 --- a/drivers/xen/pvcalls-back.c +++ b/drivers/xen/pvcalls-back.c @@ -406,7 +406,8 @@ static int pvcalls_back_connect(struct xenbus_device *dev, sa->sa_family != AF_INET) goto out; - ret = sock_create(AF_INET, SOCK_STREAM, 0, &sock); + ret = sock_create_net(current->nsproxy->net_ns, + AF_INET, SOCK_STREAM, 0, &sock); if (ret < 0) goto out; ret = inet_stream_connect(sock, sa, req->u.connect.len, 0); @@ -647,7 +648,8 @@ static int pvcalls_back_bind(struct xenbus_device *dev, goto out; } - ret = sock_create(AF_INET, SOCK_STREAM, 0, &map->sock); + ret = sock_create_net(current->nsproxy->net_ns, + AF_INET, SOCK_STREAM, 0, &map->sock); if (ret < 0) goto out; diff --git a/fs/ocfs2/cluster/tcp.c b/fs/ocfs2/cluster/tcp.c index 6ef03a02d19b..9e0571ec3ca1 100644 --- a/fs/ocfs2/cluster/tcp.c +++ b/fs/ocfs2/cluster/tcp.c @@ -1558,7 +1558,7 @@ static void o2net_start_connect(struct work_struct *work) unsigned int nofs_flag; /* - * sock_create allocates the sock with GFP_KERNEL. We must + * sock_create_net() allocates the sock with GFP_KERNEL. We must * prevent the filesystem from being reentered by memory reclaim. */ nofs_flag = memalloc_nofs_save(); @@ -1600,7 +1600,8 @@ static void o2net_start_connect(struct work_struct *work) goto out; } - ret = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock); + ret = sock_create_net(current->nsproxy->net_ns, + PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock); if (ret < 0) { mlog(0, "can't create socket: %d\n", ret); goto out; @@ -1986,7 +1987,8 @@ static int o2net_open_listening_sock(__be32 addr, __be16 port) .sin_port = port, }; - ret = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock); + ret = sock_create_net(current->nsproxy->net_ns, + PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock); if (ret < 0) { printk(KERN_ERR "o2net: Error %d while creating socket\n", ret); goto out; diff --git a/fs/smb/server/transport_tcp.c b/fs/smb/server/transport_tcp.c index 0d9007285e30..ada40b0502a1 100644 --- a/fs/smb/server/transport_tcp.c +++ b/fs/smb/server/transport_tcp.c @@ -423,18 +423,19 @@ static void tcp_destroy_socket(struct socket *ksmbd_socket) */ static int create_socket(struct interface *iface) { + struct net *net = current->nsproxy->net_ns; int ret; struct sockaddr_in6 sin6; struct sockaddr_in sin; struct socket *ksmbd_socket; bool ipv4 = false; - ret = sock_create(PF_INET6, SOCK_STREAM, IPPROTO_TCP, &ksmbd_socket); + ret = sock_create_net(net, PF_INET6, SOCK_STREAM, IPPROTO_TCP, &ksmbd_socket); if (ret) { if (ret != -EAFNOSUPPORT) pr_err("Can't create socket for ipv6, fallback to ipv4: %d\n", ret); - ret = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, - &ksmbd_socket); + ret = sock_create_net(net, PF_INET, SOCK_STREAM, IPPROTO_TCP, + &ksmbd_socket); if (ret) { pr_err("Can't create socket for ipv4: %d\n", ret); goto out_clear;