Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4257592iog; Tue, 28 Jun 2022 12:16:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uoUIKcUaFRubSfawgVM5p5rWBCjDNLjmuD2m0JdApY1QlAWF+j42jG3hoYlYNNdrFAeRb5 X-Received: by 2002:a17:90b:314a:b0:1ed:3b95:9688 with SMTP id ip10-20020a17090b314a00b001ed3b959688mr1260079pjb.18.1656443803705; Tue, 28 Jun 2022 12:16:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656443803; cv=none; d=google.com; s=arc-20160816; b=LYj3MPREInzsbgspDboxTmzYRhFDIJX3dQJDbnmKc9AMYmSZGa0EMV7gwHlB7qDlvD 8c7k3HUqhKxxpEnyyh8AMYpI38aPSQbEdHXtffghnL9nIzfORGsyKUgN/E8I8yfhqBU5 gIb/eFPCZp9uWAMXmyx7QFxDpu4EV52o4tMgZexhC8j/ueUQDBvT/lJFGLKjy1FHnbah AT2aapY9+1U6For7p3YRawWBUe0IK8t/Z8yGVbOFw+C3IlHSo+hDUdYbmbTsX9Z5KwGt XXQ0ENoVLhbMA8cGnFKN2peTTg8QeYeQczvqy/gEVTJ+TE1oKDlqYWRCjFKUxrJCPnDT r56A== 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 :dkim-signature; bh=+E9HBSea0QLQi12+8hra9Imm7sGSrMpugcSoqydPq9A=; b=ge9hWSYY+S5PGq4oFuLDhLYawKHUhuHKrlItkxJ/sz6+/pTBXp3dMEDl0oV/y6KosG ht2fuy9PjT/YOOwjUsrFENDhwMCpxC8TAN9HN/aN+2w07NcQIwx/T0Ib+rRLhA/y6qbd oBauzawki0JeTH4qcnXgxtMZbMnVt1OltHDDRdoAr+WbWuifcN92USz9Cw1WRC+30hQJ UML0s/OUEf7J4Vz3HjcmBZ+PVsODGnvL4R3gks/KKLA5eMDS+/XYK9xZnuH4W+BPeMK6 BH8qy+t0eTfoJG4I0VgZKqVDD7M6FxCyLqieshCe3W32vIOK/n0ktgubuDbipORQR0t9 c8kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dTWqNK98; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l19-20020a056a00141300b0051bc3a3670bsi512862pfu.245.2022.06.28.12.16.30; Tue, 28 Jun 2022 12:16:43 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dTWqNK98; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234958AbiF1TBH (ORCPT + 99 others); Tue, 28 Jun 2022 15:01:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234261AbiF1TAY (ORCPT ); Tue, 28 Jun 2022 15:00:24 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26341140AA; Tue, 28 Jun 2022 12:00:04 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id fd6so18898459edb.5; Tue, 28 Jun 2022 12:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+E9HBSea0QLQi12+8hra9Imm7sGSrMpugcSoqydPq9A=; b=dTWqNK98Gn4MmP59Z3IyWusFihnYIWy5+kLzy6LU7kO5oG8DE2jCQGGrI79EF8oQla 5YDvsN7S0ilHpH5A636wABoV2x8mhtF4JcksaLm6bOMuOT7HDgVUyOaaKrkKlROzvfkG TsYlcgvrWbiFnl9gkdN3sUgFEaxr4IjrbDxCAU8FQ1+ukETiyPMK7n9Kiw4/657JIMIO D0nCY9l2t8vWDj04S23NUNbQKqx6aHiSOuGlSo1P05U1l/qewYgO/rVWnuPkEDPV1D04 MGOE7t3OpvcyS2Qiul9PqzLf1GPcy9W32EBZxCmmZ5bN+2P9jmqIKdak4NCCGE0UD94X VlGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+E9HBSea0QLQi12+8hra9Imm7sGSrMpugcSoqydPq9A=; b=P+bZZ6j04uFxj6q5kpyadzp2ozcXQFWHfzt8/c0qGm9NxNfmwTrImrslVJb/nBtFT4 n49GY/SYG3/B9nMXZD/L/vap4kDu5JWgsZ33lhuKPTMzqZZs+sNSgyoIt1inFNWBH4q3 dJXpG4slB7xQ6xPlkuLvVPmgJs3d2kKqJrVDYHQaInndq0IlBxENmxcckknoKANEY6sm DxOhNJ8lwL3i/6OeWFBg9PbzmepOdrnln5YxHmJ2tOvLE3j30TmXC2erM6Vx/E61VGKq cxTR7G7c5yaekOTsLHG+LOGLhvaWdkRHqR89tROtNyLAIYRuJtrTdHeOl1ogAetZQE/R sOPA== X-Gm-Message-State: AJIora8bBV2fJvNAhu9Ikx/qhhPSgDn0Bqa6CE9eqECCYjdU41uNJ7Ck 0B8EeX0pajLPHzn1xM1IhdJkaNvTmEtDWQ== X-Received: by 2002:aa7:c486:0:b0:435:5d50:ab39 with SMTP id m6-20020aa7c486000000b004355d50ab39mr25462247edq.104.1656442803398; Tue, 28 Jun 2022 12:00:03 -0700 (PDT) Received: from 127.0.0.1localhost (188.28.125.106.threembb.co.uk. [188.28.125.106]) by smtp.gmail.com with ESMTPSA id t21-20020a05640203d500b0043573c59ea0sm9758451edw.90.2022.06.28.12.00.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 12:00:02 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "David S . Miller" , Jakub Kicinski , Jonathan Lemon , Willem de Bruijn , Jens Axboe , kernel-team@fb.com, Pavel Begunkov Subject: [RFC net-next v3 09/29] ipv4/udp: support zc with managed data Date: Tue, 28 Jun 2022 19:56:31 +0100 Message-Id: <1904009c2af0197b922e413254ef2ff2c527f743.1653992701.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Teach ipv4/udp about managed data. Make it recognise and use msg->msg_ubuf, and also set/propagate SKBFL_MANAGED_FRAG_REFS down to skb_zerocopy_iter_dgram(). Signed-off-by: Pavel Begunkov --- net/ipv4/ip_output.c | 57 +++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 581d1e233260..3fd1bf675598 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -1017,18 +1017,35 @@ static int __ip_append_data(struct sock *sk, (!exthdrlen || (rt->dst.dev->features & NETIF_F_HW_ESP_TX_CSUM))) csummode = CHECKSUM_PARTIAL; - if (flags & MSG_ZEROCOPY && length && sock_flag(sk, SOCK_ZEROCOPY)) { - uarg = msg_zerocopy_realloc(sk, length, skb_zcopy(skb)); - if (!uarg) - return -ENOBUFS; - extra_uref = !skb_zcopy(skb); /* only ref on new uarg */ - if (rt->dst.dev->features & NETIF_F_SG && - csummode == CHECKSUM_PARTIAL) { - paged = true; - zc = true; - } else { - uarg->zerocopy = 0; - skb_zcopy_set(skb, uarg, &extra_uref); + if ((flags & MSG_ZEROCOPY) && length) { + struct msghdr *msg = from; + + if (getfrag == ip_generic_getfrag && msg->msg_ubuf) { + if (skb_zcopy(skb) && msg->msg_ubuf != skb_zcopy(skb)) + return -EINVAL; + + /* Leave uarg NULL if can't zerocopy, callers should + * be able to handle it. + */ + if ((rt->dst.dev->features & NETIF_F_SG) && + csummode == CHECKSUM_PARTIAL) { + paged = true; + zc = true; + uarg = msg->msg_ubuf; + } + } else if (sock_flag(sk, SOCK_ZEROCOPY)) { + uarg = msg_zerocopy_realloc(sk, length, skb_zcopy(skb)); + if (!uarg) + return -ENOBUFS; + extra_uref = !skb_zcopy(skb); /* only ref on new uarg */ + if (rt->dst.dev->features & NETIF_F_SG && + csummode == CHECKSUM_PARTIAL) { + paged = true; + zc = true; + } else { + uarg->zerocopy = 0; + skb_zcopy_set(skb, uarg, &extra_uref); + } } } @@ -1192,13 +1209,14 @@ static int __ip_append_data(struct sock *sk, err = -EFAULT; goto error; } - } else if (!uarg || !uarg->zerocopy) { + } else if (!zc) { int i = skb_shinfo(skb)->nr_frags; err = -ENOMEM; if (!sk_page_frag_refill(sk, pfrag)) goto error; + skb_zcopy_downgrade_managed(skb); if (!skb_can_coalesce(skb, i, pfrag->page, pfrag->offset)) { err = -EMSGSIZE; @@ -1223,7 +1241,18 @@ static int __ip_append_data(struct sock *sk, skb->truesize += copy; wmem_alloc_delta += copy; } else { - err = skb_zerocopy_iter_dgram(skb, from, copy); + struct msghdr *msg = from; + + if (!skb_shinfo(skb)->nr_frags) { + if (msg->msg_managed_data) + skb_shinfo(skb)->flags |= SKBFL_MANAGED_FRAG_REFS; + } else { + /* appending, don't mix managed and unmanaged */ + if (!msg->msg_managed_data) + skb_zcopy_downgrade_managed(skb); + } + + err = skb_zerocopy_iter_dgram(skb, msg, copy); if (err < 0) goto error; } -- 2.36.1