lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 5 Jun 2023 15:12:56 +0800
From:   Zeng Heng <zengheng4@...wei.com>
To:     <tglx@...utronix.de>, <dave.hansen@...ux.intel.com>,
        <hpa@...or.com>, <mingo@...hat.com>, <bp@...en8.de>
CC:     <linux-kernel@...r.kernel.org>, <xiexiuqi@...wei.com>,
        <x86@...nel.org>, <liwei391@...wei.com>
Subject: [PATCH] x86/microcode/AMD: shrink the size of amd_ucode_patch array

About the commit <7ff6edf4fef3>, the amd_ucode_patch is expanded as
two-dimensional array. When CONFIG_MAXSMP is enabled or CONFIG_NODES_SHIFT
is set as 10, this array would occupy memory up to 12M.

Here we allocate amd_ucode_patch array dynamically in need instead of
static declaration.

Signed-off-by: Zeng Heng <zengheng4@...wei.com>
---
 arch/x86/kernel/cpu/microcode/amd.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
index f5fdeb1e3606..b6cd6ce9c016 100644
--- a/arch/x86/kernel/cpu/microcode/amd.c
+++ b/arch/x86/kernel/cpu/microcode/amd.c
@@ -57,7 +57,8 @@ struct cont_desc {
 static u32 ucode_new_rev;
 
 /* One blob per node. */
-static u8 amd_ucode_patch[MAX_NUMNODES][PATCH_MAX_SIZE];
+static u8 amd_ucode_patch_0[PATCH_MAX_SIZE];
+static u8 *amd_ucode_patch[MAX_NUMNODES] = { amd_ucode_patch_0 };
 
 /*
  * Microcode patch container file is prepended to the initrd in cpio
@@ -420,17 +421,17 @@ static int __apply_microcode_amd(struct microcode_amd *mc)
 static bool early_apply_microcode(u32 cpuid_1_eax, void *ucode, size_t size, bool save_patch)
 {
 	struct cont_desc desc = { 0 };
-	u8 (*patch)[PATCH_MAX_SIZE];
+	u8 *patch;
 	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);
+	patch	= (u8 *)__pa_nodebug(amd_ucode_patch_0);
 #else
 	new_rev = &ucode_new_rev;
-	patch	= &amd_ucode_patch[0];
+	patch	= amd_ucode_patch_0;
 #endif
 
 	desc.cpuid_1_eax = cpuid_1_eax;
@@ -881,8 +882,11 @@ static enum ucode_state load_microcode_amd(u8 family, const u8 *data, size_t siz
 
 		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));
+		if (!amd_ucode_patch[nid])
+			amd_ucode_patch[nid] = kmalloc(PATCH_MAX_SIZE, GFP_KERNEL);
+
+		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;
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ