From patchwork Mon Oct 9 12:29:50 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: 150046 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1833396vqo; Mon, 9 Oct 2023 05:31:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpbMQXi04OFTwUKyYid8TICeNZMkR7WVIMMcUKe4Kf3TluJhpxBcX09dgosqNaTWmQEisr X-Received: by 2002:a05:6a21:99a2:b0:15e:d84:1c5e with SMTP id ve34-20020a056a2199a200b0015e0d841c5emr19520276pzb.38.1696854709666; Mon, 09 Oct 2023 05:31:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696854709; cv=none; d=google.com; s=arc-20160816; b=a3X+Al5ucTMjpnosfrLcuV3qGnvGR/+YCiAd77jMhPfYuyN/uSFVXpw2qlg5a2APtd jBI52twD5njH17BIFSlY4UNmgJuoq10az7bzThDLaLMXgmQBhP7D+s1El8bsuPAP4U/6 6HRPlCTXtE4MrSxzGGK7cQaT+q1xSoaT5sth/7Avoyhmcn3j7dHMm+/B8gJeOpj+VUTf 96wzuVqMm/O5UKkmFklwYTLh6pCqt2NkodMUcJ8l1oSpDXOOQHY7wP72ifviw4vxv9mA QxdCFXrbztenhEyoV5b/KxdWiWEgyBBO+7EEFsVbgjj9Y+mb27LGAoAyyTDMFnR2B5W7 6T2w== 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=ZopQeeyf6sA66BNdOyrZ+jjB+oTsFVGGiRdfloC7HKg=; fh=LWlv3U+xZ3+vQt4tlJRIlKl5VzN7iFjjE/bzRmlxKDA=; b=tLXW6TkTG4O0kaQuirYRhxhewnvhLgmLtXIawuYvhu9wm4Kl7GzOj4+QpMJVNLNy7K +aQXIljoTJaeOzljYMZzfnBHgMOaNp/vpcz5cKyyLIVoEfO1iT0gvvTrxaAMdBe7sT4Z bVIDbptymiwSq7STUpMCOOoXQw8pPnPvl0Aaviki0lZfHLt0Xk+TqvpAVCmldbdhHUoy 9bIkLEO32V5Z6H7/RK72Z8iGEd6aV0DCgdV/DQgX4jrZdonqf/7bxHVwdc2jSRzc9kN9 yYT9qXXqcswLS3Yd2tlUEGLdFM8EVTIiTgn2/vlcXSqOVcW/HnMJYcPBcipCJHoOgKoc hxIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=hQ4kZjVN; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 s21-20020a056a00195500b0068e3b121545si7580241pfk.58.2023.10.09.05.31.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 05:31:49 -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=hQ4kZjVN; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 D1F78808A8D1; Mon, 9 Oct 2023 05:31:11 -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 S1376512AbjJIMak (ORCPT + 18 others); Mon, 9 Oct 2023 08:30:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346595AbjJIM34 (ORCPT ); Mon, 9 Oct 2023 08:29:56 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6B54EA; Mon, 9 Oct 2023 05:29:52 -0700 (PDT) Date: Mon, 09 Oct 2023 12:29:50 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696854591; 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=ZopQeeyf6sA66BNdOyrZ+jjB+oTsFVGGiRdfloC7HKg=; b=hQ4kZjVNBFwi+eqQwUIdPdBZ+qQuSrPBO97t18+3TiqApz2tpNk5VFRMH5I08UT4+LNfh9 FuBuhFkjYlzcfHOCizjblHzsCnBLZHBNyl5411wqXMM0RT/IkV0DPjIw5EU0Bkr4Gy9r+c jWsa6mInGY3XaioFBG6v0GisFnaWysRcpSDrwb0TdOnC9x/qMqWYvyDmYSFJztQ+j6UFzR 4Do57gksko6Y0kujs5v7uY4ae1wodcV8zIY6bsyRVFFR39aj79/YZ1Iw1PghuAWIq8FtY/ gutegRgj4S5CUpBXqd784rvYSDnmTMSi0hy9Mp/mTAEgLDKJ84/78SWI28wnZg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696854591; 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=ZopQeeyf6sA66BNdOyrZ+jjB+oTsFVGGiRdfloC7HKg=; b=iZo3N31IRIZ7sobKBZoXBnHJWeK009nKbqxBzEyTAiSmVCuJB9wupX1U4Vz5MlXqYlbZzs z9oEMwJy5gYpG6BQ== 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: Rework intel_find_matching_signature() Cc: Thomas Gleixner , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231002115902.797820205@linutronix.de> References: <20231002115902.797820205@linutronix.de> MIME-Version: 1.0 Message-ID: <169685459094.3135.5670681550159204450.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no 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]); Mon, 09 Oct 2023 05:31:11 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778645774834782418 X-GMAIL-MSGID: 1779281123674998080 The following commit has been merged into the x86/microcode branch of tip: Commit-ID: 24e6c7324d24b63eac8818cb2f0e8fdffe828715 Gitweb: https://git.kernel.org/tip/24e6c7324d24b63eac8818cb2f0e8fdffe828715 Author: Thomas Gleixner AuthorDate: Mon, 02 Oct 2023 13:59:50 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Tue, 03 Oct 2023 16:25:15 +02:00 x86/microcode/intel: Rework intel_find_matching_signature() 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 Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20231002115902.797820205@linutronix.de --- 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(-) diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h index 4066dd3..e7c9dc3 100644 --- a/arch/x86/include/asm/cpu.h +++ b/arch/x86/include/asm/cpu.h @@ -77,22 +77,8 @@ struct cpu_signature; void intel_collect_cpu_info(struct cpu_signature *sig); -static inline bool intel_cpu_signatures_match(unsigned int s1, unsigned int p1, - unsigned int s2, unsigned int p2) -{ - if (s1 != 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); extern struct cpumask cpus_stop_mask; diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c index 3817bb2..ef699da 100644 --- 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_signature *sig) } EXPORT_SYMBOL_GPL(intel_collect_cpu_info); -/* - * 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 != 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 = mc; - struct extended_sigtable *ext_hdr; struct extended_signature *ext_sig; + struct extended_sigtable *ext_hdr; int i; - 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; /* Look for ext. headers: */ if (get_totalsize(mc_hdr) <= intel_microcode_get_datasize(mc_hdr) + MC_HEADER_SIZE) - return 0; + return false; ext_hdr = mc + intel_microcode_get_datasize(mc_hdr) + MC_HEADER_SIZE; ext_sig = (void *)ext_hdr + EXT_HEADER_SIZE; for (i = 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; @@ -265,7 +272,7 @@ static __init struct microcode_intel *scan_microcode(void *data, size_t size, intel_microcode_sanity_check(data, false, MC_HEADER_TYPE_MICROCODE) < 0) break; - if (!intel_find_matching_signature(data, uci->cpu_sig.sig, uci->cpu_sig.pf)) + if (!intel_find_matching_signature(data, &uci->cpu_sig)) continue; /* Check whether there is newer microcode */ @@ -503,7 +510,7 @@ static enum ucode_state parse_microcode_blobs(int cpu, struct iov_iter *iter) if (cur_rev >= mc_header.rev) continue; - if (!intel_find_matching_signature(mc, uci->cpu_sig.sig, uci->cpu_sig.pf)) + if (!intel_find_matching_signature(mc, &uci->cpu_sig)) continue; kvfree(new_mc); diff --git a/drivers/platform/x86/intel/ifs/load.c b/drivers/platform/x86/intel/ifs/load.c index 61174bd..3e1880f 100644 --- 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 device *dev, const struct microcode_header_ intel_collect_cpu_info(&sig); - 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; }