LKML Archive on lore.kernel.org
 help / color / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	"Wulsch, Siegfried" <Siegfried.Wulsch@rovema.de>
Subject: Re: [PATCH] sched_clock: Prevent 64bit inatomicity on 32bit systems
Date: Sat, 06 Apr 2013 18:28:57 +0200
Message-ID: <1365265737.2609.138.camel@laptop> (raw)
In-Reply-To: <alpine.LFD.2.02.1304051544160.21884@ionos>

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@chello.nl>


  reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-06  8:10 Thomas Gleixner
2013-04-06 16:28 ` Peter Zijlstra [this message]
2013-04-08 10:24 ` [tip:sched/urgent] " tip-bot for Thomas Gleixner
2013-04-09  0:31 ` [PATCH] " Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1365265737.2609.138.camel@laptop \
    --to=peterz@infradead.org \
    --cc=Siegfried.Wulsch@rovema.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git
	git clone --mirror https://lore.kernel.org/lkml/9 lkml/git/9.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git