fs/namespace: notify pollers of legacy propagation changes
PATCH 1/1 fs/namespace: notify pollers of legacy propagation changes
From: Guopeng Zhang <[email protected]>
Changing mount propagation through the legacy mount API changes user-visible mountinfo contents, including the shared: and master:
optional fields.
The mount_setattr() path already touches the mount namespace after change_mnt_propagation(), so pollers of /proc/<pid>/mountinfo are woken when the namespace event changes.
The legacy mount --make-* path also changes propagation through change_mnt_propagation(), and MOVE_MOUNT_SET_GROUP updates the propagation relationship of the target mount. Both paths currently return without touching the affected mount namespace.
As a result, userspace polling /proc/<pid>/mountinfo can miss these propagation-only changes even though mountinfo has changed.
A simple reproducer that polls /proc/self/mountinfo while changing propagation shows the inconsistency.
Before this change:
legacy MS_SHARED: poll ret=0 revents=0x0
mount_setattr MS_SHARED: poll ret=1 revents=0xa
After this change:
legacy MS_SHARED: poll ret=1 revents=0xa
mount_setattr MS_SHARED: poll ret=1 revents=0xa
Touch the affected mount namespace after successfully changing propagation state in do_change_type() and do_set_group(). Take the vfsmount lock for write around touch_mnt_namespace(), as required by its locking rules.
--- fs/namespace.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/namespace.c +9 -0
@@ -2908,6 +2908,10 @@ static int do_change_type(const struct path *path, int ms_flags)for (m = mnt; m; m = (recurse ?next_mnt (m, mnt) :NULL ))change_mnt_propagation (m, type); +lock_mount_hash (); +touch_mnt_namespace (mnt->mnt_ns); +unlock_mount_hash (); +return 0 ; }
@@ -3479,6 +3483,11 @@ static int do_set_group(const struct path *from_path, const struct path *to_pathlist_add (&to->mnt_share, &from->mnt_share);set_mnt_shared (to); } + +lock_mount_hash (); +touch_mnt_namespace (to->mnt_ns); +unlock_mount_hash (); +return 0 ; }
Signature · 1 line
2.43.0
Christian Brauner
maintainerQuoted 57 lines · Guopeng Zhang
From: Guopeng Zhang <[email protected]>
Changing mount propagation through the legacy mount API changes user-visible mountinfo contents, including the shared: and master:
optional fields.The
mount_setattr()path already touches the mount namespace afterchange_mnt_propagation(), so pollers of /proc/<pid>/mountinfo are woken when the namespace event changes.The legacy mount --make-* path also changes propagation through
change_mnt_propagation(), andMOVE_MOUNT_SET_GROUPupdates the propagation relationship of the target mount. Both paths currently return without touching the affected mount namespace.As a result, userspace polling /proc/<pid>/mountinfo can miss these propagation-only changes even though mountinfo has changed.
A simple reproducer that polls
/proc/self/mountinfowhile changing propagation shows the inconsistency.Before this change:
legacy
MS_SHARED: poll ret=0 revents=0x0
mount_setattrMS_SHARED: poll ret=1 revents=0xaAfter this change:
legacy
MS_SHARED: poll ret=1 revents=0xa
mount_setattrMS_SHARED: poll ret=1 revents=0xaTouch the affected mount namespace after successfully changing propagation state in
do_change_type()anddo_set_group(). Take the vfsmount lock for write aroundtouch_mnt_namespace(), as required by its locking rules.Signed-off-by Guopeng Zhang <[email protected]>--- fs/namespace.c | 9 +++++++++ 1 file changed, 9 insertions(+)fs/namespace.c +4
-0@@ -2908,6 +2908,10 @@ static int do_change_type(const struct path *path, int ms_flags)for (m = mnt; m; m = (recurse ?next_mnt (m, mnt) :NULL ))change_mnt_propagation (m, type); +lock_mount_hash (); +touch_mnt_namespace (mnt->mnt_ns); +unlock_mount_hash (); +return 0 ; }
fs/namespace.c static int do_set_group(const struct path *from_path, const struct path *to_path · line 3489
Quoted 7 lines
fs/namespace.c +4
-0@@ -3479,6 +3483,11 @@ static int do_set_group(const struct path *from_path, const struct path *to_pathlist_add (&to->mnt_share, &from->mnt_share);set_mnt_shared (to); } + +lock_mount_hash (); +touch_mnt_namespace (to->mnt_ns); +unlock_mount_hash ();
Doing this would cause seqcount readers to retry on mount propagation changes when all of them really only care about mount topology changes. So this can likely use:
guard(mount_locked_reader)();touch_mnt_namespace(mnt_ns);
Even today, observing an unchanged seqcount across mnt->mnt_flags reads doesn't guarantee that it really wasn't changed.
Quoted 70 lines · Christian Brauner
Quoted 57 lines · Guopeng Zhang
From: Guopeng Zhang <[email protected]>
Changing mount propagation through the legacy mount API changes user-visible mountinfo contents, including the shared: and master:
optional fields.The
mount_setattr()path already touches the mount namespace afterchange_mnt_propagation(), so pollers of /proc/<pid>/mountinfo are woken when the namespace event changes.The legacy mount --make-* path also changes propagation through
change_mnt_propagation(), andMOVE_MOUNT_SET_GROUPupdates the propagation relationship of the target mount. Both paths currently return without touching the affected mount namespace.As a result, userspace polling /proc/<pid>/mountinfo can miss these propagation-only changes even though mountinfo has changed.
A simple reproducer that polls
/proc/self/mountinfowhile changing propagation shows the inconsistency.Before this change:
legacy
MS_SHARED: poll ret=0 revents=0x0
mount_setattrMS_SHARED: poll ret=1 revents=0xaAfter this change:
legacy
MS_SHARED: poll ret=1 revents=0xa
mount_setattrMS_SHARED: poll ret=1 revents=0xaTouch the affected mount namespace after successfully changing propagation state in
do_change_type()anddo_set_group(). Take the vfsmount lock for write aroundtouch_mnt_namespace(), as required by its locking rules.Signed-off-by Guopeng Zhang <[email protected]>--- fs/namespace.c | 9 +++++++++ 1 file changed, 9 insertions(+)fs/namespace.c +4
-0@@ -2908,6 +2908,10 @@ static int do_change_type(const struct path *path, int ms_flags)for (m = mnt; m; m = (recurse ?next_mnt (m, mnt) :NULL ))change_mnt_propagation (m, type); +lock_mount_hash (); +touch_mnt_namespace (mnt->mnt_ns); +unlock_mount_hash (); +return 0 ; }fs/namespace.c static int do_set_group(const struct path *from_path, const struct path *to_path · line 3489
Quoted 7 lines
fs/namespace.c +4
-0@@ -3479,6 +3483,11 @@ static int do_set_group(const struct path *from_path, const struct path *to_pathlist_add (&to->mnt_share, &from->mnt_share);set_mnt_shared (to); } + +lock_mount_hash (); +touch_mnt_namespace (to->mnt_ns); +unlock_mount_hash ();Doing this would cause seqcount readers to retry on mount propagation changes when all of them really only care about mount topology changes. So this can likely use:
Quoted 5 lines
guard(mount_locked_reader)();
touch_mnt_namespace(mnt_ns);Even today, observing an unchanged seqcount across
mnt->mnt_flagsreads doesn't guarantee that it really wasn't changed.
Hi Christian,
Thanks for the review and explanation.
I will send a v2 with the suggested changes.
Thanks,
Guopeng