From patchwork Sat Nov 19 16:24:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 23281 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp779738wrr; Sat, 19 Nov 2022 08:25:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf5pTSVPDL1Rzseuk+51OdVlfHML7bTFVjMbstBv/LW3DMZezmGXaUhvGoP/uV1Sn+0KwCVm X-Received: by 2002:a17:902:ab8b:b0:176:7852:dae3 with SMTP id f11-20020a170902ab8b00b001767852dae3mr4612228plr.25.1668875112896; Sat, 19 Nov 2022 08:25:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668875112; cv=none; d=google.com; s=arc-20160816; b=IqZx1eO4WfvfDtXn7qXSg9ptYDwDr+c1ejMDJ+W4WaQIIy0ZYTFC/JXNfXq8K/cBK1 ohNp3Wqnr/uZ2Qu4XGoVgYhxJXDAM9vMPsV8mS6NEYeUdqylUSRK3R/Y/gqDLl1eVwYm M7ahBOz+MOMyxW0vdSR0qGG2oR9hlLlTxIL6W/lCKhJBmz91QcT6p8d4H6n6+WaiI+ms BdKEui1whj8MdDzsXGzHM7prnYWyqqf1WTj43AGSSNe3XKqdwy5MqObEEU5JwW4Ox+rZ O09Y+waqpsNCgBUz4WeJfL0Fyzj9yNmYw5s9pTBF7uqlenr0he3+7L1Dsx/NYpJnkQ52 IEfQ== 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=044nh0fAocs34t2my+EmxZh6Xau/bd8rCjVZYOwpDww=; b=mrHoeloAloxVDIjxi54Q21FJ2FqHRCcFYfDnadsK1/IKnlTyoKQu8/W3C+1kbrAC9T C7UqlEmOEkiJwPMxoOGU61Ot1qsdm0f8S0AWz7Bn7c4VYPyASpvaPtxz3HzsPb5HaHUd eYsmj2ySrEQfq1oqc/mFgLFHIt/2953DfILzi32AWNHiGF2YrnjDjBWIVpsbtJ/cPpyc t971l+SR1I4ZbGSaLtpLzAg1a+XVJhEdxBQOQWIgpqudNrVI71CEXG+M0V5kxxhlCISt TkymDyPv48PX97ffVXFJ0fPTueF16dAIgQJIzTLQVrB0Lh2WwJ8hKgZd2Z9oAZNjSxpb ebSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fxIkU7or; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="c/smRKUy"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p1-20020a056a000a0100b0056dde9895e1si7089626pfh.46.2022.11.19.08.24.59; Sat, 19 Nov 2022 08:25:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fxIkU7or; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="c/smRKUy"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234168AbiKSQY0 (ORCPT + 99 others); Sat, 19 Nov 2022 11:24:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229689AbiKSQYH (ORCPT ); Sat, 19 Nov 2022 11:24:07 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9091317C4; Sat, 19 Nov 2022 08:24:05 -0800 (PST) Date: Sat, 19 Nov 2022 16:24:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668875044; 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=044nh0fAocs34t2my+EmxZh6Xau/bd8rCjVZYOwpDww=; b=fxIkU7or/t5BKrJKH+WF4oqSGJ6iNLHyxTPLVsVe9WyVVnrYAXS8jdU4ET5aqeoXCunLTo Ey3AgIy+x18ti+hYBwVNj+uGjheT8u+sRhjTd1sJfDQtdv3v2GCDiJ2qGbvKpDZ56VyA4P eOOrRnsKb4JACOM0/mT1uOmIGqwO6DtQCFVR6jtQTxCEtUv3xj11qo/deVIubA1DIMLzW2 Nl40AfwgZdCVSWuX8CROq9kq2OGz46UPUR8mLdRMFr/2cum82AsFp8swyIXRGcQTM4gp66 F8M6Ftvo+RPWMjm/QO1gZ7MadyNa2nvak1pfspjKOlZEO2gsYTsNZ8tVGY4kkA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668875044; 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=044nh0fAocs34t2my+EmxZh6Xau/bd8rCjVZYOwpDww=; b=c/smRKUynLuTKCwJG2dA9jMmuVppuL6EmWhcZEPQnN+56CWAG34pEn344LKvBDvcvGhGxE 9Ata/ft9dvUZsOBQ== From: "tip-bot2 for Jithu Joseph" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/microcode] platform/x86/intel/ifs: Use generic microcode headers and functions Cc: Jithu Joseph , Borislav Petkov , Tony Luck , Sohil Mehta , Hans de Goede , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20221117225039.30166-1-jithu.joseph@intel.com> References: <20221117225039.30166-1-jithu.joseph@intel.com> MIME-Version: 1.0 Message-ID: <166887504331.4906.2340046039874835740.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747331280254736478?= X-GMAIL-MSGID: =?utf-8?q?1749942390071221405?= The following commit has been merged into the x86/microcode branch of tip: Commit-ID: aa63e0fda85edf9a8431fc31a2b2d4f3f40592f9 Gitweb: https://git.kernel.org/tip/aa63e0fda85edf9a8431fc31a2b2d4f3f40592f9 Author: Jithu Joseph AuthorDate: Thu, 17 Nov 2022 14:50:39 -08:00 Committer: Borislav Petkov CommitterDate: Sat, 19 Nov 2022 11:12:06 +01:00 platform/x86/intel/ifs: Use generic microcode headers and functions Existing implementation (broken) of IFS used a header format (for IFS test images) which was very similar to microcode format, but didn’t accommodate extended signatures. This meant same IFS test image had to be duplicated for different steppings and the validation code in the driver was only looking at the primary header parameters. Going forward, IFS test image headers have been tweaked to become fully compatible with the microcode format. Newer IFS test image headers will use header version 2 in order to distinguish it from microcode images and older IFS test images. In light of the above, reuse struct microcode_header_intel directly in the IFS driver and reuse microcode functions for validation and sanity checking. [ bp: Massage commit message. ] Signed-off-by: Jithu Joseph Signed-off-by: Borislav Petkov Reviewed-by: Tony Luck Reviewed-by: Sohil Mehta Reviewed-by: Hans de Goede Link: https://lore.kernel.org/r/20221117225039.30166-1-jithu.joseph@intel.com --- arch/x86/include/asm/microcode_intel.h | 1 +- drivers/platform/x86/intel/ifs/load.c | 104 ++++-------------------- 2 files changed, 21 insertions(+), 84 deletions(-) diff --git a/arch/x86/include/asm/microcode_intel.h b/arch/x86/include/asm/microcode_intel.h index 6af1e70..f1fa979 100644 --- a/arch/x86/include/asm/microcode_intel.h +++ b/arch/x86/include/asm/microcode_intel.h @@ -43,6 +43,7 @@ struct extended_sigtable { #define EXT_HEADER_SIZE (sizeof(struct extended_sigtable)) #define EXT_SIGNATURE_SIZE (sizeof(struct extended_signature)) #define MC_HEADER_TYPE_MICROCODE 1 +#define MC_HEADER_TYPE_IFS 2 #define get_totalsize(mc) \ (((struct microcode_intel *)mc)->hdr.datasize ? \ diff --git a/drivers/platform/x86/intel/ifs/load.c b/drivers/platform/x86/intel/ifs/load.c index 9228da5..8343416 100644 --- a/drivers/platform/x86/intel/ifs/load.c +++ b/drivers/platform/x86/intel/ifs/load.c @@ -7,22 +7,8 @@ #include "ifs.h" -struct ifs_header { - u32 header_ver; - u32 blob_revision; - u32 date; - u32 processor_sig; - u32 check_sum; - u32 loader_rev; - u32 processor_flags; - u32 metadata_size; - u32 total_size; - u32 fusa_info; - u64 reserved; -}; - -#define IFS_HEADER_SIZE (sizeof(struct ifs_header)) -static struct ifs_header *ifs_header_ptr; /* pointer to the ifs image header */ +#define IFS_HEADER_SIZE (sizeof(struct microcode_header_intel)) +static struct microcode_header_intel *ifs_header_ptr; /* pointer to the ifs image header */ static u64 ifs_hash_ptr; /* Address of ifs metadata (hash) */ static u64 ifs_test_image_ptr; /* 256B aligned address of test pattern */ static DECLARE_COMPLETION(ifs_done); @@ -149,29 +135,14 @@ done: */ static int scan_chunks_sanity_check(struct device *dev) { - int metadata_size, curr_pkg, cpu, ret; struct ifs_data *ifsd = ifs_get_data(dev); struct ifs_work local_work; - char *test_ptr; - - memset(ifsd->pkg_auth, 0, (topology_max_packages() * sizeof(bool))); - metadata_size = ifs_header_ptr->metadata_size; + int curr_pkg, cpu, ret; - /* Spec says that if the Meta Data Size = 0 then it should be treated as 2000 */ - if (metadata_size == 0) - metadata_size = 2000; - /* Scan chunk start must be 256 byte aligned */ - if ((metadata_size + IFS_HEADER_SIZE) % 256) { - dev_err(dev, "Scan pattern offset within the binary is not 256 byte aligned\n"); - return -EINVAL; - } - - test_ptr = (char *)ifs_header_ptr + IFS_HEADER_SIZE + metadata_size; + memset(ifsd->pkg_auth, 0, (topology_max_packages() * sizeof(bool))); ifsd->loading_error = false; - - ifs_test_image_ptr = (u64)test_ptr; - ifsd->loaded_version = ifs_header_ptr->blob_revision; + ifsd->loaded_version = ifs_header_ptr->rev; /* copy the scan hash and authenticate per package */ cpus_read_lock(); @@ -197,67 +168,33 @@ out: return ret; } -static int ifs_sanity_check(struct device *dev, - const struct microcode_header_intel *mc_header) +static int image_sanity_check(struct device *dev, const struct microcode_header_intel *data) { - unsigned long total_size, data_size; - u32 sum, *mc; - - total_size = get_totalsize(mc_header); - data_size = get_datasize(mc_header); + struct ucode_cpu_info uci; - if ((data_size + MC_HEADER_SIZE > total_size) || (total_size % sizeof(u32))) { - dev_err(dev, "bad ifs data file size.\n"); + /* Provide a specific error message when loading an older/unsupported image */ + if (data->hdrver != MC_HEADER_TYPE_IFS) { + dev_err(dev, "Header version %d not supported\n", data->hdrver); return -EINVAL; } - if (mc_header->ldrver != 1 || mc_header->hdrver != 1) { - dev_err(dev, "invalid/unknown ifs update format.\n"); + if (intel_microcode_sanity_check((void *)data, true, MC_HEADER_TYPE_IFS)) { + dev_err(dev, "sanity check failed\n"); return -EINVAL; } - mc = (u32 *)mc_header; - sum = 0; - for (int i = 0; i < total_size / sizeof(u32); i++) - sum += mc[i]; + intel_cpu_collect_info(&uci); - if (sum) { - dev_err(dev, "bad ifs data checksum, aborting.\n"); + if (!intel_find_matching_signature((void *)data, + uci.cpu_sig.sig, + uci.cpu_sig.pf)) { + dev_err(dev, "cpu signature, processor flags not matching\n"); return -EINVAL; } return 0; } -static bool find_ifs_matching_signature(struct device *dev, struct ucode_cpu_info *uci, - const struct microcode_header_intel *shdr) -{ - unsigned int mc_size; - - mc_size = get_totalsize(shdr); - - if (!mc_size || ifs_sanity_check(dev, shdr) < 0) { - dev_err(dev, "ifs sanity check failure\n"); - return false; - } - - if (!intel_cpu_signatures_match(uci->cpu_sig.sig, uci->cpu_sig.pf, shdr->sig, shdr->pf)) { - dev_err(dev, "ifs signature, pf not matching\n"); - return false; - } - - return true; -} - -static bool ifs_image_sanity_check(struct device *dev, const struct microcode_header_intel *data) -{ - struct ucode_cpu_info uci; - - intel_cpu_collect_info(&uci); - - return find_ifs_matching_signature(dev, &uci, data); -} - /* * Load ifs image. Before loading ifs module, the ifs image must be located * in /lib/firmware/intel/ifs and named as {family/model/stepping}.{testname}. @@ -278,12 +215,11 @@ void ifs_load_firmware(struct device *dev) goto done; } - if (!ifs_image_sanity_check(dev, (struct microcode_header_intel *)fw->data)) { - dev_err(dev, "ifs header sanity check failed\n"); + ret = image_sanity_check(dev, (struct microcode_header_intel *)fw->data); + if (ret) goto release; - } - ifs_header_ptr = (struct ifs_header *)fw->data; + ifs_header_ptr = (struct microcode_header_intel *)fw->data; ifs_hash_ptr = (u64)(ifs_header_ptr + 1); ret = scan_chunks_sanity_check(dev);