The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] fs: use namespace_{lock,unlock} in dissolve_on_fput()
@ 2025-04-10 15:05 Jan Stancek
  2025-04-11 14:08 ` Christian Brauner
  2025-04-11 14:08 ` Christian Brauner
  0 siblings, 2 replies; 4+ messages in thread
From: Jan Stancek @ 2025-04-10 15:05 UTC (permalink / raw)
  To: brauner, linux-fsdevel; +Cc: viro, jack, linux-kernel, jstancek

In commit b73ec10a4587 ("fs: add fastpath for dissolve_on_fput()"),
the namespace_{lock,unlock} has been replaced with scoped_guard
using the namespace_sem. This however now also skips processing of
'unmounted' list in namespace_unlock(), and mount is not (immediately)
cleaned up.

For example, this causes LTP move_mount02 fail:
    ...
    move_mount02.c:80: TPASS: invalid-from-fd: move_mount() failed as expected: EBADF (9)
    move_mount02.c:80: TPASS: invalid-from-path: move_mount() failed as expected: ENOENT (2)
    move_mount02.c:80: TPASS: invalid-to-fd: move_mount() failed as expected: EBADF (9)
    move_mount02.c:80: TPASS: invalid-to-path: move_mount() failed as expected: ENOENT (2)
    move_mount02.c:80: TPASS: invalid-flags: move_mount() failed as expected: EINVAL (22)
    tst_test.c:1833: TINFO: === Testing on ext3 ===
    tst_test.c:1170: TINFO: Formatting /dev/loop0 with ext3 opts='' extra opts=''
    mke2fs 1.47.2 (1-Jan-2025)
    /dev/loop0 is apparently in use by the system; will not make a filesystem here!
    tst_test.c:1170: TBROK: mkfs.ext3 failed with exit code 1

The test makes number of move_mount() calls but these are all designed to fail
with specific errno. Even after test, 'losetup -d' can't detach loop device.

Define a new guard for dissolve_on_fput, that will use namespace_{lock,unlock}.

Fixes: b73ec10a4587 ("fs: add fastpath for dissolve_on_fput()")
Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 fs/namespace.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index 14935a0500a2..ee1fdb3baee0 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1830,6 +1830,8 @@ static inline void namespace_lock(void)
 	down_write(&namespace_sem);
 }
 
+DEFINE_GUARD(namespace_locked, struct rw_semaphore *, namespace_lock(), namespace_unlock())
+
 enum umount_tree_flags {
 	UMOUNT_SYNC = 1,
 	UMOUNT_PROPAGATE = 2,
@@ -2383,7 +2385,7 @@ void dissolve_on_fput(struct vfsmount *mnt)
 			return;
 	}
 
-	scoped_guard(rwsem_write, &namespace_sem) {
+	scoped_guard(namespace_locked, &namespace_sem) {
 		ns = m->mnt_ns;
 		if (!must_dissolve(ns))
 			return;
-- 
2.43.5


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

* Re: [PATCH] fs: use namespace_{lock,unlock} in dissolve_on_fput()
  2025-04-10 15:05 [PATCH] fs: use namespace_{lock,unlock} in dissolve_on_fput() Jan Stancek
@ 2025-04-11 14:08 ` Christian Brauner
  2025-04-11 14:20   ` Jan Stancek
  2025-04-11 14:08 ` Christian Brauner
  1 sibling, 1 reply; 4+ messages in thread
From: Christian Brauner @ 2025-04-11 14:08 UTC (permalink / raw)
  To: Jan Stancek; +Cc: linux-fsdevel, viro, jack, linux-kernel

On Thu, Apr 10, 2025 at 05:05:42PM +0200, Jan Stancek wrote:
> In commit b73ec10a4587 ("fs: add fastpath for dissolve_on_fput()"),
> the namespace_{lock,unlock} has been replaced with scoped_guard
> using the namespace_sem. This however now also skips processing of
> 'unmounted' list in namespace_unlock(), and mount is not (immediately)
> cleaned up.

Thank you for spotting and fixing this! My bad.

> diff --git a/fs/namespace.c b/fs/namespace.c
> index 14935a0500a2..ee1fdb3baee0 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
> @@ -1830,6 +1830,8 @@ static inline void namespace_lock(void)
>  	down_write(&namespace_sem);
>  }
>  
> +DEFINE_GUARD(namespace_locked, struct rw_semaphore *, namespace_lock(), namespace_unlock())

I'll call that namespace_lock instead if you don't mind.

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

* Re: [PATCH] fs: use namespace_{lock,unlock} in dissolve_on_fput()
  2025-04-10 15:05 [PATCH] fs: use namespace_{lock,unlock} in dissolve_on_fput() Jan Stancek
  2025-04-11 14:08 ` Christian Brauner
@ 2025-04-11 14:08 ` Christian Brauner
  1 sibling, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2025-04-11 14:08 UTC (permalink / raw)
  To: linux-fsdevel, Jan Stancek; +Cc: Christian Brauner, viro, jack, linux-kernel

On Thu, 10 Apr 2025 17:05:42 +0200, Jan Stancek wrote:
> In commit b73ec10a4587 ("fs: add fastpath for dissolve_on_fput()"),
> the namespace_{lock,unlock} has been replaced with scoped_guard
> using the namespace_sem. This however now also skips processing of
> 'unmounted' list in namespace_unlock(), and mount is not (immediately)
> cleaned up.
> 
> For example, this causes LTP move_mount02 fail:
>     ...
>     move_mount02.c:80: TPASS: invalid-from-fd: move_mount() failed as expected: EBADF (9)
>     move_mount02.c:80: TPASS: invalid-from-path: move_mount() failed as expected: ENOENT (2)
>     move_mount02.c:80: TPASS: invalid-to-fd: move_mount() failed as expected: EBADF (9)
>     move_mount02.c:80: TPASS: invalid-to-path: move_mount() failed as expected: ENOENT (2)
>     move_mount02.c:80: TPASS: invalid-flags: move_mount() failed as expected: EINVAL (22)
>     tst_test.c:1833: TINFO: === Testing on ext3 ===
>     tst_test.c:1170: TINFO: Formatting /dev/loop0 with ext3 opts='' extra opts=''
>     mke2fs 1.47.2 (1-Jan-2025)
>     /dev/loop0 is apparently in use by the system; will not make a filesystem here!
>     tst_test.c:1170: TBROK: mkfs.ext3 failed with exit code 1
> 
> [...]

Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/1] fs: use namespace_{lock,unlock} in dissolve_on_fput()
      https://git.kernel.org/vfs/vfs/c/47a742fd977a

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

* Re: [PATCH] fs: use namespace_{lock,unlock} in dissolve_on_fput()
  2025-04-11 14:08 ` Christian Brauner
@ 2025-04-11 14:20   ` Jan Stancek
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Stancek @ 2025-04-11 14:20 UTC (permalink / raw)
  To: Christian Brauner; +Cc: linux-fsdevel, viro, jack, linux-kernel

On Fri, Apr 11, 2025 at 4:09 PM Christian Brauner <brauner@kernel.org> wrote:
>
> On Thu, Apr 10, 2025 at 05:05:42PM +0200, Jan Stancek wrote:
> > In commit b73ec10a4587 ("fs: add fastpath for dissolve_on_fput()"),
> > the namespace_{lock,unlock} has been replaced with scoped_guard
> > using the namespace_sem. This however now also skips processing of
> > 'unmounted' list in namespace_unlock(), and mount is not (immediately)
> > cleaned up.
>
> Thank you for spotting and fixing this! My bad.
>
> > diff --git a/fs/namespace.c b/fs/namespace.c
> > index 14935a0500a2..ee1fdb3baee0 100644
> > --- a/fs/namespace.c
> > +++ b/fs/namespace.c
> > @@ -1830,6 +1830,8 @@ static inline void namespace_lock(void)
> >       down_write(&namespace_sem);
> >  }
> >
> > +DEFINE_GUARD(namespace_locked, struct rw_semaphore *, namespace_lock(), namespace_unlock())
>
> I'll call that namespace_lock instead if you don't mind.

I don't mind - I used "locked" because it's easier to grep for, when
it has distinct name.

Regards,
Jan


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

end of thread, other threads:[~2025-04-11 14:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-10 15:05 [PATCH] fs: use namespace_{lock,unlock} in dissolve_on_fput() Jan Stancek
2025-04-11 14:08 ` Christian Brauner
2025-04-11 14:20   ` Jan Stancek
2025-04-11 14:08 ` Christian Brauner

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