public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: Andy Lutomirski <luto@amacapital.net>,
	Brian Gerst <brgerst@gmail.com>, X86 ML <x86@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 5/5] x86/alternatives: Discard dynamic check after init
Date: Thu, 21 Jan 2016 19:34:46 +0100	[thread overview]
Message-ID: <1453401286-26966-6-git-send-email-bp@alien8.de> (raw)
In-Reply-To: <1453401286-26966-1-git-send-email-bp@alien8.de>

From: Brian Gerst <brgerst@gmail.com>

Move the code to do the dynamic check to the altinstr_aux section so
that it is discarded after alternatives have run and a static branch has
been chosen.

Boris: change it to do TESTB, as hpa suggests.

Signed-off-by: Brian Gerst <brgerst@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Kristen Carlson Accardi <kristen@linux.intel.com>
Cc: Laura Abbott <labbott@fedoraproject.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: x86-ml <x86@kernel.org>
Link: http://lkml.kernel.org/r/1452972124-7380-1-git-send-email-brgerst@gmail.com
Signed-off-by: Borislav Petkov <bp@suse.de>
---
 arch/x86/include/asm/cpufeature.h | 17 +++++++++++------
 arch/x86/kernel/cpu/common.c      |  6 ------
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index e4759223f82c..77c51f4c15b7 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -131,7 +131,6 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
 
 #if __GNUC__ >= 4 && defined(CONFIG_X86_FAST_FEATURE_TESTS)
 extern void warn_pre_alternatives(void);
-extern bool __static_cpu_has(u16 bit);
 
 /*
  * Static testing of CPU features.  Used the same as boot_cpu_has().
@@ -141,7 +140,7 @@ extern bool __static_cpu_has(u16 bit);
 static __always_inline __pure bool _static_cpu_has(u16 bit)
 {
 #ifdef CC_HAVE_ASM_GOTO
-		asm_volatile_goto("1: jmp %l[t_dynamic]\n"
+		asm_volatile_goto("1: jmp 6f\n"
 			 "2:\n"
 			 ".skip -(((5f-4f) - (2b-1b)) > 0) * "
 			         "((5f-4f) - (2b-1b)),0x90\n"
@@ -166,13 +165,19 @@ static __always_inline __pure bool _static_cpu_has(u16 bit)
 			 " .byte 0\n"			/* repl len */
 			 " .byte 0\n"			/* pad len */
 			 ".previous\n"
-			 : : "i" (bit), "i" (X86_FEATURE_ALWAYS)
-			 : : t_dynamic, t_no);
+			 ".section .altinstr_aux,\"ax\"\n"
+			 "6: testb %[bitnum],%[cap_word]\n"
+			 "   jnz %l[t_yes]\n"
+			 "   jmp %l[t_no]\n"
+			 ".previous\n"
+			 : : "i" (bit), "i" (X86_FEATURE_ALWAYS),
+			     [bitnum] "i" (1 << (bit & 7)),
+			     [cap_word] "m" (((const char *)boot_cpu_data.x86_capability)[bit >> 3])
+			 : : t_yes, t_no);
+	t_yes:
 		return true;
 	t_no:
 		return false;
-	t_dynamic:
-		return __static_cpu_has(bit);
 #else
 		return boot_cpu_has(bit);
 #endif /* CC_HAVE_ASM_GOTO */
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index a57ec0df9cc3..897c65bd3faa 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1483,12 +1483,6 @@ void warn_pre_alternatives(void)
 EXPORT_SYMBOL_GPL(warn_pre_alternatives);
 #endif
 
-inline bool __static_cpu_has(u16 bit)
-{
-	return boot_cpu_has(bit);
-}
-EXPORT_SYMBOL_GPL(__static_cpu_has);
-
 static void bsp_resume(void)
 {
 	if (this_cpu->c_bsp_resume)
-- 
2.3.5

  parent reply	other threads:[~2016-01-21 18:36 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-21 18:34 [RFC PATCH 0/5] x86/cpufeature: Cleanups and improvements Borislav Petkov
2016-01-21 18:34 ` [PATCH 1/5] x86/cpufeature: Carve out X86_FEATURE_* Borislav Petkov
2016-01-21 18:57   ` H. Peter Anvin
2016-01-21 19:03     ` Borislav Petkov
2016-01-22 11:19       ` Borislav Petkov
2016-02-03 14:36         ` David Howells
2016-01-21 18:34 ` [PATCH 2/5] x86/cpufeature: Remove static_cpu_has() Borislav Petkov
2016-01-21 19:04   ` Andy Lutomirski
2016-01-21 19:39     ` Borislav Petkov
2016-01-21 19:41       ` H. Peter Anvin
2016-01-21 19:51         ` Borislav Petkov
2016-01-21 19:05   ` H. Peter Anvin
2016-01-21 18:34 ` [PATCH 3/5] x86/cpufeature: Get rid of the non-asm goto variant Borislav Petkov
2016-01-21 18:59   ` H. Peter Anvin
2016-01-21 18:34 ` [PATCH 4/5] x86/alternatives: Add an auxilary section Borislav Petkov
2016-01-21 19:00   ` H. Peter Anvin
2016-01-21 19:07     ` Borislav Petkov
2016-01-21 19:10       ` H. Peter Anvin
2016-01-21 18:34 ` Borislav Petkov [this message]
2016-01-21 19:03   ` [PATCH 5/5] x86/alternatives: Discard dynamic check after init H. Peter Anvin
2016-01-21 21:53 ` [RFC PATCH 0/5] x86/cpufeature: Cleanups and improvements Brian Gerst
2016-01-21 22:20   ` Borislav Petkov

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=1453401286-26966-6-git-send-email-bp@alien8.de \
    --to=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --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