From patchwork Wed Jun 14 11:07:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 107902 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1166954vqr; Wed, 14 Jun 2023 04:23:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6kIP3J3otghJRvhij6Tly5pS9JejeZqwfyMMhlvLd9Gw4hMPQ5fOvvP3x8hvO2KcIp2znE X-Received: by 2002:a05:6a00:2451:b0:647:157b:cb61 with SMTP id d17-20020a056a00245100b00647157bcb61mr1777881pfj.7.1686741808168; Wed, 14 Jun 2023 04:23:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686741808; cv=none; d=google.com; s=arc-20160816; b=afZLQufOeKKxPqJ5osfQ2W+MmqnbJV0LBUje5mzrk/OfpgnACKIBoanIDX/UPRKk0K bnsrilX1U0owiOeFjoHGI1b9iidWPF/UJ7vKZWu2++ELEBfpFfnLJPX0iK4ZPIPFab9V EhEnuMNTSqrS0cEkvjZFD6zNeDmDKMu2OLECkz2aN6KQUYvBzoY4tN+BaMezZwrYKFVH KD3BNFfZhGopWJIDntOc++4Ib4ssUpMnM1uXKMIW4F3c2ijeUEwCZt55/oi3YzoOx+8C lkw5NFgDJDW9jTKzdMqq9ft36pYRqzasyJ0sHIYcmjqjcwokez057dZApQosvXztoKuT gOOg== 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=juIju8Gf3A46+CsReLgCfla8sOnVETZd+YXsqjZzcXQ=; b=oZ/aiRMokRbae8oHTWGz5RKGHJv6xJdlGdGb6uMdKxxA1O7J7cSRGtTFjp1sSgLIiF GueNM9o3ZoWHhxEQftkTLq2fXgQvvapbGvbCCapcnX4TRWhiQML1Co9RS/aG7Q03LU7m owbrwVK1FL6eTue1igAsQcQDrPLW686Kt0A2wFAw8dvma+Yies2A3y4f/9ozI75bs87x lV5Ljb8yTcOtjCLRwqPRC1YmCn1iwu1GMngL3GN/gKhh4NISaqsqKyX5SVrBEEqROwzb cMHdEXqluIjxW2xJS6MKxxLPEBifhT3bHLiZFaY6NICkOpYxBrNqT8F0GJsdgtYgYU4I Ld3A== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h12-20020aa79f4c000000b006439d34a090si10653513pfr.238.2023.06.14.04.23.15; Wed, 14 Jun 2023 04:23:28 -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 S243696AbjFNLKe (ORCPT + 99 others); Wed, 14 Jun 2023 07:10:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243489AbjFNLK0 (ORCPT ); Wed, 14 Jun 2023 07:10:26 -0400 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F3521BE5; Wed, 14 Jun 2023 04:10:23 -0700 (PDT) Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-3f8d2bfec3bso5959605e9.2; Wed, 14 Jun 2023 04:10:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686741021; x=1689333021; 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=juIju8Gf3A46+CsReLgCfla8sOnVETZd+YXsqjZzcXQ=; b=auRXcSVKt0SVqJNfm5V4LCEGGrMXp3YbhBRGdoD1rErCHSpeoMYXmbpwKOg6G9qL/3 IiSKMsj0QYxGRZBsllP82Z3a8+PqV1DdVHAf6UFXC5cbLvlyujrgmAViBpsyn5zttln4 bUa4W2oZsC2/soYVc+iD5m/VGHMGC/LzL/XbWPAVB6Ud4qN6yF3pyJa7dfQBgGYLgIF5 z8PcUJ/7rh79AUknfoy1/1rYqdxRZ7VIajOQtaDNZzq5KHK905Psv8GhFe1nkhbpJ7oh Sa/Hl8QBldkiEB1KwqCBRpIfNlf32QBYKSLARdIi2AmouQcA1NpJ6ZgO3fMpUJIkqbs4 66QQ== X-Gm-Message-State: AC+VfDxTdpKpMik3ZRVjywjMFffA1eTwBVV86tn6dgWo9+TlD0BCtAyV 8+Hhsg1pDKIhbNa0yCh1IShIDYzXdp5YBQ== X-Received: by 2002:a1c:4b0f:0:b0:3f5:6e5:1689 with SMTP id y15-20020a1c4b0f000000b003f506e51689mr12910729wma.17.1686741020904; Wed, 14 Jun 2023 04:10:20 -0700 (PDT) Received: from localhost (fwdproxy-cln-002.fbsv.net. [2a03:2880:31ff:2::face:b00c]) by smtp.gmail.com with ESMTPSA id n5-20020a7bcbc5000000b003f7eafe9d76sm17244524wmi.37.2023.06.14.04.10.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 04:10:20 -0700 (PDT) From: Breno Leitao To: io-uring@vger.kernel.org, axboe@kernel.dk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, David Ahern , Matthieu Baerts , Mat Martineau , Marcelo Ricardo Leitner , Xin Long Cc: leit@fb.com, asml.silence@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, dccp@vger.kernel.org, mptcp@lists.linux.dev, linux-sctp@vger.kernel.org, ast@kernel.org, kuniyu@amazon.com, martin.lau@kernel.org, Jason Xing , Joanne Koong , Greg Kroah-Hartman , "Jason A. Donenfeld" , Willem de Bruijn , Guillaume Nault , Andrea Righi Subject: [RFC PATCH v2 1/4] net: wire up support for file_operations->uring_cmd() Date: Wed, 14 Jun 2023 04:07:54 -0700 Message-Id: <20230614110757.3689731-2-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230614110757.3689731-1-leitao@debian.org> References: <20230614110757.3689731-1-leitao@debian.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768676978475441597?= X-GMAIL-MSGID: =?utf-8?q?1768676978475441597?= 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 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 8defc8f1d82e..58dea87077af 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 62a1b99da349..a49b8b19292b 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; @@ -1259,6 +1260,9 @@ struct proto { int (*ioctl)(struct sock *sk, int cmd, int *karg); + 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); @@ -1934,6 +1938,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 1df7e432fec5..339fa74db60f 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -3668,6 +3668,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) @@ -4008,7 +4020,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), @@ -4022,6 +4034,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), @@ -4050,7 +4063,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 3ab68415d121..1baad5ff402e 100644 --- a/net/dccp/ipv4.c +++ b/net/dccp/ipv4.c @@ -1001,6 +1001,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 9cd48df6a331..2947d4dd4922 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -1055,6 +1055,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, @@ -1091,6 +1092,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, @@ -1124,6 +1126,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 2b795c1064f5..3540e01455f7 100644 --- a/net/l2tp/l2tp_ip.c +++ b/net/l2tp/l2tp_ip.c @@ -616,6 +616,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 992b89c75631..444dacb9d804 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3883,6 +3883,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 664d1f2e9121..32b1a87d958a 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -1125,6 +1125,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 b778fc03c6e0..44cf9841af44 100644 --- a/net/socket.c +++ b/net/socket.c @@ -88,6 +88,7 @@ #include #include #include +#include #include #include @@ -117,6 +118,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, @@ -1309,6 +1312,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 Wed Jun 14 11:07:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 107897 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1163686vqr; Wed, 14 Jun 2023 04:17:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6iWFWa1GVDqo6mkWSs0iDSxSTfKcYaA3xaYQeceNgbKv/jUzutAKfe5Wx+m0I/dAyyaKtz X-Received: by 2002:a17:907:846:b0:96f:5747:a0de with SMTP id ww6-20020a170907084600b0096f5747a0demr13773583ejb.6.1686741475402; Wed, 14 Jun 2023 04:17:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686741475; cv=none; d=google.com; s=arc-20160816; b=xweKLgBjlgQdUzLzzm44MPgJ5nrAz42ygx6H0IzNw5k4XFuMX9ne5zQi2SEZvWBetT IPjxZ6yBfJio+mIQPnjqW8L/dItBNtjMcEkBswbajHbh/VS6u5p9V0uYlK8obsTXnlxD 50TCKCP6ErHNQPcC4ezER+78M2qNWOyAurldWTfglZyrlQvZ6zij/TkOVTO1KV3JWa/A vgay4KRMaVKDEYd1T0iEV++8PsnFHeWc8spBbL1PBAvFYQTBW8N03a1savkU/YIow16x 7q10wbDON2l+POIoRQGuLYOdZVZ+dxvb94EvXpgvbtM/bE0V53DQ2jvIvPOEDrTygbKh tojg== 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=bVmEOXEjwmudHUkRx4Y0SQYham7m2mb1hbXq7ueWQ90=; b=kPQIDl3PyhN+yamzk6WrlVIXQzinSr+YGVBMgrL0WxWq0tPPXi03ircLMZ8EOXcWWB UFtAvSVMIlGLrXeyycX6X0JQEKEZBrLYKkbwXVP3EqSNnzm48sqxnIFgq/SgcYcZxQQx 9/bghiGsceylDGErEAoFHniJEteYD/J9WlZQol9fDS1WtXplYsJhgVRkakS5BWZ22EWP QSBFkHEtumP9/G/zzJnbKaL6loLYm5BqqLrqHKimlX7lEQVo+oZWg/Pm5AJhmRHWTGC6 LqdSW57eBNo4khWSO+GEMBC3jdD1meeSpj+WMSGLBLQ8WNmkU6DSeugIYkxbU7Q4XI0f 6ZWw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h25-20020a170906719900b0096f59cbff93si7791297ejk.190.2023.06.14.04.17.30; Wed, 14 Jun 2023 04:17:55 -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 S243366AbjFNLKu (ORCPT + 99 others); Wed, 14 Jun 2023 07:10:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242938AbjFNLK3 (ORCPT ); Wed, 14 Jun 2023 07:10:29 -0400 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CC50199B; Wed, 14 Jun 2023 04:10:25 -0700 (PDT) Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-4f63ab1ac4aso8268012e87.0; Wed, 14 Jun 2023 04:10:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686741023; x=1689333023; 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=bVmEOXEjwmudHUkRx4Y0SQYham7m2mb1hbXq7ueWQ90=; b=GuXyeq/ZCE9MhXJwHaWCuWsgLkXG93L9d6GXawE2FHYdiTmBtfvve6d7JWIx2DrM8I PGQrlhc+5xG4hf4qO5+A4nubZ+kAXstzRfvmhFE5nPLRNih9FAsO7xEM6MFgsePAYsV1 psUuEDfk8AQPkFRZKEr0rYtn1jrpAx3o6WbwqhiiiTBqqmGbk46hEuMMlywNvBUNAvrS caYboT6I5CbygCrSZVn99ovMJF9r0OSIOGiZzZiBy4tN6S9uSt9wjTtF0wcCEO4U3IyU TB8ENfsrJsQVmejMrfSyffBlZ8br2/NJtC7JJOgaWeKqK9Y1BsabvtQog2jJtlKS4dNa d+iQ== X-Gm-Message-State: AC+VfDyKZ2/LUoz2w+Eh4x1stE+/oBqO1mV3iXcSkCjPqW2xuvhy0qmu OA2ld4sPc+HnDYWCGrsJKUguLOnpu2ZyMQ== X-Received: by 2002:a19:ab02:0:b0:4f6:3000:94a0 with SMTP id u2-20020a19ab02000000b004f6300094a0mr6630041lfe.61.1686741023155; Wed, 14 Jun 2023 04:10:23 -0700 (PDT) Received: from localhost (fwdproxy-cln-013.fbsv.net. [2a03:2880:31ff:d::face:b00c]) by smtp.gmail.com with ESMTPSA id 8-20020a05600c230800b003f7ed9dae70sm17145918wmo.0.2023.06.14.04.10.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 04:10:22 -0700 (PDT) From: Breno Leitao To: io-uring@vger.kernel.org, axboe@kernel.dk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Willem de Bruijn , David Ahern Cc: leit@fb.com, asml.silence@gmail.com, matthieu.baerts@tessares.net, martineau@kernel.org, marcelo.leitner@gmail.com, lucien.xin@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, dccp@vger.kernel.org, mptcp@lists.linux.dev, linux-sctp@vger.kernel.org, ast@kernel.org, kuniyu@amazon.com, martin.lau@kernel.org Subject: [RFC PATCH v2 2/4] net: add uring_cmd callback to UDP Date: Wed, 14 Jun 2023 04:07:55 -0700 Message-Id: <20230614110757.3689731-3-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230614110757.3689731-1-leitao@debian.org> References: <20230614110757.3689731-1-leitao@debian.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768676629389287495?= X-GMAIL-MSGID: =?utf-8?q?1768676629389287495?= 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 the io_uring representation for SIOCOUTQ and SIOCINQ. SIOCINQ and SIOCOUTQ are the only two CMDs handled by udp_ioctl(). Signed-off-by: Breno Leitao --- include/net/udp.h | 2 ++ include/uapi/linux/net.h | 5 +++++ net/ipv4/udp.c | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/include/net/udp.h b/include/net/udp.h index 10d94a42117b..046ca7231d27 100644 --- a/include/net/udp.h +++ b/include/net/udp.h @@ -285,6 +285,8 @@ 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_ioctl(struct sock *sk, int cmd, int *karg); +int udp_uring_cmd(struct sock *sk, struct io_uring_cmd *cmd, + unsigned int issue_flags); int udp_init_sock(struct sock *sk); int udp_pre_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len); int __udp_disconnect(struct sock *sk, int flags); 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 6a09757f287b..5e06b6de1c08 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 @@ -1687,6 +1688,26 @@ 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) +{ + int ret; + + switch (cmd->sqe->cmd_op) { + case SOCKET_URING_OP_SIOCINQ: + if (udp_ioctl(sk, SIOCINQ, &ret)) + return -EFAULT; + return ret; + case SOCKET_URING_OP_SIOCOUTQ: + if (udp_ioctl(sk, SIOCOUTQ, &ret)) + return -EFAULT; + return ret; + default: + return -ENOIOCTLCMD; + } +} +EXPORT_SYMBOL_GPL(udp_uring_cmd); + /* * IOCTL requests applicable to the UDP protocol */ @@ -2925,6 +2946,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 Wed Jun 14 11:07:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 107901 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1166558vqr; Wed, 14 Jun 2023 04:22:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6xXHBcEPvKcLMeEyrNGWc1m6Eb7h43kr85qR5nbSeYGd1qY00kge6CXRk79M63PjKsm5En X-Received: by 2002:a05:6a20:2308:b0:10c:9e35:857a with SMTP id n8-20020a056a20230800b0010c9e35857amr1173154pzc.49.1686741777940; Wed, 14 Jun 2023 04:22:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686741777; cv=none; d=google.com; s=arc-20160816; b=XCsxCtpWTvYBxdnGMt5eGWucHWcwTxalph0B/sz9zxx+i14aU/4h/MLgebx1lCDIJy iAuzYrrJbF9F5AuEciZyeqmYLaIMuduX0IUa5CAjQmm5WNFkVT7a0UDxCBGLPOYaxTpg Tc2Ha6GcqyY0esAUaDErdNohcU9zYuNQ7KFR4n9iFIRlDAKSGol3Xn9x+cCO1TnYDmr0 ZhIoUQh6k7h+4Vp2313e57GaSYk/Vq94uN14apasSqBFHPdFai8bpeeZjjRfcBl0xX8q rmSnHGTDu3Ecl+1lNAiA6aGscA20kWnhIsfNXf3DW17WaE55v10IUtZDt5juqRWj8KVc vW5Q== 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=qkkE+Ruzq/uQr05Vb/IRsuaLy9Kdl2xaoXLCVAa73nU=; b=fjUV8IKoRzufnUy/C1UlXt4FASY0KPComkeY8MhybYExY6WATigrSsOO7EVX+LFn4h R8wgi2jzSaDPQlgMv0zOk1cgqYQAX7+Zm4p3U1p9V/LuWLz2n7U0ooc5pYaSWorAXdIW u7demjf/iZnp/LA9ae5K30VjidKHy4UbOrE9D686cZbtb22oi5rHSacmi8mMQCLjSJq4 JaIZStUKt+mCeBlokF420TOscPJhAN/Fa048+hpfiOp38v7ssen/pov4/KPDNiWv+vHk az6SEGYv4Wdpak2LZz8zPkidBejDAv6ayRuTTW+1FfQd3o7tESIilZyH+SuDhN1wWc8C OgXQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l2-20020a170902f68200b001b382b2d311si6640097plg.471.2023.06.14.04.22.42; Wed, 14 Jun 2023 04:22:57 -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 S235683AbjFNLKm (ORCPT + 99 others); Wed, 14 Jun 2023 07:10:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242991AbjFNLK3 (ORCPT ); Wed, 14 Jun 2023 07:10:29 -0400 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D9571BEF; Wed, 14 Jun 2023 04:10:27 -0700 (PDT) Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-3f7378a75c0so5164855e9.3; Wed, 14 Jun 2023 04:10:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686741025; x=1689333025; 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=qkkE+Ruzq/uQr05Vb/IRsuaLy9Kdl2xaoXLCVAa73nU=; b=Ffc4zVjQGabstE656Dxw0WpMkANGe8mEcT19O3jvRkXKlR4LqCMlKULos/vTYO2k1W LVNuXA/CRAiCJTVdT+/u1svxPClaufVfy4yIHkE4LS5ewGvkzGSx6BB1oXZQmDCMyXzb oP71xl9DrWgeMoVUkvMCTe97Iznhbr1pL+LI2Z1n6szktiUZESF68nTnX+Dl68yDIKFE 4B3499Cf6/EGasxC1yuV/gZm3X9cg3keybMSpcb9MeHjHVXOkLT1NsQpl5bqbVMjKB13 Socir+0rgR2rIt1JuK395xz97niG0KOP3qd9BZetg7TYXA7zvvsrJoonmOZWw0bf68OP GWtA== X-Gm-Message-State: AC+VfDwjTOSqyT7tRdGSpURmlg3csShEXw/SsV92v/zCV6Vj0X7luCBH v2q3i+JSu/t5v/O40RVwaS4boWrmcZIjEA== X-Received: by 2002:a05:600c:228d:b0:3f7:8fbf:a21d with SMTP id 13-20020a05600c228d00b003f78fbfa21dmr10460822wmf.32.1686741025197; Wed, 14 Jun 2023 04:10:25 -0700 (PDT) Received: from localhost (fwdproxy-cln-016.fbsv.net. [2a03:2880:31ff:10::face:b00c]) by smtp.gmail.com with ESMTPSA id z10-20020a05600c114a00b003f7e60622f0sm17180504wmz.6.2023.06.14.04.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 04:10:24 -0700 (PDT) From: Breno Leitao To: io-uring@vger.kernel.org, axboe@kernel.dk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, David Ahern Cc: leit@fb.com, asml.silence@gmail.com, matthieu.baerts@tessares.net, martineau@kernel.org, marcelo.leitner@gmail.com, lucien.xin@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, dccp@vger.kernel.org, mptcp@lists.linux.dev, linux-sctp@vger.kernel.org, ast@kernel.org, kuniyu@amazon.com, martin.lau@kernel.org Subject: [RFC PATCH v2 3/4] net: add uring_cmd callback to TCP Date: Wed, 14 Jun 2023 04:07:56 -0700 Message-Id: <20230614110757.3689731-4-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230614110757.3689731-1-leitao@debian.org> References: <20230614110757.3689731-1-leitao@debian.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768676946750828695?= X-GMAIL-MSGID: =?utf-8?q?1768676946750828695?= This is the implementation of uring_cmd for the TCP protocol. It basically encompasses SOCKET_URING_OP_SIOCOUTQ and SOCKET_URING_OP_SIOCINQ, which calls tcp_ioctl(). tcp_ioctl() has other CMDs, such as SIOCATMARK and SIOCOUTQNSD, but they are not implemented, because they are TCP specific, and not available on UDP and RAW sockets. Signed-off-by: Breno Leitao --- include/net/tcp.h | 2 ++ net/ipv4/tcp.c | 21 +++++++++++++++++++++ net/ipv4/tcp_ipv4.c | 1 + 3 files changed, 24 insertions(+) diff --git a/include/net/tcp.h b/include/net/tcp.h index 2a7289916d42..1100b0c9df98 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -340,6 +340,8 @@ 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_ioctl(struct sock *sk, int cmd, int *karg); +int tcp_uring_cmd(struct sock *sk, struct io_uring_cmd *cmd, + unsigned int issue_flags); int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb); void tcp_rcv_established(struct sock *sk, struct sk_buff *skb); void tcp_rcv_space_adjust(struct sock *sk); diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 2cb01880755a..8bf9a41d2a67 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -279,6 +279,7 @@ #include #include #include +#include /* Track pending CMSGs. */ enum { @@ -599,6 +600,26 @@ __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) +{ + int ret; + + switch (cmd->sqe->cmd_op) { + case SOCKET_URING_OP_SIOCINQ: + if (tcp_ioctl(sk, SIOCINQ, &ret)) + return -EFAULT; + return ret; + case SOCKET_URING_OP_SIOCOUTQ: + if (tcp_ioctl(sk, SIOCOUTQ, &ret)) + return -EFAULT; + return ret; + default: + return -ENOIOCTLCMD; + } +} +EXPORT_SYMBOL_GPL(tcp_uring_cmd); + int tcp_ioctl(struct sock *sk, int cmd, int *karg) { struct tcp_sock *tp = tcp_sk(sk); diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 84a5d557dc1a..dd93a862d195 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -3107,6 +3107,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 Wed Jun 14 11:07:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 107898 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1165310vqr; Wed, 14 Jun 2023 04:20:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7GbmNUpLdidGq3JrChgwHaUCacXGafuADM4tApcia45GUKxLhvWj7n+2jJdVMDawwxoyyN X-Received: by 2002:aa7:d49a:0:b0:50b:fd52:2f4b with SMTP id b26-20020aa7d49a000000b0050bfd522f4bmr10558969edr.24.1686741648465; Wed, 14 Jun 2023 04:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686741648; cv=none; d=google.com; s=arc-20160816; b=XIlflMXBjYAretV2J3qAJypXGEzrVx2f1Y4/3dU3QlIiRS4M8p9z/7QPCJjRkfZn4i b61KxrXdNXa9o8k7NVCDAStmG4BCjdzqWx5tIO3A0Hs7qhM1j++PV7KUN8t+uQ435XpM kA0ReDlA1/Q6BboypIPmb2vaYrjEXZ2qPtDbRBt+vQCLAuFprEmqmKJhHpyJrYwGZDhj NJ+HhwbHwNRIMsuLInxKsnk90D8uXTR3y69ms/zVFxcJPxwUnRncZdqHMG6Nyu4H9WIT fdDStoHOhpyv8PqeGYTJ/UUgturiZUbUihdf7x42Ms2deT6JdeziG71zOke8wAw2OQeQ x5Iw== 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=Yc88muMtZ5aM3IzShu9BL/RZOvuDqFEnp6zrvGSRn1A=; b=aPa0Uo87KdlmcEIgKBEhdrJjqSMh703U1SsBB/k4lyXFK5S21Ju1Vd8/K/xlotVE7X ZgPl9Fwqq6S90edknLgNiyx/eCP4+TuH2mVNT8Axk/5kH/DX+8qsLftMxsTHEIULQ907 QKpKFeHpSoPTRmiZdJJymaj35TnKAaWhvdMkKlHcncqF1jpBN2gv3f9TWaBQoElZotcu Ch8D6QerLcxpNgBZJzVo5/zAA2fNKp3hbQ5kL6ZfZdDUQocoa/CrxE78tygxN3PDkVX+ oB37jkmr00k8fU8evLEuk0vYEqLaF8LS84RBPXiGDjg3tSnoGkiKqU5nE53HidkgWAUI 8GXA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g21-20020a50ee15000000b005187aa364ebsi1702754eds.481.2023.06.14.04.20.22; Wed, 14 Jun 2023 04:20:48 -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 S242938AbjFNLLA (ORCPT + 99 others); Wed, 14 Jun 2023 07:11:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243558AbjFNLKa (ORCPT ); Wed, 14 Jun 2023 07:10:30 -0400 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E1F91BF8; Wed, 14 Jun 2023 04:10:29 -0700 (PDT) Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-3f7368126a6so4440265e9.0; Wed, 14 Jun 2023 04:10:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686741027; x=1689333027; 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=Yc88muMtZ5aM3IzShu9BL/RZOvuDqFEnp6zrvGSRn1A=; b=lCGDgBpjVoHWjtVL+jFcdLuj6zQq44H9cEy/NwrKQEew8Okc5Z6Fcod9wDJpHkrlAQ 06SPd67KDa0PirISrBgFnPFCFlZtCrEQ2pKpAN8cl5isSedqJlEtlCFFXUZmFAHSigcr 8uSMIcaxyaAab2XbwmgEnLjOxgvCJ9CkWg9bJ6yd/eOVwM0BDOHDAx00o3GXAEQT+0Ii 1IsMqRtcV8KuSrZ4g4uTzgyDsYwozl0348bg83wsj/HkfhWE19pmfYrx1oPcWhS793T2 N/aWo8WZJGXZtgqHnX1gzCmkgbgTw95m9LsHvKgStRAgq5MisHs0RPm6kp5q36oxumaj 1Faw== X-Gm-Message-State: AC+VfDzIF7HQK1EIitcpL/zadnjCPRHnfu3IjiSrHdSFX96sFgkSYL0i IzKhpz0DZzhWomasRp0qm7BbajfjPt4W8w== X-Received: by 2002:a05:600c:364f:b0:3f6:d09:5d46 with SMTP id y15-20020a05600c364f00b003f60d095d46mr9656122wmq.20.1686741027064; Wed, 14 Jun 2023 04:10:27 -0700 (PDT) Received: from localhost (fwdproxy-cln-020.fbsv.net. [2a03:2880:31ff:14::face:b00c]) by smtp.gmail.com with ESMTPSA id i10-20020a05600c290a00b003f819dfa0ddsm9941676wmd.28.2023.06.14.04.10.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 04:10:26 -0700 (PDT) From: Breno Leitao To: io-uring@vger.kernel.org, axboe@kernel.dk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, David Ahern Cc: leit@fb.com, asml.silence@gmail.com, matthieu.baerts@tessares.net, martineau@kernel.org, marcelo.leitner@gmail.com, lucien.xin@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, dccp@vger.kernel.org, mptcp@lists.linux.dev, linux-sctp@vger.kernel.org, ast@kernel.org, kuniyu@amazon.com, martin.lau@kernel.org Subject: [RFC PATCH v2 4/4] net: add uring_cmd callback to raw "protocol" Date: Wed, 14 Jun 2023 04:07:57 -0700 Message-Id: <20230614110757.3689731-5-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230614110757.3689731-1-leitao@debian.org> References: <20230614110757.3689731-1-leitao@debian.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768676810806227596?= X-GMAIL-MSGID: =?utf-8?q?1768676810806227596?= This is the implementation of uring_cmd for the raw "protocol". It basically encompasses SOCKET_URING_OP_SIOCOUTQ and SOCKET_URING_OP_SIOCINQ, which call raw_ioctl with SIOCOUTQ and SIOCINQ. These two commands (SIOCOUTQ and SIOCINQ), are the only two commands that are handled by raw_ioctl(). Signed-off-by: Breno Leitao --- include/net/raw.h | 3 +++ net/ipv4/raw.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/net/raw.h b/include/net/raw.h index 32a61481a253..5d5ec63274a8 100644 --- a/include/net/raw.h +++ b/include/net/raw.h @@ -96,4 +96,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 7782ff5e6539..31c3f9c41354 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; @@ -885,6 +886,27 @@ static int raw_ioctl(struct sock *sk, int cmd, int *karg) } } +int raw_uring_cmd(struct sock *sk, struct io_uring_cmd *cmd, + unsigned int issue_flags) +{ + int ret; + + switch (cmd->sqe->cmd_op) { + case SOCKET_URING_OP_SIOCINQ: { + if (raw_ioctl(sk, SIOCINQ, &ret)) + return -EFAULT; + return ret; + } + case SOCKET_URING_OP_SIOCOUTQ: + if (raw_ioctl(sk, SIOCOUTQ, &ret)) + return -EFAULT; + return ret; + default: + return -ENOIOCTLCMD; + } +} +EXPORT_SYMBOL_GPL(raw_uring_cmd); + #ifdef CONFIG_COMPAT static int compat_raw_ioctl(struct sock *sk, unsigned int cmd, unsigned long arg) { @@ -924,6 +946,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,