From: Borislav Petkov <bp@alien8.de>
To: X86 ML <x86@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 11/13] x86/microcode/AMD: Unify load_ucode_amd_ap()
Date: Tue, 17 Jan 2017 18:37:32 +0100 [thread overview]
Message-ID: <20170117173734.14251-12-bp@alien8.de> (raw)
In-Reply-To: <20170117173734.14251-1-bp@alien8.de>
From: Borislav Petkov <bp@suse.de>
Use a version for both bitness by adding a helper which does the actual
container finding and parsing which can be used on any CPU - BSP or AP.
Streamlines the paths more.
Signed-off-by: Borislav Petkov <bp@suse.de>
---
arch/x86/kernel/cpu/microcode/amd.c | 84 ++++++++++++++-----------------------
1 file changed, 31 insertions(+), 53 deletions(-)
diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
index 782e01311e4e..f1a61f181c9a 100644
--- a/arch/x86/kernel/cpu/microcode/amd.c
+++ b/arch/x86/kernel/cpu/microcode/amd.c
@@ -271,7 +271,7 @@ static bool get_builtin_microcode(struct cpio_data *cp, unsigned int family)
#endif
}
-void __init load_ucode_amd_bsp(unsigned int cpuid_1_eax)
+void __load_ucode_amd(unsigned int cpuid_1_eax, struct cpio_data *ret)
{
struct ucode_cpu_info *uci;
struct cpio_data cp;
@@ -291,95 +291,74 @@ void __init load_ucode_amd_bsp(unsigned int cpuid_1_eax)
if (!get_builtin_microcode(&cp, x86_family(cpuid_1_eax)))
cp = find_microcode_in_initrd(path, use_pa);
- if (!(cp.data && cp.size))
- return;
-
/* Needed in load_microcode_amd() */
uci->cpu_sig.sig = cpuid_1_eax;
- apply_microcode_early_amd(cpuid_1_eax, cp.data, cp.size, true, NULL);
+ *ret = cp;
}
-#ifdef CONFIG_X86_32
-/*
- * On 32-bit, since AP's early load occurs before paging is turned on, we
- * cannot traverse cpu_equiv_table and microcode_cache in kernel heap memory.
- * So during cold boot, AP will apply_ucode_in_initrd() just like the BSP.
- * In save_microcode_in_initrd_amd() BSP's patch is copied to amd_ucode_patch,
- * which is used upon resume from suspend.
- */
-void load_ucode_amd_ap(unsigned int cpuid_1_eax)
+void __init load_ucode_amd_bsp(unsigned int cpuid_1_eax)
{
- struct microcode_amd *mc;
- struct cpio_data cp;
-
- mc = (struct microcode_amd *)__pa_nodebug(amd_ucode_patch);
- if (mc->hdr.patch_id && mc->hdr.processor_rev_id) {
- __apply_microcode_amd(mc);
- return;
- }
+ struct cpio_data cp = { };
- if (!get_builtin_microcode(&cp, x86_family(cpuid_1_eax)))
- cp = find_microcode_in_initrd((const char *)__pa_nodebug(ucode_path), true);
+ __load_ucode_amd(cpuid_1_eax, &cp);
if (!(cp.data && cp.size))
return;
- /*
- * This would set amd_ucode_patch above so that the following APs can
- * use it directly instead of going down this path again.
- */
apply_microcode_early_amd(cpuid_1_eax, cp.data, cp.size, true, NULL);
}
-#else
+
void load_ucode_amd_ap(unsigned int cpuid_1_eax)
{
struct equiv_cpu_entry *eq;
struct microcode_amd *mc;
+ struct cont_desc *desc;
u16 eq_id;
+ if (IS_ENABLED(CONFIG_X86_32)) {
+ mc = (struct microcode_amd *)__pa_nodebug(amd_ucode_patch);
+ desc = (struct cont_desc *)__pa_nodebug(&cont);
+ } else {
+ mc = (struct microcode_amd *)amd_ucode_patch;
+ desc = &cont;
+ }
+
/* First AP hasn't cached it yet, go through the blob. */
- if (!cont.data) {
- struct cpio_data cp;
+ if (!desc->data) {
+ struct cpio_data cp = { };
- if (cont.size == -1)
+ if (desc->size == -1)
return;
reget:
- if (!get_builtin_microcode(&cp, x86_family(cpuid_1_eax))) {
- cp = find_microcode_in_initrd(ucode_path, false);
-
- if (!(cp.data && cp.size)) {
- /*
- * Mark it so that other APs do not scan again
- * for no real reason and slow down boot
- * needlessly.
- */
- cont.size = -1;
- return;
- }
+ __load_ucode_amd(cpuid_1_eax, &cp);
+ if (!(cp.data && cp.size)) {
+ /*
+ * Mark it so that other APs do not scan again for no
+ * real reason and slow down boot needlessly.
+ */
+ desc->size = -1;
+ return;
}
- if (!apply_microcode_early_amd(cpuid_1_eax, cp.data, cp.size, false, &cont)) {
- cont.data = NULL;
- cont.size = -1;
+ if (!apply_microcode_early_amd(cpuid_1_eax, cp.data, cp.size, false, desc)) {
+ desc->data = NULL;
+ desc->size = -1;
return;
}
}
- eq = (struct equiv_cpu_entry *)(cont.data + CONTAINER_HDR_SZ);
+ eq = (struct equiv_cpu_entry *)(desc->data + CONTAINER_HDR_SZ);
eq_id = find_equiv_id(eq, cpuid_1_eax);
if (!eq_id)
return;
- if (eq_id == cont.eq_id) {
+ if (eq_id == desc->eq_id) {
u32 rev, dummy;
microcode_rdmsr(MSR_AMD64_PATCH_LEVEL, rev, dummy);
-
- mc = (struct microcode_amd *)amd_ucode_patch;
-
if (mc && rev < mc->hdr.patch_id) {
if (!__apply_microcode_amd(mc))
ucode_new_rev = mc->hdr.patch_id;
@@ -394,7 +373,6 @@ void load_ucode_amd_ap(unsigned int cpuid_1_eax)
goto reget;
}
}
-#endif /* CONFIG_X86_32 */
static enum ucode_state
load_microcode_amd(int cpu, u8 family, const u8 *data, size_t size);
--
2.11.0
next prev parent reply other threads:[~2017-01-17 17:38 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-17 17:37 [PATCH 00/13] x86/microcode: 4.11 queue Borislav Petkov
2017-01-17 17:37 ` [PATCH 01/13] x86/microcode/intel: Drop stashed AP patch pointer optimization Borislav Petkov
2017-01-17 19:59 ` Thomas Gleixner
2017-01-17 17:37 ` [PATCH 02/13] x86/microcode: Use own MSR accessors Borislav Petkov
2017-01-17 17:51 ` Thomas Gleixner
2017-01-17 18:11 ` Borislav Petkov
2017-01-17 19:12 ` Thomas Gleixner
2017-01-17 22:33 ` Borislav Petkov
2017-01-18 9:46 ` Thomas Gleixner
2017-01-17 17:37 ` [PATCH 03/13] x86/microcode/AMD: Clean up find_equiv_id() Borislav Petkov
2017-01-17 17:54 ` Thomas Gleixner
2017-01-17 18:49 ` Borislav Petkov
2017-01-17 19:02 ` Thomas Gleixner
2017-01-17 23:12 ` Borislav Petkov
2017-01-17 17:37 ` [PATCH 04/13] x86/microcode/AMD: Shorten function parameter's name Borislav Petkov
2017-01-17 19:59 ` Thomas Gleixner
2017-01-17 17:37 ` [PATCH 05/13] x86/microcode/AMD: Extend the container struct Borislav Petkov
2017-01-17 20:02 ` Thomas Gleixner
2017-01-17 17:37 ` [PATCH 06/13] x86/microcode/AMD: Rework container parsing Borislav Petkov
2017-01-17 20:29 ` Thomas Gleixner
2017-01-17 23:31 ` Borislav Petkov
2017-01-18 14:44 ` Borislav Petkov
2017-01-18 14:58 ` Borislav Petkov
2017-01-17 17:37 ` [PATCH 07/13] x86/microcode: Decrease CPUID use Borislav Petkov
2017-01-17 20:34 ` Thomas Gleixner
2017-01-17 17:37 ` [PATCH 08/13] x86/microcode/AMD: Get rid of global this_equiv_id Borislav Petkov
2017-01-17 20:36 ` Thomas Gleixner
2017-01-17 17:37 ` [PATCH 09/13] x86/microcode/AMD: Use find_microcode_in_initrd() Borislav Petkov
2017-01-17 20:36 ` Thomas Gleixner
2017-01-17 17:37 ` [PATCH 10/13] x86/microcode/AMD: Check patch level only on the BSP Borislav Petkov
2017-01-17 20:43 ` Thomas Gleixner
2017-01-17 17:37 ` Borislav Petkov [this message]
2017-01-17 20:58 ` [PATCH 11/13] x86/microcode/AMD: Unify load_ucode_amd_ap() Thomas Gleixner
2017-01-17 21:18 ` Thomas Gleixner
2017-01-17 17:37 ` [PATCH 12/13] x86/microcode/AMD: Simplify saving from initrd Borislav Petkov
2017-01-17 21:19 ` Thomas Gleixner
2017-01-17 17:37 ` [PATCH 13/13] x86/microcode/AMD: Remove AP scanning optimization Borislav Petkov
2017-01-17 21:24 ` Thomas Gleixner
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=20170117173734.14251-12-bp@alien8.de \
--to=bp@alien8.de \
--cc=linux-kernel@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.