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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1365265737.2609.138.camel@laptop>
Date:	Sat, 06 Apr 2013 18:28:57 +0200
From:	Peter Zijlstra <peterz@...radead.org>
To:	Thomas Gleixner <tglx@...utronix.de>
Cc:	LKML <linux-kernel@...r.kernel.org>,
	Ingo Molnar <mingo@...nel.org>,
	"H. Peter Anvin" <hpa@...or.com>,
	Steven Rostedt <rostedt@...dmis.org>,
	"Wulsch, Siegfried" <Siegfried.Wulsch@...ema.de>
Subject: Re: [PATCH] sched_clock: Prevent 64bit inatomicity on 32bit systems

On Sat, 2013-04-06 at 10:10 +0200, Thomas Gleixner wrote:
> Index: linux-stable/kernel/sched/clock.c
> ===================================================================
> --- linux.orig/kernel/sched/clock.c
> +++ linux/kernel/sched/clock.c
> @@ -176,10 +176,36 @@ static u64 sched_clock_remote(struct sch
>         u64 this_clock, remote_clock;
>         u64 *ptr, old_val, val;
>  
> +#if BITS_PER_LONG != 64
> +again:
> +       /*
> +        * Careful here: The local and the remote clock values need to
> +        * be read out atomic as we need to compare the values and
> +        * then update either the local or the remote side. So the
> +        * cmpxchg64 below only protects one readout.
> +        *
> +        * We must reread via sched_clock_local() in the retry case on
> +        * 32bit as an NMI could use sched_clock_local() via the
> +        * tracer and hit between the readout of
> +        * the low32bit and the high 32bit portion.
> +        */
> +       this_clock = sched_clock_local(my_scd);
> +       /*
> +        * We must enforce atomic readout on 32bit, otherwise the
> +        * update on the remote cpu can hit inbetween the readout of
> +        * the low32bit and the high 32bit portion.
> +        */
> +       remote_clock = cmpxchg64(&scd->clock, 0, 0);
> +#else
> +       /*
> +        * On 64bit the read of [my]scd->clock is atomic versus the
> +        * update, so we can avoid the above 32bit dance.
> +        */
>         sched_clock_local(my_scd);
>  again:
>         this_clock = my_scd->clock;
>         remote_clock = scd->clock;
> +#endif

Yeah, I like your version better.. just before reading your email I
realized I could use the return value of sched_clock_local() to avoid a
cmpxchg64() :-)

That said, with this there's a subtle behavioural change between 32 and
64 bits with your patch; see how 32bit has sched_clock_local() inside
the retry loop whereas 64 bit does not.

Not sure we should worry about that though.

Thanks!

Acked-by: Peter Zijlstra <a.p.zijlstra@...llo.nl>

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