Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp25669imw; Tue, 12 Jul 2022 13:56:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uu8ZKvQmxQVgGdFlxnwplZcdvI+IbmagNW+2X2GSJu4T+xVrb+/O6gndwRkZ7s8M7/vyyB X-Received: by 2002:a17:90a:f0c8:b0:1f0:671b:f594 with SMTP id fa8-20020a17090af0c800b001f0671bf594mr4810926pjb.238.1657659383986; Tue, 12 Jul 2022 13:56:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657659383; cv=none; d=google.com; s=arc-20160816; b=pvWeUgcdzSO6Oc5I+Vxbx80EBRUsbm4hPDZwnI4HD+qWg8riQ3rySqbIDtDK9cP2lg Kb2mo+tmwO26k2bXCnk3TK0RpFoh5CMm8wUr01QYMe1JYlELw3AFRTGzLocVKaY1Ucc2 If39jiAUWZRCQuxrVdNloZjfJ5OIWWywWaKNXJ9YwXyVtGrnyjdvJjnPSAmUhh+4JeJI 7EqkG94nHT0PG8HF1TQJoLUBNFkpAa0h7T/DXHKMQlO38oqBE3aLYkeC+gDv/1jyIR5u JeWAHoRzcSk6fZPZqWy+VL2MpPKX2YZbDf54LqFlAs7p3LTd31foBg5RcGiaEOhQ2G9Z krxg== 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=93tCkgQSnWP7j8MKkQNUUkCctSIIcngjSEkqdPJ6fOw=; b=LJSP4Or2fPytv1myb1Ppo6YDAo9xZs5goFDApJl9kyftiMIiWxmvk6KKSZNwAQJWJE 8r6OOR8a/Plyxv3Q/rjR4JIWEG08scHdH0IDhv7sO022iS/54pJkQk7EdZCHxLq6+AS3 Iqnw5SKqfR4Df765aCpSsoU0U5mP+FVVEjWBQe5Y1YYIgwf6LYrJbc0fVcOla7S15lV+ 6A1dF7AmAgipf8Cl4/o9jKsGfGnbMiGDT97kGg3vdqex6t9dFBsavlvmJLOy8S9/JF8+ M1JY/+MhAPONhhvxQzAbNkcZpUFRsfHcLFKmdeGstYzlNxJcispdD1c9yn82QXkl4mRe l8xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fc571E8S; 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 y17-20020aa78f31000000b0052acf3f4090si8604449pfr.55.2022.07.12.13.56.09; Tue, 12 Jul 2022 13:56:23 -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=fc571E8S; 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 S233231AbiGLUx7 (ORCPT + 99 others); Tue, 12 Jul 2022 16:53:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231349AbiGLUxn (ORCPT ); Tue, 12 Jul 2022 16:53:43 -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 7C937D0380; Tue, 12 Jul 2022 13:53:20 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id c131-20020a1c3589000000b003a2cc290135so93713wma.2; Tue, 12 Jul 2022 13:53:20 -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=93tCkgQSnWP7j8MKkQNUUkCctSIIcngjSEkqdPJ6fOw=; b=fc571E8SVwODapQL0U19Opr1UFzf0q5QnKd1RASOgTqD1+rq7tyYrd2eHiC2uwlrv2 EovC5vq+D1z7pKbUvECinQEEkM7S/iWcjjF0EAQ6UZWiqBQSJuqKr7w8pEIJuOU0Rt4I 3bgNyzwq9YAWUNvU8FZWQwILB/QCx1RZHjLCla1ibLyUZT3hICnZlq2txEtzfoFnN1Dd N5XdC4dMGlMR5kYfJzbrDkrflgM2w5kj/4pFoD38YxbfgYaDqUx5tnFDJu+fcPL2jyXg 6tvdPx9kKv9fVmV2b2rMsR0IpV7spxDBuGCGiPtNVEEJsp654oiUwaRw8j6GggKgZQAE MdOw== 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=93tCkgQSnWP7j8MKkQNUUkCctSIIcngjSEkqdPJ6fOw=; b=W1NU2Ub4bEBIstTVKb88F5BKtILt8dssulu7GK3mv7pchDaYwsEU4mIm0Bbgv+NupA BjBHyYJ1P7NEV4ro9opnU6N237YNhLTycg+TRUPBosZSM72iCPZi/Eh+DbbRbbEnzRW+ 253cz1db6gX3of1XHK4RFSqgTD2nWNvJEGjg9MzqTeIU+RxnguoTO6+Q7MKlz53WLEu8 OUVPCj6h2YqlvB0vfluyNpIYCl8xX14SxTdHoVpHzYbZumyAv1EcsAbjs6BSzBRyWiFk ncTgu+rtJnN032njG321ZS98qI5W0fu9x33fKxcTOqmLy+InFZzY7Y+VsoEUo8wKK837 7oGQ== X-Gm-Message-State: AJIora9+vmGVYvXkaoFjUmgEIv1A5JWhpHN4m+x5K7yMfA8dT5KLpVwh nUrxs8jfNU7zPm6g5ebhoI/hwfOcILg= X-Received: by 2002:a7b:cd82:0:b0:3a1:7528:2d79 with SMTP id y2-20020a7bcd82000000b003a175282d79mr6043091wmj.79.1657659198241; Tue, 12 Jul 2022 13:53:18 -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 c14-20020a7bc00e000000b003a044fe7fe7sm89833wmb.9.2022.07.12.13.53.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 13:53:17 -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 , David Ahern , kernel-team@fb.com, Pavel Begunkov Subject: [PATCH net-next v5 09/27] ipv4/udp: support externally provided ubufs Date: Tue, 12 Jul 2022 21:52:33 +0100 Message-Id: X-Mailer: git-send-email 2.37.0 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 how to use external ubuf_info provided in msghdr and also prepare it for managed frags by sprinkling skb_zcopy_downgrade_managed() when it could mix managed and not managed frags. Signed-off-by: Pavel Begunkov --- net/ipv4/ip_output.c | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 581d1e233260..df7f9dfbe8be 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; -- 2.37.0