From patchwork Fri Oct 21 10:16:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13014562 X-Patchwork-Delegate: kuba@kernel.org 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 2B8B9C433FE for ; Fri, 21 Oct 2022 10:18:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230523AbiJUKS6 (ORCPT ); Fri, 21 Oct 2022 06:18:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231167AbiJUKSo (ORCPT ); Fri, 21 Oct 2022 06:18:44 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FD9625D66C; Fri, 21 Oct 2022 03:18:39 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id bg9-20020a05600c3c8900b003bf249616b0so1652069wmb.3; Fri, 21 Oct 2022 03:18:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YFGZLS7Na8k6WOdiyoxTx78eZiB1yoNR/NfyuPKeoNw=; b=GS939ykh70x0f5EIYYk8lEd0n2d+AIeP1VZA7Q9oYrrZZgrUD80hg9NIBmIK93rWdi ImzxlIo8iclXkpLE1n1OedcpvoD8J+dDRi1TuU9nnHx8S9ax3mFC+4FgSRLyhysAB4vy KUT+Ek7xVn5Q1FnFHsbK+fZcdQk9KaDeIMzkmNJWyNP8mq0FrydPw0VDjPbV85eU+9yQ YH8YLy2FWc4dxc0IwW4qfdEZXVTaH6KlL80XXpPcWCtY43WBGKGe8vmEqG6fXOb+G5bc Q8mGo6isIGqTow1+ozHyoXZzMcE6kp6hnYN+Q6jq1H7OlhwuJQBJKZYdy5ilSkaecwyK QWxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=YFGZLS7Na8k6WOdiyoxTx78eZiB1yoNR/NfyuPKeoNw=; b=LZZVS+KSWPb+7abj/4YlGze8w3ADFXi0f3M03y73JvYIfaCpl38lAfwMvDzW8kYfN1 nJeAtLqV1ozlBHoWxu2I3qVMM1o2xEmVt3RP5x4sO49VHnIq4pU4/nrX1eo2jPNwL6+f nWdauudDn8xl/SAs99U4dk88jnbLnkcFlbrDc/90dty+54xZ8gp9UZvdtwFVUoeCo/vP IOjIJ25mvw9N4ogkJj90WoVOKlZzK2EDb+ClFzD3jXqLl7ntcCFFxmSybvZvodubSi1L GQfYvWmWu/IwNKVq+TIaaMIwyfChR/CUcwBCW9fjaZDQzxVFNYX1brYAf3f6hdmP5ucW JmJQ== X-Gm-Message-State: ACrzQf1fmPlRtLmIdEp3PYEmpdCPNTACdfugC2iWbiAYPOvBJvAzKvUT NgS5fpuq51RyFDAiS4V4dHA= X-Google-Smtp-Source: AMsMyM7SNgaJuRQkrZB19yur58rRdWLcLGXVr2ZmAOerojd99u8bQkOJP90LCLoH98abzYJvSHp5UQ== X-Received: by 2002:a1c:27c6:0:b0:3c2:e6df:c79b with SMTP id n189-20020a1c27c6000000b003c2e6dfc79bmr32179622wmn.14.1666347517669; Fri, 21 Oct 2022 03:18:37 -0700 (PDT) Received: from 127.0.0.1localhost.com ([2620:10d:c092:600::2:f27e]) by smtp.gmail.com with ESMTPSA id ba3-20020a0560001c0300b002365254ea42sm1565184wrb.1.2022.10.21.03.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 03:18:36 -0700 (PDT) From: Pavel Begunkov To: Jens Axboe , Jakub Kicinski , Paolo Abeni , "David S . Miller" Cc: io-uring@vger.kernel.org, asml.silence@gmail.com, netdev@vger.kernel.org, Stefan Metzmacher Subject: [PATCH for-6.1 1/3] net: flag sockets supporting msghdr originated zerocopy Date: Fri, 21 Oct 2022 11:16:39 +0100 Message-Id: <3dafafab822b1c66308bb58a0ac738b1e3f53f74.1666346426.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org We need an efficient way in io_uring to check whether a socket supports zerocopy with msghdr provided ubuf_info. Add a new flag into the struct socket flags fields. Cc: # 6.0 Signed-off-by: Pavel Begunkov Acked-by: Jakub Kicinski --- include/linux/net.h | 1 + net/ipv4/tcp.c | 1 + net/ipv4/udp.c | 1 + 3 files changed, 3 insertions(+) diff --git a/include/linux/net.h b/include/linux/net.h index 711c3593c3b8..18d942bbdf6e 100644 --- a/include/linux/net.h +++ b/include/linux/net.h @@ -41,6 +41,7 @@ struct net; #define SOCK_NOSPACE 2 #define SOCK_PASSCRED 3 #define SOCK_PASSSEC 4 +#define SOCK_SUPPORT_ZC 5 #ifndef ARCH_HAS_SOCKET_TYPES /** diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 0c51abeee172..aeb7b9eaddc7 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -457,6 +457,7 @@ void tcp_init_sock(struct sock *sk) WRITE_ONCE(sk->sk_sndbuf, READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_wmem[1])); WRITE_ONCE(sk->sk_rcvbuf, READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_rmem[1])); + set_bit(SOCK_SUPPORT_ZC, &sk->sk_socket->flags); sk_sockets_allocated_inc(sk); } EXPORT_SYMBOL(tcp_init_sock); diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index d63118ce5900..03616fc5162c 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -1620,6 +1620,7 @@ int udp_init_sock(struct sock *sk) { skb_queue_head_init(&udp_sk(sk)->reader_queue); sk->sk_destruct = udp_destruct_sock; + set_bit(SOCK_SUPPORT_ZC, &sk->sk_socket->flags); return 0; } EXPORT_SYMBOL_GPL(udp_init_sock); From patchwork Fri Oct 21 10:16:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13014563 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 818D8C4321E for ; Fri, 21 Oct 2022 10:19:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230512AbiJUKT2 (ORCPT ); Fri, 21 Oct 2022 06:19:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230123AbiJUKSt (ORCPT ); Fri, 21 Oct 2022 06:18:49 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 345662413E4; Fri, 21 Oct 2022 03:18:41 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id c3-20020a1c3503000000b003bd21e3dd7aso4675232wma.1; Fri, 21 Oct 2022 03:18:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=M2LfrtTV1vRKc7J7VJ5UwaKJfx82Qm1fvaWqDX51XpU=; b=VfwUVkR/Cnq8Ix+NAH+WJ3Qp07261Kqnye9ofG37njZ3mhGP5i90wRwkrSZmUFvBrq 7qpalCNbeA7zRDAplaFY7Uxk6fVXxLdqE838IIv9PeauMVvOuocl1z+bO6A4Kwgr9fr1 r7sHxE+koFFFC/cvTMVJgk0hnvLYPB2AXSoWG2XE5bKQqe+EgQkpsp9o3krdmG/tL3uX NosuNfUkQTiFiA4Vi5P81SL7AV+sCtJZesU3vgQIeqlbqxR4igh8IpQ5qZRZR69o5PwS TzKWHOldo62wJnLKMbUbR6b86clvzh6l43WpmIU41M+TVOtU2ucC0UnGCii0OOR5eYWq sKZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=M2LfrtTV1vRKc7J7VJ5UwaKJfx82Qm1fvaWqDX51XpU=; b=C1iWTekz/BX9e4Nh6dCSQLAYi3USvR+Wu21z6rK3bndE8+diLABsMkDCXEAfLO7EFU hI3seHWVpaLnm6vprHbyUWR1qxhJ4jc2rhdmPfb266Xm8MvkK0Zl+GqL8AxpsvRrJD15 F3HZdaen0XdWAJScqYH4fr4kdKdpasW9uh/jrD3/FGfb11RK+DGdvQJ+xVJ0lwtITB9s RvthUGUvmq6PfLITpofrxWy7Qc2ne+Frzhfx66lwF0Wh1O8B93qPVjTPu/JQdL8Qs6LF h6A3w5QRsIxuN/XmAOjKGBIvpVc728ZlVol3DjFvcgkHzOZclvqMC5Uz4Zeo+v5YG1r2 sjsA== X-Gm-Message-State: ACrzQf1Dub7vBXqD86sxWhPN1rohj5VJbXFFaRgCuiYwHnS2UTOneDh7 Id9utNXNn4pzqXnEobFU7K5S3npY4vk= X-Google-Smtp-Source: AMsMyM7RYUkfL2yfkxUORjlpQxQfc8xn2EZhWU3TJsiP/2OGqD1DJyATIfGrO9bJZiQyANyRhrVO0Q== X-Received: by 2002:a05:600c:ad7:b0:3c6:facf:1f5f with SMTP id c23-20020a05600c0ad700b003c6facf1f5fmr15552036wmr.171.1666347518942; Fri, 21 Oct 2022 03:18:38 -0700 (PDT) Received: from 127.0.0.1localhost.com ([2620:10d:c092:600::2:f27e]) by smtp.gmail.com with ESMTPSA id ba3-20020a0560001c0300b002365254ea42sm1565184wrb.1.2022.10.21.03.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 03:18:38 -0700 (PDT) From: Pavel Begunkov To: Jens Axboe , Jakub Kicinski , Paolo Abeni , "David S . Miller" Cc: io-uring@vger.kernel.org, asml.silence@gmail.com, netdev@vger.kernel.org, Stefan Metzmacher Subject: [PATCH for-6.1 2/3] io_uring/net: fail zc send when unsupported by socket Date: Fri, 21 Oct 2022 11:16:40 +0100 Message-Id: <2db3c7f16bb6efab4b04569cd16e6242b40c5cb3.1666346426.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org If a protocol doesn't support zerocopy it will silently fall back to copying. This type of behaviour has always been a source of troubles so it's better to fail such requests instead. Cc: # 6.0 Signed-off-by: Pavel Begunkov --- io_uring/net.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/io_uring/net.c b/io_uring/net.c index 8c7226b5bf41..26ff3675214d 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -1056,6 +1056,8 @@ int io_send_zc(struct io_kiocb *req, unsigned int issue_flags) sock = sock_from_file(req->file); if (unlikely(!sock)) return -ENOTSOCK; + if (!test_bit(SOCK_SUPPORT_ZC, &sock->flags)) + return -EOPNOTSUPP; msg.msg_name = NULL; msg.msg_control = NULL; From patchwork Fri Oct 21 10:16:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13014564 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 91F67C433FE for ; Fri, 21 Oct 2022 10:19:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230513AbiJUKTa (ORCPT ); Fri, 21 Oct 2022 06:19:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231184AbiJUKSs (ORCPT ); Fri, 21 Oct 2022 06:18:48 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9DB725DAF3; Fri, 21 Oct 2022 03:18:42 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id iv17so1856596wmb.4; Fri, 21 Oct 2022 03:18:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=M/A4q3HXrE5Zm8Jfq7QBtdlkzWJNy1pjXWdj/kLDVls=; b=cj9sSxFCdimjWtRyw8D7kG8AtHwWzcLT8BPA2YG8stWB07xQNMhvGRel/9RWcCEdFh eTG/Pr8blMWgpBHWHEZU6hbtUk3GlIsr1rt/20NOu6uCorb+/IUnUfUSYpron6dz4EUv yG3agISXBKHqsa2BpflAscVh6QSFLUuuUs6Yok5wlLPG0nEcEezzzYdhj9XAGWHhkU+Z 4JE/A9x5sbIh0KzAOdS3SOkVwaOQWGN5CPMAxzmttBjX26zXan+5EZYIdFIAmHllSKJq hvVyqyga/a7DnLZfG6R4uVOcnT/q53vRGdNVdHHEHUboMpxT8r9uJNTvjjJ9G8UHONdf dJsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=M/A4q3HXrE5Zm8Jfq7QBtdlkzWJNy1pjXWdj/kLDVls=; b=5/gufWgQR9EfUnHO/urSbxLbiBGFc6Q1eDHwsU0M1NIFlS8UCTJIJVpBAIAc0crZi7 hzqMRFNQM+ORxvSYo4ghBkHTHWj+x+ao9D0/5efjp1ibzmgnzbPqnkb/yabYIVjUOHVT lLS3AH1nxlzpKu86YfUlxSp5ErHlghsb4+oEo8Edq/r0CrXZB3Dq/OcuiFlYZk/tU80R eufX+q1O6oXKYy6Sb3NrTsJHZMqMtFXIAuYcfN/5ZG318D8cof9v6Qwi44N+M8LpMevK sveTXrV4sxiQt/7JWh/ErcHSXMGYP1ZXrm4V32XbEugnghVkc9SOxcHN8mvmZPiXT+7k VQdg== X-Gm-Message-State: ACrzQf2QBjonEihBG+nL/lxPpa/CpqO8tgSldXJO6PgyYrJoXrPXS6M3 t+P2R9hcjxhEW1NKbTtLz1uNFrPLAso= X-Google-Smtp-Source: AMsMyM48tf2dQfO7hQr6iPZ99mqU9YYyg/Mbx68rSS7aHJKyLp80qNh4oX/6gYCXq+MQsP10VVyZ0w== X-Received: by 2002:a7b:c841:0:b0:3c6:ce2f:3438 with SMTP id c1-20020a7bc841000000b003c6ce2f3438mr12551544wml.51.1666347520315; Fri, 21 Oct 2022 03:18:40 -0700 (PDT) Received: from 127.0.0.1localhost.com ([2620:10d:c092:600::2:f27e]) by smtp.gmail.com with ESMTPSA id ba3-20020a0560001c0300b002365254ea42sm1565184wrb.1.2022.10.21.03.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 03:18:39 -0700 (PDT) From: Pavel Begunkov To: Jens Axboe , Jakub Kicinski , Paolo Abeni , "David S . Miller" Cc: io-uring@vger.kernel.org, asml.silence@gmail.com, netdev@vger.kernel.org, Stefan Metzmacher Subject: [PATCH for-6.1 3/3] io_uring/net: fail zc sendmsg when unsupported by socket Date: Fri, 21 Oct 2022 11:16:41 +0100 Message-Id: <0854e7bb4c3d810a48ec8b5853e2f61af36a0467.1666346426.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The previous patch fails zerocopy send requests for protocols that don't support it, do the same for zerocopy sendmsg. Signed-off-by: Pavel Begunkov --- io_uring/net.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/io_uring/net.c b/io_uring/net.c index 26ff3675214d..15dea91625e2 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -1153,6 +1153,8 @@ int io_sendmsg_zc(struct io_kiocb *req, unsigned int issue_flags) sock = sock_from_file(req->file); if (unlikely(!sock)) return -ENOTSOCK; + if (!test_bit(SOCK_SUPPORT_ZC, &sock->flags)) + return -EOPNOTSUPP; if (req_has_async_data(req)) { kmsg = req->async_data;