Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1353162

Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic

From Vineet Gupta <vgupta@synopsys.com>
Newsgroups linux.kernel
Subject Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic
Date 2016-03-08 16:50 +0100
Message-ID <ras3w-2Le-35@gated-at.bofh.it> (permalink)
References <raqXM-25J-23@gated-at.bofh.it> <rarqO-2vx-23@gated-at.bofh.it>
Organization Synopsys

Show all headers | View raw


On Tuesday 08 March 2016 08:30 PM, Christoph Lameter wrote:
> On Tue, 8 Mar 2016, Vineet Gupta wrote:
> 
>> This in turn happened because slab_unlock() doesn't serialize properly
>> (doesn't use atomic clear) with a concurrent running
>> slab_lock()->test_and_set_bit()
> 
> This is intentional because of the increased latency of atomic
> instructions. Why would the unlock need to be atomic? This patch will
> cause regressions.
> 
> Guess this is an architecture specific issue of modified
> cachelines not becoming visible to other processors?

Absolutely not - we verified with the hardware coherency tracing that there was no
foul play there. And I would dare not point finger at code which was last updated
in 2011 w/o being absolutely sure.

Let me explain this in bit more detail. Like I mentioned in commitlog, this config
of ARC doesn't have exclusive load/stores (LLOCK/SCOND) so atomic ops are
implemented using a "central" spin lock. The spin lock itself is implemented using
EX instruction (atomic R-W)

Generated code for slab_lock() - essentially bit_spin_lock() is below (I've
removed generated code for CONFIG_PREEMPT for simplicity)

80543b0c <slab_lock>:
80543b0c:	push_s     blink
...
80543b3a:	mov_s      r15,0x809de168   <-- @smp_bitops_lock
80543b40:	mov_s      r17,1
80543b46:	mov_s      r16,0

# spin lock() inside test_and_set_bit() - see arc bitops.h (!LLSC code)
80543b78:	clri       r4
80543b7c:	dmb        3
80543b80:	mov_s      r2,r17
80543b82:	ex         r2,[r15]
80543b86:	breq       r2,1,80543b82
80543b8a:	dmb        3

# set the bit
80543b8e:	ld_s       r2,[r13,0] <--- (A) Finds PG_locked is set
80543b90:	or         r3,r2,1    <--- (B) other core unlocks right here
80543b94:	st_s       r3,[r13,0] <--- (C) sets PG_locked (overwrites unlock)

# spin_unlock
80543b96:	dmb        3
80543b9a:	mov_s      r3,r16
80543b9c:	ex         r3,[r15]
80543ba0:	dmb        3
80543ba4:	seti       r4

# check the old bit
80543ba8:	bbit0      r2,0,80543bb8   <--- bit was set, branch not taken
80543bac:	b_s        80543b68        <--- enter the test_bit() loop

   80543b68:	ld_s       r2,[r13,0]	   <-- (C) reads the bit, set by SELF
   80543b6a:	bbit1    r2,0,80543b68              spins infinitely

...


Now using hardware coherency tracing (and using the cycle timestamps) we verified
(A) and (B)

Thing is with exclusive load/store this race can't just happen since the
intervening ST will cause the ST in (C) to NOT commit and the LD/ST will be retried.

And there will be very few production systems which are SMP but lack exclusive
load/stores.

Are you convinced now !

-Vineet

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] mm: slub: Ensure that slab_unlock() is atomic Vineet Gupta <Vineet.Gupta1@synopsys.com> - 2016-03-08 15:40 +0100
  Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic Christoph Lameter <cl@linux.com> - 2016-03-08 16:10 +0100
    Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic Vineet Gupta <vgupta@synopsys.com> - 2016-03-08 16:50 +0100
      Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic Christoph Lameter <cl@linux.com> - 2016-03-08 21:50 +0100
        Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic Vineet Gupta <Vineet.Gupta1@synopsys.com> - 2016-03-09 07:50 +0100
          Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic Peter Zijlstra <peterz@infradead.org> - 2016-03-09 11:20 +0100
            Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic Peter Zijlstra <peterz@infradead.org> - 2016-03-09 11:40 +0100
              Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic Vineet Gupta <Vineet.Gupta1@synopsys.com> - 2016-03-09 12:20 +0100
            Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic Vineet Gupta <Vineet.Gupta1@synopsys.com> - 2016-03-09 12:10 +0100
              Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic Peter Zijlstra <peterz@infradead.org> - 2016-03-09 12:50 +0100
                Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic Vineet Gupta <Vineet.Gupta1@synopsys.com> - 2016-03-09 13:00 +0100
                Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic Peter Zijlstra <peterz@infradead.org> - 2016-03-09 13:30 +0100
                Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic Vineet Gupta <Vineet.Gupta1@synopsys.com> - 2016-03-14 09:10 +0100
            Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic Vineet Gupta <Vineet.Gupta1@synopsys.com> - 2016-03-09 14:30 +0100
              Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic Peter Zijlstra <peterz@infradead.org> - 2016-03-09 16:00 +0100
                Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic Vineet Gupta <Vineet.Gupta1@synopsys.com> - 2016-03-10 07:00 +0100
                Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic Peter Zijlstra <peterz@infradead.org> - 2016-03-10 10:20 +0100
  Re: [PATCH] mm: slub: Ensure that slab_unlock() is atomic Vlastimil Babka <vbabka@suse.cz> - 2016-03-08 16:40 +0100

csiph-web