From nobody Sun Feb 8 21:32:26 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67483C7EE23 for ; Mon, 5 Jun 2023 07:33:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229667AbjFEHdl (ORCPT ); Mon, 5 Jun 2023 03:33:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230227AbjFEHdZ (ORCPT ); Mon, 5 Jun 2023 03:33:25 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A90C8CD for ; Mon, 5 Jun 2023 00:33:18 -0700 (PDT) Received: from kwepemi500024.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QZPtc5H8XztQWV; Mon, 5 Jun 2023 15:12:08 +0800 (CST) Received: from huawei.com (10.175.103.91) by kwepemi500024.china.huawei.com (7.221.188.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 5 Jun 2023 15:14:27 +0800 From: Zeng Heng To: , , , , CC: , , , Subject: [PATCH] x86/microcode/AMD: shrink the size of amd_ucode_patch array Date: Mon, 5 Jun 2023 15:12:56 +0800 Message-ID: <20230605071256.1813504-1-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemi500024.china.huawei.com (7.221.188.100) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- 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/micr= ocode/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; =20 /* 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] =3D { amd_ucode_patch_0 }; =20 /* * 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 siz= e, bool save_patch) { struct cont_desc desc =3D { 0 }; - u8 (*patch)[PATCH_MAX_SIZE]; + u8 *patch; struct microcode_amd *mc; u32 rev, dummy, *new_rev; bool ret =3D false; =20 #ifdef CONFIG_X86_32 new_rev =3D (u32 *)__pa_nodebug(&ucode_new_rev); - patch =3D (u8 (*)[PATCH_MAX_SIZE])__pa_nodebug(&amd_ucode_patch); + patch =3D (u8 *)__pa_nodebug(amd_ucode_patch_0); #else new_rev =3D &ucode_new_rev; - patch =3D &amd_ucode_patch[0]; + patch =3D amd_ucode_patch_0; #endif =20 desc.cpuid_1_eax =3D cpuid_1_eax; @@ -881,8 +882,11 @@ static enum ucode_state load_microcode_amd(u8 family, = const u8 *data, size_t siz =20 ret =3D UCODE_NEW; =20 - memset(&amd_ucode_patch[nid], 0, PATCH_MAX_SIZE); - memcpy(&amd_ucode_patch[nid], p->data, min_t(u32, p->size, PATCH_MAX_SIZ= E)); + if (!amd_ucode_patch[nid]) + amd_ucode_patch[nid] =3D 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= )); } =20 return ret; --=20 2.25.1