Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5759185rwd; Wed, 24 May 2023 06:29:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7j954s51fb4hvdOp5kX7dLqzZLitvIVknwcKjgkarYTOYsRquDftXqp4zXeTBV9/pKxDyA X-Received: by 2002:a05:6a20:3c89:b0:10b:6e18:b698 with SMTP id b9-20020a056a203c8900b0010b6e18b698mr12479549pzj.49.1684934991064; Wed, 24 May 2023 06:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684934991; cv=none; d=google.com; s=arc-20160816; b=r5tqKgnBBP29b9dwZlRk7TJs8tRBgYgOXw4KOdYEgtSp2CutPFFuCQWu+1+turC0vH 4QaY0ZWkHpbnsfXcw/xZy1FdYiGctePtZO/CLNoVkKy3WkDVgWTxIrF+b1qn/S4Gx9rB nNp1SGuZsH3ozsZ3VsSrBmoswkEt0ap2PqrRWQSEwbTRgVP8xxx/aKLBw4Is9dkVFQhI bQ/zJUDZC8Q+vWwEiw1eYJH1VLybSLD4+2I0n9vgiDukhdXFOHSbZbwqj37o/xnqlCX1 /5fnogCds6IvtK4OoO6IXc1UHSt3KtfJRiYepDoYn7hBpl61lQg63/YpbBh3Pg1WkmS3 RZaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:content-id:mime-version:subject :cc:to:references:in-reply-to:from:organization:dkim-signature; bh=zd0OFfNiZ9y269Uix6ptp+k9hpY/9UM79H7Ki9EesyY=; b=Ia9kEZy17STXXI564nYVCw4Dd4vZ0G8TLdDBNrnGmLyiPweEyuuhMBa+l+B4jEtFrD m2zUcwbczSfBroI09+8NJ6eZz0LLPSDf3CgYlQr3Bb4AsqsLumce7oiZpFos/kP5c7n5 MXxHokQ4BZdiKB22eOqwLcCj2ezkxPO1P3XF+LrOH/5wJG/mmRbAYnLbpQWCIqAr0uwt 6BYOF5L7ctTD0XkXcvG8i+m2TN119MU8M+lwq095qr9B0KL7qyApnVKiz9t16s5hArzJ fti3ZfylR70i2bXenmnYcpgtQLIp1Gz0rkN3UM6GxutoHd0V/66SmI5BVFjLKJ4DkosF w4Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QFwLrmNO; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h17-20020a17090acf1100b00250c48910bdsi1344044pju.70.2023.05.24.06.29.38; Wed, 24 May 2023 06:29:51 -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=@redhat.com header.s=mimecast20190719 header.b=QFwLrmNO; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232009AbjEXNXI (ORCPT + 99 others); Wed, 24 May 2023 09:23:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230420AbjEXNWk (ORCPT ); Wed, 24 May 2023 09:22:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89B4C12E for ; Wed, 24 May 2023 06:21:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684934508; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zd0OFfNiZ9y269Uix6ptp+k9hpY/9UM79H7Ki9EesyY=; b=QFwLrmNOdqTbPjUxjlfwgHgUI6gcnJHhgJuOzSDMTk3RcRUuk61iy2zwZNDMt6dO+sRXsu yfjLKdyowg2e5eJfXgI7qb2a870eDPyigCebl/ISJRJJg+ISENWxulgGWOdcKLIPwK/dkg ooNk9JUFdrGX9vaQ0kOZLReuHpaHYkY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-221-p0cb3Y9GNjKJiZIUxGFWzw-1; Wed, 24 May 2023 09:21:40 -0400 X-MC-Unique: p0cb3Y9GNjKJiZIUxGFWzw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6B37085A5AA; Wed, 24 May 2023 13:21:38 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9ED140C6EC4; Wed, 24 May 2023 13:21:34 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <82041a42-e7b0-bde3-0f70-8ad180565794@huawei.com> References: <82041a42-e7b0-bde3-0f70-8ad180565794@huawei.com> <20230522121125.2595254-1-dhowells@redhat.com> <20230522121125.2595254-4-dhowells@redhat.com> To: Yunsheng Lin Cc: dhowells@redhat.com, netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Al Viro , Christoph Hellwig , Jens Axboe , Jeff Layton , Christian Brauner , Chuck Lever III , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH net-next v10 03/16] net: Add a function to splice pages into an skbuff for MSG_SPLICE_PAGES MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3587227.1684934494.1@warthog.procyon.org.uk> Date: Wed, 24 May 2023 14:21:34 +0100 Message-ID: <3587228.1684934494@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Yunsheng Lin wrote: > > + * Returns the amount of data spliced/copied or -EMSGSIZE if there's > > I am not seeing any copying done directly in the skb_splice_from_iter(), > maybe iov_iter_extract_pages() has done copying for it? Ah, I took the code for that out and deferred it. The comment needs amending. > > + ret = skb_append_pagefrags(skb, page, off, part, > > + frag_limit); > > + if (ret < 0) { > > + iov_iter_revert(iter, len); > > I am not sure I understand the error handling here, doesn't 'len' > indicate the remaining size of the data to be appended to skb, Yes. > maybe we should revert the size of data that is already appended to skb > here? Does 'spliced' need to be adjusted accordingly? Neither. > I am not very familiar with the 'struct iov_iter' yet An iov_iter struct is a cursor over a buffer. It advances as we draw data or space from that buffer. Sometimes we overdraw and have to back up a bit - hence the revert function. It could possibly be renamed to something more appropriate as (if/when ITER_PIPE is removed) it doesn't actually change the buffer. So looking at skb_splice_from_iter(): iov_iter_extract_pages() is used to get a list of pages from the buffer that we think we're going to be able to handle. If the buffer is of type IOVEC or UBUF those pages would have pins inserted into them also; otherwise no pin or ref will be taken on them. MSG_SPLICE_PAGES should not be used with IOVEC or UBUF types for the moment as the network layer does not yet handle pins. iov_iter_extract_pages() will advance the iterator past the page fragments it has returned. If skb_append_pagefrags() indicates that it could not attach the page, this isn't necessarily fatal - it could return -EMSGSIZE to indicate there was no space, in which case we return to the caller to create a new skbuff. If a non-fatal error occurs, we may already have committed some parts of the buffer to the skbuff and rewinding into that part of the buffer would cause a repeat of the data which would be bad. What the iov_iter_revert() is doing is rewinding iterator back past the part of the extracted pages that we didn't get to use so that we will pick up where we left off next time we're called. It does *not* and must not revert the data we've already transferred. Arguably, I should revert when I return -EIO because sendpage_ok() returned false, but that's a fatal error. David