From: Dave Hansen <dave.hansen@intel.com>
To: "Xin Li (Intel)" <xin@zytor.com>, linux-kernel@vger.kernel.org
Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
peterz@infradead.org, andrew.cooper3@citrix.com,
sohil.mehta@intel.com, nikunj@amd.com, thomas.lendacky@amd.com,
seanjc@google.com, stable@vger.kernel.org
Subject: Re: [PATCH v1] x86/smp: Set up exception handling before cr4_init()
Date: Fri, 6 Feb 2026 11:19:35 -0800 [thread overview]
Message-ID: <a7be319d-381f-469d-9d5b-ddcf43d884e4@intel.com> (raw)
In-Reply-To: <20260206185035.1250577-1-xin@zytor.com>
> + /*
> + * AP startup assembly code has setup the following before calling
> + * start_secondary() on 64-bit:
> + *
> + * 1) CS set to __KERNEL_CS.
> + * 2) CR3 switched to the init_top_pgt.
> + * 3) CR4.PAE, CR4.PSE and CR4.PGE are set.
> + * 4) GDT set to per-CPU gdt_page.
> + * 5) ALL data segments set to the NULL descriptor.
> + * 6) MSR_GS_BASE set to per-CPU offset.
> + * 7) IDT set to bringup IDT.
> + * 8) CR0 set to CR0_STATE.
> + *
> + * So it's ready to setup exception handling.
> + */
> cpu_init_exception_handling(false);
This is fine because very little of that ^ is ever going to change. It's
not great that it duplicates the assembly logic, but it's good
documentation I guess.
> + /*
> + * Ensure bits set in cr4_pinned_bits are set in CR4.
> + *
> + * cr4_pinned_bits is a subset of cr4_pinned_mask, which includes
> + * the following bits:
> + * X86_CR4_SMEP
> + * X86_CR4_SMAP
> + * X86_CR4_UMIP
> + * X86_CR4_FSGSBASE
> + * X86_CR4_CET
> + * X86_CR4_FRED
> + */
> + cr4_init();
I'm not as big of a fan of this comment. The next pinned bit that gets
added will make this stale. Could we try to make this more timeless, please?
I'm also not sure I like the asymmetry of this between the boot and
secondary CPUs. On a boot CPU, CR4.SMEP will get set via
identify_boot_cpu() and eventually setup_smep(). On a secondary CPU,
it'll get set in cr4_init() and *not* in setup_smep().
This asymmetry is (I think) part of what the root of the problem is here
and how this bug came to be.
I really think the current pinning behavior is too invasive. It has zero
benefit to be pinning CR bits this early in bringup. It's only causing pain.
I _really_ think we need a defined per-cpu point where pinning comes
into effect. Marking the CPU online is one idea.
Thoughts?
next prev parent reply other threads:[~2026-02-06 19:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-06 18:50 Xin Li (Intel)
2026-02-06 19:19 ` Dave Hansen [this message]
2026-02-08 19:02 ` Xin Li
2026-02-09 7:28 ` Sohil Mehta
2026-02-09 8:16 ` Xin Li
2026-02-09 15:14 ` Dave Hansen
2026-02-10 0:18 ` Sohil Mehta
2026-02-10 1:13 ` Dave Hansen
2026-02-10 3:11 ` Xin Li
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=a7be319d-381f-469d-9d5b-ddcf43d884e4@intel.com \
--to=dave.hansen@intel.com \
--cc=andrew.cooper3@citrix.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=nikunj@amd.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
--cc=sohil.mehta@intel.com \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
--cc=xin@zytor.com \
/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®