Skip to contentSkip to conversation

fuse: Fix VM_MAYSHARE and direct_io_allow_mmap

PATCH In review Bernd Schubert 2 participants 2 messages Dec 13, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fuse: Fix VM_MAYSHARE and direct_io_allow_mmap

There were multiple issues with direct_io_allow_mmap:
- fuse_link_write_file() was missing, resulting in warnings in fuse_write_file_get() and EIO from msync()
- "vma->vm_ops = &fuse_file_vm_ops" was not set, but especially fuse_page_mkwrite is needed.

The semantics of invalidate_inode_pages2() is so far not clearly defined in fuse_file_mmap. It dates back to
commit 3121bfe76311 ("fuse: fix "direct_io" private mmap") Though, as direct_io_allow_mmap is a new feature, that was for MAP_PRIVATE only. As invalidate_inode_pages2() is calling into fuse_launder_folio() and writes out dirty pages, it should be save to call invalidate_inode_pages2 for MAP_PRIVATE and MAP_SHARED as well.

Cc Hao Xu <[email protected]>
Cc Miklos Szeredi <[email protected]>
Cc Dharmendra Singh <[email protected]>
Cc Amir Goldstein <[email protected]>
Fixes e78662e818f9 ("fuse: add a new fuse init flag to relax restrictions in no cache mode")
---
 fs/fuse/file.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/fuse/file.c +4 -1
index a660f1f21540..174aa16407c4 100644
@@ -2475,7 +2475,10 @@ static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)
 
 		invalidate_inode_pages2(file->f_mapping);
 
-		return generic_file_mmap(file, vma);
+		if (!(vma->vm_flags & VM_MAYSHARE)) {
+			/* MAP_PRIVATE */
+			return generic_file_mmap(file, vma);
+		}
 	}
 
 	if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE))
Signature · 1 line
2.40.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Bernd Schubert

There were multiple issues with direct_io_allow_mmap:
- fuse_link_write_file() was missing, resulting in warnings in fuse_write_file_get() and EIO from msync()
- "vma->vm_ops = &fuse_file_vm_ops" was not set, but especially fuse_page_mkwrite is needed.

Quoted 6 lines

The semantics of invalidate_inode_pages2() is so far not clearly defined in fuse_file_mmap. It dates back to
commit 3121bfe76311 ("fuse: fix "direct_io" private mmap") Though, as direct_io_allow_mmap is a new feature, that was for MAP_PRIVATE only. As invalidate_inode_pages2() is calling into fuse_launder_folio() and writes out dirty pages, it should be save to call

typo: safe to call...

Quoted 11 lines

invalidate_inode_pages2 for MAP_PRIVATE and MAP_SHARED as well.

Cc Hao Xu <[email protected]>
Cc Miklos Szeredi <[email protected]>
Cc Dharmendra Singh <[email protected]>
Cc Amir Goldstein <[email protected]>
Fixes e78662e818f9 ("fuse: add a new fuse init flag to relax restrictions in no cache mode")

---

Thanks,
Amir.

Quoted 22 lines
 fs/fuse/file.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/fuse/file.c +4 -2
index a660f1f21540..174aa16407c4 100644
@@ -2475,7 +2475,10 @@ static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)
 
                invalidate_inode_pages2(file->f_mapping);
 
-               return generic_file_mmap(file, vma);
+               if (!(vma->vm_flags & VM_MAYSHARE)) {
+                       /* MAP_PRIVATE */
+                       return generic_file_mmap(file, vma);
+               }
        }
 
        if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE))
--

2.40.1