From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: x86@kernel.org, Borislav Petkov <bp@alien8.de>
Subject: [patch 3/5] x86/microcode/amd: Cache builtin/initrd microcode early
Date: Tue, 10 Oct 2023 17:08:44 +0200 (CEST) [thread overview]
Message-ID: <20231010150702.551141238@linutronix.de> (raw)
In-Reply-To: 20231010145130.987300357@linutronix.de
There is no reason to scan builtin/initrd microcode on each AP.
Cache the builtin/initrd microcode in an early initcall so that the early
AP loader can utilize the cache.
The existing fs initcall which invoked save_microcode_in_initrd_amd() is
still required to maintain the initrd_gone flag. Rename it accordingly.
This will be removed once the AP loader code is converted to use the cache.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
arch/x86/kernel/cpu/microcode/amd.c | 8 +++++++-
arch/x86/kernel/cpu/microcode/core.c | 20 ++++----------------
2 files changed, 11 insertions(+), 17 deletions(-)
--- a/arch/x86/kernel/cpu/microcode/amd.c
+++ b/arch/x86/kernel/cpu/microcode/amd.c
@@ -527,12 +527,17 @@ void load_ucode_amd_early(unsigned int c
static enum ucode_state load_microcode_amd(u8 family, const u8 *data, size_t size);
-int __init save_microcode_in_initrd_amd(unsigned int cpuid_1_eax)
+static int __init save_microcode_in_initrd(void)
{
+ unsigned int cpuid_1_eax = native_cpuid_eax(1);
+ struct cpuinfo_x86 *c = &boot_cpu_data;
struct cont_desc desc = { 0 };
enum ucode_state ret;
struct cpio_data cp;
+ if (c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10)
+ return 0;
+
find_blobs_in_containers(cpuid_1_eax, &cp);
if (!(cp.data && cp.size))
return -EINVAL;
@@ -549,6 +554,7 @@ int __init save_microcode_in_initrd_amd(
return 0;
}
+early_initcall(save_microcode_in_initrd);
/*
* a small, trivial cache of per-family ucode patches
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -185,24 +185,13 @@ void load_ucode_ap(void)
}
}
-static int __init save_microcode_in_initrd(void)
+/* Temporary workaround until find_microcode_in_initrd() is __init */
+static int __init mark_initrd_gone(void)
{
- struct cpuinfo_x86 *c = &boot_cpu_data;
- int ret = -EINVAL;
-
- switch (c->x86_vendor) {
- case X86_VENDOR_AMD:
- if (c->x86 >= 0x10)
- ret = save_microcode_in_initrd_amd(cpuid_eax(1));
- break;
- default:
- break;
- }
-
initrd_gone = true;
-
- return ret;
+ return 0;
}
+fs_initcall(mark_initrd_gone);
struct cpio_data find_microcode_in_initrd(const char *path)
{
@@ -895,5 +884,4 @@ static int __init microcode_init(void)
return error;
}
-fs_initcall(save_microcode_in_initrd);
late_initcall(microcode_init);
next prev parent reply other threads:[~2023-10-10 15:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-10 15:08 [patch 0/5] x86/microcode/amd: Use cached microcode for early loading Thomas Gleixner
2023-10-10 15:08 ` [patch 1/5] x86/microcode/amd: Use correct per CPU ucode_cpu_info Thomas Gleixner
2023-10-11 9:01 ` [tip: x86/microcode] " tip-bot2 for Thomas Gleixner
2023-10-20 11:37 ` tip-bot2 for Thomas Gleixner
2023-10-24 13:21 ` tip-bot2 for Thomas Gleixner
2023-10-10 15:08 ` [patch 2/5] x86/microcode/amd: Cache builtin microcode too Thomas Gleixner
2023-10-11 9:01 ` [tip: x86/microcode] " tip-bot2 for Thomas Gleixner
2023-10-20 11:37 ` tip-bot2 for Thomas Gleixner
2023-10-24 13:21 ` tip-bot2 for Thomas Gleixner
2023-10-10 15:08 ` Thomas Gleixner [this message]
2023-10-11 9:01 ` [tip: x86/microcode] x86/microcode/amd: Cache builtin/initrd microcode early tip-bot2 for Thomas Gleixner
2023-10-10 15:08 ` [patch 4/5] x86/microcode/amd: Use cached microcode for AP load Thomas Gleixner
2023-10-11 9:01 ` [tip: x86/microcode] " tip-bot2 for Thomas Gleixner
2023-10-10 15:08 ` [patch 5/5] x86/microcode: Mop up early loading leftovers Thomas Gleixner
2023-10-11 9:00 ` [tip: x86/microcode] " tip-bot2 for 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=20231010150702.551141238@linutronix.de \
--to=tglx@linutronix.de \
--cc=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox