* [PATCH] x86/microcode/AMD: Increase microcode PATCH_MAX_SIZE
@ 2020-04-09 15:34 John Allen
2020-04-14 15:46 ` [tip: x86/urgent] " tip-bot2 for John Allen
0 siblings, 1 reply; 8+ messages in thread
From: John Allen @ 2020-04-09 15:34 UTC (permalink / raw)
To: bp, linux-kernel; +Cc: tglx, mingo, hpa, x86
Future AMD cpus will have microcode patches that exceed the default 4K
page size.
Signed-off-by: John Allen <john.allen@amd.com>
Cc: stable@vger.kernel.org
---
diff --git a/arch/x86/include/asm/microcode_amd.h b/arch/x86/include/asm/microcode_amd.h
index 6685e1218959..7063b5a43220 100644
--- a/arch/x86/include/asm/microcode_amd.h
+++ b/arch/x86/include/asm/microcode_amd.h
@@ -41,7 +41,7 @@ struct microcode_amd {
unsigned int mpb[0];
};
-#define PATCH_MAX_SIZE PAGE_SIZE
+#define PATCH_MAX_SIZE (3 * PAGE_SIZE)
#ifdef CONFIG_MICROCODE_AMD
extern void __init load_ucode_amd_bsp(unsigned int family);
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [tip: x86/urgent] x86/microcode/AMD: Increase microcode PATCH_MAX_SIZE
2020-04-09 15:34 [PATCH] x86/microcode/AMD: Increase microcode PATCH_MAX_SIZE John Allen
@ 2020-04-14 15:46 ` tip-bot2 for John Allen
0 siblings, 0 replies; 8+ messages in thread
From: tip-bot2 for John Allen @ 2020-04-14 15:46 UTC (permalink / raw)
To: linux-tip-commits
Cc: John Allen, Borislav Petkov, stable, #, v4.14.., x86, LKML
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: bdf89df3c54518eed879d8fac7577fcfb220c67e
Gitweb: https://git.kernel.org/tip/bdf89df3c54518eed879d8fac7577fcfb220c67e
Author: John Allen <john.allen@amd.com>
AuthorDate: Thu, 09 Apr 2020 10:34:29 -05:00
Committer: Borislav Petkov <bp@suse.de>
CommitterDate: Tue, 14 Apr 2020 17:34:46 +02:00
x86/microcode/AMD: Increase microcode PATCH_MAX_SIZE
Future AMD CPUs will have microcode patches that exceed the default 4K
patch size. Raise our limit.
Signed-off-by: John Allen <john.allen@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: stable@vger.kernel.org # v4.14..
Link: https://lkml.kernel.org/r/20200409152931.GA685273@mojo.amd.com
---
arch/x86/include/asm/microcode_amd.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/microcode_amd.h b/arch/x86/include/asm/microcode_amd.h
index 6685e12..7063b5a 100644
--- a/arch/x86/include/asm/microcode_amd.h
+++ b/arch/x86/include/asm/microcode_amd.h
@@ -41,7 +41,7 @@ struct microcode_amd {
unsigned int mpb[0];
};
-#define PATCH_MAX_SIZE PAGE_SIZE
+#define PATCH_MAX_SIZE (3 * PAGE_SIZE)
#ifdef CONFIG_MICROCODE_AMD
extern void __init load_ucode_amd_bsp(unsigned int family);
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] x86/microcode/AMD: Increase microcode PATCH_MAX_SIZE
2023-07-21 16:42 ` John Allen
@ 2023-07-22 7:28 ` Borislav Petkov
0 siblings, 0 replies; 8+ messages in thread
From: Borislav Petkov @ 2023-07-22 7:28 UTC (permalink / raw)
To: John Allen; +Cc: linux-kernel, tglx, mingo, hpa, x86
On Fri, Jul 21, 2023 at 11:42:03AM -0500, John Allen wrote:
> Yes, this appears to be working on my machine as well.
>
> Tested-by: John Allen <john.allen@amd.com>
Thanks, I'll queue it.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] x86/microcode/AMD: Increase microcode PATCH_MAX_SIZE
2023-07-21 15:49 ` Borislav Petkov
@ 2023-07-21 16:42 ` John Allen
2023-07-22 7:28 ` Borislav Petkov
0 siblings, 1 reply; 8+ messages in thread
From: John Allen @ 2023-07-21 16:42 UTC (permalink / raw)
To: Borislav Petkov; +Cc: linux-kernel, tglx, mingo, hpa, x86
On Fri, Jul 21, 2023 at 05:49:42PM +0200, Borislav Petkov wrote:
> Remove stable@.
>
> This below seems to work here on a couple of machines.
>
> Can you run it too pls to confirm?
>
> Thx.
Yes, this appears to be working on my machine as well.
Tested-by: John Allen <john.allen@amd.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] x86/microcode/AMD: Increase microcode PATCH_MAX_SIZE
2023-07-20 20:28 [PATCH] " John Allen
2023-07-21 4:47 ` Jiri Slaby
@ 2023-07-21 15:49 ` Borislav Petkov
2023-07-21 16:42 ` John Allen
1 sibling, 1 reply; 8+ messages in thread
From: Borislav Petkov @ 2023-07-21 15:49 UTC (permalink / raw)
To: John Allen; +Cc: linux-kernel, tglx, mingo, hpa, x86
Remove stable@.
This below seems to work here on a couple of machines.
Can you run it too pls to confirm?
Thx.
---
From: "Borislav Petkov (AMD)" <bp@alien8.de>
Date: Wed, 7 Jun 2023 21:01:06 +0200
Subject: [PATCH] x86/microcode/AMD: Rip out static buffers
Load straight from the containers (initrd or builtin, for example).
There's no need to cache the patch per node.
This even simplifies the code a bit with the opportunity for more
cleanups later.
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
---
arch/x86/include/asm/microcode_amd.h | 6 +-
arch/x86/kernel/cpu/microcode/amd.c | 91 +++++++++-------------------
arch/x86/kernel/cpu/microcode/core.c | 4 +-
3 files changed, 31 insertions(+), 70 deletions(-)
diff --git a/arch/x86/include/asm/microcode_amd.h b/arch/x86/include/asm/microcode_amd.h
index e6662adf3af4..a995b7685223 100644
--- a/arch/x86/include/asm/microcode_amd.h
+++ b/arch/x86/include/asm/microcode_amd.h
@@ -44,13 +44,11 @@ struct microcode_amd {
#define PATCH_MAX_SIZE (3 * PAGE_SIZE)
#ifdef CONFIG_MICROCODE_AMD
-extern void __init load_ucode_amd_bsp(unsigned int family);
-extern void load_ucode_amd_ap(unsigned int family);
+extern void load_ucode_amd_early(unsigned int cpuid_1_eax);
extern int __init save_microcode_in_initrd_amd(unsigned int family);
void reload_ucode_amd(unsigned int cpu);
#else
-static inline void __init load_ucode_amd_bsp(unsigned int family) {}
-static inline void load_ucode_amd_ap(unsigned int family) {}
+static inline void load_ucode_amd_early(unsigned int cpuid_1_eax) {}
static inline int __init
save_microcode_in_initrd_amd(unsigned int family) { return -EINVAL; }
static inline void reload_ucode_amd(unsigned int cpu) {}
diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
index 87208e46f7ed..a28b103256ff 100644
--- a/arch/x86/kernel/cpu/microcode/amd.c
+++ b/arch/x86/kernel/cpu/microcode/amd.c
@@ -56,9 +56,6 @@ struct cont_desc {
static u32 ucode_new_rev;
-/* One blob per node. */
-static u8 amd_ucode_patch[MAX_NUMNODES][PATCH_MAX_SIZE];
-
/*
* Microcode patch container file is prepended to the initrd in cpio
* format. See Documentation/arch/x86/microcode.rst
@@ -415,20 +412,17 @@ static int __apply_microcode_amd(struct microcode_amd *mc)
*
* Returns true if container found (sets @desc), false otherwise.
*/
-static bool early_apply_microcode(u32 cpuid_1_eax, void *ucode, size_t size, bool save_patch)
+static bool early_apply_microcode(u32 cpuid_1_eax, void *ucode, size_t size)
{
struct cont_desc desc = { 0 };
- u8 (*patch)[PATCH_MAX_SIZE];
struct microcode_amd *mc;
u32 rev, dummy, *new_rev;
bool ret = false;
#ifdef CONFIG_X86_32
new_rev = (u32 *)__pa_nodebug(&ucode_new_rev);
- patch = (u8 (*)[PATCH_MAX_SIZE])__pa_nodebug(&amd_ucode_patch);
#else
new_rev = &ucode_new_rev;
- patch = &amd_ucode_patch[0];
#endif
desc.cpuid_1_eax = cpuid_1_eax;
@@ -452,9 +446,6 @@ static bool early_apply_microcode(u32 cpuid_1_eax, void *ucode, size_t size, boo
if (!__apply_microcode_amd(mc)) {
*new_rev = mc->hdr.patch_id;
ret = true;
-
- if (save_patch)
- memcpy(patch, mc, min_t(u32, desc.psize, PATCH_MAX_SIZE));
}
return ret;
@@ -507,7 +498,7 @@ static void find_blobs_in_containers(unsigned int cpuid_1_eax, struct cpio_data
*ret = cp;
}
-void __init load_ucode_amd_bsp(unsigned int cpuid_1_eax)
+static void apply_ucode_from_containers(unsigned int cpuid_1_eax)
{
struct cpio_data cp = { };
@@ -515,42 +506,12 @@ void __init load_ucode_amd_bsp(unsigned int cpuid_1_eax)
if (!(cp.data && cp.size))
return;
- early_apply_microcode(cpuid_1_eax, cp.data, cp.size, true);
+ early_apply_microcode(cpuid_1_eax, cp.data, cp.size);
}
-void load_ucode_amd_ap(unsigned int cpuid_1_eax)
+void load_ucode_amd_early(unsigned int cpuid_1_eax)
{
- struct microcode_amd *mc;
- struct cpio_data cp;
- u32 *new_rev, rev, dummy;
-
- if (IS_ENABLED(CONFIG_X86_32)) {
- mc = (struct microcode_amd *)__pa_nodebug(amd_ucode_patch);
- new_rev = (u32 *)__pa_nodebug(&ucode_new_rev);
- } else {
- mc = (struct microcode_amd *)amd_ucode_patch;
- new_rev = &ucode_new_rev;
- }
-
- native_rdmsr(MSR_AMD64_PATCH_LEVEL, rev, dummy);
-
- /*
- * Check whether a new patch has been saved already. Also, allow application of
- * the same revision in order to pick up SMT-thread-specific configuration even
- * if the sibling SMT thread already has an up-to-date revision.
- */
- if (*new_rev && rev <= mc->hdr.patch_id) {
- if (!__apply_microcode_amd(mc)) {
- *new_rev = mc->hdr.patch_id;
- return;
- }
- }
-
- find_blobs_in_containers(cpuid_1_eax, &cp);
- if (!(cp.data && cp.size))
- return;
-
- early_apply_microcode(cpuid_1_eax, cp.data, cp.size, false);
+ return apply_ucode_from_containers(cpuid_1_eax);
}
static enum ucode_state load_microcode_amd(u8 family, const u8 *data, size_t size);
@@ -578,23 +539,6 @@ int __init save_microcode_in_initrd_amd(unsigned int cpuid_1_eax)
return 0;
}
-void reload_ucode_amd(unsigned int cpu)
-{
- u32 rev, dummy __always_unused;
- struct microcode_amd *mc;
-
- mc = (struct microcode_amd *)amd_ucode_patch[cpu_to_node(cpu)];
-
- rdmsr(MSR_AMD64_PATCH_LEVEL, rev, dummy);
-
- if (rev < mc->hdr.patch_id) {
- if (!__apply_microcode_amd(mc)) {
- ucode_new_rev = mc->hdr.patch_id;
- pr_info("reload patch_level=0x%08x\n", ucode_new_rev);
- }
- }
-}
-
/*
* a small, trivial cache of per-family ucode patches
*/
@@ -655,6 +599,28 @@ static struct ucode_patch *find_patch(unsigned int cpu)
return cache_find_patch(equiv_id);
}
+void reload_ucode_amd(unsigned int cpu)
+{
+ u32 rev, dummy __always_unused;
+ struct microcode_amd *mc;
+ struct ucode_patch *p;
+
+ p = find_patch(cpu);
+ if (!p)
+ return;
+
+ mc = p->data;
+
+ rdmsr(MSR_AMD64_PATCH_LEVEL, rev, dummy);
+
+ if (rev < mc->hdr.patch_id) {
+ if (!__apply_microcode_amd(mc)) {
+ ucode_new_rev = mc->hdr.patch_id;
+ pr_info("reload patch_level=0x%08x\n", ucode_new_rev);
+ }
+ }
+}
+
static int collect_cpu_info_amd(int cpu, struct cpu_signature *csig)
{
struct cpuinfo_x86 *c = &cpu_data(cpu);
@@ -875,9 +841,6 @@ static enum ucode_state load_microcode_amd(u8 family, const u8 *data, size_t siz
continue;
ret = UCODE_NEW;
-
- memset(&amd_ucode_patch[nid], 0, PATCH_MAX_SIZE);
- memcpy(&amd_ucode_patch[nid], p->data, min_t(u32, p->size, PATCH_MAX_SIZE));
}
return ret;
diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index 3afcf3de0dd4..192adf5f948e 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -172,7 +172,7 @@ void __init load_ucode_bsp(void)
if (intel)
load_ucode_intel_bsp();
else
- load_ucode_amd_bsp(cpuid_1_eax);
+ load_ucode_amd_early(cpuid_1_eax);
}
static bool check_loader_disabled_ap(void)
@@ -200,7 +200,7 @@ void load_ucode_ap(void)
break;
case X86_VENDOR_AMD:
if (x86_family(cpuid_1_eax) >= 0x10)
- load_ucode_amd_ap(cpuid_1_eax);
+ load_ucode_amd_early(cpuid_1_eax);
break;
default:
break;
--
2.41.0
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] x86/microcode/AMD: Increase microcode PATCH_MAX_SIZE
2023-07-21 4:47 ` Jiri Slaby
@ 2023-07-21 7:38 ` Borislav Petkov
0 siblings, 0 replies; 8+ messages in thread
From: Borislav Petkov @ 2023-07-21 7:38 UTC (permalink / raw)
To: Jiri Slaby; +Cc: John Allen, linux-kernel, tglx, mingo, hpa, x86, stable
On Fri, Jul 21, 2023 at 06:47:39AM +0200, Jiri Slaby wrote:
> is now 32M instead of 12M. That is a complete waste on my _one_ node system.
> Can we make amd_ucode_patch dynamic first, depending on num_online_nodes()?
I have a small set which gets rid of all those arrays - I just need to
finish it.
:-(
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] x86/microcode/AMD: Increase microcode PATCH_MAX_SIZE
2023-07-20 20:28 [PATCH] " John Allen
@ 2023-07-21 4:47 ` Jiri Slaby
2023-07-21 7:38 ` Borislav Petkov
2023-07-21 15:49 ` Borislav Petkov
1 sibling, 1 reply; 8+ messages in thread
From: Jiri Slaby @ 2023-07-21 4:47 UTC (permalink / raw)
To: John Allen, bp, linux-kernel; +Cc: tglx, mingo, hpa, x86, stable
On 20. 07. 23, 22:28, John Allen wrote:
> Future AMD cpus will have microcode patches that exceed the current
> limit of three 4K pages. Increase substantially to avoid future size
> increases.
Hi,
so with my current distro (openSUSE TW):
$ zgrep NODES_SHIFT /proc/config.gz
CONFIG_NODES_SHIFT=10
This:
static u8 amd_ucode_patch[MAX_NUMNODES][PATCH_MAX_SIZE];
is now 32M instead of 12M. That is a complete waste on my _one_ node
system. Can we make amd_ucode_patch dynamic first, depending on
num_online_nodes()?
> Signed-off-by: John Allen <john.allen@amd.com>
> Cc: stable@vger.kernel.org
> ---
> arch/x86/include/asm/microcode_amd.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/include/asm/microcode_amd.h b/arch/x86/include/asm/microcode_amd.h
> index e6662adf3af4..e3d5f5ae2f46 100644
> --- a/arch/x86/include/asm/microcode_amd.h
> +++ b/arch/x86/include/asm/microcode_amd.h
> @@ -41,7 +41,7 @@ struct microcode_amd {
> unsigned int mpb[];
> };
>
> -#define PATCH_MAX_SIZE (3 * PAGE_SIZE)
> +#define PATCH_MAX_SIZE (8 * PAGE_SIZE)
>
> #ifdef CONFIG_MICROCODE_AMD
> extern void __init load_ucode_amd_bsp(unsigned int family);
thanks,
--
js
suse labs
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] x86/microcode/AMD: Increase microcode PATCH_MAX_SIZE
@ 2023-07-20 20:28 John Allen
2023-07-21 4:47 ` Jiri Slaby
2023-07-21 15:49 ` Borislav Petkov
0 siblings, 2 replies; 8+ messages in thread
From: John Allen @ 2023-07-20 20:28 UTC (permalink / raw)
To: bp, linux-kernel; +Cc: tglx, mingo, hpa, x86, John Allen, stable
Future AMD cpus will have microcode patches that exceed the current
limit of three 4K pages. Increase substantially to avoid future size
increases.
Signed-off-by: John Allen <john.allen@amd.com>
Cc: stable@vger.kernel.org
---
arch/x86/include/asm/microcode_amd.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/microcode_amd.h b/arch/x86/include/asm/microcode_amd.h
index e6662adf3af4..e3d5f5ae2f46 100644
--- a/arch/x86/include/asm/microcode_amd.h
+++ b/arch/x86/include/asm/microcode_amd.h
@@ -41,7 +41,7 @@ struct microcode_amd {
unsigned int mpb[];
};
-#define PATCH_MAX_SIZE (3 * PAGE_SIZE)
+#define PATCH_MAX_SIZE (8 * PAGE_SIZE)
#ifdef CONFIG_MICROCODE_AMD
extern void __init load_ucode_amd_bsp(unsigned int family);
--
2.39.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-07-22 7:30 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-09 15:34 [PATCH] x86/microcode/AMD: Increase microcode PATCH_MAX_SIZE John Allen
2020-04-14 15:46 ` [tip: x86/urgent] " tip-bot2 for John Allen
2023-07-20 20:28 [PATCH] " John Allen
2023-07-21 4:47 ` Jiri Slaby
2023-07-21 7:38 ` Borislav Petkov
2023-07-21 15:49 ` Borislav Petkov
2023-07-21 16:42 ` John Allen
2023-07-22 7:28 ` Borislav Petkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).