Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2255974rwl; Thu, 6 Apr 2023 07:53:23 -0700 (PDT) X-Google-Smtp-Source: AKy350akm4Zv2syWAJ7GG9ZOxzththJXDB7/jpYCB9UxIxDKntCvnj8ubWI64i7icqU+1io3N5fd X-Received: by 2002:a17:906:4e56:b0:948:b988:8cc3 with SMTP id g22-20020a1709064e5600b00948b9888cc3mr6321177ejw.75.1680792803307; Thu, 06 Apr 2023 07:53:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680792803; cv=none; d=google.com; s=arc-20160816; b=xuRAIYRwCdCCIYm5Iu1c7BIuov3+RDdwzIan8sfGVXJRtcOy/EmtXXgikE60OGs0Yh O1Y2m6PfL8HDaE6bNbclEiRv+wFNZXSNOydGhz1dXHdwH58SeqmXfdMQpXeugPGjCFcI fsNJV5BOVYdsWjljaXwM7Nt0powFkxewlhZPzb7HEIgIbkYMz3rOk8GkyD3WNOBe9vi4 CsnK3kUrd1QsLGXDRemeembNRHeCQpoyGT10V3RbBJwcIdeS1jWWIus4WGFZ9YRrRJWs lwn9IMYrWEV8ebvoF+HSxoFjOc3iNTq4B/+otPaKbA5Ao75fTxQpCUjSH0IG6vK5pUhj RsWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=u2hQpIwdyjopD7Ctm0hdWyBQx9VM3k+j6PUbn2br7cg=; b=KiCWdOyMCgiImUYqUeYhdgzm5XUdEyYxcY3eunHaBX2m8qfB9z7ir4tevYfVT1uY7M AzcDcfg+trX9FqrJsm4yHc5MzGZA7mD3J5/fr8wlLsRZSxOpyICCAIlyBMO1CvNfsGS1 koN3DzHdENe3tyG8lZFfI+B+XEgXIArUxk7TxgiVwLxeIHMwGVd+Ul8hDvJ3tlcTW1sO sAI76UuJjthe5H4dElskYUmIG3uOCoYGPDNQhC6zcTHitjtEWHEw9VWskaVfkUiqBFkT GVIbkxVkAksjffb8Jj44tH5LfQxyEdUYL4nvmiL1a+tEVqfBdSOiXDyXLUgHHoE+UxMx Pwvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kf6-20020a17090776c600b0093ba0e728f9si1259685ejc.1002.2023.04.06.07.52.56; Thu, 06 Apr 2023 07:53:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239428AbjDFOqK (ORCPT + 99 others); Thu, 6 Apr 2023 10:46:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239086AbjDFOpm (ORCPT ); Thu, 6 Apr 2023 10:45:42 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 923EEA278; Thu, 6 Apr 2023 07:44:57 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id n19so22735226wms.0; Thu, 06 Apr 2023 07:44:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680792235; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u2hQpIwdyjopD7Ctm0hdWyBQx9VM3k+j6PUbn2br7cg=; b=zH43ZYA/DAZJvpVKDHLEqPVM/Hk5gTdTVimLb6a+VWGK+FOJPEhKLKWCX2TczSnVhj Kx0fHHQ7XN73jGOn/iT2TqWjPgp9+l8umpNbvjW0U1G0CJ/4mYBNg8eTejCR9mY88eFT HkzgF3iyMgQzksTqNk4NO46hs69Z7fij6Aj2eH4oFjw/th9famJZePfX9t0LwB2A7/w4 859AYMnsCxkPmPlAYtS0RWOXdqyVXBcV7II6YsnlM2YnmNgD1Nm+VPASFmscZ+L7fNGb A+nR3KwBJ2msyl3RMHnYrcXJ65r/yVmfSb3OZJufy2vUzsstFM52+Z7Wd7chM+/6yKYl Hl2g== X-Gm-Message-State: AAQBX9fGNl709hjSHsXrskV5Mh/9HqO3C/YpBodms5t1QhrOR2er2lAr EU08TcWZqrlVdgl4iPYlDbnz6TlnEvAZoA== X-Received: by 2002:a7b:cc84:0:b0:3df:ee64:4814 with SMTP id p4-20020a7bcc84000000b003dfee644814mr6994248wma.20.1680792235371; Thu, 06 Apr 2023 07:43:55 -0700 (PDT) Received: from localhost (fwdproxy-cln-030.fbsv.net. [2a03:2880:31ff:1e::face:b00c]) by smtp.gmail.com with ESMTPSA id z3-20020a05600c0a0300b003ee6aa4e6a9sm5660970wmp.5.2023.04.06.07.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 07:43:54 -0700 (PDT) From: Breno Leitao To: io-uring@vger.kernel.org, netdev@vger.kernel.org, kuba@kernel.org, asml.silence@gmail.com, axboe@kernel.dk Cc: leit@fb.com, edumazet@google.com, pabeni@redhat.com, davem@davemloft.net, dccp@vger.kernel.org, mptcp@lists.linux.dev, linux-kernel@vger.kernel.org, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, matthieu.baerts@tessares.net, marcelo.leitner@gmail.com Subject: [RFC PATCH 1/4] net: wire up support for file_operations->uring_cmd() Date: Thu, 6 Apr 2023 07:43:27 -0700 Message-Id: <20230406144330.1932798-2-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230406144330.1932798-1-leitao@debian.org> References: <20230406144330.1932798-1-leitao@debian.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.5 required=5.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Create the initial plumbing to call protocol specific uring_cmd callbacks. These are io_uring specific callbacks that implement ioctl-like operation types, such as SIOCINQ, SIOCOUTQ and others. In order to achieve this, create uring_cmd callback placeholders in file_ops, proto and proto_ops structures. Create also the functions that does the plumbing from io_uring_cmd() up to sk_proto->uring_cmd(). If the callback is not implemented, -EOPNOTSUPP is returned. That way, the io_uring issue path calls file_operations->uring_cmd (sock_uring_cmd()). This function calls proto_ops->uring_cmd (sock_common_uring_cmd()). sock_common_uring_cmd() is responsible for calling protocol specific (struct proto_ops) uring_cmd callback (sock_common_uring_cmd()). sock_common_uring_cmd() then calls the proto specific (struct proto) uring_cmd function, which are implemented in the upcoming patch. By the end, uring_cmd() function has access to 'struct io_uring_cmd' which points to the whole SQE, and any field could be accessed from the function pointer. Signed-off-by: Breno Leitao --- include/linux/net.h | 2 ++ include/net/sock.h | 6 ++++++ net/core/sock.c | 17 +++++++++++++++-- net/dccp/ipv4.c | 1 + net/ipv4/af_inet.c | 3 +++ net/l2tp/l2tp_ip.c | 1 + net/mptcp/protocol.c | 1 + net/sctp/protocol.c | 1 + net/socket.c | 13 +++++++++++++ 9 files changed, 43 insertions(+), 2 deletions(-) diff --git a/include/linux/net.h b/include/linux/net.h index b73ad8e3c212..efcc47a57069 100644 --- a/include/linux/net.h +++ b/include/linux/net.h @@ -182,6 +182,8 @@ struct proto_ops { int (*compat_ioctl) (struct socket *sock, unsigned int cmd, unsigned long arg); #endif + int (*uring_cmd)(struct socket *sock, struct io_uring_cmd *cmd, + unsigned int issue_flags); int (*gettstamp) (struct socket *sock, void __user *userstamp, bool timeval, bool time32); int (*listen) (struct socket *sock, int len); diff --git a/include/net/sock.h b/include/net/sock.h index 573f2bf7e0de..57437a1e041c 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -111,6 +111,7 @@ typedef struct { struct sock; struct proto; struct net; +struct io_uring_cmd; typedef __u32 __bitwise __portpair; typedef __u64 __bitwise __addrpair; @@ -1247,6 +1248,9 @@ struct proto { int (*ioctl)(struct sock *sk, int cmd, unsigned long arg); + int (*uring_cmd)(struct sock *sk, + struct io_uring_cmd *cmd, + unsigned int issue_flags); int (*init)(struct sock *sk); void (*destroy)(struct sock *sk); void (*shutdown)(struct sock *sk, int how); @@ -1921,6 +1925,8 @@ int sock_common_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, int flags); int sock_common_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval, unsigned int optlen); +int sock_common_uring_cmd(struct socket *sock, struct io_uring_cmd *cmd, + unsigned int issue_flags); void sk_common_release(struct sock *sk); diff --git a/net/core/sock.c b/net/core/sock.c index c25888795390..1bf5e4d4ba29 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -3669,6 +3669,18 @@ int sock_common_setsockopt(struct socket *sock, int level, int optname, } EXPORT_SYMBOL(sock_common_setsockopt); +int sock_common_uring_cmd(struct socket *sock, struct io_uring_cmd *cmd, + unsigned int issue_flags) +{ + struct sock *sk = sock->sk; + + if (!sk->sk_prot || !sk->sk_prot->uring_cmd) + return -EOPNOTSUPP; + + return sk->sk_prot->uring_cmd(sk, cmd, issue_flags); +} +EXPORT_SYMBOL(sock_common_uring_cmd); + void sk_common_release(struct sock *sk) { if (sk->sk_prot->destroy) @@ -4009,7 +4021,7 @@ static void proto_seq_printf(struct seq_file *seq, struct proto *proto) { seq_printf(seq, "%-9s %4u %6d %6ld %-3s %6u %-3s %-10s " - "%2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c\n", + "%2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c\n", proto->name, proto->obj_size, sock_prot_inuse_get(seq_file_net(seq), proto), @@ -4023,6 +4035,7 @@ static void proto_seq_printf(struct seq_file *seq, struct proto *proto) proto_method_implemented(proto->disconnect), proto_method_implemented(proto->accept), proto_method_implemented(proto->ioctl), + proto_method_implemented(proto->uring_cmd), proto_method_implemented(proto->init), proto_method_implemented(proto->destroy), proto_method_implemented(proto->shutdown), @@ -4051,7 +4064,7 @@ static int proto_seq_show(struct seq_file *seq, void *v) "maxhdr", "slab", "module", - "cl co di ac io in de sh ss gs se re sp bi br ha uh gp em\n"); + "cl co di ac io ur in de sh ss gs se re sp bi br ha uh gp em\n"); else proto_seq_printf(seq, list_entry(v, struct proto, node)); return 0; diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c index b780827f5e0a..47047ad05e65 100644 --- a/net/dccp/ipv4.c +++ b/net/dccp/ipv4.c @@ -999,6 +999,7 @@ static const struct proto_ops inet_dccp_ops = { /* FIXME: work on tcp_poll to rename it to inet_csk_poll */ .poll = dccp_poll, .ioctl = inet_ioctl, + .uring_cmd = sock_common_uring_cmd, .gettstamp = sock_gettstamp, /* FIXME: work on inet_listen to rename it to sock_common_listen */ .listen = inet_dccp_listen, diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 8db6747f892f..1c54c3b59f2e 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -1036,6 +1036,7 @@ const struct proto_ops inet_stream_ops = { .getname = inet_getname, .poll = tcp_poll, .ioctl = inet_ioctl, + .uring_cmd = sock_common_uring_cmd, .gettstamp = sock_gettstamp, .listen = inet_listen, .shutdown = inet_shutdown, @@ -1071,6 +1072,7 @@ const struct proto_ops inet_dgram_ops = { .getname = inet_getname, .poll = udp_poll, .ioctl = inet_ioctl, + .uring_cmd = sock_common_uring_cmd, .gettstamp = sock_gettstamp, .listen = sock_no_listen, .shutdown = inet_shutdown, @@ -1103,6 +1105,7 @@ static const struct proto_ops inet_sockraw_ops = { .getname = inet_getname, .poll = datagram_poll, .ioctl = inet_ioctl, + .uring_cmd = sock_common_uring_cmd, .gettstamp = sock_gettstamp, .listen = sock_no_listen, .shutdown = inet_shutdown, diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c index 4db5a554bdbd..cdfaaada0695 100644 --- a/net/l2tp/l2tp_ip.c +++ b/net/l2tp/l2tp_ip.c @@ -617,6 +617,7 @@ static const struct proto_ops l2tp_ip_ops = { .getname = l2tp_ip_getname, .poll = datagram_poll, .ioctl = inet_ioctl, + .uring_cmd = sock_common_uring_cmd, .gettstamp = sock_gettstamp, .listen = sock_no_listen, .shutdown = inet_shutdown, diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 3ad9c46202fc..b8182eab5ebf 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3808,6 +3808,7 @@ static const struct proto_ops mptcp_stream_ops = { .getname = inet_getname, .poll = mptcp_poll, .ioctl = inet_ioctl, + .uring_cmd = sock_common_uring_cmd, .gettstamp = sock_gettstamp, .listen = mptcp_listen, .shutdown = inet_shutdown, diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c index c365df24ad33..b1aaf644076f 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -1127,6 +1127,7 @@ static const struct proto_ops inet_seqpacket_ops = { .getname = inet_getname, /* Semantics are different. */ .poll = sctp_poll, .ioctl = inet_ioctl, + .uring_cmd = sock_common_uring_cmd, .gettstamp = sock_gettstamp, .listen = sctp_inet_listen, .shutdown = inet_shutdown, /* Looks harmless. */ diff --git a/net/socket.c b/net/socket.c index 9c92c0e6c4da..c683110c1523 100644 --- a/net/socket.c +++ b/net/socket.c @@ -87,6 +87,7 @@ #include #include #include +#include #include #include @@ -116,6 +117,7 @@ unsigned int sysctl_net_busy_poll __read_mostly; static ssize_t sock_read_iter(struct kiocb *iocb, struct iov_iter *to); static ssize_t sock_write_iter(struct kiocb *iocb, struct iov_iter *from); static int sock_mmap(struct file *file, struct vm_area_struct *vma); +static int sock_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags); static int sock_close(struct inode *inode, struct file *file); static __poll_t sock_poll(struct file *file, @@ -159,6 +161,7 @@ static const struct file_operations socket_file_ops = { #ifdef CONFIG_COMPAT .compat_ioctl = compat_sock_ioctl, #endif + .uring_cmd = sock_uring_cmd, .mmap = sock_mmap, .release = sock_close, .fasync = sock_fasync, @@ -1319,6 +1322,16 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg) return err; } +static int sock_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags) +{ + struct socket *sock = cmd->file->private_data; + + if (!sock->ops || !sock->ops->uring_cmd) + return -EOPNOTSUPP; + + return sock->ops->uring_cmd(sock, cmd, issue_flags); +} + /** * sock_create_lite - creates a socket * @family: protocol family (AF_INET, ...) -- 2.34.1