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]
Message-ID: <AANLkTil84IIgzlPcycNWJFRpZIGRqTFL6FGffzqOaSEx@mail.gmail.com>
Date:	Fri, 11 Jun 2010 13:07:55 -0700
From:	Linus Torvalds <torvalds@...ux-foundation.org>
To:	Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
Cc:	paulmck@...ux.vnet.ibm.com, linux-kernel@...r.kernel.org
Subject: Re: sequence lock in Linux

On Fri, Jun 11, 2010 at 12:40 PM, Mathieu Desnoyers
<mathieu.desnoyers@...icios.com> wrote:
>
> Is it just me, or the following code:
>
> static __always_inline unsigned read_seqbegin(const seqlock_t *sl)
> {
>        unsigned ret;
>
> repeat:
>        ret = sl->sequence;
>        smp_rmb();
>        if (unlikely(ret & 1)) {
>                cpu_relax();
>                goto repeat;
>        }
>
>        return ret;
> }
>
> could use a ACCESS_ONCE() around the sl->sequence read ? I'm concerned about the
> compiler generating code that reads the sequence number chunkwise.

What compiler would do that? That would seem to be a compiler bug, or
a compiler that is just completely crazy.

But it wouldn't be _wrong_ to make it do ACCESS_ONCE(). I just suspect
that any compiler that cares is not a compiler worth worrying about,
and the compiler should be shot in the head rather than us necessarily
worrying about it.

There is no way a sane compiler can do anything but one read anyway.
We do end up using all the bits (for the "return ret") part, so a
compiler that reads the low bit separately is just being a totally
moronic one - we wouldn't want to touch such a stupid compiler with a
ten-foot pole.

But at the same time, ACCESS_ONCE() ends up being a reasonable hint to
programmers, so I wouldn't object to it. I just don't think we should
pander to "compilers can be crazy". If compilers are crazy, we
shouldn't use them.

                 Linus
--
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

Powered by Openwall GNU/*/Linux Powered by OpenVZ