Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2574806imw; Sun, 10 Jul 2022 09:41:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uRP6ABBqAuuUO7kHUHnJXY8TzphuXX3VQGe4RvCrT10sH5+jLwSujfm6OvNxeZVPFPAwKo X-Received: by 2002:a63:2014:0:b0:411:90a4:6e9c with SMTP id g20-20020a632014000000b0041190a46e9cmr11688741pgg.500.1657471262832; Sun, 10 Jul 2022 09:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657471262; cv=none; d=google.com; s=arc-20160816; b=h2DyWNWgiThM9gUSjLIQ/1ROJzICzcJ9hzV3DsCV9BabRSZV/CTwlPonsh4s2KUAWr zhqlqa3n5n/qT4uIhs9HFsUXf31YjOLsOy8hwVeREobD3ovnp4I9tq/CGv5sWxdkfnUq k+IM2EJre++vcEp5XPlKSw/B+dt1sanZr/7nDp6LBUX0QAuyR6GuKmIQ/+jG1M1+pVKu t7JGacpUWMpFHw4LlQOH+WeZO0HTbAUoIMvT8mEsU7WHcz5eo51+8b9zp3YRRqfoYVyP rYpK2S8G+JNlh/onpqC7NJZKOQ/NXiOO+xbfdTTrCezXiU3LrAgOGkwVzh40476e6dn5 ks7w== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=eMgRGxbVsMXN7IYB3SnzBesf1OLMCyopM1dSk4QUn7o=; b=GI3f4Ke+rpa7fzqnDj4OoPXZgPQmunfLQ7ndRrhPLRWIV3iazAK5N9LakhgLiBaHOD BS+f+gsx5or5i81Lj7LTp6Fu/dVBjv74N4dhUPwJgFPG6YGQqqW6okCirD01hW7I9oVp QwloAEgdbyFNwYMhQdc2FnepPEF3A5hNI43Eg9G7+ZgAxJF7aL2uF65QtWDrMf/7qUEh iqHvafa24mJom5T6gqTWmpDh18UiMDSSMo0Of7uW9unrQZ5sYh4qhng+cUR7zFDIiRtR 1IlLT6ZmlVxMxdcknp39SLAkZFCcOp+yUFWOfCRlWHm8FiCy8K+Da003O/qmbgaIatS5 NjdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eIFqQ3fy; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b2-20020a170902b60200b0016c3f7f6e21si3381251pls.387.2022.07.10.09.40.51; Sun, 10 Jul 2022 09:41:02 -0700 (PDT) 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=@intel.com header.s=Intel header.b=eIFqQ3fy; 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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229591AbiGJQBr (ORCPT + 99 others); Sun, 10 Jul 2022 12:01:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbiGJQBq (ORCPT ); Sun, 10 Jul 2022 12:01:46 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCF9A12A88; Sun, 10 Jul 2022 09:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657468905; x=1689004905; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Z/zdwQGtGZpw5TUuqOObVGsMWxYIOgqz24mXmC4bem8=; b=eIFqQ3fyE7gWZ9YGW1WHiz0Z6YhJlvV5xCia7yqgeOZ8wFe1HY18sdCh K49ezB4L0f/NJFvVigmRC99h1ysSzsOtGWZclh+lES1toyb6dK2i0QXJY MhWxdgOfueWXm0gikMfh6bL/GjtzKXwFL1WTliZYXAHV7MUMD7ugcJIca 3V39WaNLJ0MjK9ib8HwxmvYALgyvGq1f3Fky6dC/EJ9y182jeydY6zV7E 30KBU3z7sdoCd9zg3RPpTLHs3AkuB4sL48AayaYIcKiwBJIQjRWnDXHp+ oRbWR2F0FtmzywugmgoOffJO/6hkenpXfnWnT4cnF9Q6vVf6GZmkt9iMr w==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="370832390" X-IronPort-AV: E=Sophos;i="5.92,261,1650956400"; d="scan'208";a="370832390" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2022 09:01:45 -0700 X-IronPort-AV: E=Sophos;i="5.92,261,1650956400"; d="scan'208";a="621798255" Received: from jithujos.sc.intel.com ([172.25.103.66]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2022 09:01:39 -0700 From: Jithu Joseph To: hdegoede@redhat.com, markgross@kernel.org Cc: ashok.raj@intel.com, tony.luck@intel.com, gregkh@linuxfoundation.org, ravi.v.shankar@intel.com, jithu.joseph@intel.com, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH v2] platform/x86/intel/ifs: Allow non-default names for IFS image Date: Sun, 10 Jul 2022 09:00:11 -0700 Message-Id: <20220710160011.995800-1-jithu.joseph@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Existing implementation limits IFS images to be loaded only from a default file-name /lib/firmware/intel/ifs/ff-mm-ss.scan. But there are situations where there may be multiple scan files that can be run on a particular system stored in /lib/firmware/intel/ifs E.g. 1. Because test contents are larger than the memory reserved for IFS by BIOS 2. To provide increased test coverage 3. Custom test files to debug certain specific issues in the field Renaming each of these to ff-mm-ss.scan and then loading might be possible in some environments. But on systems where /lib is read-only this is not a practical solution. Modify the semantics of the driver file /sys/devices/virtual/misc/intel_ifs_0/reload such that, it interprets the input as the filename to be loaded. Signed-off-by: Jithu Joseph --- Changes in v2 - drop treating "1" specially, i.e treat everything as a file-name drivers/platform/x86/intel/ifs/ifs.h | 11 ++++---- drivers/platform/x86/intel/ifs/core.c | 2 +- drivers/platform/x86/intel/ifs/load.c | 25 +++++++++++++------ drivers/platform/x86/intel/ifs/sysfs.c | 13 +++------- .../ABI/testing/sysfs-platform-intel-ifs | 3 +-- 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/drivers/platform/x86/intel/ifs/ifs.h b/drivers/platform/x86/intel/ifs/ifs.h index 73c8e91cf144..577cee7db86a 100644 --- a/drivers/platform/x86/intel/ifs/ifs.h +++ b/drivers/platform/x86/intel/ifs/ifs.h @@ -34,12 +34,13 @@ * socket in a two step process using writes to MSRs to first load the * SHA hashes for the test. Then the tests themselves. Status MSRs provide * feedback on the success/failure of these steps. When a new test file - * is installed it can be loaded by writing to the driver reload file:: + * is installed it can be loaded by writing the filename to the driver reload file:: * - * # echo 1 > /sys/devices/virtual/misc/intel_ifs_0/reload + * # echo mytest > /sys/devices/virtual/misc/intel_ifs_0/reload * - * Similar to microcode, the current version of the scan tests is stored - * in a fixed location: /lib/firmware/intel/ifs.0/family-model-stepping.scan + * The file will be loaded from /lib/firmware/intel/ifs/mytest + * The default file /lib/firmware/intel/ifs/family-model-stepping.scan + * will be loaded during module insertion. * * Running tests * ------------- @@ -225,7 +226,7 @@ static inline struct ifs_data *ifs_get_data(struct device *dev) return &d->data; } -void ifs_load_firmware(struct device *dev); +int ifs_load_firmware(struct device *dev, const char *file_name); int do_core_test(int cpu, struct device *dev); const struct attribute_group **ifs_get_groups(void); diff --git a/drivers/platform/x86/intel/ifs/core.c b/drivers/platform/x86/intel/ifs/core.c index 27204e3d674d..9c319ada62d8 100644 --- a/drivers/platform/x86/intel/ifs/core.c +++ b/drivers/platform/x86/intel/ifs/core.c @@ -53,7 +53,7 @@ static int __init ifs_init(void) if ((msrval & BIT(ifs_device.data.integrity_cap_bit)) && !misc_register(&ifs_device.misc)) { down(&ifs_sem); - ifs_load_firmware(ifs_device.misc.this_device); + ifs_load_firmware(ifs_device.misc.this_device, NULL); up(&ifs_sem); return 0; } diff --git a/drivers/platform/x86/intel/ifs/load.c b/drivers/platform/x86/intel/ifs/load.c index d056617ddc85..89d76bd8b40a 100644 --- a/drivers/platform/x86/intel/ifs/load.c +++ b/drivers/platform/x86/intel/ifs/load.c @@ -232,17 +232,27 @@ static bool ifs_image_sanity_check(struct device *dev, const struct microcode_he /* * 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}. + * in the folder /lib/firmware/intel/ifs/ */ -void ifs_load_firmware(struct device *dev) +int ifs_load_firmware(struct device *dev, const char *file_name) { struct ifs_data *ifsd = ifs_get_data(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); + char scan_path[64]; + int ret = -EINVAL; + int file_name_len; + + if (!file_name) { + 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); + } else { + if (strchr(file_name, '/')) + goto done; + file_name_len = strchrnul(file_name, '\n') - file_name; + if (snprintf(scan_path, sizeof(scan_path), "intel/ifs/%.*s", + file_name_len, file_name) >= sizeof(scan_path)) + goto done; + } ret = request_firmware_direct(&fw, scan_path, dev); if (ret) { @@ -263,4 +273,5 @@ void ifs_load_firmware(struct device *dev) release_firmware(fw); done: ifsd->loaded = (ret == 0); + return ret; } diff --git a/drivers/platform/x86/intel/ifs/sysfs.c b/drivers/platform/x86/intel/ifs/sysfs.c index 37d8380d6fa8..b4716b7d36aa 100644 --- a/drivers/platform/x86/intel/ifs/sysfs.c +++ b/drivers/platform/x86/intel/ifs/sysfs.c @@ -94,23 +94,16 @@ static ssize_t reload_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct ifs_data *ifsd = ifs_get_data(dev); - bool res; - - - if (kstrtobool(buf, &res)) - return -EINVAL; - if (!res) - return count; + int ret; if (down_interruptible(&ifs_sem)) return -EINTR; - ifs_load_firmware(dev); + ret = ifs_load_firmware(dev, buf); up(&ifs_sem); - return ifsd->loaded ? count : -ENODEV; + return ret ? ret : count; } static DEVICE_ATTR_WO(reload); diff --git a/Documentation/ABI/testing/sysfs-platform-intel-ifs b/Documentation/ABI/testing/sysfs-platform-intel-ifs index 486d6d2ff8a0..0b373f73a2b6 100644 --- a/Documentation/ABI/testing/sysfs-platform-intel-ifs +++ b/Documentation/ABI/testing/sysfs-platform-intel-ifs @@ -35,5 +35,4 @@ What: /sys/devices/virtual/misc/intel_ifs_/reload Date: April 21 2022 KernelVersion: 5.19 Contact: "Jithu Joseph" -Description: Write "1" (or "y" or "Y") to reload the IFS image from - /lib/firmware/intel/ifs/ff-mm-ss.scan. +Description: Write to reload the IFS image from /lib/firmware/intel/. base-commit: 88084a3df1672e131ddc1b4e39eeacfd39864acf -- 2.25.1