From patchwork Fri Oct 20 11:38:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 156075 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp995211vqb; Fri, 20 Oct 2023 04:48:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFD4bEAj2Bj/UE1IDOBj3e8vdsefUEUQRm+5zCTioDXRW2AVsES52M0xo6+1V1Dx7yM9ZNP X-Received: by 2002:a17:90a:1e:b0:27d:3c3b:ced4 with SMTP id 30-20020a17090a001e00b0027d3c3bced4mr1423749pja.43.1697802496031; Fri, 20 Oct 2023 04:48:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697802496; cv=none; d=google.com; s=arc-20160816; b=TIiiuE2SAso7Q2k3WIMMPMShJG3gqhwWepgQEUVh/1ZSmxOmn5o+dIhszNPsWo+lvK J73oIKcwhwvP6T2qEJjrd2QBaljuORhRfrIx0XeU0ASiZ04ebBFVBm1+Qwcgf7gsF+zu ro8j+84DphgDf+8FmPjmExIQf+/VHXMtI/ViL2j6SmrTllhZcFe78CSA0zbj6q6LsHvK UFs+bIEu7VyNRsSqCyOuVo2PRpmwhiiK5hhXpqGKtrOqmlEffNz2c3/8q13HvURux+jh Bfm/5Lxm9QG8ZMff/wlQlYaAs5qfiWQ+lD/8qA80XE3bCWakIus5EA7cSK8uAFAfwfZ0 Ztjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=jPmISQfOI9Lk3CN4yTAr/E5Cty5s1Zbxbjjihvi3/qY=; fh=LWlv3U+xZ3+vQt4tlJRIlKl5VzN7iFjjE/bzRmlxKDA=; b=MyDNWL+sZHoSHj239YqAp8XKm70hJDS7XAtX+Po9oNErkcU9Iv2uPAdEF3uH/ReMcY E8qXszEW6s4n/KKu3Q15U9Ri/0p/UtmQBJ5gBJg7fP/tDMmMymcnFUMWGgVR4wQHqWlr hOT0BygOsvvruDEkdclZRo1q2Z/IeqGsDJGTCOUyTfO91pHQehu2ruRiXJPlRhZFWucy QRawbHGPHL/396vkZD1QFso0IidnB4CYzsJnKts1p/xV8umogg7sPlzrslVEn479qQD0 dqNnm/5BPCxz+UHQJiHY07vbQL22pIjUEOTeVXu3+RizxrvKty/uEcHH3uv4+woqZYR4 P6dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aQ3y3Go2; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=33uzqY1S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id lx12-20020a17090b4b0c00b0027dbf69ec11si1889063pjb.160.2023.10.20.04.48.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 04:48:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aQ3y3Go2; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=33uzqY1S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 836DB82D2B47; Fri, 20 Oct 2023 04:48:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377216AbjJTLsD (ORCPT + 25 others); Fri, 20 Oct 2023 07:48:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377303AbjJTLr6 (ORCPT ); Fri, 20 Oct 2023 07:47:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 263E1171C; Fri, 20 Oct 2023 04:38:34 -0700 (PDT) Date: Fri, 20 Oct 2023 11:38:01 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697801881; 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=jPmISQfOI9Lk3CN4yTAr/E5Cty5s1Zbxbjjihvi3/qY=; b=aQ3y3Go2L+iEw5n03Ix+WXTbf6C4Sgfp9a0v4o/oF45G9TGdfEjpFMy2CjMMiZaioGQv9Z g45T90+7wBogOqp35DRqPMSR8K6ACRGx0gLLCo+bJo9S0kgZ1DFKf/XjS7oB1PGFWPwlnm bC1/wY8GJjW/mr4aFw8w/o+qOoEt8CRnEtOkvlJ2XJo9cCJNYfBqIh2BSj2mBrIpWcrXFF KhCIbf463wudGi02AzwRmN8nin3FFS+4JYr6C7QUCHq4S82WCAfeMvTcEql72mWy6mTN67 NwnDYIfpdbKsWt6CCiEcDxEF7cEfjVRhqMtOa2m48TpDMgW/YrdlLA4DsWNQeA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697801881; 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=jPmISQfOI9Lk3CN4yTAr/E5Cty5s1Zbxbjjihvi3/qY=; b=33uzqY1S34jbwL08VDozAbjhyELliccSoT+GThmFn38u2cisDIWjcgygndNoVLisqQpQ0V Ra4IFkVadc8hXSAQ== 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: <169780188118.3135.1886512940729658294.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.8 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 agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Fri, 20 Oct 2023 04:48:13 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778683061410403437 X-GMAIL-MSGID: 1780274950443535512 The following commit has been merged into the x86/microcode branch of tip: Commit-ID: 6b072022ab2e1e83b7588144ee0080f7197b71da Gitweb: https://git.kernel.org/tip/6b072022ab2e1e83b7588144ee0080f7197b71da Author: Thomas Gleixner AuthorDate: Mon, 02 Oct 2023 13:59:40 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Thu, 19 Oct 2023 14:10:00 +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/microcode/intel.c index 26f759b..9463b14 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); -/* - * Returns 1 if update has been found, 0 otherwise. - */ -static int has_newer_microcode(void *mc, unsigned int csig, int cpf, int new_rev) -{ - struct microcode_header_intel *mc_hdr = mc; - - if (mc_hdr->rev <= 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; @@ -559,14 +546,12 @@ out: return ret; } -static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *iter) +static enum ucode_state parse_microcode_blobs(int cpu, struct iov_iter *iter) { struct ucode_cpu_info *uci = ucode_cpu_info + cpu; unsigned int curr_mc_size = 0, new_mc_size = 0; - enum ucode_state ret = UCODE_OK; - int new_rev = uci->cpu_sig.rev; + int cur_rev = uci->cpu_sig.rev; u8 *new_mc = NULL, *mc = NULL; - unsigned int csig, cpf; while (iov_iter_count(iter)) { struct microcode_header_intel mc_header; @@ -583,6 +568,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 = mc_size - sizeof(mc_header); if (data_size > iov_iter_count(iter)) { pr_err("error! Bad data in microcode data file (truncated file?)\n"); @@ -605,16 +591,17 @@ static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *iter) break; } - csig = uci->cpu_sig.sig; - cpf = uci->cpu_sig.pf; - if (has_newer_microcode(mc, csig, cpf, new_rev)) { - vfree(new_mc); - new_rev = mc_header.rev; - new_mc = mc; - new_mc_size = mc_size; - mc = NULL; /* trigger new vmalloc */ - ret = UCODE_NEW; - } + if (cur_rev >= mc_header.rev) + continue; + + if (!intel_find_matching_signature(mc, uci->cpu_sig.sig, uci->cpu_sig.pf)) + continue; + + vfree(new_mc); + cur_rev = mc_header.rev; + new_mc = mc; + new_mc_size = mc_size; + mc = NULL; } vfree(mc); @@ -634,9 +621,9 @@ static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *iter) save_microcode_patch(new_mc, new_mc_size); pr_debug("CPU%d found a matching microcode update with version 0x%x (current=0x%x)\n", - cpu, new_rev, uci->cpu_sig.rev); + cpu, cur_rev, uci->cpu_sig.rev); - return ret; + return UCODE_NEW; } static bool is_blacklisted(unsigned int cpu) @@ -685,7 +672,7 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device) kvec.iov_base = (void *)firmware->data; kvec.iov_len = firmware->size; iov_iter_kvec(&iter, ITER_SOURCE, &kvec, 1, firmware->size); - ret = generic_load_microcode(cpu, &iter); + ret = parse_microcode_blobs(cpu, &iter); release_firmware(firmware);