From patchwork Sat May 20 00:00:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13248991 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 0D0C3C77B7A for ; Sat, 20 May 2023 00:01:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 97733280008; Fri, 19 May 2023 20:01:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FFC4280001; Fri, 19 May 2023 20:01:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72BC3280008; Fri, 19 May 2023 20:01:32 -0400 (EDT) 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 5E4C7280001 for ; Fri, 19 May 2023 20:01:32 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 315FC40B98 for ; Sat, 20 May 2023 00:01:32 +0000 (UTC) X-FDA: 80808679224.30.B3BC8AA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 728BF40010 for ; Sat, 20 May 2023 00:01:30 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fSpUNEGJ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684540890; 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=xQ2t4u4rThOkZRLMA9uKelfSlhpr/X6lAppYFOWSBHwHtP0anHtcCpwWyNPF+7hYyrzZNq 4L9ez4uRqu026YPN7zn3E5H/D5JsrUSPJP0eolM491NmFe/ap1f0J8F+uMVUHo61GWjOPk ezYg3cSvf1JEJhmzhbwwCT3tFphbw44= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fSpUNEGJ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684540890; a=rsa-sha256; cv=none; b=wYuqSWuSKqDhJnf5Pshuvp61mkpmtmsxqcp/R194AEpaxVb5/yOo1U7svj8X+vin5NUChH 6x0vpNYe2INlGAihj7f6AHs+NcBfQOnf3ySzThYcobDejgik35tsS+Z9ZuQPSB/G3+0Dwf eKlu4ZDFIKUXIfEgphCVBv3KkMrKScg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684540889; 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=fSpUNEGJhNE0zYhngruldELX7seJXyvO8ti+Ui5RZ8y9KbQ7qP6GzYS+LOCKtZUrmZNdx9 ZzzA3ZM9ifVT3Uv5H6n4rt9jBX2fmtP1L6OVZJOY4D3a3TRvbFlETW7yP6wNxkLjLaIfyH 8d9W88toLSn6ajFqdsORNeJb5eAtvD4= 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-492-Pp1IPtIWMIWF9TLbVOsNMg-1; Fri, 19 May 2023 20:01:24 -0400 X-MC-Unique: Pp1IPtIWMIWF9TLbVOsNMg-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 8268C3C01DB4; Sat, 20 May 2023 00:01:23 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 48D497AF5; Sat, 20 May 2023 00:01:21 +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 , Christian Brauner , 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 v21 10/30] overlayfs: Implement splice-read Date: Sat, 20 May 2023 01:00:29 +0100 Message-Id: <20230520000049.2226926-11-dhowells@redhat.com> In-Reply-To: <20230520000049.2226926-1-dhowells@redhat.com> References: <20230520000049.2226926-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspam-User: X-Stat-Signature: qqk8i3x4omm51pb4szjepqnzr9ai6ucr X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 728BF40010 X-HE-Tag: 1684540890-875016 X-HE-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mnrO0APF7BmSNE91Oa0K0ghlzN7r0SsFU08karVLHTPYmbCabm3Siw7K5ZtG1vc277GjK4+Ra7ZcFRxEVQkz3X7kfoIgJdud7FyudD65RkUCfRxHOyhnMlbD6Os+0o/8zmbD00KAqneM1M1V7iY3zTyXu6KfNX43SEaJws7nZQLF4lchZHiFVnIDbHocPD4iNMCsODykOArFSIUW+M8w/NmWZzq8QW8YM/7CtySg7l9JAYaeaGJhXTdRovijOHv8L4BOKTui3ARLg8ISewpamAdOHTODtKB1CR6ebOqMPw9PK4fVjeBgV7haMX/mwjiPki/jz38e5iwIjViuX6Hjrzf55eWY2wUIZrexTnnrhjZw== 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 Acked-by: Christian Brauner --- 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,