From patchwork Tue Mar 14 22:07:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13175047 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 9038EC7618B for ; Tue, 14 Mar 2023 22:08:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24C128E0005; Tue, 14 Mar 2023 18:08:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FE288E0003; Tue, 14 Mar 2023 18:08:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04E648E0005; Tue, 14 Mar 2023 18:08:25 -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 E6CF48E0003 for ; Tue, 14 Mar 2023 18:08:25 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9A28A160E0D for ; Tue, 14 Mar 2023 22:08:25 +0000 (UTC) X-FDA: 80568893370.17.44CE238 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id E451B40014 for ; Tue, 14 Mar 2023 22:08:23 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eG6ejL6M; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.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=1678831703; 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=x6T/VFwqZCZhXGUjG9IKv0jR22f9aMgpSQxHJhZ/aiNJdGwFXl+lPNNicnLmynCJOT22YT 3ZWZHoSwKjvdY+/w1GG4wNfkwI5z7ayfbKzEOhoHDRsGwDY6kG/fhu3zLba5+qNVyySPik j3BpJiX4fG0opUD+4c8fuOVEdtnVEu0= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eG6ejL6M; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.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=1678831703; a=rsa-sha256; cv=none; b=stfdLkm0nkd0nsoqCXI2aJBux1n5fSOJ9MPGnm0b+GTsxDbERYLN4XBQB1SzVVTQRdWctK 43LGqCqHaV7y8ZmZy7nr18e9+6lflmJubdCGe+VE5ZHF16kgnpCaymmgGvp77e30OFna9K uF2gnGqbqQ6amtofjT/q6irkuOrjjsU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831703; 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=eG6ejL6MxEJrZU/a70OVDPXbUjEFK0vJK9NbZmX1dG7gtMEcIhPUDANpZ7FQCLkfWWzkui 6n5IDXXywLzyD58+t18fY5dwNtsH/hKaDIkXiHeV/FqoRT78qC0Dx6ot0OJKlP6ct2J+O2 GyrKFfvnIeC6JoJ6yNmgmwXli5UPNwg= 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-482-OmsvrtS9MnWFP7mBkgbzgQ-1; Tue, 14 Mar 2023 18:08:20 -0400 X-MC-Unique: OmsvrtS9MnWFP7mBkgbzgQ-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 15FA9811E6E; Tue, 14 Mar 2023 22:08:19 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id B11D347507A; Tue, 14 Mar 2023 22:08:16 +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 v18 04/15] overlayfs: Implement splice-read Date: Tue, 14 Mar 2023 22:07:46 +0000 Message-Id: <20230314220757.3827941-5-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: E451B40014 X-Stat-Signature: askwbjo3omxx3ky7hkasncgwrewq8tz7 X-HE-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9SdOUyKy3vbWkbOjR4y8HT+OQTIeeNHqhPAe5/qZ1A0Eh3LqU0rhV+1eSxG2fXh4USTRl+SVO5fj9RbMWa6/EqPqDEN6eivJvQikQRHs/cwhpog5Ei0yY32wagRl1zkSKLvNPDnI0RavvD0aPjSWfUF7brHvCL5YayGlxDVcqZR3DUTLhiurqcVMS13Uf6DOTIWXCUgRhkXT2TVbZqZWhG8v5WPWRQ7QjFT5fEme2iSY1JyeOFC60zEXzUvf79GXhMoRrSeVTlLVxvB0WOqkGxlgX93/geesu542xJCkZUtLu0SYm9Jbc7I5U5Q/48ij3R1DasyHRhFvRH1b6iU/ulgEuPjmOoFZYg8G6/pB/bXXPUwSTFB7vLa428v9/dAUB 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,