From patchwork Wed Mar 15 16:35:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176336 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 322A7C7618B for ; Wed, 15 Mar 2023 16:36:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C78816B007E; Wed, 15 Mar 2023 12:36:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C28DF6B0080; Wed, 15 Mar 2023 12:36:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA2626B0081; Wed, 15 Mar 2023 12:36:14 -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 980716B007E for ; Wed, 15 Mar 2023 12:36:14 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 35B7B160DB5 for ; Wed, 15 Mar 2023 16:36:14 +0000 (UTC) X-FDA: 80571685068.23.CBFF8A8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 7D75D4001C for ; Wed, 15 Mar 2023 16:36:12 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="JogAK2/A"; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1678898172; 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=dYj2cHeTi+L0GFXth78hEo7twXxpDbIFvcsIQSFsR8OYB8AngBToZSOH1FxJqeFg+9YrqE am1afH714pLzaODgT7ojAaD8d/gUa6RZOrzE3rUDNjbY51hs1MSf0mcr8fuSkw1U3pIyXI 4mg9oO89zGh2Rp89YhxOwbF337Yfar4= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="JogAK2/A"; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1678898172; a=rsa-sha256; cv=none; b=maq5ppCHNzJ4suej93y24V/+sONNSD9J/3XyoyztOBhOAEsWNrrGwg+iklaJ9fDcSGjOn0 VQO2k/C6E9IgwwnwTlmSU8qtKv8rZ7REwGXLCVHsYXUVHcJOEzRVQkT65m48bN05d1AxHT x2N09lWRy5iOSBam6tYgWgPnCr8QmYU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898171; 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=JogAK2/AhjBAWlxTzpsgVTypL9q3zjnUGTTOwkHrk9HebcVKeyQJns0RECDhHi/tRZPIcD OMriBO2+k/pHJOMziVCsX8SEb2JoAGZ0gCDyQ/QwFsPiGUyBu7lvEj1j29c6u/HsT+EWt2 +ld6cukSjpMdFTGugLbTtelh8Jjvabc= 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-552-0l7YBVunPwOyKLm554H8jA-1; Wed, 15 Mar 2023 12:36:08 -0400 X-MC-Unique: 0l7YBVunPwOyKLm554H8jA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 38265101A556; Wed, 15 Mar 2023 16:36:05 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id D47622027040; Wed, 15 Mar 2023 16:36:02 +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 v19 04/15] overlayfs: Implement splice-read Date: Wed, 15 Mar 2023 16:35:38 +0000 Message-Id: <20230315163549.295454-5-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 6ny9w8gjnzg6tqmie66wdcqr9ah19q3u X-Rspamd-Queue-Id: 7D75D4001C X-HE-Tag: 1678898172-116418 X-HE-Me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bALq/DaQL0WbseAXSHPH60GmxGL8hjttKpZbW/hvmMWUjXlJUKGr6UxMGH8pKMsSLU6jKOPH9WHb8sSSKvn237eweMWJSGKf9U+5FG+ceoUHW2x+yb05Ig1Fpa1Ki4i5bmxm3ZwFdB9n3SVGLJ/SFJys9DIl4qC/grXlRyMTV++9xJU7WwBxUGoGP1+ojRj6gmIe3C28y/C0Ij0UHwmGi9I5qYiPZYwIjVN8zdZxzTOnMITaPhj+NvCfOvkndH91da0VXGXeEE8Gos3voCrtpzCQdCnIElflMg6sqWTPIiqVXTjYyfPpiW9eMEPMWOA6+n10GpKD8VPujxvvB2e+iXfPB+EQVq1bm5ykPRfhjbP4DuB3xU 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 Reviewed-by: Christian Brauner Reviewed-by: David Hildenbrand --- 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,