Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2257439rwl; Thu, 6 Apr 2023 07:54:43 -0700 (PDT) X-Google-Smtp-Source: AKy350bicRjA7FTx9g2Dhp8zjhbraHFchu9aoMHFEOe6tMAlbYKKcEmJ0NsFuYalJGHF6wMV3T9H X-Received: by 2002:aa7:d417:0:b0:502:a619:b6f2 with SMTP id z23-20020aa7d417000000b00502a619b6f2mr4934421edq.10.1680792882746; Thu, 06 Apr 2023 07:54:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680792882; cv=none; d=google.com; s=arc-20160816; b=ndMFHRfCMGwoQ3RxCPSbIPwBO4DABAQGp4CnFb4jDmMA04ACiOR2FlWUUBAYeYtSud vCR4oZYqCxiYzI++AhPi4SKNIcAJe7xsm7H1AhNjM+BXBTLY694SVWv3IMjowLvYyHOb a4XWkupVpgNs9EsIxyEC3JGA6qFdKBsA0qVENunjHhIbk7XVXgeXclr+C6s+vZ2/ndVN o8VfVrDZFnq9nMlB5Yg/+wTvXdD4f6BsE0qZ3N06wB1pSaS9Liq1whZKbjRNer84u26L wv5kRYFxoXRexykWBlh6EEPG6uBSANpaWxAkBDDfKkfAU2M70Thy4hB3nkVmIoDwv0Qp M0oA== 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=DdgssL2Y+ar153QBlAv7JBtrBbAm616EZvQGP5HdHt4=; b=wHdUGhhK6i+Tn8lcEKurQQ/oZ4v/0se8JAc8ZfBDUJTaEwp/yRw/CR3ArsPiRpie/6 wNvTJDAnucZUB/4w1jQEG4IWKc/eddqdtIebLAMQpO/73eSrD8JnVrkGOnHWzjZfq9At +r474rtgl8/9mgj2+mRb8r5FERDBQ8F+XARfeHSbCg/694JofPl/ZRCkgCpB4D+xeS5P bkE22O6IqR4qpO09a/wGCB4xK036MA9oESnOdx2gyYNjL6MDOIvy/nD5BFdnRkr1tvJ9 ++yfOr3qwNbyCGxMtojr/STAwd+sg1kq9L7dP2WN2t+ywqL4WLqZhRFoQ6dH9oTzCwAT QD+A== 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 w13-20020aa7dccd000000b004fd23c8cf1esi1161686edu.52.2023.04.06.07.54.17; Thu, 06 Apr 2023 07:54:42 -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 S239460AbjDFOqR (ORCPT + 99 others); Thu, 6 Apr 2023 10:46:17 -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-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 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, RCVD_IN_MSPIKE_H2,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 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, -- 2.34.1