public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] fs/9p: fix mmap regression
@ 2023-07-18 20:50 Eric Van Hensbergen
  2023-07-18 20:50 ` [PATCH v2 1/4] fs/9p: remove unnecessary and overrestrictive check Eric Van Hensbergen
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Eric Van Hensbergen @ 2023-07-18 20:50 UTC (permalink / raw)
  To: Latchesar Ionkov, Dominique Martinet, Christian Schoenebeck
  Cc: v9fs, linux-kernel, kernel, Robert Schwebel, Eric Van Hensbergen

This series attempts to fix a reported exception with mmap
on newer kernels. 

original regression report follows:

TL;DR: mmap() seems to be broken on 9pfs on Linux 6.4. setting
"rootflags=ignoreqv" fixes it as well, but it feels like a regression.

I'm tracking down an issue which recently turned up in DistroKit [1] (an
embedded Linux distro based on the ptxdist build system). The issue was a bit
uggly, as my CI didn't find it (systems boot up normally after a while, and I
only use 9p for virtual qemu machines, while most of the test farm is real
hardware).

The qemu machine in question is qemu-system-arm, emulating an ARM v7a machine.

When starting the systems interactively, I get a lot of error output from
ldconfig, like this:

[   17.412964] systemd-rc-once[127]: ldconfig: Cannot mmap file /lib/libgcc_s.so.1.
[   17.418851] systemd-rc-once[127]: ldconfig: Cannot mmap file /lib/libstdc++.so.
[   17.425009] systemd-rc-once[127]: ldconfig: Cannot mmap file /lib/libstdc++.so.6.0.30.
[   17.436671] systemd-rc-once[127]: ldconfig: Cannot mmap file /lib/libstdc++.so.6.
[   17.448451] systemd-rc-once[127]: ldconfig: Cannot mmap file /lib/libatomic.so.
[   17.456418] systemd-rc-once[127]: ldconfig: Cannot mmap file /lib/libatomic.so.1.2.0.
...

Running ldconfig with strace shows this, for all libraries::

| statx(AT_FDCWD, "/lib/libnm.so.0", AT_STATX_SYNC_AS_STAT|AT_SYMLINK_NOFOLLOW|AT_NO_AUTOMOUNT, STATX_BASIC_STATS, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFLNK|0777, stx_size=14, ...}) = 0
| statx(AT_FDCWD, "/lib/libnm.so.0", AT_STATX_SYNC_AS_STAT|AT_NO_AUTOMOUNT, STATX_BASIC_STATS, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|064 4, stx_size=862228, ...}) = 0
| openat(AT_FDCWD, "/lib/libnm.so.0", O_RDONLY|O_LARGEFILE) = 4
| statx(4, "", AT_STATX_SYNC_AS_STAT|AT_NO_AUTOMOUNT|AT_EMPTY_PATH, STATX_BASIC_STATS, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_s ize=862228, ...}) = 0
| mmap2(NULL, 862228, PROT_READ, MAP_SHARED, 4, 0) = -1 ENODEV (No such device)
| write(2, "ldconfig: ", 10ldconfig: )              = 10
| write(2, "Cannot mmap file /lib/libnm.so.0"..., 34Cannot mmap file /lib/libnm.so.0.) = 34
| write(2, "\n", 1)                       = 1
| close(4)                                = 0

I could track down the breakage to

  1543b4c5071c54d76aad7a7a26a6e43082269b0c

My test setup has, in addition to the patch above, the following patches also
reverted on top of a vanilla 6.4 kernel:

  4eb3117888a923f6b9b1ad2dd093641c49a63ae5
  21e26d5e54ab7cfe6b488fd27d4d70956d07e03b

as 1543b cannot be reverted without those; however, the effect only goes away
when I also revert 1543b. The kernel has no other patches applied, only these
three reverts.

Reported-by: Robert Schwebel <r.schwebel@pengutronix.de>
Signed-off-by: Eric Van Hensbergen <ericvh@kernel.org>
---
Changes in v2:
- fix requested changes in commit messages
- add patch to remove unnecessary invalidate_inode_pages in mmap readonly path
- Link to v1: https://lore.kernel.org/r/20230716-fixes-overly-restrictive-mmap-v1-0-0683b283b932@kernel.org

---
Eric Van Hensbergen (4):
      fs/9p: remove unnecessary and overrestrictive check
      fs/9p: fix typo in comparison logic for cache mode
      fs/9p: fix type mismatch in file cache mode helper
      fs/9p: remove unnecessary invalidate_inode_pages2

 fs/9p/fid.h      | 6 +++---
 fs/9p/vfs_file.c | 3 ---
 2 files changed, 3 insertions(+), 6 deletions(-)
---
base-commit: 95f41d87810083d8b3dedcce46a4e356cf4a9673
change-id: 20230716-fixes-overly-restrictive-mmap-30a23501e787

Best regards,
-- 
Eric Van Hensbergen <ericvh@kernel.org>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/4] fs/9p: remove unnecessary and overrestrictive check
  2023-07-18 20:50 [PATCH v2 0/4] fs/9p: fix mmap regression Eric Van Hensbergen
@ 2023-07-18 20:50 ` Eric Van Hensbergen
  2023-07-19 13:18   ` Christian Schoenebeck
  2023-07-18 20:50 ` [PATCH v2 2/4] fs/9p: fix typo in comparison logic for cache mode Eric Van Hensbergen
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Eric Van Hensbergen @ 2023-07-18 20:50 UTC (permalink / raw)
  To: Latchesar Ionkov, Dominique Martinet, Christian Schoenebeck
  Cc: v9fs, linux-kernel, kernel, Robert Schwebel, Eric Van Hensbergen

This eliminates a check for shared that was overrestrictive and
duplicated a check in generic_file_readonly_mmap.

Reviewed-by: Dominique Martinet <asmadeus@codewreck.org>
Reviewed-by: Christian Schoenebeck <linux_oss@crudebyte.com>
Signed-off-by: Eric Van Hensbergen <ericvh@kernel.org>
---
 fs/9p/vfs_file.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
index 2996fb00387fa..bda3abd6646b8 100644
--- a/fs/9p/vfs_file.c
+++ b/fs/9p/vfs_file.c
@@ -506,8 +506,6 @@ v9fs_file_mmap(struct file *filp, struct vm_area_struct *vma)
 
 	if (!(v9ses->cache & CACHE_WRITEBACK)) {
 		p9_debug(P9_DEBUG_CACHE, "(no mmap mode)");
-		if (vma->vm_flags & VM_MAYSHARE)
-			return -ENODEV;
 		invalidate_inode_pages2(filp->f_mapping);
 		return generic_file_readonly_mmap(filp, vma);
 	}

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/4] fs/9p: fix typo in comparison logic for cache mode
  2023-07-18 20:50 [PATCH v2 0/4] fs/9p: fix mmap regression Eric Van Hensbergen
  2023-07-18 20:50 ` [PATCH v2 1/4] fs/9p: remove unnecessary and overrestrictive check Eric Van Hensbergen
@ 2023-07-18 20:50 ` Eric Van Hensbergen
  2023-07-18 20:50 ` [PATCH v2 3/4] fs/9p: fix type mismatch in file cache mode helper Eric Van Hensbergen
  2023-07-18 20:50 ` [PATCH v2 4/4] fs/9p: remove unnecessary invalidate_inode_pages2 Eric Van Hensbergen
  3 siblings, 0 replies; 7+ messages in thread
From: Eric Van Hensbergen @ 2023-07-18 20:50 UTC (permalink / raw)
  To: Latchesar Ionkov, Dominique Martinet, Christian Schoenebeck
  Cc: v9fs, linux-kernel, kernel, Robert Schwebel, Eric Van Hensbergen

There appears to be a typo in the comparison statement for the logic
which sets a file's cache mode based on mount flags.

Reviewed-by: Christian Schoenebeck <linux_oss@crudebyte.com>
Reviewed-by: Dominique Martinet <asmadeus@codewreck.org>
Signed-off-by: Eric Van Hensbergen <ericvh@kernel.org>
---
 fs/9p/fid.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/9p/fid.h b/fs/9p/fid.h
index 0c51889a60b33..297c2c377e3dd 100644
--- a/fs/9p/fid.h
+++ b/fs/9p/fid.h
@@ -57,7 +57,7 @@ static inline void v9fs_fid_add_modes(struct p9_fid *fid, int s_flags,
 	   (s_flags & V9FS_DIRECT_IO) || (f_flags & O_DIRECT)) {
 		fid->mode |= P9L_DIRECT; /* no read or write cache */
 	} else if ((!(s_cache & CACHE_WRITEBACK)) ||
-				(f_flags & O_DSYNC) | (s_flags & V9FS_SYNC)) {
+				(f_flags & O_DSYNC) || (s_flags & V9FS_SYNC)) {
 		fid->mode |= P9L_NOWRITECACHE;
 	}
 }

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/4] fs/9p: fix type mismatch in file cache mode helper
  2023-07-18 20:50 [PATCH v2 0/4] fs/9p: fix mmap regression Eric Van Hensbergen
  2023-07-18 20:50 ` [PATCH v2 1/4] fs/9p: remove unnecessary and overrestrictive check Eric Van Hensbergen
  2023-07-18 20:50 ` [PATCH v2 2/4] fs/9p: fix typo in comparison logic for cache mode Eric Van Hensbergen
@ 2023-07-18 20:50 ` Eric Van Hensbergen
  2023-07-18 20:50 ` [PATCH v2 4/4] fs/9p: remove unnecessary invalidate_inode_pages2 Eric Van Hensbergen
  3 siblings, 0 replies; 7+ messages in thread
From: Eric Van Hensbergen @ 2023-07-18 20:50 UTC (permalink / raw)
  To: Latchesar Ionkov, Dominique Martinet, Christian Schoenebeck
  Cc: v9fs, linux-kernel, kernel, Robert Schwebel, Eric Van Hensbergen

There were two flags (s_flags and s_cache) which had incorrect signed
type in the parameters of the file cache mode helper function.

Reviewed-by: Dominique Martinet <asmadeus@codewreck.org>
Signed-off-by: Eric Van Hensbergen <ericvh@kernel.org>
---
 fs/9p/fid.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/9p/fid.h b/fs/9p/fid.h
index 297c2c377e3dd..29281b7c38870 100644
--- a/fs/9p/fid.h
+++ b/fs/9p/fid.h
@@ -46,8 +46,8 @@ static inline struct p9_fid *v9fs_fid_clone(struct dentry *dentry)
  * NOTE: these are set after open so only reflect 9p client not
  * underlying file system on server.
  */
-static inline void v9fs_fid_add_modes(struct p9_fid *fid, int s_flags,
-	int s_cache, unsigned int f_flags)
+static inline void v9fs_fid_add_modes(struct p9_fid *fid, unsigned int s_flags,
+	unsigned int s_cache, unsigned int f_flags)
 {
 	if (fid->qid.type != P9_QTFILE)
 		return;

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 4/4] fs/9p: remove unnecessary invalidate_inode_pages2
  2023-07-18 20:50 [PATCH v2 0/4] fs/9p: fix mmap regression Eric Van Hensbergen
                   ` (2 preceding siblings ...)
  2023-07-18 20:50 ` [PATCH v2 3/4] fs/9p: fix type mismatch in file cache mode helper Eric Van Hensbergen
@ 2023-07-18 20:50 ` Eric Van Hensbergen
  2023-07-19 13:08   ` Christian Schoenebeck
  3 siblings, 1 reply; 7+ messages in thread
From: Eric Van Hensbergen @ 2023-07-18 20:50 UTC (permalink / raw)
  To: Latchesar Ionkov, Dominique Martinet, Christian Schoenebeck
  Cc: v9fs, linux-kernel, kernel, Robert Schwebel, Eric Van Hensbergen

There was an invalidate_inode_pages2
added to mmap that is unnecessary.

Signed-off-by: Eric Van Hensbergen <ericvh@kernel.org>
---
 fs/9p/vfs_file.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
index bda3abd6646b8..3809f3a531499 100644
--- a/fs/9p/vfs_file.c
+++ b/fs/9p/vfs_file.c
@@ -506,7 +506,6 @@ v9fs_file_mmap(struct file *filp, struct vm_area_struct *vma)
 
 	if (!(v9ses->cache & CACHE_WRITEBACK)) {
 		p9_debug(P9_DEBUG_CACHE, "(no mmap mode)");
-		invalidate_inode_pages2(filp->f_mapping);
 		return generic_file_readonly_mmap(filp, vma);
 	}
 

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 4/4] fs/9p: remove unnecessary invalidate_inode_pages2
  2023-07-18 20:50 ` [PATCH v2 4/4] fs/9p: remove unnecessary invalidate_inode_pages2 Eric Van Hensbergen
@ 2023-07-19 13:08   ` Christian Schoenebeck
  0 siblings, 0 replies; 7+ messages in thread
From: Christian Schoenebeck @ 2023-07-19 13:08 UTC (permalink / raw)
  To: Latchesar Ionkov, Dominique Martinet, Eric Van Hensbergen
  Cc: v9fs, linux-kernel, kernel, Robert Schwebel, Eric Van Hensbergen

On Tuesday, July 18, 2023 10:50:18 PM CEST Eric Van Hensbergen wrote:
> There was an invalidate_inode_pages2
> added to mmap that is unnecessary.
> 
> Signed-off-by: Eric Van Hensbergen <ericvh@kernel.org>
> ---

Reviewed-by: Christian Schoenebeck <linux_oss@crudebyte.com>

>  fs/9p/vfs_file.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
> index bda3abd6646b8..3809f3a531499 100644
> --- a/fs/9p/vfs_file.c
> +++ b/fs/9p/vfs_file.c
> @@ -506,7 +506,6 @@ v9fs_file_mmap(struct file *filp, struct vm_area_struct *vma)
>  
>  	if (!(v9ses->cache & CACHE_WRITEBACK)) {
>  		p9_debug(P9_DEBUG_CACHE, "(no mmap mode)");
> -		invalidate_inode_pages2(filp->f_mapping);
>  		return generic_file_readonly_mmap(filp, vma);
>  	}
>  
> 
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/4] fs/9p: remove unnecessary and overrestrictive check
  2023-07-18 20:50 ` [PATCH v2 1/4] fs/9p: remove unnecessary and overrestrictive check Eric Van Hensbergen
@ 2023-07-19 13:18   ` Christian Schoenebeck
  0 siblings, 0 replies; 7+ messages in thread
From: Christian Schoenebeck @ 2023-07-19 13:18 UTC (permalink / raw)
  To: Latchesar Ionkov, Dominique Martinet, Eric Van Hensbergen
  Cc: v9fs, linux-kernel, kernel, Robert Schwebel, Eric Van Hensbergen

On Tuesday, July 18, 2023 10:50:15 PM CEST Eric Van Hensbergen wrote:
> This eliminates a check for shared that was overrestrictive and
> duplicated a check in generic_file_readonly_mmap.
> 
> Reviewed-by: Dominique Martinet <asmadeus@codewreck.org>
> Reviewed-by: Christian Schoenebeck <linux_oss@crudebyte.com>
> Signed-off-by: Eric Van Hensbergen <ericvh@kernel.org>
> ---
>  fs/9p/vfs_file.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
> index 2996fb00387fa..bda3abd6646b8 100644
> --- a/fs/9p/vfs_file.c
> +++ b/fs/9p/vfs_file.c
> @@ -506,8 +506,6 @@ v9fs_file_mmap(struct file *filp, struct vm_area_struct *vma)
>  
>  	if (!(v9ses->cache & CACHE_WRITEBACK)) {
>  		p9_debug(P9_DEBUG_CACHE, "(no mmap mode)");

"(r/o mmap mode)" ?

> -		if (vma->vm_flags & VM_MAYSHARE)
> -			return -ENODEV;
>  		invalidate_inode_pages2(filp->f_mapping);
>  		return generic_file_readonly_mmap(filp, vma);
>  	}
> 
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-07-19 13:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-18 20:50 [PATCH v2 0/4] fs/9p: fix mmap regression Eric Van Hensbergen
2023-07-18 20:50 ` [PATCH v2 1/4] fs/9p: remove unnecessary and overrestrictive check Eric Van Hensbergen
2023-07-19 13:18   ` Christian Schoenebeck
2023-07-18 20:50 ` [PATCH v2 2/4] fs/9p: fix typo in comparison logic for cache mode Eric Van Hensbergen
2023-07-18 20:50 ` [PATCH v2 3/4] fs/9p: fix type mismatch in file cache mode helper Eric Van Hensbergen
2023-07-18 20:50 ` [PATCH v2 4/4] fs/9p: remove unnecessary invalidate_inode_pages2 Eric Van Hensbergen
2023-07-19 13:08   ` Christian Schoenebeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox