From patchwork Wed Mar 8 16:52:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13166161 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08480C64EC4 for ; Wed, 8 Mar 2023 16:53:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C0846B0080; Wed, 8 Mar 2023 11:53:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 922E6280001; Wed, 8 Mar 2023 11:53:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 700656B0082; Wed, 8 Mar 2023 11:53:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 583146B0080 for ; Wed, 8 Mar 2023 11:53:16 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DD3E21C649E for ; Wed, 8 Mar 2023 16:53:15 +0000 (UTC) X-FDA: 80546326350.23.B1A7F43 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 3B82740003 for ; Wed, 8 Mar 2023 16:53:14 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=h9pSBFGD; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678294394; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=74aMisHJvcrsbS5g8R7662ZNEA+1A6hMiypJVvVd5yo=; b=GVIyyxZiFkBmXkQ8RkdZxXQ+zJDKE/fS6dJChDCrCOtBxlIilwKG827/JuWXv9V3cePoTQ fJDS27G+d/iV+XP+9PBhEPs7Mh9nCbIVyuGY4uy47lDqoAeOd6q5Zr+8LJhwl03biXwhnl KJYUs/Yqmgfj8LISv63zWYWSBzpxqOY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=h9pSBFGD; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678294394; a=rsa-sha256; cv=none; b=5eeA2GqxzTHoGmtO4shE2o+7dQ0RAja6mplAJiI3QKGlToBjpu/I9JXyjER9FbO53IvX28 u1wApvReG1A2B21nUHr8nUATnVJ3XcJOoJIlSI7WiSG3jTq1w0Qf9l0NloEHInDuiyAvV1 To2gU8VzEhCvjqkLrMZ2GGTiC2zBSaE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678294393; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=74aMisHJvcrsbS5g8R7662ZNEA+1A6hMiypJVvVd5yo=; b=h9pSBFGDozA5WX9rkJrPn5RCfal8Yoo46W1SmPmJ0dEjql3NuuWJo1mw2OiinfUOyCgavo 8r0W19zFEPz8Gg60adYv0Uoe92jAk0k9nFsP8UvYT0guSXV6HvORAchrL3Sfx4yZAedMGJ vfnwQlNrNlR3ForZ9B54B8YRpJM2fBc= 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-629-CMD8rN7nNP6tp5tN6HG62A-1; Wed, 08 Mar 2023 11:53:11 -0500 X-MC-Unique: CMD8rN7nNP6tp5tN6HG62A-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DFF60100F909; Wed, 8 Mar 2023 16:53:09 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE39D492C3E; Wed, 8 Mar 2023 16:53:07 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard , Miklos Szeredi , linux-unionfs@vger.kernel.org Subject: [PATCH v17 04/14] overlayfs: Implement splice-read Date: Wed, 8 Mar 2023 16:52:41 +0000 Message-Id: <20230308165251.2078898-5-dhowells@redhat.com> In-Reply-To: <20230308165251.2078898-1-dhowells@redhat.com> References: <20230308165251.2078898-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Stat-Signature: borck6sqryitirijkdedtos6np3icfzq X-Rspam-User: X-Rspamd-Queue-Id: 3B82740003 X-Rspamd-Server: rspam06 X-HE-Tag: 1678294394-379457 X-HE-Meta: U2F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w+M/PA8eTdy2FpNyVwxDNbKE4r94KYq8UVJM5EI117WI8t5UJE8PymQO/akdQJ9hKgeS2Ruh4QvWS4Or4pwiSfK4UTwtZlLYfugwEdweiah9M0OoTz9DKV7Z6JPuHPV8Cm9833qMqWxHS8Kp5Tz7C56La0FLwob4JwTqVK39fkiXb8+t/2+M1Ac9pJCc8OzCMfX8fwQbmoHZGldFpgQHaIWypUFi80Vqr3ZgGquybUsYwlZA7CexYQ0mVDY5i0slVJMqMSrrM/Cri7hffIBSw9kYffoWucQtKfxm8keJWK7+25uocpjUDbtxSsbwX/tt/baKwuNvqIDZcLYnGhstE X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Implement splice-read for overlayfs by passing the request down a layer rather than going through generic_file_splice_read() which is going to be changed to assume that ->read_folio() is present on buffered files. Signed-off-by: David Howells cc: Christoph Hellwig cc: Jens Axboe cc: Al Viro cc: John Hubbard cc: David Hildenbrand cc: Matthew Wilcox cc: Miklos Szeredi cc: linux-unionfs@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- Notes: ver #17) - Use vfs_splice_read() helper rather than open-coding checks. ver #15) - Remove redundant FMODE_CAN_ODIRECT check on real file. - Do rw_verify_area() on the real file, not the overlay file. - Fix a file leak. fs/overlayfs/file.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 7c04f033aadd..86197882ff35 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -419,6 +419,27 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) return ret; } +static ssize_t ovl_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, size_t len, + unsigned int flags) +{ + const struct cred *old_cred; + struct fd real; + ssize_t ret; + + ret = ovl_real_fdget(in, &real); + if (ret) + return ret; + + old_cred = ovl_override_creds(file_inode(in)->i_sb); + ret = vfs_splice_read(real.file, ppos, pipe, len, flags); + revert_creds(old_cred); + ovl_file_accessed(in); + + fdput(real); + return ret; +} + /* * Calling iter_file_splice_write() directly from overlay's f_op may deadlock * due to lock order inversion between pipe->mutex in iter_file_splice_write() @@ -695,7 +716,7 @@ const struct file_operations ovl_file_operations = { .fallocate = ovl_fallocate, .fadvise = ovl_fadvise, .flush = ovl_flush, - .splice_read = generic_file_splice_read, + .splice_read = ovl_splice_read, .splice_write = ovl_splice_write, .copy_file_range = ovl_copy_file_range,