From nobody Fri Jan 2 18:51:21 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 D02D6E95A96 for ; Mon, 9 Oct 2023 12:31:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376622AbjJIMb0 (ORCPT ); Mon, 9 Oct 2023 08:31:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376470AbjJIMaC (ORCPT ); Mon, 9 Oct 2023 08:30:02 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C37ED10B; Mon, 9 Oct 2023 05:29:56 -0700 (PDT) Date: Mon, 09 Oct 2023 12:29:54 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696854595; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fSBwPPuYTEKMKf339cHrJEKhRr6JzbrWL6jhZW7JOqU=; b=chLe2qC+V5FptQb70dLL6BZzCWEBYt4FWxNpnNwHIhQ2wM3rlHA2VpkN/0unTIkG/CoWvB KJ8Eyy5JgQ4moI5S6jrNWngy81hngsKa/uQeMIkJZ5W4RznJMtSZ2HT8tJQc6CHWoJtRQ8 76P7Sz+cvrtdtC2kmwnMW+YwVQ1WGm4InoT7WbiC+/XuTJa4AZVbt5uU9Zjx8WNIrj8raq BaDn18ZwgDjJ7IWNM9CTFdNdz3wMytbxwzO9iJUAVlaCXM7gmo5kSffXiKUM0Xi4dMOdEJ AgsL7wy9vptNoX3bjsmEXq8P6VINGER5BQkEFHWcpsV6BCXcDx+TLxcI3L2evA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696854595; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fSBwPPuYTEKMKf339cHrJEKhRr6JzbrWL6jhZW7JOqU=; b=nZJXKM1Wm5ktKnhSeXDCwVLk/R624mW7L8BVMrcAuZjjkIkXrMqjT4KdGrOirDH2754xvx 555pT2f8Ngj/tNCQ== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/microcode] x86/microcode/intel: Simplify and rename generic_load_microcode() Cc: Thomas Gleixner , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231002115902.330295409@linutronix.de> References: <20231002115902.330295409@linutronix.de> MIME-Version: 1.0 Message-ID: <169685459487.3135.1600341788116234467.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/microcode branch of tip: Commit-ID: 6dea0b60b5b3f7d810877d1d0ccf3778bb142d00 Gitweb: https://git.kernel.org/tip/6dea0b60b5b3f7d810877d1d0ccf3778b= b142d00 Author: Thomas Gleixner AuthorDate: Mon, 02 Oct 2023 13:59:40 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Mon, 02 Oct 2023 18:31:20 +02:00 x86/microcode/intel: Simplify and rename generic_load_microcode() so it becomes less obfuscated and rename it because there is nothing generic about it. Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20231002115902.330295409@linutronix.de --- arch/x86/kernel/cpu/microcode/intel.c | 47 +++++++++----------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/mi= crocode/intel.c index 24dd483..60862f6 100644 --- a/arch/x86/kernel/cpu/microcode/intel.c +++ b/arch/x86/kernel/cpu/microcode/intel.c @@ -240,19 +240,6 @@ int intel_microcode_sanity_check(void *mc, bool print_= err, int hdr_type) } EXPORT_SYMBOL_GPL(intel_microcode_sanity_check); =20 -/* - * Returns 1 if update has been found, 0 otherwise. - */ -static int has_newer_microcode(void *mc, unsigned int csig, int cpf, int n= ew_rev) -{ - struct microcode_header_intel *mc_hdr =3D mc; - - if (mc_hdr->rev <=3D new_rev) - return 0; - - return intel_find_matching_signature(mc, csig, cpf); -} - static void save_microcode_patch(void *data, unsigned int size) { struct microcode_header_intel *p; @@ -561,14 +548,12 @@ out: return ret; } =20 -static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *i= ter) +static enum ucode_state parse_microcode_blobs(int cpu, struct iov_iter *it= er) { struct ucode_cpu_info *uci =3D ucode_cpu_info + cpu; unsigned int curr_mc_size =3D 0, new_mc_size =3D 0; - enum ucode_state ret =3D UCODE_OK; - int new_rev =3D uci->cpu_sig.rev; + int cur_rev =3D uci->cpu_sig.rev; u8 *new_mc =3D NULL, *mc =3D NULL; - unsigned int csig, cpf; =20 while (iov_iter_count(iter)) { struct microcode_header_intel mc_header; @@ -585,6 +570,7 @@ static enum ucode_state generic_load_microcode(int cpu,= struct iov_iter *iter) pr_err("error! Bad data in microcode data file (totalsize too small)\n"= ); break; } + 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"); @@ -607,16 +593,17 @@ static enum ucode_state generic_load_microcode(int cp= u, struct iov_iter *iter) break; } =20 - csig =3D uci->cpu_sig.sig; - cpf =3D uci->cpu_sig.pf; - if (has_newer_microcode(mc, csig, cpf, new_rev)) { - vfree(new_mc); - new_rev =3D mc_header.rev; - new_mc =3D mc; - new_mc_size =3D mc_size; - mc =3D NULL; /* trigger new vmalloc */ - ret =3D UCODE_NEW; - } + if (cur_rev >=3D mc_header.rev) + continue; + + if (!intel_find_matching_signature(mc, uci->cpu_sig.sig, uci->cpu_sig.pf= )) + continue; + + vfree(new_mc); + cur_rev =3D mc_header.rev; + new_mc =3D mc; + new_mc_size =3D mc_size; + mc =3D NULL; } =20 vfree(mc); @@ -636,9 +623,9 @@ static enum ucode_state generic_load_microcode(int cpu,= struct iov_iter *iter) save_microcode_patch(new_mc, new_mc_size); =20 pr_debug("CPU%d found a matching microcode update with version 0x%x (curr= ent=3D0x%x)\n", - cpu, new_rev, uci->cpu_sig.rev); + cpu, cur_rev, uci->cpu_sig.rev); =20 - return ret; + return UCODE_NEW; } =20 static bool is_blacklisted(unsigned int cpu) @@ -687,7 +674,7 @@ static enum ucode_state request_microcode_fw(int cpu, s= truct device *device) kvec.iov_base =3D (void *)firmware->data; kvec.iov_len =3D firmware->size; iov_iter_kvec(&iter, ITER_SOURCE, &kvec, 1, firmware->size); - ret =3D generic_load_microcode(cpu, &iter); + ret =3D parse_microcode_blobs(cpu, &iter); =20 release_firmware(firmware);