Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758917AbeAIXJ6 (ORCPT + 1 other); Tue, 9 Jan 2018 18:09:58 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:53712 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757295AbeAIXJ5 (ORCPT ); Tue, 9 Jan 2018 18:09:57 -0500 Date: Wed, 10 Jan 2018 00:09:47 +0100 (CET) From: Thomas Gleixner To: Tom Lendacky cc: x86@kernel.org, linux-kernel@vger.kernel.org, Rik van Riel , Andi Kleen , Peter Zijlstra , Linus Torvalds , Jiri Kosina , Dan Williams , Dave Hansen , Borislav Petkov , Andy Lutomirski , Kees Cook , Tim Chen , Greg Kroah-Hartman , David Woodhouse , Paul Turner Subject: Re: [PATCH v1 1/2] x86/retpoline: Add a function to clear the RETPOLINE_AMD feature In-Reply-To: <12147db9-e975-268f-55ee-247868e0e0d8@amd.com> Message-ID: References: <20180109223723.29322.59126.stgit@tlendack-t1.amdoffice.net> <20180109223736.29322.5436.stgit@tlendack-t1.amdoffice.net> <12147db9-e975-268f-55ee-247868e0e0d8@amd.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On Tue, 9 Jan 2018, Tom Lendacky wrote: > On 1/9/2018 4:46 PM, Thomas Gleixner wrote: > > Urgh. That's an awful hack. why not do the obvious? > > My first attempt was very similar to your change below, but testing > showed that spectre_v2_check_boottime_disable() is called before the > X86_FEATURE_LFENCE_RDTSC can be set. I can look at moving where the > X86_FEATURE_LFENCE_RDTSC is set, maybe into early_init_amd() or such > if you think that would be best. Wait, we can move the selection _AFTER_ identify_boot_cpu(). Thanks, tglx 8<---------------- --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -152,7 +152,5 @@ # define THUNK_TARGET(addr) [thunk_target] "rm" (addr) #endif -void spectre_v2_check_boottime_disable(void); - #endif /* __ASSEMBLY__ */ #endif /* __NOSPEC_BRANCH_H__ */ --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -24,6 +24,8 @@ #include #include +static void __init spectre_v2_check_boottime_disable(void); + void __init check_bugs(void) { identify_boot_cpu(); @@ -33,6 +35,9 @@ void __init check_bugs(void) print_cpu_info(&boot_cpu_data); } + /* Select the proper spectre mitigation before patching alternatives */ + spectre_v2_check_boottime_disable(); + #ifdef CONFIG_X86_32 /* * Check whether we are able to run this kernel safely on SMP. @@ -106,7 +111,7 @@ static inline bool match_option(const ch return len == arglen && !strncmp(arg, opt, len); } -void __init spectre_v2_check_boottime_disable(void) +static void __init spectre_v2_check_boottime_disable(void) { char arg[20]; int ret; @@ -148,14 +153,21 @@ void __init spectre_v2_check_boottime_di retpoline: if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) { retpoline_amd: + if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD || + !boot_cpu_has(X86_FEATURE_LFENCE_RDTSC)) { + pr_info("AMD retpoline not supported, fall back to generic\n"); + goto retpoline_generic; + } + spectre_v2_enabled = retp_compiler() ? SPECTRE_V2_RETPOLINE_AMD : SPECTRE_V2_RETPOLINE_MINIMAL_AMD; setup_force_cpu_cap(X86_FEATURE_RETPOLINE_AMD); - } else { - retpoline_generic: - spectre_v2_enabled = retp_compiler() ? - SPECTRE_V2_RETPOLINE_GENERIC : SPECTRE_V2_RETPOLINE_MINIMAL; + setup_force_cpu_cap(X86_FEATURE_RETPOLINE); + return; } +retpoline_generic: + spectre_v2_enabled = retp_compiler() ? + SPECTRE_V2_RETPOLINE_GENERIC : SPECTRE_V2_RETPOLINE_MINIMAL; setup_force_cpu_cap(X86_FEATURE_RETPOLINE); return; #else --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -1322,8 +1322,6 @@ void __init setup_arch(char **cmdline_p) register_refined_jiffies(CLOCK_TICK_RATE); - spectre_v2_check_boottime_disable(); - #ifdef CONFIG_EFI if (efi_enabled(EFI_BOOT)) efi_apply_memmap_quirks();