From: Peter Zijlstra <peterz@infradead.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Jan Kiszka <jan.kiszka@siemens.com>, x86 <x86@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: Re: x2apic_wrmsr_fence vs. Intel manual
Date: Mon, 2 Mar 2020 17:35:16 +0100 [thread overview]
Message-ID: <20200302163516.GB2579@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <87lfoienjp.fsf@nanos.tec.linutronix.de>
On Mon, Mar 02, 2020 at 05:20:26PM +0100, Thomas Gleixner wrote:
> Jan Kiszka <jan.kiszka@siemens.com> writes:
> > as I generated a nice bug around fence vs. x2apic icr writes, I studied
> > the kernel code and the Intel manual in this regard more closely. But
> > there is a discrepancy:
> >
> > arch/x86/include/asm/apic.h:
> >
> > /*
> > * Make previous memory operations globally visible before
> > * sending the IPI through x2apic wrmsr. We need a serializing instruction or
> > * mfence for this.
> > */
> > static inline void x2apic_wrmsr_fence(void)
> > {
> > asm volatile("mfence" : : : "memory");
> > }
> >
> > Intel SDM, 10.12.3 MSR Access in x2APIC Mode:
> >
> > "A WRMSR to an APIC register may complete before all preceding stores
> > are globally visible; software can prevent this by inserting a
> > serializing instruction or the sequence MFENCE;LFENCE before the WRMSR."
> >
> > The former dates back to ce4e240c279a, but that commit does not mention
> > why lfence is not needed. Did the manual read differently back then? Or
> > why are we safe? To my reading of lfence, it also has a certain
> > instruction serializing effect that mfence does not have.
>
> The 2011 SDM says:
>
> A WRMSR to an APIC register may complete before all preceding stores
> are globally visible; software can prevent this by inserting a
> serializing instruction, an SFENCE, or an MFENCE before the WRMSR.
>
> Sigh....
*groan*, The only way I can explain this is...
... because we changed the definition of LFENCE from:
- wait until completion of all prior LOADs
to
- wait until completion of all prior instructions
Because Spectre (and because apparently it was implemented that way,
mostly). It could be that MFENCE, which is basically a completion
barrier for all prior LOADs *AND* STOREs, is no longer a stict superset
of LFENCE anymore...
Which makes the otherwise perverted sequence: MFENCE;LFENCE, actually
mean something :/
la-la-la
Would be good to have that clarified though.
next prev parent reply other threads:[~2020-03-02 16:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-02 16:11 Jan Kiszka
2020-03-02 16:20 ` Thomas Gleixner
2020-03-02 16:33 ` Jan Kiszka
2020-03-02 16:35 ` Peter Zijlstra [this message]
2020-03-04 18:27 ` Dave Hansen
2020-03-04 18:39 ` Jan Kiszka
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=20200302163516.GB2579@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=hpa@zytor.com \
--cc=jan.kiszka@siemens.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®