mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Tom Lendacky <thomas.lendacky@amd.com>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	Rik van Riel <riel@redhat.com>, Andi Kleen <ak@linux.intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Jiri Kosina <jikos@kernel.org>,
	Dan Williams <dan.j.williams@intel.com>,
	Dave Hansen <dave.hansen@intel.com>,
	Borislav Petkov <bp@alien8.de>, Andy Lutomirski <luto@kernel.org>,
	Kees Cook <keescook@google.com>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linux-foundation.org>,
	David Woodhouse <dwmw@amazon.co.uk>, Paul Turner <pjt@google.com>
Subject: Re: [PATCH v1 1/2] x86/retpoline: Add a function to clear the RETPOLINE_AMD feature
Date: Wed, 10 Jan 2018 00:09:47 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.20.1801100004040.2200@nanos> (raw)
In-Reply-To: <12147db9-e975-268f-55ee-247868e0e0d8@amd.com>

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 <asm/pgtable.h>
 #include <asm/set_memory.h>
 
+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();

  reply	other threads:[~2018-01-09 23:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-09 22:37 [PATCH v1 0/2] x86/retpoline: Clear RETPOLINE_AMD if LFENCE is not serializing Tom Lendacky
2018-01-09 22:37 ` [PATCH v1 1/2] x86/retpoline: Add a function to clear the RETPOLINE_AMD feature Tom Lendacky
2018-01-09 22:46   ` Thomas Gleixner
2018-01-09 23:01     ` Tom Lendacky
2018-01-09 23:09       ` Thomas Gleixner [this message]
2018-01-09 23:38         ` Tom Lendacky
2018-01-09 23:43           ` Thomas Gleixner
2018-01-10  0:22             ` Tom Lendacky
2018-01-09 22:37 ` [PATCH v1 2/2] x86/cpu/AMD: Clear RETPOLINE_AMD if LFENCE is not serializing Tom Lendacky

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=alpine.DEB.2.20.1801100004040.2200@nanos \
    --to=tglx@linutronix.de \
    --cc=ak@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=dwmw@amazon.co.uk \
    --cc=gregkh@linux-foundation.org \
    --cc=jikos@kernel.org \
    --cc=keescook@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pjt@google.com \
    --cc=riel@redhat.com \
    --cc=thomas.lendacky@amd.com \
    --cc=tim.c.chen@linux.intel.com \
    --cc=torvalds@linux-foundation.org \
    --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

all inboxes | Powered by JetHome®