[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180215183956.GC30522@ZenIV.linux.org.uk>
Date: Thu, 15 Feb 2018 18:39:57 +0000
From: Al Viro <viro@...IV.linux.org.uk>
To: Enrico Weigelt <lkml@...ux.net>
Cc: Richard Weinberger <richard.weinberger@...il.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: fs_struct refcounting: spinlock vs atomic
On Thu, Feb 15, 2018 at 02:46:19PM +0100, Enrico Weigelt wrote:
> On 15.02.2018 10:14, Richard Weinberger wrote:
> > On Wed, Feb 14, 2018 at 10:13 PM, Enrico Weigelt <lkml@...ux.net> wrote:
> > > Hi folks,
> > >
> > >
> > > in fork.c, a spinlock is held for fs_struct refcounting, while other
> > > places - eg. switch_task_namespaces uses atomic_dec_and_test() on
> > > the nsproxy.
> > >
> > > What's the exact difference here ? Could the atomic counting also used
> > > for fs_struct ?
> >
> > Well, the spinlock protects more than just the counter. So atomic won't do it.
>
> Okay. Is that needed in that case ?
>
> See unshare() syscall:
>
> if (new_fs) {
> fs = current->fs;
> spin_lock(&fs->lock);
> current->fs = new_fs;
> if (--fs->users)
> new_fs = NULL;
> else
> new_fs = fs;
> spin_unlock(&fs->lock);
> }
>
> Seems to me, that we're just refcounting here, and once it went dont to
> zero, nobody else can access it anymore.
Not true. We also assume that once fs_struct has been locked, the number of
tasks with reference to it won't change. See fs/exec.c:check_unsafe_exec(),
for example.
Powered by blists - more mailing lists