From nobody Fri Dec 19 04:49:16 2025 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 509C8CA0ECA for ; Tue, 12 Sep 2023 07:58:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232097AbjILH6d (ORCPT ); Tue, 12 Sep 2023 03:58:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232005AbjILH6T (ORCPT ); Tue, 12 Sep 2023 03:58:19 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A770510F9 for ; Tue, 12 Sep 2023 00:57:59 -0700 (PDT) Message-ID: <20230912065501.335403273@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694505478; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=COGYr1lbubEBgG3WbXJ/GVEKTFAghSZ0FbZctrPsvVg=; b=YzkFuM3cXvL7U+GFXHBgzX+Itn6q5lxrdVInucl/2b4dkqwYdNXJjH8K9kgQpoWv3+57rI Ti3gtX3exvhhqH2WwOX/w4KYF8FcQaIHhYV8YkElUtTyGMaYSqYMTxfIGK7pluirZxNfY3 PuAEkXJeHiK5a11mhHJ7FW0VDbNu1FZr1Gcpu27qIEj6HaSWPtAKj0XsbwGpc+RHccWK31 Znf0STWPS7uyexU07tV2FLRmdW8xZVlyke5er+KQHOkgdlaPO3RRrTBD1idPwana0LCy0e COjldBjzysxhRdHvEQ66GmSxjQ1jBg/3nhXCHuMX3fMUohfH6OsAxhVrV+MvCg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694505478; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=COGYr1lbubEBgG3WbXJ/GVEKTFAghSZ0FbZctrPsvVg=; b=2HZZaqcxlL+qDqMELaTxx4FwXn7FKdec/94PPTZ8yDAljReKhNA6udFZFPpDyzJyvrEkg4 6v533y9o3NKWbvCg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Borislav Petkov , "Chang S. Bae" , Arjan van de Ven , Nikolay Borisov Subject: [patch V3 09/30] x86/microcode/intel: Switch to kvmalloc() References: <20230912065249.695681286@linutronix.de> MIME-Version: 1.0 Date: Tue, 12 Sep 2023 09:57:57 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Microcode blobs are getting larger and might soon reach the kmalloc() limit. Switch over kvmalloc(). Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/microcode/intel.c | 50 +++++++++++++++++------------= ----- 1 file changed, 26 insertions(+), 24 deletions(-) --- --- a/arch/x86/kernel/cpu/microcode/intel.c +++ b/arch/x86/kernel/cpu/microcode/intel.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -243,7 +242,7 @@ EXPORT_SYMBOL_GPL(intel_microcode_sanity =20 static void update_ucode_pointer(struct microcode_intel *mc) { - kfree(ucode_patch_va); + kvfree(ucode_patch_va); =20 /* * Save the virtual address for early loading and for eventual free @@ -254,11 +253,14 @@ static void update_ucode_pointer(struct =20 static void save_microcode_patch(struct microcode_intel *patch) { - struct microcode_intel *mc; + unsigned int size =3D get_totalsize(&patch->hdr); + struct microcode_intel *mc =3D NULL; =20 - mc =3D kmemdup(patch, get_totalsize(&patch->hdr), GFP_KERNEL); + mc =3D kvmemdup(patch, size, GFP_KERNEL); if (mc) update_ucode_pointer(mc); + else + pr_err("Unable to allocate microcode memory size: %u\n", size); } =20 /* Scan CPIO for microcode matching the boot CPUs family, model, stepping = */ @@ -530,36 +532,34 @@ static enum ucode_state read_ucode_intel =20 if (!copy_from_iter_full(&mc_header, sizeof(mc_header), iter)) { pr_err("error! Truncated or inaccessible header in microcode data file\= n"); - break; + goto fail; } =20 mc_size =3D get_totalsize(&mc_header); if (mc_size < sizeof(mc_header)) { pr_err("error! Bad data in microcode data file (totalsize too small)\n"= ); - break; + goto fail; } - data_size =3D mc_size - sizeof(mc_header); if (data_size > iov_iter_count(iter)) { pr_err("error! Bad data in microcode data file (truncated file?)\n"); - break; + goto fail; } =20 /* For performance reasons, reuse mc area when possible */ if (!mc || mc_size > curr_mc_size) { - vfree(mc); - mc =3D vmalloc(mc_size); + kvfree(mc); + mc =3D kvmalloc(mc_size, GFP_KERNEL); if (!mc) - break; + goto fail; curr_mc_size =3D mc_size; } =20 memcpy(mc, &mc_header, sizeof(mc_header)); data =3D mc + sizeof(mc_header); if (!copy_from_iter_full(data, data_size, iter) || - intel_microcode_sanity_check(mc, true, MC_HEADER_TYPE_MICROCODE) < 0= ) { - break; - } + intel_microcode_sanity_check(mc, true, MC_HEADER_TYPE_MICROCODE) < 0) + goto fail; =20 if (cur_rev >=3D mc_header.rev) continue; @@ -567,24 +567,26 @@ static enum ucode_state read_ucode_intel if (!intel_find_matching_signature(mc, uci->cpu_sig.sig, uci->cpu_sig.pf= )) continue; =20 - vfree(new_mc); + kvfree(new_mc); cur_rev =3D mc_header.rev; new_mc =3D mc; mc =3D NULL; } =20 - vfree(mc); - - if (iov_iter_count(iter)) { - vfree(new_mc); - return UCODE_ERROR; - } + if (iov_iter_count(iter)) + goto fail; =20 + kvfree(mc); if (!new_mc) return UCODE_NFOUND; =20 ucode_patch_late =3D (struct microcode_intel *)new_mc; return UCODE_NEW; + +fail: + kvfree(mc); + kvfree(new_mc); + return UCODE_ERROR; } =20 static bool is_blacklisted(unsigned int cpu) @@ -643,9 +645,9 @@ static enum ucode_state request_microcod static void finalize_late_load(int result) { if (!result) - save_microcode_patch(ucode_patch_late); - - vfree(ucode_patch_late); + update_ucode_pointer(ucode_patch_late); + else + kvfree(ucode_patch_late); ucode_patch_late =3D NULL; }