From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753477AbeAJBVu (ORCPT + 1 other); Tue, 9 Jan 2018 20:21:50 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:53922 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752854AbeAJBVq (ORCPT ); Tue, 9 Jan 2018 20:21:46 -0500 Message-Id: <20180110011350.581018470@linutronix.de> User-Agent: quilt/0.63-1 Date: Wed, 10 Jan 2018 02:06:54 +0100 From: Thomas Gleixner To: LKML Cc: Linus Torvalds , x86@kernel.org, Peter Zijlstra , Borislav Petkov , David Woodhouse , Tim Chen , Andrea Arcangeli , Andi Kleen , Greg KH , Dave Hansen , Andy Lutomirski , Arjan Van De Ven Subject: [patch RFC 2/5] x86/spectre: Simplify spectre code a bit References: <20180110010652.404145126@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Disposition: inline; filename=x86-spectre--Simplify-spectre-code-a-bit.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Make the sysfs print use a string array, use __defined(RETPOLINE) instead of the ugly ifdefs. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/bugs.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -78,10 +78,18 @@ enum spectre_v2_mitigation { SPECTRE_V2_RETPOLINE_AMD, }; +static const char *spectre_v2_strings[] = { + [SPECTRE_V2_NONE] = "Vulnerable", + [SPECTRE_V2_RETPOLINE_MINIMAL] = "Mitigation: Minimal generic ASM retpoline", + [SPECTRE_V2_RETPOLINE_MINIMAL_AMD] = "Mitigation: Minimal AMD ASM retpoline", + [SPECTRE_V2_RETPOLINE_GENERIC] = "Mitigation: Full generic retpoline", + [SPECTRE_V2_RETPOLINE_AMD] = "Mitigation: Full AMD retpoline", +}; + #undef pr_fmt #define pr_fmt(fmt) "Spectre V2 mitigation: " fmt -static int spectre_v2_enabled = SPECTRE_V2_NONE; +static enum spectre_v2_mitigation spectre_v2_enabled = SPECTRE_V2_NONE; static void __init spec2_print_if_insecure(const char *reason) { @@ -97,11 +105,7 @@ static void __init spec2_print_if_secure static inline bool retp_compiler(void) { -#ifdef RETPOLINE - return true; -#else - return false; -#endif + return __is_defined(RETPOLINE); } static inline bool match_option(const char *arg, int arglen, const char *opt) @@ -182,6 +186,8 @@ static void __init spectre_v2_check_boot return; } +#undef pr_fmt + #ifdef CONFIG_SYSFS ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf) @@ -207,17 +213,6 @@ ssize_t cpu_show_spectre_v2(struct devic if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2)) return sprintf(buf, "Not affected\n"); - switch (spectre_v2_enabled) { - case SPECTRE_V2_RETPOLINE_MINIMAL: - return sprintf(buf, "Mitigation: Minimal generic ASM retpoline\n"); - case SPECTRE_V2_RETPOLINE_MINIMAL_AMD: - return sprintf(buf, "Mitigation: Minimal AMD ASM retpoline\n"); - case SPECTRE_V2_RETPOLINE_GENERIC: - return sprintf(buf, "Mitigation: Full generic retpoline\n"); - case SPECTRE_V2_RETPOLINE_AMD: - return sprintf(buf, "Mitigation: Full AMD retpoline\n"); - default: - return sprintf(buf, "Vulnerable\n"); - } + return sprintf(buf, "%s\n", spectre_v2_strings[spectre_v2_enabled]); } #endif