public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH REBASED RESEND] x86/cpu: Move early cpu initialization into a separate translation unit
Date: Fri, 22 Jun 2018 18:58:24 +0300	[thread overview]
Message-ID: <20180622155824.npfinfnpidplufad@black.fi.intel.com> (raw)
In-Reply-To: <alpine.DEB.2.21.1806221720500.2402@nanos.tec.linutronix.de>

On Fri, Jun 22, 2018 at 03:35:18PM +0000, Thomas Gleixner wrote:
> On Fri, 22 Jun 2018, Kirill A. Shutemov wrote:
> > On Fri, Jun 22, 2018 at 02:05:47PM +0000, Thomas Gleixner wrote:
> > > On Tue, 12 Jun 2018, Kirill A. Shutemov wrote:
> > > 
> > > > __pgtable_l5_enabled shouldn't be needed after system has booted, we can
> > > > mark it as __initdata, but it requires preparation.
> > > > 
> > > > This patch moves early cpu initialization into a separate translation
> > > > unit. This limits effect of USE_EARLY_PGTABLE_L5 to less code.
> > > > 
> > > > Without the change cpu_init() uses __pgtable_l5_enabled. cpu_init() is
> > > > not __init function and it leads to section mismatch.
> > > > 
> > > > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > > > Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
> > > 
> > > Second thoughts.
> > > 
> > > The only place where __pgtable_l5_enabled() is used in common.c is in
> > > early_identify_cpu() which is marked __init. So how is that section
> > > mismatch triggered?
> > 
> > Yeah, it's not obvious:
> > 
> > cpu_init()
> >   load_mm_ldt()
> >     ldt_slot_va()
> >       LDT_BASE_ADDR
> >         LDT_PGD_ENTRY
> > 	  pgtable_l5_enabled()
> 
> 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.

> So, no. That does not work and the proper fix is:
> 
> -unsigned int __pgtable_l5_enabled __initdata;
> +unsigned int __pgtable_l5_enabled __ro_after_init;
> 
> and make cpu/common.c use the early variant. The extra 4 bytes storage are
> not a problem and cpu_init() is not a fast path at all.

Okay, I'll prepare the patch.

BTW, if we go this path after all, shouldn't we revert these:

  046c0dbec023 ("x86: Mark native_set_p4d() as __always_inline")
  1ea66554d3b0 ("x86/mm: Mark p4d_offset() __always_inline")

?

I can send it as part of the patchset.

-- 
 Kirill A. Shutemov

  reply	other threads:[~2018-06-22 15:58 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 [this message]
2018-06-22 16:16         ` Thomas Gleixner
2018-06-22 16:36           ` Peter Zijlstra
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=20180622155824.npfinfnpidplufad@black.fi.intel.com \
    --to=kirill.shutemov@linux.intel.com \
    --cc=hpa@zytor.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