From: Jingbo Xu <jefflexu@linux.alibaba.com>
To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org
Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: [PATCH v3 7/9] erofs: implement .mmap for page cache sharing
Date: Fri, 3 Feb 2023 11:01:41 +0800 [thread overview]
Message-ID: <20230203030143.73105-8-jefflexu@linux.alibaba.com> (raw)
In-Reply-To: <20230203030143.73105-1-jefflexu@linux.alibaba.com>
In mmap(2), replace vma->vm_file with the anonymous file associated with
the blob, so that the vma will be linked to the address_space of the
blob.
One thing worth noting is that, we return error early in mmap(2) if
users attempt to map beyond the file size. Normally filesystems won't
restrict this in mmap(2). The checking is done in the fault handler,
and SIGBUS will be signaled to users if they actually attempt to access
the area beyond the end of the file. However since vma->vm_file has
been changed to the anonymous file in mmap(2), we can no way derive the
file size of the original file. As file size is immutable in ro
filesystem, let's fail early in mmap(2) in this case.
Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
---
fs/erofs/fscache.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
index bdeb048b78b5..af6ba52bbe8b 100644
--- a/fs/erofs/fscache.c
+++ b/fs/erofs/fscache.c
@@ -432,9 +432,36 @@ static ssize_t erofs_fscache_share_file_read_iter(struct kiocb *iocb,
return res;
}
+vm_fault_t erofs_fscache_share_fault(struct vm_fault *vmf)
+{
+ struct erofs_fscache_finfo *finfo = vmf->vma->vm_file->private_data;
+
+ if (unlikely(vmf->pgoff >= finfo->max_idx))
+ return VM_FAULT_SIGBUS;
+ return filemap_fault(vmf);
+}
+
+static const struct vm_operations_struct erofs_fscache_share_file_vm_ops = {
+ .fault = erofs_fscache_share_fault,
+};
+
+static int erofs_fscache_share_file_mmap(struct file *file,
+ struct vm_area_struct *vma)
+{
+ struct file *realfile = file->private_data;
+ struct erofs_fscache_finfo *finfo = realfile->private_data;
+
+ vma_set_file(vma, realfile);
+ vma->vm_pgoff = (finfo->pa >> PAGE_SHIFT) + vma->vm_pgoff;
+ vma->vm_ops = &erofs_fscache_share_file_vm_ops;
+ file_accessed(file);
+ return 0;
+}
+
const struct file_operations erofs_fscache_share_file_fops = {
.llseek = generic_file_llseek,
.read_iter = erofs_fscache_share_file_read_iter,
+ .mmap = erofs_fscache_share_file_mmap,
.open = erofs_fscache_share_file_open,
.release = erofs_fscache_share_file_release,
};
--
2.19.1.6.gb485710b
next prev parent reply other threads:[~2023-02-03 3:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-03 3:01 [PATCH v3 0/9] erofs: support page cache sharing between EROFS images in fscache mode Jingbo Xu
2023-02-03 3:01 ` [PATCH v3 1/9] erofs: support readahead in meta routine Jingbo Xu
2023-02-03 3:01 ` [PATCH v3 2/9] erofs: remove unused device mapping in the " Jingbo Xu
2023-02-03 3:01 ` [PATCH v3 3/9] erofs: unify anonymous inodes for blob Jingbo Xu
2023-02-03 3:01 ` [PATCH v3 4/9] erofs: allocate anonymous file of blob for page cache sharing Jingbo Xu
2023-02-03 3:01 ` [PATCH v3 5/9] erofs: set accurate anony inode size " Jingbo Xu
2023-02-03 3:01 ` [PATCH v3 6/9] erofs: implement .read_iter " Jingbo Xu
2023-02-03 3:01 ` Jingbo Xu [this message]
2023-02-03 15:12 ` [PATCH v3 7/9] erofs: implement .mmap " kernel test robot
2023-02-03 3:01 ` [PATCH v3 8/9] erofs: add helper checking if page cache sharing shall be enabled Jingbo Xu
2023-02-03 3:01 ` [PATCH v3 9/9] erofs: introduce 'sharecache' mount option Jingbo Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230203030143.73105-8-jefflexu@linux.alibaba.com \
--to=jefflexu@linux.alibaba.com \
--cc=chao@kernel.org \
--cc=huyue2@coolpad.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=xiang@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).