[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20150316124544.GG15066@leverpostej>
Date: Mon, 16 Mar 2015 12:45:45 +0000
From: Mark Rutland <mark.rutland@....com>
To: Christoph Lameter <cl@...ux.com>
Cc: "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Catalin Marinas <Catalin.Marinas@....com>,
David Rientjes <rientjes@...gle.com>,
Jesper Dangaard Brouer <brouer@...hat.com>,
Joonsoo Kim <iamjoonsoo.kim@....com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Pekka Enberg <penberg@...nel.org>,
Steve Capper <steve.capper@...aro.org>
Subject: [PATCHv2] mm/slub: fix lockups on PREEMPT && !SMP kernels
On Fri, Mar 13, 2015 at 04:29:23PM +0000, Christoph Lameter wrote:
> On Fri, 13 Mar 2015, Mark Rutland wrote:
>
> > */
> > - do {
> > - tid = this_cpu_read(s->cpu_slab->tid);
> > - c = raw_cpu_ptr(s->cpu_slab);
> > - } while (IS_ENABLED(CONFIG_PREEMPT) && unlikely(tid != c->tid));
> > + c = raw_cpu_ptr(s->cpu_slab);
> > + tid = READ_ONCE(c->tid);
> >
>
> Ok that works for the !SMP case. What about SMP and PREEMPT now?
>
> And yes code like this was deemed safe for years and the race condition is
> very subtle and difficult to trigger (also given that PREEMPT is rarely
> used these days).
Do you mean if the READ_ONCE(c->tid) gives us a torn value that happens
to be a future value of c->tid?
Are you happy to retain the loop, but with the c->tid access replaced
with READ_ONCE(c->tid)?
If torn values are an issue for the raw access then the loop doesn't
guarantee that c and tid were read on the same CPU as the comment above
it implies. The cmpxchg saves us given the torn value would have to
match some currently active tid, and I guess the loop saves a pointless
cmpxchg when it does detect a mismatch.
Mark.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists