From nobody Mon Sep 15 03:55:52 2025 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 E9916C46467 for ; Mon, 16 Jan 2023 23:15:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235346AbjAPXPf (ORCPT ); Mon, 16 Jan 2023 18:15:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235300AbjAPXOp (ORCPT ); Mon, 16 Jan 2023 18:14:45 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80BDA2FCD9 for ; Mon, 16 Jan 2023 15:10:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673910633; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QRj9zo8/4XGZMXr1F9brjuZIjMqL4+pPYiSkNjAxJaI=; b=BNZJFHS95LNIstxQTbNzgAn/AVuyY0qbXxbIPPMELFD6JXQH1ZuCAy3ueuAyr+E64RuGpm B3lez+r1fmYhuKrXuJv6P8GPLXcQLDQKMR//PerQr+HeSr90sQLKDzZHTkBzjI3Z5i5biA Qsda3TktSnPOARFRxLMMfh2jjmOstnk= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-612-R7KYRgH-NsqGjrjFzNEidA-1; Mon, 16 Jan 2023 18:10:27 -0500 X-MC-Unique: R7KYRgH-NsqGjrjFzNEidA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4611F2A59556; Mon, 16 Jan 2023 23:10:27 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id F21AD51FF; Mon, 16 Jan 2023 23:10:25 +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 Subject: [PATCH v6 20/34] vfs: Make splice use iov_iter_extract_pages() From: David Howells To: Al Viro Cc: Christoph Hellwig , Matthew Wilcox , linux-fsdevel@vger.kernel.org, dhowells@redhat.com, Christoph Hellwig , Matthew Wilcox , Jens Axboe , Jan Kara , Jeff Layton , Logan Gunthorpe , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 16 Jan 2023 23:10:25 +0000 Message-ID: <167391062544.2311931.15195962488932892568.stgit@warthog.procyon.org.uk> In-Reply-To: <167391047703.2311931.8115712773222260073.stgit@warthog.procyon.org.uk> References: <167391047703.2311931.8115712773222260073.stgit@warthog.procyon.org.uk> User-Agent: StGit/1.5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make splice's iter_to_pipe() use iov_iter_extract_pages(). Splice requests will rejected if the request if the cleanup mode is going to be anything other than put_pages() since we're going to be attaching pages from the iterator to a pipe and then returning to the caller, leaving the spliced pages to their fates at some unknown time in the future. Note this will cause some requests to fail that could work before - such as splicing from an XARRAY-type iterator - if there's any way to do it as extraction doesn't take refs or pins on non-user-backed iterators. Signed-off-by: David Howells cc: Al Viro cc: Christoph Hellwig cc: Matthew Wilcox cc: linux-fsdevel@vger.kernel.org --- fs/splice.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 19c5b5adc548..c3433266ba1b 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -1159,14 +1159,18 @@ static int iter_to_pipe(struct iov_iter *from, size_t total =3D 0; int ret =3D 0; =20 + /* For the moment, all pages attached to a pipe must have refs, not pins.= */ + if (WARN_ON(iov_iter_extract_mode(from, FOLL_SOURCE_BUF) !=3D FOLL_GET)) + return -EIO; + while (iov_iter_count(from)) { - struct page *pages[16]; + struct page *pages[16], **ppages =3D pages; ssize_t left; size_t start; int i, n; =20 - left =3D iov_iter_get_pages(from, pages, ~0UL, 16, &start, - FOLL_SOURCE_BUF); + left =3D iov_iter_extract_pages(from, &ppages, ~0UL, 16, + FOLL_SOURCE_BUF, &start); if (left <=3D 0) { ret =3D left; break;