Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3608772pxb; Mon, 25 Jan 2021 23:17:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJzc7IASzjaxVAS0pOjDv7mzHfOAjpBN8HQAOpJ+sc1za/X6rkTo7SlJJSb2bF+trh2WQxE0 X-Received: by 2002:aa7:d304:: with SMTP id p4mr3334865edq.144.1611645442609; Mon, 25 Jan 2021 23:17:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611645442; cv=none; d=google.com; s=arc-20160816; b=Mu8T9YWL9lYKvXB1fXzr/JZwllYGT3nwSxx6Uth4XptklDSnFfckngv+D4Vqy9KuEj 18JGwrywkkJKOQd5hReHOujD/npJYJysQ2t14sXFNOiIm+6CO43BBf3E9URj1TKrvkKz 1WruhqI65UOOtkaXi5XqKoXbqGM3gQJlVjLSrHgDzClKdZFyuuaPdFfpDvEQfaYZoByz +oMHQ0JPTYcQszIvYn0D8uasN/SPQdQVow9QqMmLy7/BDH28dMlw9ZXEGsHfs7vM8X0H GfVPFmTj9A1G5PbyPH+vKOImTHQR77Z3A9BvPgljbOcG4FV+gC8PjwK1CjohlJXV3PiR 2EyA== 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=bO1o95yEacxJCi6anL6VGLU0D9m8E1qC04Zr1YukLIY=; b=yt3mOWX3ITlwmqDwEUc50f0lIJxQASjYYVzf4bW8FLKF+2BQiZpXn4lndiOBDuFKOG n3mNHQL4Xa04KkKpsgetW9Ya/L2N54pGTzBd8nmdtmAb643AFlDGWMQmjLbEyfdSsK7C HdVzGAk+lGPkBUL+i88OrpwiaYsdmxJxnSH3DIEie+J21gVP/YMqrm/AyowvBVWlLF2W z57MWWtIoycM2vTdy6vJxD8h7jJcfgAOhp4KzEYDRlcK3w249/rEd1hu/qNhU7fpUINP AB8C7sPmVdUXLyp6xxt2RPwMDGSFPbnMw647MjR3Q0xDBlZq7dJa7hvZvtJPpA4Glgig LN3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=ZTJkmBtN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=android.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q26si8414241edr.555.2021.01.25.23.16.57; Mon, 25 Jan 2021 23:17:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=ZTJkmBtN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=android.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730250AbhAZHNF (ORCPT + 99 others); Tue, 26 Jan 2021 02:13:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730264AbhAYPmq (ORCPT ); Mon, 25 Jan 2021 10:42:46 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66BCFC0698C0 for ; Mon, 25 Jan 2021 07:31:16 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id h9so2809332wrr.9 for ; Mon, 25 Jan 2021 07:31:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bO1o95yEacxJCi6anL6VGLU0D9m8E1qC04Zr1YukLIY=; b=ZTJkmBtNvj+HaYd99yGGaGslCoSskPBt4H7l7Hk5qHb2OnXsuo+Dhoo+EFFsfD6JRu JTmgHLcpu21RVZAAYl3fnJF3ueXF+96EV/yA3ocS784tVf2+2daHcyNs8fLEeEG3OfPP TS6oFJAoYqmjxoPh/KNH5UN7r87b9yUMjxcnv2Z+JuvmysnIhIYKj99Sao0k3p709nIw b/3vldccwOQED9RavZ+r4Ip6qeV14H43+xB2oI2RjnTAhg3sbulT8odCQBX2BENwidl8 JrPx8Y7YyYrBUivhBUdFamIUb7KcT4AavuKxnMJ4V687huqvVsyESxpTfeJOaTrczksv AMlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bO1o95yEacxJCi6anL6VGLU0D9m8E1qC04Zr1YukLIY=; b=X7JwBinNWK3PjcEnmdCaNK1KTnLW3j00OTsUXsvsMjfYU/imeZFF71u+DCvbPDq5Sv TKbCSZFO+n54lMzJkyCuO6SNiiECjhFz97BH3MpZikaf6yxAGgw1nxxFY4gefQJWVdq6 sGxGux26eQKc0ssOa9inARwqn/DxWpqcl+NT6rL4ROyQHieeUehX5OiYYDwMEGayN/BM BTaXuKj6bQiQvd/2nTrHczJ/kOJe1yW/VGrAnEa/ZFz53LFgheq9lvj1g8jjkI6Xzt7y Ku6jFenGEzaNndIkyEFbfcjLTwE2OdD+Ftf0SDwDuXOeE5EfENbz58XBH+pal8nRgbNh Wcxg== X-Gm-Message-State: AOAM531nuA5spajGtPLGEkQu9VnVKRAj+Vl/iURTgaI01AM9lz3xyReb DiSQ0z94GTu9STpYJutvFptOVg== X-Received: by 2002:adf:f606:: with SMTP id t6mr1611833wrp.360.1611588675183; Mon, 25 Jan 2021 07:31:15 -0800 (PST) Received: from balsini.lon.corp.google.com ([2a00:79e0:d:210:4cd4:5994:40fe:253d]) by smtp.gmail.com with ESMTPSA id o14sm22611965wri.48.2021.01.25.07.31.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jan 2021 07:31:14 -0800 (PST) From: Alessio Balsini To: Miklos Szeredi Cc: Akilesh Kailash , Amir Goldstein , Antonio SJ Musumeci , David Anderson , Giuseppe Scrivano , Jann Horn , Jens Axboe , Martijn Coenen , Palmer Dabbelt , Paul Lawrence , Peng Tao , Stefano Duo , Zimuzo Ezeozue , wuyan , fuse-devel@lists.sourceforge.net, kernel-team@android.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND V12 8/8] fuse: Introduce passthrough for mmap Date: Mon, 25 Jan 2021 15:30:57 +0000 Message-Id: <20210125153057.3623715-9-balsini@android.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog In-Reply-To: <20210125153057.3623715-1-balsini@android.com> References: <20210125153057.3623715-1-balsini@android.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Enabling FUSE passthrough for mmap-ed operations not only affects performance, but has also been shown as mandatory for the correct functioning of FUSE passthrough. yanwu noticed [1] that a FUSE file with passthrough enabled may suffer data inconsistencies if the same file is also accessed with mmap. What happens is that read/write operations are directly applied to the lower file system (and its cache), while mmap-ed operations are affecting the FUSE cache. Extend the FUSE passthrough implementation to also handle memory-mapped FUSE file, to both fix the cache inconsistencies and extend the passthrough performance benefits to mmap-ed operations. [1] https://lore.kernel.org/lkml/20210119110654.11817-1-wu-yan@tcl.com/ Signed-off-by: Alessio Balsini --- fs/fuse/file.c | 3 +++ fs/fuse/fuse_i.h | 1 + fs/fuse/passthrough.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index cddada1e8bd9..e3741a94c1f9 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2370,6 +2370,9 @@ static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma) if (FUSE_IS_DAX(file_inode(file))) return fuse_dax_mmap(file, vma); + if (ff->passthrough.filp) + return fuse_passthrough_mmap(file, vma); + if (ff->open_flags & FOPEN_DIRECT_IO) { /* Can't provide the coherency needed for MAP_SHARED */ if (vma->vm_flags & VM_MAYSHARE) diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 815af1845b16..7b0d65984608 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1244,5 +1244,6 @@ int fuse_passthrough_setup(struct fuse_conn *fc, struct fuse_file *ff, void fuse_passthrough_release(struct fuse_passthrough *passthrough); ssize_t fuse_passthrough_read_iter(struct kiocb *iocb, struct iov_iter *to); ssize_t fuse_passthrough_write_iter(struct kiocb *iocb, struct iov_iter *from); +ssize_t fuse_passthrough_mmap(struct file *file, struct vm_area_struct *vma); #endif /* _FS_FUSE_I_H */ diff --git a/fs/fuse/passthrough.c b/fs/fuse/passthrough.c index 24866c5fe7e2..284979f87747 100644 --- a/fs/fuse/passthrough.c +++ b/fs/fuse/passthrough.c @@ -135,6 +135,47 @@ ssize_t fuse_passthrough_write_iter(struct kiocb *iocb_fuse, return ret; } +ssize_t fuse_passthrough_mmap(struct file *file, struct vm_area_struct *vma) +{ + int ret; + const struct cred *old_cred; + struct fuse_file *ff = file->private_data; + struct inode *fuse_inode = file_inode(file); + struct file *passthrough_filp = ff->passthrough.filp; + struct inode *passthrough_inode = file_inode(passthrough_filp); + + if (!passthrough_filp->f_op->mmap) + return -ENODEV; + + if (WARN_ON(file != vma->vm_file)) + return -EIO; + + vma->vm_file = get_file(passthrough_filp); + + old_cred = override_creds(ff->passthrough.cred); + ret = call_mmap(vma->vm_file, vma); + revert_creds(old_cred); + + if (ret) + fput(passthrough_filp); + else + fput(file); + + if (file->f_flags & O_NOATIME) + return ret; + + if ((!timespec64_equal(&fuse_inode->i_mtime, + &passthrough_inode->i_mtime) || + !timespec64_equal(&fuse_inode->i_ctime, + &passthrough_inode->i_ctime))) { + fuse_inode->i_mtime = passthrough_inode->i_mtime; + fuse_inode->i_ctime = passthrough_inode->i_ctime; + } + touch_atime(&file->f_path); + + return ret; +} + int fuse_passthrough_open(struct fuse_dev *fud, struct fuse_passthrough_out *pto) { -- 2.30.0.280.ga3ce27912f-goog