From: Peter Zijlstra <peterz@infradead.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Ingo Molnar <mingo@redhat.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
LKML <linux-kernel@vger.kernel.org>,
Borislav Petkov <bp@alien8.de>
Subject: Re: [PATCH REBASED RESEND] x86/cpu: Move early cpu initialization into a separate translation unit
Date: Fri, 22 Jun 2018 18:36:35 +0200 [thread overview]
Message-ID: <20180622163635.GO2494@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <alpine.DEB.2.21.1806221809070.2402@nanos.tec.linutronix.de>
On Fri, Jun 22, 2018 at 06:16:05PM +0200, Thomas Gleixner wrote:
> On Fri, 22 Jun 2018, Kirill A. Shutemov wrote:
> > On Fri, Jun 22, 2018 at 03:35:18PM +0000, Thomas Gleixner wrote:
> > > How is that supposed to work correctly?
> > >
> > > start_kernel()
> > > ....
> > > trap_init()
> > > cpu_init()
> > >
> > > ....
> > > check_bugs()
> > > alternative_instructions()
> > >
> > > So the first invocation of cpu_init() on the boot CPU will then use
> > > static_cpu_has() which is not yet initialized proper.
> >
> > Ouch.
> >
> > Is there a way to catch such improper static_cpu_has() users?
> > Silent misbehaviour is risky.
>
> Yes, it is. I don't think we have something in place right now, but we
> should add it definitely. PeterZ ????
So static_cpu_has() _should_ work. That thing is mightily convoluted,
but behold:
| static __always_inline __pure bool _static_cpu_has(u16 bit)
| {
| asm_volatile_goto("1: jmp 6f\n"
| "2:\n"
| ".skip -(((5f-4f) - (2b-1b)) > 0) * "
| "((5f-4f) - (2b-1b)),0x90\n"
<snip magic shite>
| ".section .altinstr_aux,\"ax\"\n"
| "6:\n"
| " testb %[bitnum],%[cap_byte]\n"
| " jnz %l[t_yes]\n"
| " jmp %l[t_no]\n"
| ".previous\n"
| : : [feature] "i" (bit),
| [always] "i" (X86_FEATURE_ALWAYS),
| [bitnum] "i" (1 << (bit & 7)),
| [cap_byte] "m" (((const char *)boot_cpu_data.x86_capability)[bit >> 3])
| : : t_yes, t_no);
| t_yes:
| return true;
| t_no:
| return false;
| }
So by default that emits, before patching:
jmp 6f
'however many single byte NOPs are needed'
.section.altinstr_aux
6: testb %[bitnum],%[cap_byte]
jnz %l[t_yes]
jmp %l[t_no]
.previous
Which is a dynamic test for the bit in the bitmask. Which always works,
irrespective of the alternative patching.
The magic, which I cut out, will rewrite the "jmp 6f, nops" thing to
"jmp %l[y_{yes,no}]" at the alternative patching and we'll loose the
dynamic test, pinning the condition forever more.
next prev parent reply other threads:[~2018-06-22 16:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-12 10:36 [PATCH REBASED RESEND] x86/cpu: Move early cpu initialization into a separate translation unit Kirill A. Shutemov
2018-06-22 14:05 ` Thomas Gleixner
2018-06-22 15:14 ` Kirill A. Shutemov
2018-06-22 15:35 ` Thomas Gleixner
2018-06-22 15:58 ` Kirill A. Shutemov
2018-06-22 16:16 ` Thomas Gleixner
2018-06-22 16:36 ` Peter Zijlstra [this message]
2018-06-22 16:50 ` Thomas Gleixner
2018-06-22 17:43 ` Borislav Petkov
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=20180622163635.GO2494@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--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