From nobody Fri Dec 19 05:00:13 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 B82A2C0015E for ; Sat, 12 Aug 2023 20:06:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231179AbjHLUGa (ORCPT ); Sat, 12 Aug 2023 16:06:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230523AbjHLUG1 (ORCPT ); Sat, 12 Aug 2023 16:06:27 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D92291BD1 for ; Sat, 12 Aug 2023 13:05:59 -0700 (PDT) Message-ID: <20230812195728.708313227@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1691870348; 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=rDI1ykgeaxeUMJlpq0aKo/7WMXntCc7/NJHkM9TFISc=; b=ESEHMgas6zDqDY1Q70SV3AEf1kfnaElwEZ7nZVWCQ2jwa+IUQMfl1AJmpWBsKVA/CAO3qx +65QuC0aPiePqdwsKp0Nje52wp+8XJ/VGyPc3LtxBUyMzicyAP/5m95if+ww2FIWkuhT7A ALJFmn3HgVT2vB+cBUCTSrBChYCMFIHxxJVSgPnMgsukOgcg1gRDHo+SwUI6sj1Bhoca06 +JAGWDQCmwLhOxPcgr9HCUOMP5tNxL4Pgli+NStl99Ub8hnrycayEMfBAnktVhjILQ95I/ +7ZTQ2V5mJ427wOes8RFCm86u+u3g2uLwRv9BvIq7ILg/c4LhDabHu8eHOW1OQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1691870348; 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=rDI1ykgeaxeUMJlpq0aKo/7WMXntCc7/NJHkM9TFISc=; b=LWFB0AQXcLWH4U6txqX5zCIBRJOxtLsNjIsAHcf0vltZm1PZBY/VM3UFXL8zJ0sPOpmZEM e9vD35QS7SIJkyBQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Borislav Petkov , Ashok Raj , Arjan van de Ven , Nikolay Borisov Subject: [patch V2 20/37] x86/microcode/intel: Rework intel_find_matching_signature() References: <20230812194003.682298127@linutronix.de> MIME-Version: 1.0 Date: Sat, 12 Aug 2023 21:59:07 +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" Take a cpu_signature argument and work from there. Move the match() helper next to the callsite as there is no point for having it in a header. Signed-off-by: Thomas Gleixner --- V2: New patch --- arch/x86/include/asm/cpu.h | 16 +--------------- arch/x86/kernel/cpu/microcode/intel.c | 31 +++++++++++++++++++----------= -- drivers/platform/x86/intel/ifs/load.c | 2 +- 3 files changed, 21 insertions(+), 28 deletions(-) --- a/arch/x86/include/asm/cpu.h +++ b/arch/x86/include/asm/cpu.h @@ -77,22 +77,8 @@ struct cpu_signature; =20 void intel_collect_cpu_info(struct cpu_signature *sig); =20 -static inline bool intel_cpu_signatures_match(unsigned int s1, unsigned in= t p1, - unsigned int s2, unsigned int p2) -{ - if (s1 !=3D s2) - return false; - - /* Processor flags are either both 0 ... */ - if (!p1 && !p2) - return true; - - /* ... or they intersect. */ - return p1 & p2; -} - extern u64 x86_read_arch_cap_msr(void); -int intel_find_matching_signature(void *mc, unsigned int csig, int cpf); +bool intel_find_matching_signature(void *mc, struct cpu_signature *sig); int intel_microcode_sanity_check(void *mc, bool print_err, int hdr_type); =20 extern struct cpumask cpus_stop_mask; --- a/arch/x86/kernel/cpu/microcode/intel.c +++ b/arch/x86/kernel/cpu/microcode/intel.c @@ -82,29 +82,36 @@ void intel_collect_cpu_info(struct cpu_s } EXPORT_SYMBOL_GPL(intel_collect_cpu_info); =20 -/* - * Returns 1 if update has been found, 0 otherwise. - */ -int intel_find_matching_signature(void *mc, unsigned int csig, int cpf) +static inline bool cpu_signatures_match(struct cpu_signature *s1, unsigned= int sig2, + unsigned int pf2) +{ + if (s1->sig !=3D sig2) + return false; + + /* Processor flags are either both 0 or they intersect. */ + return ((!s1->pf && !pf2) || (s1->pf & pf2)); +} + +bool intel_find_matching_signature(void *mc, struct cpu_signature *sig) { struct microcode_header_intel *mc_hdr =3D mc; - struct extended_sigtable *ext_hdr; struct extended_signature *ext_sig; + struct extended_sigtable *ext_hdr; int i; =20 - if (intel_cpu_signatures_match(csig, cpf, mc_hdr->sig, mc_hdr->pf)) - return 1; + if (cpu_signatures_match(sig, mc_hdr->sig, mc_hdr->pf)) + return true; =20 /* Look for ext. headers: */ if (get_totalsize(mc_hdr) <=3D intel_microcode_get_datasize(mc_hdr) + MC_= HEADER_SIZE) - return 0; + return false; =20 ext_hdr =3D mc + intel_microcode_get_datasize(mc_hdr) + MC_HEADER_SIZE; ext_sig =3D (void *)ext_hdr + EXT_HEADER_SIZE; =20 for (i =3D 0; i < ext_hdr->count; i++) { - if (intel_cpu_signatures_match(csig, cpf, ext_sig->sig, ext_sig->pf)) - return 1; + if (cpu_signatures_match(sig, ext_sig->sig, ext_sig->pf)) + return true; ext_sig++; } return 0; @@ -272,7 +279,7 @@ static __init struct microcode_intel *sc intel_microcode_sanity_check(data, false, MC_HEADER_TYPE_MICROCODE) = < 0) break; =20 - if (!intel_find_matching_signature(data, uci->cpu_sig.sig, uci->cpu_sig.= pf)) + if (!intel_find_matching_signature(data, &uci->cpu_sig)) continue; =20 /* Check whether there is newer microcode */ @@ -583,7 +590,7 @@ static enum ucode_state read_ucode_intel if (cur_rev >=3D mc_header.rev) continue; =20 - if (!intel_find_matching_signature(mc, uci->cpu_sig.sig, uci->cpu_sig.pf= )) + if (!intel_find_matching_signature(mc, &uci->cpu_sig)) continue; =20 kvfree(new_mc); --- a/drivers/platform/x86/intel/ifs/load.c +++ b/drivers/platform/x86/intel/ifs/load.c @@ -242,7 +242,7 @@ static int image_sanity_check(struct dev =20 intel_collect_cpu_info(&sig); =20 - if (!intel_find_matching_signature((void *)data, sig.sig, sig.pf)) { + if (!intel_find_matching_signature((void *)data, &sig)) { dev_err(dev, "cpu signature, processor flags not matching\n"); return -EINVAL; }