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


Groups > linux.kernel > #1434816

Re: [PATCH 1/2] ipc/sem.c: Fix complex_count vs. simple op race

From Manfred Spraul <manfred@colorfullife.com>
Newsgroups linux.kernel
Subject Re: [PATCH 1/2] ipc/sem.c: Fix complex_count vs. simple op race
Date 2016-06-30 21:50 +0200
Message-ID <rPQ8h-5co-5@gated-at.bofh.it> (permalink)
References <rKbyN-6Lx-13@gated-at.bofh.it> <rLuJ3-kK-9@gated-at.bofh.it> <rMhTr-6TQ-5@gated-at.bofh.it> <rNiu6-68M-31@gated-at.bofh.it> <rOTKV-2x9-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 06/28/2016 07:27 AM, Davidlohr Bueso wrote:
> On Thu, 23 Jun 2016, Manfred Spraul wrote:
>
>> What I'm not sure yet is if smp_load_acquire() is sufficient:
>>
>> Thread A:
>>>       if (!READ_ONCE(sma->complex_mode)) {
>> The code is test_and_test, no barrier requirements for first test
>
> Yeah, it would just make us take the big lock unnecessarily, nothing 
> fatal
> and I agree its probably worth the optimization. It still might be worth
> commenting.
>
I'll extend the comment: "no locking and no memory barrier"
>>>                /*
>>>                 * It appears that no complex operation is around.
>>>                 * Acquire the per-semaphore lock.
>>>                 */
>>>                spin_lock(&sem->lock);
>>>
>>>                if (!smp_load_acquire(&sma->complex_mode)) {
>>>                        /* fast path successful! */
>>>                        return sops->sem_num;
>>>                }
>>>                spin_unlock(&sem->lock);
>>>        }
>>
>> Thread B:
>>>       WRITE_ONCE(sma->complex_mode, true);
>>>
>>>        /* We need a full barrier:
>>>         * The write to complex_mode must be visible
>>>         * before we read the first sem->lock spinlock state.
>>>         */
>>>        smp_mb();
>>>
>>>        for (i = 0; i < sma->sem_nsems; i++) {
>>>                sem = sma->sem_base + i;
>>>                spin_unlock_wait(&sem->lock);
>>>        }
>>
>> If thread A is allowed to issue read_spinlock;read complex_mode;write 
>> spinlock, then thread B would not notice that thread A is in the 
>> critical section
>
> Are you referring to the sem->lock word not being visibly locked 
> before we
> read complex_mode (for the second time)? This issue was fixed in 
> 2c610022711
> (locking/qspinlock: Fix spin_unlock_wait() some more). So 
> smp_load_acquire
> should be enough afaict, or are you referring to something else?
>
You are right, I didn't read this patch fully.
If I understand it right, it means that spin_lock() is both an acquire 
and a release - for qspinlocks.

It this valid for all spinlock implementations, for all architectures?
Otherwise: How can I detect in generic code if I can rely on a release 
inside spin_lock()?

--
     Manfred

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


Thread

Re: [PATCH 1/2] ipc/sem.c: Fix complex_count vs. simple op race Manfred Spraul <manfred@colorfullife.com> - 2016-06-23 21:30 +0200
  Re: [PATCH 1/2] ipc/sem.c: Fix complex_count vs. simple op race Davidlohr Bueso <dave@stgolabs.net> - 2016-06-28 07:30 +0200
    Re: [PATCH 1/2] ipc/sem.c: Fix complex_count vs. simple op race Manfred Spraul <manfred@colorfullife.com> - 2016-06-30 21:50 +0200
      Re: [PATCH 1/2] ipc/sem.c: Fix complex_count vs. simple op race Davidlohr Bueso <dave@stgolabs.net> - 2016-07-01 19:00 +0200

csiph-web