lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 27 Jun 2018 20:33:05 +0300
From:   Andy Shevchenko <andy.shevchenko@...il.com>
To:     Peter Zijlstra <peterz@...radead.org>
Cc:     Mark Rutland <mark.rutland@....com>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Will Deacon <will.deacon@....com>,
        Boqun Feng <boqun.feng@...il.com>,
        Peter Hurley <peter@...leysoftware.com>
Subject: Re: [PATCHv2 01/11] atomic/tty: Fix up atomic abuse in ldsem

On Tue, Jun 26, 2018 at 10:30 PM, Peter Zijlstra <peterz@...radead.org> wrote:
> On Tue, Jun 26, 2018 at 09:53:18PM +0300, Andy Shevchenko wrote:
>> On Mon, Jun 25, 2018 at 1:59 PM, Mark Rutland <mark.rutland@....com> wrote:
>> > From: Peter Zijlstra <peterz@...radead.org>
>> >
>> > Mark found ldsem_cmpxchg() needed an (atomic_long_t *) cast to keep
>> > working after making the atomic_long interface type safe.
>> >
>> > Needing casts is bad form, which made me look at the code. There are no
>> > ld_semaphore::count users outside of these functions so there is no
>> > reason why it can not be an atomic_long_t in the first place, obviating
>> > the need for this cast.
>> >
>> > That also ensures the loads use atomic_long_read(), which implies (at
>> > least) READ_ONCE() in order to guarantee single-copy-atomic loads.
>> >
>> > When using atomic_long_try_cmpxchg() the ldsem_cmpxchg() wrapper gets
>> > very thin (the only difference is not changing *old on success, which
>> > most callers don't seem to care about).
>> >
>> > So rework the whole thing to use atomic_long_t and its accessors
>> > directly.
>> >
>> > While there, fixup all the horrible comment styles.
>>
>>
>> > -               ldsem_atomic_update(-LDSEM_WAIT_BIAS, sem);
>> > +               atomic_long_add_return(-LDSEM_WAIT_BIAS, &sem->count);
>>
>> I suppose it's simple atomic_long_add() here?
>
> Different ordering rules for those two. I didn't look hard enough to see
> if that mattered here.

Indeed. So, to follow semantics it would be something like

smp_mb__before_atomic();
atomic_long_add_relaxed();
smp_mb__after_atomic();

though I do not dare to convert that way (as I understood the simple
atomic_long_add_return() variant might be implemented better).

-- 
With Best Regards,
Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ