Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp992958pxb; Fri, 22 Apr 2022 16:11:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJ0QRztVifUpnYHRMuHFcoqMwtz4AFDf8ng91lnvm+Ki0nWJHMfdkvtHA5mQIbmLO32BD7 X-Received: by 2002:a17:903:284:b0:158:8e21:2108 with SMTP id j4-20020a170903028400b001588e212108mr6851183plr.37.1650669119360; Fri, 22 Apr 2022 16:11:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650669119; cv=none; d=google.com; s=arc-20160816; b=WcQhU+JKuy02RlB4FOg3TXLJS8T1h/ylw/nKRzgRRq/pcoPYPzXYEWJv+LK9ABpO3Q aR2YWjXOxD7foOhrPwXj3xOQRRAqMn1ocSHtj5EGtjHqMrZ1zZJ+c+IBrN8eAU4DukJ2 x8og5lwaUqH8opIVFheTBdD0hfqjhrQoaj/AK2eavMqrQyHCoyJiT+IrZBK/hCIvSv7C MefvWJ62XPul5HAQfC3WOKso+P5pXd7aW5NhmdMh8PKvGMb3SIR7H3bIQyJYHw7yxZE3 gUAv64mbHYwwHewNsMt8SLyzUZP4vxWuzzyS8LLVC2sMQqWbOShL6TGr8GhjnKbQoDRf LjrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eb0DNzmHUH9vHG3urAwSV2vvOl1O2H/h5dMVex5b9Uc=; b=hN8GCCYPDf1dh1bU5ymq+DMZNxhuLjmF3U52Nj16tTkpLr2pRdii+XMRUeO50oo2v1 vgsglNzwi+dTk8AQsKiLcsNWkhKkoAsBaLKoF28XgESzMg0t7GwuTIOP3s4lI7ekfGmO ppAXFOV/HtZ/YTXTxGtTqxuJSUFaUPv81nzljFVIVRv2T9x7LOmndJXEfPhXKaERGVba 6tcJhK0JfsA/a1CrG+ssSxMSeYaC4gl83UULNmdcOs2bz2tFjhkbqiQOh2PrkhbraHyk vsEuaWuYl3G5/klUc7s52yX1P7aoF7hFMtOY8yW1wfRcZZJNZwbxYiy9ShEMPqE7ykab qH8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JHGS5N9M; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id f11-20020a170902ce8b00b00156aa98a93bsi6289061plg.31.2022.04.22.16.11.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 16:11:59 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JHGS5N9M; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4B0EA375E40; Fri, 22 Apr 2022 15:13:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231736AbiDVWMF (ORCPT + 99 others); Fri, 22 Apr 2022 18:12:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231954AbiDVWJd (ORCPT ); Fri, 22 Apr 2022 18:09:33 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 129AF2D8237; Fri, 22 Apr 2022 13:56:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650660986; x=1682196986; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0y0ARuJOG0aT4gpANTyQc+sN+Oa1pFODX+GbED6WNn4=; b=JHGS5N9ModePPiL74LtAFQs+1pUJHVOR6gKQD52h4652GwhjvPCqCyG/ vIauOx+hIyywA/d46oRGff3VdVtcL7Fwe1NNK6LMOPd3kpo1UDTXhr3D4 t+JAt4nY76EfhI+WC9iZMuXhSjSTlrX8T+5nd2tOiH+k2Kqgdly2MMLIV M5BjEhkIiXdV8fapwqYE6bK3C+ZdWCAcvkuXoAzKv/Q9lWYQ6r9ImugQz EhxPmLAmcFCo8O0vtqZ53YSOzb6LiuQwcEqCxm23FYzfCtqETuKrT+1Ka CLK6tbBsVtn0HEXgww3YOo8ryVFC72iKgwHmLBTLpg4QB4EUZrmzb/m1J w==; X-IronPort-AV: E=McAfee;i="6400,9594,10324"; a="289897457" X-IronPort-AV: E=Sophos;i="5.90,282,1643702400"; d="scan'208";a="289897457" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Apr 2022 13:02:27 -0700 X-IronPort-AV: E=Sophos;i="5.90,282,1643702400"; d="scan'208";a="511719334" Received: from agluck-desk3.sc.intel.com ([172.25.222.78]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Apr 2022 13:02:26 -0700 From: Tony Luck To: hdegoede@redhat.com, markgross@kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, corbet@lwn.net, gregkh@linuxfoundation.org, andriy.shevchenko@linux.intel.com, jithu.joseph@intel.com, ashok.raj@intel.com, tony.luck@intel.com, rostedt@goodmis.org, dan.j.williams@intel.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, platform-driver-x86@vger.kernel.org, patches@lists.linux.dev, ravi.v.shankar@intel.com Subject: [PATCH v4 04/10] platform/x86/intel/ifs: Read IFS firmware image Date: Fri, 22 Apr 2022 13:02:13 -0700 Message-Id: <20220422200219.2843823-5-tony.luck@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220422200219.2843823-1-tony.luck@intel.com> References: <20220419163859.2228874-1-tony.luck@intel.com> <20220422200219.2843823-1-tony.luck@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=unavailable 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 From: Jithu Joseph Driver probe routine allocates structure to communicate status and parameters between functions in the driver. Also call load_ifs_binary() to load the scan image file. There is a separate scan image file for each processor family, model, stepping combination. This is read from the static path: /lib/firmware/intel/ifs/{ff-mm-ss}.scan Step 1 in loading is to generate the correct path and use request_firmware_direct() to load into memory. Subsequent patches will use the IFS MSR interfaces to copy the image to BIOS reserved memory and validate the SHA256 checksums. Signed-off-by: Jithu Joseph Co-developed-by: Tony Luck Signed-off-by: Tony Luck --- drivers/platform/x86/intel/ifs/Makefile | 2 +- drivers/platform/x86/intel/ifs/core.c | 36 ++++++++++++++++++++++++- drivers/platform/x86/intel/ifs/ifs.h | 25 +++++++++++++++++ drivers/platform/x86/intel/ifs/load.c | 28 +++++++++++++++++++ 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 drivers/platform/x86/intel/ifs/ifs.h create mode 100644 drivers/platform/x86/intel/ifs/load.c diff --git a/drivers/platform/x86/intel/ifs/Makefile b/drivers/platform/x86/intel/ifs/Makefile index af904880e959..98b6fde15689 100644 --- a/drivers/platform/x86/intel/ifs/Makefile +++ b/drivers/platform/x86/intel/ifs/Makefile @@ -1,3 +1,3 @@ obj-$(CONFIG_INTEL_IFS) += intel_ifs.o -intel_ifs-objs := core.o +intel_ifs-objs := core.o load.o diff --git a/drivers/platform/x86/intel/ifs/core.c b/drivers/platform/x86/intel/ifs/core.c index 5713e6ee90f0..ed4ded6755b2 100644 --- a/drivers/platform/x86/intel/ifs/core.c +++ b/drivers/platform/x86/intel/ifs/core.c @@ -6,6 +6,8 @@ #include +#include "ifs.h" + enum test_types { IFS_SAF, }; @@ -20,10 +22,27 @@ static const struct x86_cpu_id ifs_cpu_ids[] __initconst = { }; MODULE_DEVICE_TABLE(x86cpu, ifs_cpu_ids); +static struct ifs_device ifs_devices[] = { + [IFS_SAF] = { + .data = { + .integrity_cap_bit = MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT, + }, + .misc = { + .name = "intel_ifs_0", + .nodename = "intel_ifs/0", + .minor = MISC_DYNAMIC_MINOR, + }, + }, +}; + +#define IFS_NUMTESTS ARRAY_SIZE(ifs_devices) + static int __init ifs_init(void) { const struct x86_cpu_id *m; + int ndevices = 0; u64 msrval; + int i; m = x86_match_cpu(ifs_cpu_ids); if (!m) @@ -38,11 +57,26 @@ static int __init ifs_init(void) if (rdmsrl_safe(MSR_INTEGRITY_CAPS, &msrval)) return -ENODEV; - return 0; + for (i = 0; i < IFS_NUMTESTS; i++) { + if (!(msrval & BIT(ifs_devices[i].data.integrity_cap_bit))) + continue; + + if (!misc_register(&ifs_devices[i].misc)) { + ndevices++; + ifs_load_firmware(ifs_devices[i].misc.this_device); + } + } + + return ndevices ? 0 : -ENODEV; } static void __exit ifs_exit(void) { + int i; + + for (i = 0; i < IFS_NUMTESTS; i++) + if (ifs_devices[i].misc.this_device) + misc_deregister(&ifs_devices[i].misc); } module_init(ifs_init); diff --git a/drivers/platform/x86/intel/ifs/ifs.h b/drivers/platform/x86/intel/ifs/ifs.h new file mode 100644 index 000000000000..9a0f8e2077e2 --- /dev/null +++ b/drivers/platform/x86/intel/ifs/ifs.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright(c) 2022 Intel Corporation. */ + +#ifndef _IFS_H_ +#define _IFS_H_ + +#include +#include + +/** + * struct ifs_data - attributes related to intel IFS driver + * @integrity_cap_bit - MSR_INTEGRITY_CAPS bit enumerating this test + */ +struct ifs_data { + int integrity_cap_bit; +}; + +struct ifs_device { + struct ifs_data data; + struct miscdevice misc; +}; + +void ifs_load_firmware(struct device *dev); + +#endif diff --git a/drivers/platform/x86/intel/ifs/load.c b/drivers/platform/x86/intel/ifs/load.c new file mode 100644 index 000000000000..9fb71d38c819 --- /dev/null +++ b/drivers/platform/x86/intel/ifs/load.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright(c) 2022 Intel Corporation. */ + +#include + +#include "ifs.h" + +/* + * 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}. + */ +void ifs_load_firmware(struct device *dev) +{ + const struct firmware *fw; + char scan_path[32]; + int ret; + + snprintf(scan_path, sizeof(scan_path), "intel/ifs/%02x-%02x-%02x.scan", + boot_cpu_data.x86, boot_cpu_data.x86_model, boot_cpu_data.x86_stepping); + + ret = request_firmware_direct(&fw, scan_path, dev); + if (ret) { + dev_err(dev, "ifs file %s load failed\n", scan_path); + return; + } + + release_firmware(fw); +} -- 2.35.1