From: Borislav Petkov <bp@alien8.de>
To: "H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@kernel.org>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>,
X86 ML <x86@kernel.org>, LKML <linux-kernel@vger.kernel.org>,
Borislav Petkov <bp@suse.de>
Subject: [PATCH] x86, microcode, AMD: Unify valid container checks
Date: Mon, 3 Feb 2014 21:41:44 +0100 [thread overview]
Message-ID: <1391460104-7261-1-git-send-email-bp@alien8.de> (raw)
In-Reply-To: <20140203203323.GG4281@pd.tnic>
From: Borislav Petkov <bp@suse.de>
For additional coverage, BorisO and friends unknowlingly did swap AMD
microcode with Intel microcode blobs in order to see what happens. What
did happen on 32-bit was
[ 5.722656] BUG: unable to handle kernel paging request at be3a6008
[ 5.722693] IP: [<c106d6b4>] load_microcode_amd+0x24/0x3f0
[ 5.722716] *pdpt = 0000000000000000 *pde = 0000000000000000
because there was a valid initrd there but without valid microcode in it
and the container check happened *after* the relocated ramdisk handling
on 32-bit, which was clearly wrong.
While at it, take care of the ramdisk relocation on both 32- and 64-bit
as it is done on both. Also, comment what we're doing because this code
is a bit tricky.
Reported-and-tested-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
---
arch/x86/kernel/cpu/microcode/amd_early.c | 43 +++++++++++++++++++++----------
1 file changed, 29 insertions(+), 14 deletions(-)
diff --git a/arch/x86/kernel/cpu/microcode/amd_early.c b/arch/x86/kernel/cpu/microcode/amd_early.c
index 8384c0fa206f..617a9e284245 100644
--- a/arch/x86/kernel/cpu/microcode/amd_early.c
+++ b/arch/x86/kernel/cpu/microcode/amd_early.c
@@ -285,6 +285,15 @@ static void __init collect_cpu_sig_on_bsp(void *arg)
uci->cpu_sig.sig = cpuid_eax(0x00000001);
}
+
+static void __init get_bsp_sig(void)
+{
+ unsigned int bsp = boot_cpu_data.cpu_index;
+ struct ucode_cpu_info *uci = ucode_cpu_info + bsp;
+
+ if (!uci->cpu_sig.sig)
+ smp_call_function_single(bsp, collect_cpu_sig_on_bsp, NULL, 1);
+}
#else
void load_ucode_amd_ap(void)
{
@@ -337,31 +346,37 @@ void load_ucode_amd_ap(void)
int __init save_microcode_in_initrd_amd(void)
{
+ unsigned long cont;
enum ucode_state ret;
u32 eax;
-#ifdef CONFIG_X86_32
- unsigned int bsp = boot_cpu_data.cpu_index;
- struct ucode_cpu_info *uci = ucode_cpu_info + bsp;
-
- if (!uci->cpu_sig.sig)
- smp_call_function_single(bsp, collect_cpu_sig_on_bsp, NULL, 1);
+ if (!container)
+ return -EINVAL;
+#ifdef CONFIG_X86_32
+ get_bsp_sig();
+ cont = (unsigned long)container;
+#else
/*
- * Take into account the fact that the ramdisk might get relocated
- * and therefore we need to recompute the container's position in
- * virtual memory space.
+ * We need the physical address of the container for both bitness since
+ * boot_params.hdr.ramdisk_image is a physical address.
*/
- container = (u8 *)(__va((u32)relocated_ramdisk) +
- ((u32)container - boot_params.hdr.ramdisk_image));
+ cont = __pa(container);
#endif
+
+ /*
+ * Take into account the fact that the ramdisk might get relocated and
+ * therefore we need to recompute the container's position in virtual
+ * memory space.
+ */
+ if (relocated_ramdisk)
+ container = (u8 *)(__va(relocated_ramdisk) +
+ (cont - boot_params.hdr.ramdisk_image));
+
if (ucode_new_rev)
pr_info("microcode: updated early to new patch_level=0x%08x\n",
ucode_new_rev);
- if (!container)
- return -EINVAL;
-
eax = cpuid_eax(0x00000001);
eax = ((eax >> 8) & 0xf) + ((eax >> 20) & 0xff);
--
1.8.5.2.192.g7794a68
next prev parent reply other threads:[~2014-02-03 20:41 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <52DE94A9.9060505@oracle.com>
2014-01-21 16:14 ` AMD microcode loading broken on 32 bit Borislav Petkov
2014-01-21 17:55 ` Boris Ostrovsky
2014-01-21 18:25 ` Borislav Petkov
2014-01-23 18:08 ` Boris Ostrovsky
2014-01-23 18:54 ` Gene Heskett
2014-01-23 19:09 ` Boris Ostrovsky
2014-01-23 19:36 ` Gene Heskett
2014-01-23 19:29 ` Borislav Petkov
2014-01-23 19:41 ` Boris Ostrovsky
2014-01-28 16:24 ` Borislav Petkov
2014-01-28 20:43 ` Boris Ostrovsky
2014-01-28 20:52 ` Borislav Petkov
2014-01-28 21:05 ` Boris Ostrovsky
2014-01-28 21:30 ` Borislav Petkov
2014-01-28 21:37 ` Boris Ostrovsky
2014-01-28 23:10 ` Boris Ostrovsky
2014-01-28 23:22 ` Borislav Petkov
2014-01-30 15:13 ` Borislav Petkov
2014-01-30 19:41 ` Boris Ostrovsky
2014-01-30 19:54 ` Borislav Petkov
2014-02-03 17:55 ` [PATCH -v2] x86, microcode, AMD: Sanity-check initrd image Borislav Petkov
2014-02-03 19:13 ` Boris Ostrovsky
2014-02-03 19:30 ` Borislav Petkov
2014-02-03 19:37 ` Boris Ostrovsky
2014-02-03 19:52 ` Borislav Petkov
2014-02-03 20:28 ` Boris Ostrovsky
2014-02-03 20:33 ` Borislav Petkov
2014-02-03 20:41 ` Borislav Petkov [this message]
2014-02-06 19:39 ` [tip:x86/urgent] x86, microcode, AMD: Unify valid container checks tip-bot for 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=1391460104-7261-1-git-send-email-bp@alien8.de \
--to=bp@alien8.de \
--cc=boris.ostrovsky@oracle.com \
--cc=bp@suse.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@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.