lkml.org 
[lkml]   [2019]   [Nov]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [patch V2 11/16] x86/ioperm: Share I/O bitmap if identical
Date
From: Peter Zijlstra <peterz@infradead.org>
> On Thu, Nov 14, 2019 at 11:02:01AM +0000, 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->refcnd, 1);
> > > > }
> >
> > What happens if two threads of the same process enter the above
> > at the same time?
>
> Suppose there's just the two threads, and both will change it. Then both
> do copy-on-write and the original gets freed.

I was probably forgetting that the linux kernel uses (more or less) full 'process'
structures for threads, rather than separate 'thread' data areas.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

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