[lkml]   [2018]   [Apr]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH] x86: Use boot_cpu_has() instead of this_cpu_has() in build_cr3_noflush()
From: Sai Praneeth <>

When the platform supports PCID and if CONFIG_DEBUG_VM is enabled,
build_cr3_noflush() (called via switch_mm()) does a sanity check to see
if X86_FEATURE_PCID is set. Presently, build_cr3_noflush() uses
"this_cpu_has(X86_FEATURE_PCID)" to perform the check but this_cpu_has()
works only after SMP is initialized (i.e. per cpu cpu_info's should be
populated) and this happens to be very late in the boot process (during

As efi_runtime_services() are called during (early) kernel boot time
and run time, modify build_cr3_noflush() to use boot_cpu_has() all the
time. As suggested by Dave, this should be OK because all cpu's have
same capabilities anyways (for x86).

Without this change we see below warning during kernel boot.

WARNING: CPU: 0 PID: 0 at arch/x86/include/asm/tlbflush.h:134
Modules linked in:
CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.16.0-02277-gbc16d4052f1a #1
Hardware name: System manufacturer System Product Name/Z170-K, BIOS 3301
RIP: 0010:load_new_mm_cr3+0x114/0x170
RSP: 0000:ffffffff9b203e38 EFLAGS: 00010046
RAX: 0000000000000000 RBX: ffffffff9b26f5a0 RCX: 0000000000000000
RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffff9b20a000
RBP: ffffffff9b203e90 R08: 0000000000000000 R09: 000000000f63eb29
R10: ffffffff9b203ea8 R11: 00000000c3292018 R12: 0000000000000000
R13: ffffffff9b2e1180 R14: 000000000001ee80 R15: 0000000000000000
FS: 0000000000000000(0000) GS:ffff968df6c00000(0000)
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffff968df6fff000 CR3: 00000004261e6002 CR4: 00000000000606b0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:

Dave also suggested that we put a warning in this_cpu_has() if it's used
early in the boot process. This is still work in progress as it effects

Signed-off-by: Sai Praneeth Prakhya <>
Reported-by: Linus Torvalds <>
Cc: Lee Chun-Yi <>
Cc: Borislav Petkov <>
Cc: Tony Luck <>
Cc: Andy Lutomirski <>
Cc: Michael S. Tsirkin <>
Cc: Ricardo Neri <>
Cc: Matt Fleming <>
Cc: Ard Biesheuvel <>
Cc: Ravi Shankar <>
Cc: Ingo Molnar <>
Cc: Thomas Gleixner <>
Cc: Peter Zijlstra <>
Cc: Andrew Morton <>
Cc: Dave Hansen <>
arch/x86/include/asm/tlbflush.h | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
index 84137c22fdfa..42e040859067 100644
--- a/arch/x86/include/asm/tlbflush.h
+++ b/arch/x86/include/asm/tlbflush.h
@@ -131,7 +131,12 @@ static inline unsigned long build_cr3(pgd_t *pgd, u16 asid)
static inline unsigned long build_cr3_noflush(pgd_t *pgd, u16 asid)
- VM_WARN_ON_ONCE(!this_cpu_has(X86_FEATURE_PCID));
+ /*
+ * Use boot_cpu_has() instead of this_cpu_has() as this function
+ * might be called during early boot. This should work even after
+ * boot because all cpu's have same capabilities anyways.
+ */
+ VM_WARN_ON_ONCE(!boot_cpu_has(X86_FEATURE_PCID));
return __sme_pa(pgd) | kern_pcid(asid) | CR3_NOFLUSH;

 \ /
  Last update: 2018-04-04 21:35    [W:0.040 / U:9.120 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site