From patchwork Thu Oct 20 01:42:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13012532 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 9664BC4332F for ; Thu, 20 Oct 2022 01:43:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230506AbiJTBnm (ORCPT ); Wed, 19 Oct 2022 21:43:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229917AbiJTBnm (ORCPT ); Wed, 19 Oct 2022 21:43:42 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 982421CFC78 for ; Wed, 19 Oct 2022 18:43:40 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id r14so27795020edc.7 for ; Wed, 19 Oct 2022 18:43: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=Uk4Vo1LH3Y0LsC69wP89X8QzUmIOLtPnDtQx2bziQqw=; b=goc05PYiCXRyN5rUUAexrjU9whf9SOm60BuHlruuCRX72YUDHOZDTKxGmvfesbONqd 9VBJJ2IvaQw5N5Q12oF8MbIP1FXNO/6zg2Qgnb2fT5KGAVWsF598OduJmAiSiI1vAaAE hdXfKdojebxVOMLoGEBXuiX0VyuxDT5YWpmqQsrT9+Nroomn00hbKvbR/Vk4q2GC8G8q oNSu4tdslEzE3Dwf0Qaj8zWzIUtQLHe4ifGZDf33jByXOkNXsOKc55OGxfe7btCwGZx5 cJZrTtPF/riv/RJs640C10PJHwHzaHxEJyPeuFYu51Opot/8rzJJtoR5CVGCrbOsRG64 PFVw== 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=Uk4Vo1LH3Y0LsC69wP89X8QzUmIOLtPnDtQx2bziQqw=; b=q8jYx+PNvyTulDGC3CucJyjj08U9XMVywRmn2hl+h58Hg4ZbDGF1wnnxWzK/a984+n InZyU2U7DmLdcTXqI1+DCLmH1pHjw3OqQ32oCUQBdVBOZTUEO+flJpGzRT1/P3/lFaqv AGPGLS5OYLeZMe86Tkp7V05gj36QaHK+frpiIcahme8K3XpWCDdnQe5lM5MKn3Xag/VQ XRZvZiiqk9FOot60gymJc1QGe4nnZ6YcPd0o2hXMNV3RbSPzotKjKerehLRk6h3+ovZE 6dM070e/+xpoFqJphADv+2h1wF4I6cnd+UvJZ2dpGCTHYK8RjEPA/N8rWzl5XlwSBI1F 9MWQ== X-Gm-Message-State: ACrzQf327RyhzajkJl7hTfxm4ub/3YeeyqvkXFIH4FrEY3ThOKrzI0sI EOW6XogVzx1Y5/arI50tvwBFxsSAR54= X-Google-Smtp-Source: AMsMyM5G9QlAts1Cej4tAcMOOpr6SB4UPirIEIoHeNj5KKTEv94vhFg6fdBUshE8pjYsYkA7uwtXrw== X-Received: by 2002:a05:6402:500d:b0:459:3e56:e6f9 with SMTP id p13-20020a056402500d00b004593e56e6f9mr10312131eda.367.1666230218750; Wed, 19 Oct 2022 18:43:38 -0700 (PDT) Received: from 127.0.0.1localhost (94.197.72.2.threembb.co.uk. [94.197.72.2]) by smtp.gmail.com with ESMTPSA id g16-20020a170906539000b0073d5948855asm9695530ejo.1.2022.10.19.18.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 18:43:38 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Stefan Metzmacher Subject: [PATCH for-6.1 1/2] io_uring/net: fail zc send for unsupported protocols Date: Thu, 20 Oct 2022 02:42:35 +0100 Message-Id: X-Mailer: git-send-email 2.38.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@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. For now explicitly whitelist supported protocols in io_uring, which should be turned later into a socket flag. Cc: # 6.0 Signed-off-by: Pavel Begunkov --- io_uring/net.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/io_uring/net.c b/io_uring/net.c index 8c7226b5bf41..28127f1de1f0 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -120,6 +120,13 @@ static void io_netmsg_recycle(struct io_kiocb *req, unsigned int issue_flags) } } +static inline bool io_sock_support_zc(struct socket *sock) +{ + return likely(sock->sk && sk_fullsock(sock->sk) && + (sock->sk->sk_protocol == IPPROTO_TCP || + sock->sk->sk_protocol == IPPROTO_UDP)); +} + static struct io_async_msghdr *io_msg_alloc_async(struct io_kiocb *req, unsigned int issue_flags) { @@ -1056,6 +1063,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 (!io_sock_support_zc(sock)) + return -EOPNOTSUPP; msg.msg_name = NULL; msg.msg_control = NULL; From patchwork Thu Oct 20 01:42:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13012533 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 01E6FC43217 for ; Thu, 20 Oct 2022 01:43:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229917AbiJTBnn (ORCPT ); Wed, 19 Oct 2022 21:43:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230456AbiJTBnm (ORCPT ); Wed, 19 Oct 2022 21:43:42 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96A0B1D1AA5 for ; Wed, 19 Oct 2022 18:43:41 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id z97so27768035ede.8 for ; Wed, 19 Oct 2022 18:43:41 -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=oahsLGuUWEVpsNcRBCatufFOnEuT47UKOe02aPsu6Vg=; b=pixuOYghgjQBw+OBR7JoIofGVn75LyFAeiXHdP5Sy5XgGFgiKqJWP2s7vkZumZVVdt P9FvWjE2YBkws61e18+J0KiJnvH7nvUFHA58rfRHoCDy/mFbzMBCO4llw27l9CFxQouJ tj4Pcs3ICnd94fuELb5bZs7oFiWvohJqr8MGZb581NzWaBzYVgHsphXkktBvXLah2kgE ndqpoojKlNwEA+cOsHUaO3zAP1lnk1zvQmDmsIbP/YGd0LINAz8Hei1lUmg/6Ov+nhCn n44Pa8HOQQ6PK9Z349lF8gNE/ZQ6+2adpvjEbm9wQ2D/+tsGnGhK1izLqaW97jH21VDB c9zg== 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=oahsLGuUWEVpsNcRBCatufFOnEuT47UKOe02aPsu6Vg=; b=iHUoiu8GrvAXrwPA5o59VlSckJV5feawWcTn21ZXcVO8JpYgo44qEOFP5FK9EHnoKc 0HLJZW1EBw36jcYiK32rj2sPbrD3DoR0k598IUllzURknZqAQbBGgkOAxuDZS/JboRTS /nC7qQ8SV0wmOAMMtf0Mq3iO099bhHpvCaSQm98s5nwFnFBGgwl8ZkKJ4gl9QrqWGV2w rIwe4KawH/VeIoWEpbp3/iLEja9X0VW/VletREqxeBwDlPLgqpNzm6wAksTU5fEGnI9I Bthhuw9Z8lwrNB69NxPtP+jOcY3hbliWhemJraKMDd0AP7NFzJk5gjSYhiQVLkOauW8c ZYsw== X-Gm-Message-State: ACrzQf0wY+wVn06q99bBN3aKtJ8QB90I9EJ01YpViXi1r7XBiHl4X7jx vcjj+Tl1h2I1a4hiBA5LInLEuwybBpc= X-Google-Smtp-Source: AMsMyM67CzsXWbWAQqSl+T9pd21J2uD/IIyZL6a0DREbqiqsVknCPyK0OAjJDyRe2kg1XfWNySPL1Q== X-Received: by 2002:a05:6402:11ce:b0:45c:a364:2c3d with SMTP id j14-20020a05640211ce00b0045ca3642c3dmr10231999edw.204.1666230219909; Wed, 19 Oct 2022 18:43:39 -0700 (PDT) Received: from 127.0.0.1localhost (94.197.72.2.threembb.co.uk. [94.197.72.2]) by smtp.gmail.com with ESMTPSA id g16-20020a170906539000b0073d5948855asm9695530ejo.1.2022.10.19.18.43.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 18:43:39 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Stefan Metzmacher Subject: [PATCH for-6.1 2/2] io_uring/net: fail zc sendmsg for unsupported protocols Date: Thu, 20 Oct 2022 02:42:36 +0100 Message-Id: <0f5e5b81ab680649bf56f025da94497f3f6a3f53.1666229889.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: io-uring@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 28127f1de1f0..735eec545115 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -1160,6 +1160,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 (!io_sock_support_zc(sock)) + return -EOPNOTSUPP; if (req_has_async_data(req)) { kmsg = req->async_data;