Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2611467rdb; Tue, 12 Sep 2023 07:12:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5MTaW5U4yeWUNK9X9WwFwnFB7tMzhBVBw+WXFc/nr4g04iA6/0q4U6Reht0mmdWhbORFy X-Received: by 2002:a17:90a:72c2:b0:269:6c5:11a7 with SMTP id l2-20020a17090a72c200b0026906c511a7mr10222903pjk.17.1694527935874; Tue, 12 Sep 2023 07:12:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694527935; cv=none; d=google.com; s=arc-20160816; b=w6gZuGeUpyzX6B2DL3kJQkyfzphTL481kH+siiOSUbPXMw8Qk/u9CVisSD8cuH/598 Po0Tvy2f4JjPiWJIx5U/5npopGgieLhMxVsUsac23fe8wAgeXi0CbzCUtjCByLb8kEkH Lcy0z0rLlr+1RMHWUXoAbCyFPqGRJHMpaLC0SwrhIgC2CyFE24IShRvNvRaCLEn1kaE6 SxJtC1lCaQPMAOsIWRFZRZ+SAGtrMiq/pEwLRHX7G9tneb73pzkJjLa78HSeVREBbHoe ZHKF+tgq4skRNL8qZfmyUCMGgOPaAGRnTKPKM6vZy8F50Sl+29FAnNV8fF7tK3Lde/AJ scZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=COGYr1lbubEBgG3WbXJ/GVEKTFAghSZ0FbZctrPsvVg=; fh=u57tXYamzTrJA+Ht8n1u7SfTMptrQaIb6LVW+jsaYf4=; b=KbWEdubW/LCZX3gDIK6D26gveXXsRgSC2wBk+ABtfrghOVbk4imchsSrsGV6Dg9VCK KOTrUn7c+fsx6sdbokR2YrEPfajR/Zkq604MysAYoRw0Dt77OAVBZQB/p1BbMYA/ScV6 JT2TP0LcTWQkVll4spN8LIZZFMGMR4FeL07FdWEga6bDdgaTZQyw/1Zih6wlhDGlpET6 TDOUcxEkv9WTc2oDn1Bd2ooHIthSLnXyhyY2IsegBLtqrWp0uKDQgXQ14M7qM0LYALZL vZlMpYXHCLtKQt0u8x6HCwVcJCIMXijXXGYCvQsdEPnNlM7CJWyo8HukDcZrN2qnJvGf SCFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=YzkFuM3c; dkim=neutral (no key) header.i=@linutronix.de header.b=2HZZaqcx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id d15-20020a17090a7bcf00b00262ffca5a31si10047250pjl.161.2023.09.12.07.12.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 07:12:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=YzkFuM3c; dkim=neutral (no key) header.i=@linutronix.de header.b=2HZZaqcx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 869E181D6DA9; Tue, 12 Sep 2023 00:58:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231583AbjILH6b (ORCPT + 99 others); Tue, 12 Sep 2023 03:58:31 -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 Content-Type: text/plain; charset=UTF-8 Date: Tue, 12 Sep 2023 09:57:57 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 12 Sep 2023 00:58:49 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 static void update_ucode_pointer(struct microcode_intel *mc) { - kfree(ucode_patch_va); + kvfree(ucode_patch_va); /* * Save the virtual address for early loading and for eventual free @@ -254,11 +253,14 @@ static void update_ucode_pointer(struct static void save_microcode_patch(struct microcode_intel *patch) { - struct microcode_intel *mc; + unsigned int size = get_totalsize(&patch->hdr); + struct microcode_intel *mc = NULL; - mc = kmemdup(patch, get_totalsize(&patch->hdr), GFP_KERNEL); + mc = kvmemdup(patch, size, GFP_KERNEL); if (mc) update_ucode_pointer(mc); + else + pr_err("Unable to allocate microcode memory size: %u\n", size); } /* Scan CPIO for microcode matching the boot CPUs family, model, stepping */ @@ -530,36 +532,34 @@ static enum ucode_state read_ucode_intel 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; } mc_size = 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 = 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; } /* For performance reasons, reuse mc area when possible */ if (!mc || mc_size > curr_mc_size) { - vfree(mc); - mc = vmalloc(mc_size); + kvfree(mc); + mc = kvmalloc(mc_size, GFP_KERNEL); if (!mc) - break; + goto fail; curr_mc_size = mc_size; } memcpy(mc, &mc_header, sizeof(mc_header)); data = 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; if (cur_rev >= 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; - vfree(new_mc); + kvfree(new_mc); cur_rev = mc_header.rev; new_mc = mc; mc = NULL; } - vfree(mc); - - if (iov_iter_count(iter)) { - vfree(new_mc); - return UCODE_ERROR; - } + if (iov_iter_count(iter)) + goto fail; + kvfree(mc); if (!new_mc) return UCODE_NFOUND; ucode_patch_late = (struct microcode_intel *)new_mc; return UCODE_NEW; + +fail: + kvfree(mc); + kvfree(new_mc); + return UCODE_ERROR; } 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 = NULL; }