Re: [PATCH] vfs: document locking for mnt_notify_add()
From: Jann Horn
Date: Tue Jun 02 2026 - 11:42:52 EST
On Tue, Jun 2, 2026 at 3:14 PM Christian Brauner <brauner@xxxxxxxxxx> wrote:
> On Fri, May 29, 2026 at 09:38:08PM +0200, Jann Horn wrote:
> > To allow mnt_notify_add() to reference the namespace_sem, move it into
> > fs/namespace.c.
> >
> > Signed-off-by: Jann Horn <jannh@xxxxxxxxxx>
> > ---
> > I'm sending this patch because I spent some time staring at this
> > trying to figure out if this was buggy or not.
> >
> > I don't know if this is working as intended or working by accident,
> > and it might be nice if this was cleaned up to have simpler locking;
>
> The locking is rather simple: namespace_sem. But maybe I misunderstand.
> It just piggy-backs on the same logic as mnt_add_to_ns() in that
> mnt_add_to_ns() may be called to add mount into a newly allocated
> namespaces without namespace semaphore held. So the locking context is
> guaranteed by mnt_add_to_ns(). To put another way: if you have quarrels
> with mnt_notify_add() you likely also have quarrels with the contextual
> locking of mnt_add_to_ns().
Ah, okay, thanks for the explanation. Yeah, I guess I just didn't
understand the larger context of what's going on here.