lkml.org 
[lkml]   [2019]   [Nov]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRE: [patch V2 11/16] x86/ioperm: Share I/O bitmap if identical
On Thu, 14 Nov 2019, David Laight wrote:
> From: Peter Zijlstra
> > Sent: 12 November 2019 09:15
> ...
> > > + /*
> > > + * If the bitmap is not shared, then nothing can take a refcount as
> > > + * current can obviously not fork at the same time. If it's shared
> > > + * duplicate it and drop the refcount on the original one.
> > > + */
> > > + if (refcount_read(&iobm->refcnt) > 1) {
> > > + iobm = kmemdup(iobm, sizeof(*iobm), GFP_KERNEL);
> > > + if (!iobm)
> > > + return -ENOMEM;
> > > + io_bitmap_exit();
> > refcount_set(&iobm->refcnt, 1);
> > > }
>
> What happens if two threads of the same process enter the above
> at the same time?
> (I've not looked for a lock, but since kmemdup() can sleep I'd suspect there isn't one.)
>
> Also can another thread call fork() - eg while the kmemdup() is sleeping?

That's not a problem at all. The io bitmap which is duplicated can neither
be modified nor freed while the duplication is in progress. That's what the
refcount is for. The threads drop their refcount _after_ duplication.

And fork is not a problem either because that just increments the refcount.

Thanks,

tglx


\
 
 \ /
  Last update: 2019-11-14 13:40    [W:0.163 / U:0.996 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site