From patchwork Thu Apr 6 14:43:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13203571 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0722C76196 for ; Thu, 6 Apr 2023 14:46:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239023AbjDFOqJ (ORCPT ); Thu, 6 Apr 2023 10:46:09 -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-Google-Smtp-Source: AKy350ZgmlAfEXBuRNCxqVsFtSwwqu9iI8uQRJYIj5j4dClcLR4Hwq/ycqV8cmCEdqbvst2HHlsNjQ== 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 Precedence: bulk List-ID: X-Mailing-List: io-uring@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, ...) From patchwork Thu Apr 6 14:43:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13203573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11FB5C77B6F for ; Thu, 6 Apr 2023 14:46:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239433AbjDFOqL (ORCPT ); Thu, 6 Apr 2023 10:46:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239216AbjDFOpn (ORCPT ); Thu, 6 Apr 2023 10:45:43 -0400 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11980A27D; Thu, 6 Apr 2023 07:45:01 -0700 (PDT) Received: by mail-wm1-f49.google.com with SMTP id j18-20020a05600c1c1200b003ee5157346cso25667783wms.1; Thu, 06 Apr 2023 07:45:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680792237; 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=DdgssL2Y+ar153QBlAv7JBtrBbAm616EZvQGP5HdHt4=; b=k0QRsq8ynYY37v5Kl0//zAYbx7ZbSuK7OXYRgJjMaSzObEkO30AuCs3Sqr2T1IOdyZ Lz+sqt2HlP02/4f9dUTMfrHBbGfMph8+Y8kwF7K/cwLvJmJtQDMTP17GuMBj1fIbUVmd Gy4oP0xAbRvMrNprHp6WAKQM7BlPqu0olVXfxHof5kFWYqxQZvhqIwt6YxGfTrPcLp8R y1AGGojXSjHlj4odjGA44P7IPxwtKEaOF5glKy0XaYvYCxd1BmoVqpbtTVgInOA1Do2U spJR0LbS+u/AhcY20JZ6si0bzoVQEtAmw/gJQXhV5/ry26KOCS6PRyjDamHXqMagijo8 eJTQ== X-Gm-Message-State: AAQBX9cS3wrwc6e5Jz+IZF8n7k5KWYs0HhnoES1rsBVhGR9wXz8dUuX5 nj3fosARfkbJ0oBBKf4aK/PREqOuJloJgQ== X-Google-Smtp-Source: AKy350ZnKTn89DhKxJeGfgPbuAFyAbgRVP4wqJkdvOw2VZiQJhmbrpuVfhfGag2Nw9LzoY39sAkViQ== X-Received: by 2002:a7b:c384:0:b0:3e9:f15b:935b with SMTP id s4-20020a7bc384000000b003e9f15b935bmr7264583wmj.32.1680792236817; Thu, 06 Apr 2023 07:43:56 -0700 (PDT) Received: from localhost (fwdproxy-cln-117.fbsv.net. [2a03:2880:31ff:75::face:b00c]) by smtp.gmail.com with ESMTPSA id g23-20020a7bc4d7000000b003e91b9a92c9sm1773473wmk.24.2023.04.06.07.43.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 07:43:56 -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 2/4] net: add uring_cmd callback to UDP Date: Thu, 6 Apr 2023 07:43:28 -0700 Message-Id: <20230406144330.1932798-3-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 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org This is the implementation of uring_cmd for the udp protocol. It basically encompasses SOCKET_URING_OP_SIOCOUTQ and SOCKET_URING_OP_SIOCINQ, which is similar to the SIOCOUTQ and SIOCINQ ioctls. The return value is exactly the same as the regular ioctl (udp_ioctl()). Signed-off-by: Breno Leitao --- include/net/udp.h | 2 ++ include/uapi/linux/net.h | 5 +++++ net/ipv4/udp.c | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/include/net/udp.h b/include/net/udp.h index de4b528522bb..c0e829dacc2f 100644 --- a/include/net/udp.h +++ b/include/net/udp.h @@ -283,6 +283,8 @@ void udp_flush_pending_frames(struct sock *sk); int udp_cmsg_send(struct sock *sk, struct msghdr *msg, u16 *gso_size); void udp4_hwcsum(struct sk_buff *skb, __be32 src, __be32 dst); int udp_rcv(struct sk_buff *skb); +int udp_uring_cmd(struct sock *sk, struct io_uring_cmd *cmd, + unsigned int issue_flags); int udp_ioctl(struct sock *sk, int cmd, unsigned long arg); int udp_init_sock(struct sock *sk); int udp_pre_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len); diff --git a/include/uapi/linux/net.h b/include/uapi/linux/net.h index 4dabec6bd957..dd8e7ced7d24 100644 --- a/include/uapi/linux/net.h +++ b/include/uapi/linux/net.h @@ -55,4 +55,9 @@ typedef enum { #define __SO_ACCEPTCON (1 << 16) /* performed a listen */ +enum { + SOCKET_URING_OP_SIOCINQ = 0, + SOCKET_URING_OP_SIOCOUTQ, +}; + #endif /* _UAPI_LINUX_NET_H */ diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index c605d171eb2d..d6d60600831b 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -113,6 +113,7 @@ #include #include #include +#include #if IS_ENABLED(CONFIG_IPV6) #include #endif @@ -1711,6 +1712,20 @@ static int first_packet_length(struct sock *sk) return res; } +int udp_uring_cmd(struct sock *sk, struct io_uring_cmd *cmd, + unsigned int issue_flags) +{ + switch (cmd->sqe->cmd_op) { + case SOCKET_URING_OP_SIOCOUTQ: + return sk_wmem_alloc_get(sk); + case SOCKET_URING_OP_SIOCINQ: + return max_t(int, 0, first_packet_length(sk)); + default: + return -ENOIOCTLCMD; + } +} +EXPORT_SYMBOL_GPL(udp_uring_cmd); + /* * IOCTL requests applicable to the UDP protocol */ @@ -2952,6 +2967,7 @@ struct proto udp_prot = { .connect = ip4_datagram_connect, .disconnect = udp_disconnect, .ioctl = udp_ioctl, + .uring_cmd = udp_uring_cmd, .init = udp_init_sock, .destroy = udp_destroy_sock, .setsockopt = udp_setsockopt, From patchwork Thu Apr 6 14:43:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13203574 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59D64C76196 for ; Thu, 6 Apr 2023 14:46:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239461AbjDFOqv (ORCPT ); Thu, 6 Apr 2023 10:46:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239436AbjDFOqX (ORCPT ); Thu, 6 Apr 2023 10:46:23 -0400 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E073B747; Thu, 6 Apr 2023 07:45:19 -0700 (PDT) Received: by mail-wm1-f48.google.com with SMTP id v20-20020a05600c471400b003ed8826253aso3639289wmo.0; Thu, 06 Apr 2023 07:45:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680792238; 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=/E+V5ftFxihSr5OwTsP6mRvxZ0E7DUpfGVsbz2Q5J9s=; b=Heuf53frOnWj2vnEAdeLh528Qc+H4OuPe7T/yRLFykciqUSrY8Ofc/58Kdla1Y44Uz BAKI1CadIz93t50hCDLnuQ0lx82mJ2Ksz+0fozrtVEIePEz/Fq10R2IDDMtoC2Q70BMF 81i4E2Jzc3iD4nClUwFIcjBMNFMBqzKE7JpFT53v39yIy529b2gAuZoWidf4DReEt4im kZ36KpwqlTZFomSLg1dqPSzyY3QoBzOl+YF5m9ibT57fPdhHQx35gAUlcosidioLwn4N Z/K5y8/RH7eMZO4RxYlY6x1QBgXVX4RxX0DSrn27selwVSIvvCOqeRmqudxYCY7hx5M/ 4DOA== X-Gm-Message-State: AAQBX9d9Ij3IboppBa4JuxNyo3ENOgGpI9JjmKBR/SZ0dfyR+eMO0rXS bZGuuC2qDAJKqQJ22AupgA3oFL6PwjknLA== X-Google-Smtp-Source: AKy350boXoaX2U+68b5W1nhQ1K2p9mO1JGBZo+3g2JbcFKZDQ8rkzAlnAxX6lWaojVTpVA42zxtfYg== X-Received: by 2002:a1c:7515:0:b0:3ea:ed4d:38f6 with SMTP id o21-20020a1c7515000000b003eaed4d38f6mr7398933wmc.4.1680792238142; Thu, 06 Apr 2023 07:43:58 -0700 (PDT) Received: from localhost (fwdproxy-cln-020.fbsv.net. [2a03:2880:31ff:14::face:b00c]) by smtp.gmail.com with ESMTPSA id jb10-20020a05600c54ea00b003ede2c4701dsm5430687wmb.14.2023.04.06.07.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 07:43:57 -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 3/4] net: add uring_cmd callback to TCP Date: Thu, 6 Apr 2023 07:43:29 -0700 Message-Id: <20230406144330.1932798-4-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 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org This is the implementation of uring_cmd for the TCP protocol. It basically encompasses SOCKET_URING_OP_SIOCOUTQ and SOCKET_URING_OP_SIOCINQ, which is similar to the SIOCOUTQ and SIOCINQ ioctls. The return value is exactly the same as the regular ioctl (tcp_ioctl()). Signed-off-by: Breno Leitao --- include/net/tcp.h | 2 ++ net/ipv4/tcp.c | 32 ++++++++++++++++++++++++++++++++ net/ipv4/tcp_ipv4.c | 1 + 3 files changed, 35 insertions(+) diff --git a/include/net/tcp.h b/include/net/tcp.h index db9f828e9d1e..4dfd6bd63261 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -342,6 +342,8 @@ void tcp_release_cb(struct sock *sk); void tcp_wfree(struct sk_buff *skb); void tcp_write_timer_handler(struct sock *sk); void tcp_delack_timer_handler(struct sock *sk); +int tcp_uring_cmd(struct sock *sk, struct io_uring_cmd *cmd, + unsigned int issue_flags); int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg); int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb); void tcp_rcv_established(struct sock *sk, struct sk_buff *skb); diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 288693981b00..cf2822242e28 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -279,6 +279,7 @@ #include #include #include +#include /* Track pending CMSGs. */ enum { @@ -596,6 +597,37 @@ __poll_t tcp_poll(struct file *file, struct socket *sock, poll_table *wait) } EXPORT_SYMBOL(tcp_poll); +int tcp_uring_cmd(struct sock *sk, struct io_uring_cmd *cmd, + unsigned int issue_flags) +{ + struct tcp_sock *tp = tcp_sk(sk); + bool slow; + int ret; + + switch (cmd->sqe->cmd_op) { + case SOCKET_URING_OP_SIOCINQ: + if (sk->sk_state == TCP_LISTEN) + return -EINVAL; + + slow = lock_sock_fast(sk); + ret = tcp_inq(sk); + unlock_sock_fast(sk, slow); + return ret; + case SOCKET_URING_OP_SIOCOUTQ: + if (sk->sk_state == TCP_LISTEN) + return -EINVAL; + + if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) + ret = 0; + else + ret = READ_ONCE(tp->write_seq) - tp->snd_una; + return ret; + default: + return -ENOIOCTLCMD; + } +} +EXPORT_SYMBOL_GPL(tcp_uring_cmd); + int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg) { struct tcp_sock *tp = tcp_sk(sk); diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index ea370afa70ed..900081fa2e1a 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -3103,6 +3103,7 @@ struct proto tcp_prot = { .disconnect = tcp_disconnect, .accept = inet_csk_accept, .ioctl = tcp_ioctl, + .uring_cmd = tcp_uring_cmd, .init = tcp_v4_init_sock, .destroy = tcp_v4_destroy_sock, .shutdown = tcp_shutdown, From patchwork Thu Apr 6 14:43:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13203572 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F374C7618D for ; Thu, 6 Apr 2023 14:46:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239426AbjDFOqK (ORCPT ); Thu, 6 Apr 2023 10:46:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239206AbjDFOpm (ORCPT ); Thu, 6 Apr 2023 10:45:42 -0400 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDA69A26B; Thu, 6 Apr 2023 07:44:58 -0700 (PDT) Received: by mail-wr1-f49.google.com with SMTP id h17so39746960wrt.8; Thu, 06 Apr 2023 07:44:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680792239; 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=ZSwILUq0bXFsvcMRWtndpmGM8P1qf1/sQjCxk4q0WaQ=; b=sk5WTKzXIQ4S/RT2IGTAT1q2Ph3JGvLwoTwMzBuWB3YGwnHCB0Jd30lpg6Y0XfWKCf QbePU3tPiClTEPRH+k4/6dOdjoKJjUMoBtzy2klUc4WuHvRzzwPp18Yf3+91qyACBOyg qPV/t57maMh5wgp8HATS3JPcBuym9fOvcWwTvDmyPyTx1ONlPbnlWkM3QYBOIFl67zSf /Y8C77QXXAFpt4uPoQHS42kC8Re9jcLHzLPCQ2e3ydm+9siL7aB14LcxfWUiBYnBwfmz L9BWlIF0sxmBio+r/k6DQXe1XiMIGsKaoO7u00df4gFMC6oLpvjPEx7zzmOmTTpo9HKF HlCQ== X-Gm-Message-State: AAQBX9dOOxpI/c5XSMm+cEZls35g3NFcAbxrL+anb5TGYC+vqOXJd6Kj CwkFBXPB0tPersOeo/qtvAjMm8Y/D78UVw== X-Google-Smtp-Source: AKy350Zn7t1xL+3RJUFBdw9cSQ8W+2kDMZmMrQPe3DuhdPo/XAA2bkpkQ5mYgwteGvnTnO9WbUeBwQ== X-Received: by 2002:a5d:5259:0:b0:2e2:730a:c7dc with SMTP id k25-20020a5d5259000000b002e2730ac7dcmr7620959wrc.25.1680792239398; Thu, 06 Apr 2023 07:43:59 -0700 (PDT) Received: from localhost (fwdproxy-cln-024.fbsv.net. [2a03:2880:31ff:18::face:b00c]) by smtp.gmail.com with ESMTPSA id d16-20020adff2d0000000b002df7c38dc3esm1927729wrp.87.2023.04.06.07.43.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 07:43:58 -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 4/4] net: add uring_cmd callback to raw "protocol" Date: Thu, 6 Apr 2023 07:43:30 -0700 Message-Id: <20230406144330.1932798-5-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 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org This is the implementation of uring_cmd for the raw "protocol". It basically encompasses SOCKET_URING_OP_SIOCOUTQ and SOCKET_URING_OP_SIOCINQ, which is similar to the SIOCOUTQ and SIOCINQ ioctls. The return value is exactly the same as the regular ioctl (raw_ioctl()). Signed-off-by: Breno Leitao --- include/net/raw.h | 3 +++ net/ipv4/raw.c | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/net/raw.h b/include/net/raw.h index 2c004c20ed99..ba7a96dce16b 100644 --- a/include/net/raw.h +++ b/include/net/raw.h @@ -99,4 +99,7 @@ static inline bool raw_sk_bound_dev_eq(struct net *net, int bound_dev_if, #endif } +int raw_uring_cmd(struct sock *sk, struct io_uring_cmd *cmd, + unsigned int issue_flags); + #endif /* _RAW_H */ diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index 94df935ee0c5..3db828bc1224 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -75,6 +75,7 @@ #include #include #include +#include struct raw_frag_vec { struct msghdr *msg; @@ -857,6 +858,29 @@ static int raw_getsockopt(struct sock *sk, int level, int optname, return do_raw_getsockopt(sk, level, optname, optval, optlen); } +int raw_uring_cmd(struct sock *sk, struct io_uring_cmd *cmd, + unsigned int issue_flags) +{ + switch (cmd->sqe->cmd_op) { + case SOCKET_URING_OP_SIOCOUTQ: + return sk_wmem_alloc_get(sk); + case SOCKET_URING_OP_SIOCINQ: { + struct sk_buff *skb; + int amount = 0; + + spin_lock_bh(&sk->sk_receive_queue.lock); + skb = skb_peek(&sk->sk_receive_queue); + if (skb) + amount = skb->len; + spin_unlock_bh(&sk->sk_receive_queue.lock); + return amount; + } + default: + return -ENOIOCTLCMD; + } +} +EXPORT_SYMBOL_GPL(raw_uring_cmd); + static int raw_ioctl(struct sock *sk, int cmd, unsigned long arg) { switch (cmd) { @@ -925,6 +949,7 @@ struct proto raw_prot = { .connect = ip4_datagram_connect, .disconnect = __udp_disconnect, .ioctl = raw_ioctl, + .uring_cmd = raw_uring_cmd, .init = raw_sk_init, .setsockopt = raw_setsockopt, .getsockopt = raw_getsockopt,