Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp164955rwd; Fri, 19 May 2023 17:29:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6sUX5vEONTYpmurLPTj48XipK1sbpOtCujO+HNS6j/3iV779KdM3dZtrK0ieCy3dJcoRh4 X-Received: by 2002:a17:903:496:b0:1ac:3303:daf5 with SMTP id jj22-20020a170903049600b001ac3303daf5mr3783583plb.27.1684542550087; Fri, 19 May 2023 17:29:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684542550; cv=none; d=google.com; s=arc-20160816; b=RdXhXjVbyUUTxC2AOyfPU4WTIrYfx5LQiu+Sqhlsf7slFEo+XFYPSyHWdtDlMgKP6n CpF5Lu7EOUtMXyYKEGiis+MPaka1jj/cW55RU3cKUFX4uguz23KwMOAUdHlCcu5Uj5CT q95fTNuKuPoan30OxySqh22LSMVW49hwhSQzO4kZySq+VqLIjHENW6D5/1eI4qnCUMQ6 joTnUxFrUwcq7zAIX0xNY6TFIjvL4q3HYxdu6vgi9H2fL3oEH+Pgs/ih0E+mo9NiWVER mIRDJBQcSfz8CMPmrQmSVByk5GWcChtepgcZ9W4lHaGXXIcJWlz4tmPlbIQqriJXAuaQ ZuDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=74aMisHJvcrsbS5g8R7662ZNEA+1A6hMiypJVvVd5yo=; b=VXXO/eVo53unpIw/Z+qe0ThDu49mB/SANylEXt+LXif1oPx1m0+t8vpV8SyIkQ//kz ymz0scKG0Mrsc4/eC/kVB6gB/DXL69ZnVz9nsnoocRchg4skWSjyrhu7gKqqIqACcADr B9g8/5b72so6BDDdo1GGd5wyEE+PkO5OFVDEyCe865XltWAbYEfXXdjwL1aP5ArVUrQz mzAI+o3YsIjLhB5Skk1ijfxN8CZiUcXc3l2tVfZwR9x+SHKLNdUpiKPtqeUJvukbpjEe 4zJZmrO9we88nivSIkoPXPbvJA4O/Abt2QdhF0fcYpH8vnRfJz6Ag/7rYpKPg460QG6K eC8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S8+cDYPz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b13-20020a170903228d00b001acb03ca5aasi350171plh.612.2023.05.19.17.28.55; Fri, 19 May 2023 17:29:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S8+cDYPz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230303AbjETADT (ORCPT + 99 others); Fri, 19 May 2023 20:03:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230256AbjETADR (ORCPT ); Fri, 19 May 2023 20:03:17 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA92210E9 for ; Fri, 19 May 2023 17:01:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684540888; 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=S8+cDYPzz14JaxQlPhkN/MLQ9oVozadalqgj2uM+HaygMwAs/o5WgAj3Yb6kJdplZ7mjPw dbEj+UI2e8vuy0U7rJnjWlDZh+PQeC9eBGK+eA4QjOyX7+HIGs349J4vxVpIhWEJfugRig BEIBg+31yHT6qSiuP7j8zP9IoZs4Ktw= 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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,