Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2257021rwl; Thu, 6 Apr 2023 07:54:20 -0700 (PDT) X-Google-Smtp-Source: AKy350YmIsXxoXqcYO0CUwXDlbX02eK2z0fiG5aBLLtzQzhFHwT/11uhi6w/U7VPhw4KgRqPBJdp X-Received: by 2002:a17:902:e884:b0:1a2:296:9355 with SMTP id w4-20020a170902e88400b001a202969355mr12700424plg.16.1680792860448; Thu, 06 Apr 2023 07:54:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680792860; cv=none; d=google.com; s=arc-20160816; b=C/xcMnlIFTXkjsjMAXRgV4B3dNqapIQkCgJpBEQzmbf/H2ZPsvvN6NvMKKwWVfvISo Bv55VC82jb3FSDq7x0Acboq4T697VkdFm22zp37vxSSKHBhjRfqLNB2HuXHI3uW0mbLj MWXTKx4pK0H6DBAfHZJl6TRFtmocE7UiuQ2HE00X6nR9krByKxTSnMQW2YZE/sHJu0ls 0ptCEeFUqnn1tHr+KEP+piUJhDE+c1pO0tsvoXhrPtJv7Ltm8sMUyrvU8Y2kmBHIF3VA XQVrgOgp/xwuQ7s/PUest5WPMA5R/ruO4dnCo2pyC2ymKIhwgiagAgvS4EAAP5PFfjZJ wT9w== 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=ZSwILUq0bXFsvcMRWtndpmGM8P1qf1/sQjCxk4q0WaQ=; b=Sc5cqCBQbczDXty8pvRY830hvo9eBIxJmv+pAxirbiTc3v/29WnFIvfco2J7+x99Dv j8UVGafABWVUZ+Yyny2My8XXRDu2wop8AA2qD5V70ckvCgUEsCV5hjLIcpJGVTOveTRc W7vZ3FTeWi/9hYD8zfYDQCrLMUCXGcDnDhY+qsgjwe9JKVIjuJx+x3qFKqO8rjH3y4Dd mwssDfIIylfzZxSgbirzqUJj5+drFVqVaDPmcwEwjPxIekLPrLzJbJS8IruB+Y5xMhAf IfpfgsZ3nbFolRKCoa7aF2qXd3xg776V5tglNijKZnCFpsEPN537VRgHk3hPwwiGcjOI S/sg== 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 d15-20020a634f0f000000b005139874b88bsi1476032pgb.87.2023.04.06.07.54.07; Thu, 06 Apr 2023 07:54:20 -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 S239441AbjDFOqN (ORCPT + 99 others); Thu, 6 Apr 2023 10:46:13 -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-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 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 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, -- 2.34.1