From patchwork Mon May 22 13:49:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13250590 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 DAF96C77B73 for ; Mon, 22 May 2023 13:51:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 764FC280008; Mon, 22 May 2023 09:51:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 714E6280002; Mon, 22 May 2023 09:51:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B609280008; Mon, 22 May 2023 09:51:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4E5DB280002 for ; Mon, 22 May 2023 09:51:12 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E4D3E402E4 for ; Mon, 22 May 2023 13:51:11 +0000 (UTC) X-FDA: 80818027542.13.96BB5D3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 02929140017 for ; Mon, 22 May 2023 13:51:09 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZmwXM83o; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf09.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=1684763470; 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=qKMmGOYRCa7hSrkLF/RgczhPclegMdhS5TKhbjFywHM=; b=jANZ6/giH/H3N7ho/pR+zvX415u0cGrUPzdqUzk0jkgj5GXLxmvA7OV+/NRRGVL8A3IXKT YQWuh0GD1bsJNwXYfihhEogB237vIbRScb86PRRxXsL+5053QP2uTZPHPrqXWbWoPiWhx7 BhR/OF0dJeFhVCmhJ/q/2zv9TttDzgI= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZmwXM83o; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf09.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=1684763470; a=rsa-sha256; cv=none; b=DwNogf2iSMEwWbkcsPp+DNFwN8nHHYkj534HcB+mQ1wY7VUir0Sy7aaSEe4878N4P1wTgm 1TQECSAgUAgnwEYWSF5jbPhvAwFIGWAgUYo7SLMBb8CNeIbUz3d9untk1Nf2eAoHF2I84v vLjCErE8fnhF9rMwiJitG4UjtY70Cxo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684763469; 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=qKMmGOYRCa7hSrkLF/RgczhPclegMdhS5TKhbjFywHM=; b=ZmwXM83o18fbv+Cl8bq9P44ri/bGoLoK1L8LwrilgB3tEbwgIwhtcUiAThIQBHodow+AN4 Uj6885YCYIFVJysQcR2pQWIwDXdRurbKc8pv+sfqQfOOUxeQJzY+PzB189xGrfKKuqdown kfMBeULMxyS28jQijryP/OmDU2jRCME= 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-526-8G5_LAk8MpyrjZMsu_4Waw-1; Mon, 22 May 2023 09:51:06 -0400 X-MC-Unique: 8G5_LAk8MpyrjZMsu_4Waw-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 036831C0170D; Mon, 22 May 2023 13:51:05 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A30C40C1438; Mon, 22 May 2023 13:51:01 +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 , Amir Goldstein , linux-unionfs@vger.kernel.org Subject: [PATCH v22 10/31] overlayfs: Implement splice-read Date: Mon, 22 May 2023 14:49:57 +0100 Message-Id: <20230522135018.2742245-11-dhowells@redhat.com> In-Reply-To: <20230522135018.2742245-1-dhowells@redhat.com> References: <20230522135018.2742245-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Queue-Id: 02929140017 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: qhc343xhynqf66oszkrcaj97anm4hej5 X-HE-Tag: 1684763469-398281 X-HE-Meta: U2FsdGVkX18mb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WQO6Dur6n7IjT2Kuvqaq4w5LgBPApVZIMKlBhREeShUIhopC8uXCRzcePTAJ0ig258pzwIC75uUz49G/zDOdlhb9Nk+nXGFMA+PM05UcPhfc72t3hdSovan1qLIsjOo39f4Q+oTY8ZYO5r1JfZMAXH8+DiVJ/sgdIa6bNo+yvJOzKZYfrlT/RsFV2f7mN39Z+Am+vF5HyUOpRnwBOmGGFQxRtnOhbDMAC3u99ZOzUSfGyw0trIP3gYllWgFO0Kv/Uq3BnBUzY+b7VcrGuyQ616br8SiYXAWC6WLr5UlH+R6cNlUPDcx9rHYBvqFVOvmshbeavWH/l4OIzYNFxzWmonkxi3gzV9CdlrqYLY= 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 Acked-by: Christian Brauner cc: Christoph Hellwig cc: Jens Axboe cc: Al Viro cc: John Hubbard cc: David Hildenbrand cc: Matthew Wilcox cc: Miklos Szeredi cc: Amir Goldstein 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,