Skip to contentSkip to conversation

Introduce In Field Scan driver

PATCH In review Jithu Joseph 9 participants 152 messages Apr 7, 2022 – May 11, 2022

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v2 cover Introduce In Field Scan driver

Note to Maintainers:
Requesting x86 Maintainers to take a look at patch1 as it touches arch/x86 portion of the kernel.

Patch 2/10 - Adds Documentation. Requesting Documentation maintainer to review it.

Requesting Greg KH to review the sysfs changes added by patch8 (note that in this revision we no longer touch /sys/devices/system/cpu as in previous version and limit ourselves to only /sys/devices/platform/intel_ifs)

Patch10 - adds tracing support, requesting Steven Rostedt to review that.

Rest of the patches adds the IFS platform driver, requesting Platform driver maintainers to review them.

This is the v2 version incorporating the review feedback from the RFC version [1]

In Field Scan (IFS) is a hardware feature to run circuit level tests on a CPU core to detect problems that are not caught by parity or ECC checks. See References section to understand more about CPU core errors and how and when they are encountered.

Intel will provide a firmware file containing the scan tests. Similar to microcode there is a separate file for each family-model-stepping. The tests in the file are divided into some number of "chunks" that can be run individually.

The driver loads the tests into memory reserved BIOS local to each CPU 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.

Tests are run by synchronizing execution of all threads on a core and then writing to the ACTIVATE_SCAN MSR on all threads. Instruction execution continues when:

1) all tests have completed
2) execution was interrupted
3) a test detected a problem

In all cases reading the SCAN_STATUS MSR provides details on what happened. Interrupted tests may be restarted.

The IFS driver provides interfaces from /sys to control execution:

/sys/devices/platform/intel_ifs/run_test
Writing <cpu#> to this file will trigger a scan on that core e.g echo 5 > sys/devices/platform/intel_ifs/run_test will trigger scan on the core containing cpu5

Results of the tests are also provided in /sys:

/sys/devices/platform/intel_ifs/status
Status (pass/fail/untested) for the last test

/sys/devices/platform/intel_ifs/details
Hex value of the SCAN_STATUS MSR for the most recent test. Note that the error_code field may contain driver defined software code not defined in the Intel SDM.

Driver design choices:

1) The ACTIVATE_SCAN MSR allows for running any consecutive subrange or available tests. But the driver always tries to run all tests and only uses the subrange feature to restart an interrupted test.

2) Hardware allows for some number of cores to be tested in parallel. The driver does not make use of this, it only tests one core at a time.

References
Links to a few articles, papers, presentation [2] [3] [4] [5] which talk about cpu core errors encountered in the wild which could be relevant to this work.

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://sigops.org/s/conferences/hotos/2021/papers/hotos21-s01-hochschild.pdf
[3] https://www.youtube.com/watch?v=QMF3rqhjYuM
[4] https://engineering.fb.com/2021/02/23/data-infrastructure/silent-data-corruption/
[5] https://www.theregister.com/2021/06/04/google_chip_flaws/

Changes since RFC:
- Renamed collect_cpu_info_early() - >cpu_collect_info_early() (Patch 1; GregKH)
- Refactored collect_cpu_info_early(), cpu_signatures_match() from microcode specific file to intel-generic file (Patch 1; Borislav Petkov)
- Keep the same platform driver object through-out the life-time of the driver (patch 4; Dan Wiliiams)
- Replace platform_device_register_simple() with platform_device_alloc/add() so that sysfs files are available instantateously (patch 4; Dan Wiliiams)
- Move IFS binary loading to driver_probe context from module_init context (patch4; Dan Wiliiams)
- Remove the version check during scan image load so as to allow user to move to any IFS binary (Patch 4)
- Replace pr_* macros with dev_* macros (Patches 3-9; Dan Wiliiams)
- Replace percpu kthreads with work_queue worker threads (Patch 7; Dan Wiliiams)
- Remove hotplug callbacks which are no longer required due to above change (Patch 7; Dan Wiliiams)
- Remove percpu ifs_state data structure as it is no longer needed (Patch 7)
- Refactored test logic into a separate runtest.c file (Patch 7, Tony Luck)
- Moved sysfs interface from /sys/devices/system/cpu/ifs and /sys/devices/system/cpu/cpu#/ifs to /sys/devices/platform/intel_ifs
- Done away with global/percpu testing interfaces. To trigger a test, there is a single run_test file which takes cpu_number as input. This hugely reduces the number of sysfs file needed. Userspace can iterate over all the cpus to achevie global testing (Patch8; Dan Wiliiams)
- Remove the reload sysfs interface for IFS binary loading. Since binary loading is done from the probe context, reloading can be acheieved using driver bind sysfs interface (Patch 8; Dan Williams)
- Updated the Documentation/ ABI files to reflect the sysfs changes
- Change trace event structure field ordering (patch 10; Steven Rostedt)
- misc changes
- adding enum type for ifs_status_err_code
- replace sprintf with sysfs_emit in sysfs.c

Jithu Joseph (8):
x86/microcode/intel: expose collect_cpu_info_early() for IFS platform/x86/intel/ifs: Add driver for In-Field Scan platform/x86/intel/ifs: Load IFS Image platform/x86/intel/ifs: Check IFS Image sanity platform/x86/intel/ifs: Authenticate and copy to secured memory platform/x86/intel/ifs: Add scan test support platform/x86/intel/ifs: Add IFS sysfs interface platform/x86/intel/ifs: add ABI documentation for IFS

Tony Luck (2):
Documentation: In-Field Scan
trace: platform/x86/intel/ifs: Add trace point to track Intel IFS
operations

 .../ABI/testing/sysfs-platform-intel-ifs      |  54 ++++
 Documentation/x86/ifs.rst                     | 114 +++++++
 Documentation/x86/index.rst                   |   1 +
 MAINTAINERS                                   |   7 +
 arch/x86/include/asm/microcode_intel.h        |   4 +
 arch/x86/kernel/cpu/intel.c                   |  47 +++
 arch/x86/kernel/cpu/microcode/intel.c         |  55 +---
 drivers/platform/x86/intel/Kconfig            |   1 +
 drivers/platform/x86/intel/Makefile           |   1 +
 drivers/platform/x86/intel/ifs/Kconfig        |   9 +
 drivers/platform/x86/intel/ifs/Makefile       |   3 +
 drivers/platform/x86/intel/ifs/core.c         | 121 +++++++
 drivers/platform/x86/intel/ifs/ifs.h          | 137 ++++++++
 drivers/platform/x86/intel/ifs/load.c         | 285 +++++++++++++++++
 drivers/platform/x86/intel/ifs/runtest.c      | 300 ++++++++++++++++++
 drivers/platform/x86/intel/ifs/sysfs.c        | 139 ++++++++
 include/trace/events/intel_ifs.h              |  38 +++
 17 files changed, 1266 insertions(+), 50 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-ifs
 create mode 100644 Documentation/x86/ifs.rst
 create mode 100644 drivers/platform/x86/intel/ifs/Kconfig
 create mode 100644 drivers/platform/x86/intel/ifs/Makefile
 create mode 100644 drivers/platform/x86/intel/ifs/core.c
 create mode 100644 drivers/platform/x86/intel/ifs/ifs.h
 create mode 100644 drivers/platform/x86/intel/ifs/load.c
 create mode 100644 drivers/platform/x86/intel/ifs/runtest.c
 create mode 100644 drivers/platform/x86/intel/ifs/sysfs.c
 create mode 100644 include/trace/events/intel_ifs.h
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/10 x86/microcode/intel: expose collect_cpu_info_early() for IFS

IFS is a CPU feature that allows a binary blob, similar to microcode, to be loaded and consumed to perform low level validation of CPU circuitry. In fact, it carries the same Processor Signature (family/model/stepping) details that are contained in Intel microcode blobs. In support of an IFS driver to trigger loading, validation, and running of these tests blobs, export cpu_signatures_match() and collect_cpu_info_early().

Rename collect_cpu_info_early() to cpu_collect_info_early() to keep a more appropriate prefix.

Per Boris [1], move these helpers to a generic location.

No functional change intended.

---
 arch/x86/include/asm/microcode_intel.h |  4 ++
 arch/x86/kernel/cpu/intel.c            | 47 ++++++++++++++++++++++
 arch/x86/kernel/cpu/microcode/intel.c  | 55 +++-----------------------
 3 files changed, 56 insertions(+), 50 deletions(-)
arch/x86/include/asm/microcode_intel.h +4 -0
index d85a07d7154f..cf0fd1d712b4 100644
@@ -68,6 +68,10 @@ static inline u32 intel_get_microcode_revision(void)
 	return rev;
 }
 
+int cpu_collect_info_early(struct ucode_cpu_info *uci);
+bool cpu_signatures_match(unsigned int s1, unsigned int p1,
+			  unsigned int s2, unsigned int p2);
+
 #ifdef CONFIG_MICROCODE_INTEL
 extern void __init load_ucode_intel_bsp(void);
 extern void load_ucode_intel_ap(void);
arch/x86/kernel/cpu/intel.c +47 -0

53 lines not on this page · raw message

arch/x86/kernel/cpu/microcode/intel.c +5 -50

97 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH v2 01/10] x86/microcode/intel: expose collect_cpu_info_early() for IFS

arch/x86/include/asm/microcode_intel.h static inline u32 intel_get_microcode_revision(void) · line 74

Quoted 12 lines · Jithu Joseph
arch/x86/include/asm/microcode_intel.h +4 -0
index d85a07d7154f..cf0fd1d712b4 100644
@@ -68,6 +68,10 @@ static inline u32 intel_get_microcode_revision(void)
 	return rev;
 }
 
+int cpu_collect_info_early(struct ucode_cpu_info *uci);
+bool cpu_signatures_match(unsigned int s1, unsigned int p1,
+			  unsigned int s2, unsigned int p2);
+

So you can't move the functions to cpu/intel.c but put the prototype declarations in the microcode header - they should go to arch/x86/include/asm/cpu.h or so.

arch/x86/kernel/cpu/intel.c static bool bad_spectre_microcode(struct cpuinfo_x86 *c) · line 184

Quoted 12 lines
arch/x86/include/asm/microcode_intel.h +0 -0
 #ifdef CONFIG_MICROCODE_INTEL
 extern void __init load_ucode_intel_bsp(void);
 extern void load_ucode_intel_ap(void);
arch/x86/kernel/cpu/intel.c +1 -0
index 8321c43554a1..2008c8267fd3 100644
@@ -181,6 +181,53 @@ static bool bad_spectre_microcode(struct cpuinfo_x86 *c)
 	return false;
 }
 
+bool cpu_signatures_match(unsigned int s1, unsigned int p1,

That function is Intel-specific:

intel_cpu_signatures_match()

and it is small enough to stick it in the above header and make it an inline without the need for an export.

Quoted 5 lines
arch/x86/kernel/cpu/intel.c +5 -0
+			  unsigned int s2, unsigned int p2)
+{
+	if (s1 != s2)
+		return false;
+

arch/x86/kernel/cpu/intel.c static bool bad_spectre_microcode(struct cpuinfo_x86 *c) · line 199

Quoted 10 lines
arch/x86/kernel/cpu/intel.c +10 -0
+	/* Processor flags are either both 0 ... */
+	if (!p1 && !p2)
+		return true;
+
+	/* ... or they intersect. */
+	return p1 & p2;
+}
+EXPORT_SYMBOL_GPL(cpu_signatures_match);
+
+int cpu_collect_info_early(struct ucode_cpu_info *uci)

intel_collect_cpu_info_early()

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#3 lore raw

Re: [PATCH v2 01/10] x86/microcode/intel: expose collect_cpu_info_early() for IFS

Quoted 6 lines · Borislav Petkov

arch/x86/kernel/cpu/intel.c static bool bad_spectre_microcode(struct cpuinfo_x86 *c) · line 199

Quoted 3 lines · Jithu Joseph
arch/x86/kernel/cpu/intel.c +3 -0
+EXPORT_SYMBOL_GPL(cpu_signatures_match);
+
+int cpu_collect_info_early(struct ucode_cpu_info *uci)

intel_collect_cpu_info_early()

That function name does not make sense in context of that driver...

Thanks,

tglx

#4 lore raw

PATCH v2 2/10 Documentation: In-Field Scan

In reply to Jithu Joseph

From: Tony Luck <[email protected]>

Add documentation for In-Field Scan (IFS). This documentation describes the basics of IFS, the loading IFS image, chunk authentication, running scan and how to check result via sysfs as well as tunable parameters.

The CORE_CAPABILITIES MSR enumerates whether IFS is supported.

The full github location for distributing the IFS images is still being decided. So just a placeholder included for now in the documentation.

---
 Documentation/x86/ifs.rst   | 114 ++++++++++++++++++++++++++++++++++++
 Documentation/x86/index.rst |   1 +
 2 files changed, 115 insertions(+)
 create mode 100644 Documentation/x86/ifs.rst
Documentation/x86/ifs.rst new file +114 -0
new file mode 100644
index 000000000000..f8a1b1f57de8
@@ -0,0 +1,114 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=============
+In-Field Scan
+=============
+
+Introduction
+------------
+
+In Field Scan (IFS) is a hardware feature to run circuit level tests on
+a CPU core to detect problems that are not caught by parity or ECC checks.
+
+IFS Image
+---------
+
+Intel provides a firmware file containing the scan tests via
+github [#f1]_.  Similar to microcode there is a separate file for each
+family-model-stepping.
+
+IFS Image Loading
+-----------------
+
+The driver loads the tests into memory reserved BIOS local to each CPU
+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 triggering a driver bind as below::
+
+  # echo "intel_ifs" > /sys/bus/platform/drivers/intel_ifs/unbind
+  # echo "intel_ifs" > /sys/bus/platform/drivers/intel_ifs/bind
+
+Similar to microcode, the current version of the scan tests is stored
+in a fixed location: /lib/firmware/intel/ifs/family-model-stepping.scan
+
+Triggering tests
+----------------
+
+Tests are run by the driver synchronizing execution of all threads on a
+core and then writing to the ACTIVATE_SCAN MSR on all threads. Instruction
+execution continues when:
+
+1) All tests have completed.
+2) Execution was interrupted.
+3) A test detected a problem.
+
+In all cases reading the SCAN_STATUS MSR provides details on what
+happened. The driver makes the value of this MSR visible to applications
+via the "details" file (see below). Interrupted tests may be restarted.
+
+The IFS driver provides sysfs interfaces via /sys/devices/platform/intel_ifs/
+to control execution:
+
+Test a specific core::
+
+  # echo <cpu#> > /sys/devices/platform/intel_ifs/run_test
+
+when HT is enabled any of the sibling cpu# can be specified to test its
+corresponding physical core. Since the tests are per physical core, the
+result of testing any thread is same. It is only necessary to test one
+thread.
+
+For e.g. to test core corresponding to cpu5
+
+  # echo 5 > /sys/devices/platform/intel_ifs/run_test
+
+Results of the last test is provided in /sys::
+
+  $ cat /sys/devices/platform/intel_ifs/status
+  pass
+
+Status can be one of pass, fail, untested
+
+Additional details of the last test is provided by the details file::
+
+  $ cat /sys/devices/platform/intel_ifs/details
+  0x8081
+
+The details file reports the hex value of the SCAN_STATUS MSR.
+Hardware defined error codes are documented in volume 4 of the Intel
+Software Developer's Manual but the error_code field may contain one of
+the following driver defined software codes:
+
++------+--------------------+
+| 0xFD | Software timeout   |
++------+--------------------+
+| 0xFE | Partial completion |
++------+--------------------+
+
+Driver design choices
+---------------------
+
+1) The ACTIVATE_SCAN MSR allows for running any consecutive subrange or
+available tests. But the driver always tries to run all tests and only
+uses the subrange feature to restart an interrupted test.
+
+2) Hardware allows for some number of cores to be tested in parallel.
+The driver does not make use of this, it only tests one core at a time.
+
+Tunable Parameters
+------------------
+
+This module accepts two tunable parameters. These could be provided at
+load time or can be modified at runtime through module parameter.
+(/sys/module/ifs/parameters/<parameter_name>). The parameters are as
+described below.
+
+1. noirq: When set (default), system interrupts are not allowed to interrupt an ifs scan.
+Unsetting this might be helpful to improve the irq latency during the test.
+
+2. retry: Maximum retry counter when the test chunk is not executed due to an event such as
+interrupt. The default value for this parameter is 5, it accepts a value between 1 and 20.
+If test status continuously reports as "untested", increasing the value might help.
+
+.. [#f1] https://github.com/intel
Documentation/x86/index.rst +1 -0
index f498f1d36cd3..be58b7638d9e 100644
@@ -33,6 +33,7 @@ x86-specific Documentation
    usb-legacy-support
    i386/index
    x86_64/index
+   ifs
    sva
    sgx
    features
Signature · 1 line
2.17.1
#5 lore raw

PATCH v2 3/10 platform/x86/intel/ifs: Add driver for In-Field Scan

In reply to Jithu Joseph

Cloud Service Providers that operate fleets of servers have reported
[1] occasions where they can detect that a CPU has gone bad due to effects like electromigration, or isolated manufacturing defects. However, that detection method is A/B testing seemingly random application failures looking for a pattern. In-Field Scan (IFS) is a driver for a platform capability to load a crafted 'scan image' to run targeted low level diagnostics outside of the CPU's architectural error detection capabilities.

[1]: https://www.youtube.com/watch?v=QMF3rqhjYuM

IFS will be available in some server SKUs starting with Sapphire Rapids.

Add basic parts of the IFS module (initialization and check IFS capability support in a processor).

MSR IA32_CORE_CAPABILITY is a feature-enumerating MSR, bit 2 of which reports MSR_INTEGRITY_CAPABILITIES. Processor that supports IFS should reports the MSR_INTEGRITY_CAPABILITIES enabled.

Please check the latest Intel 64 and IA-32 Architectures Software Developer's Manual for more detailed information on the MSR and the MSR_INTEGRITY_CAPABILITIES.

---
 MAINTAINERS                             |  7 ++++
 drivers/platform/x86/intel/Kconfig      |  1 +
 drivers/platform/x86/intel/Makefile     |  1 +
 drivers/platform/x86/intel/ifs/Kconfig  |  9 +++++
 drivers/platform/x86/intel/ifs/Makefile |  3 ++
 drivers/platform/x86/intel/ifs/core.c   | 44 +++++++++++++++++++++++++
 drivers/platform/x86/intel/ifs/ifs.h    | 11 +++++++
 7 files changed, 76 insertions(+)
 create mode 100644 drivers/platform/x86/intel/ifs/Kconfig
 create mode 100644 drivers/platform/x86/intel/ifs/Makefile
 create mode 100644 drivers/platform/x86/intel/ifs/core.c
 create mode 100644 drivers/platform/x86/intel/ifs/ifs.h
MAINTAINERS +7 -0
index 777cd6fa2b3d..4c9912c0d725 100644
@@ -9685,6 +9685,13 @@ B:	https://bugzilla.kernel.org
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git
 F:	drivers/idle/intel_idle.c
 
+INTEL IN FIELD SCAN (IFS) DRIVER
+M:	Jithu Joseph <[email protected]>
+R:	Ashok Raj <[email protected]>
+R:	Tony Luck <[email protected]>
+S:	Maintained
+F:	drivers/platform/x86/intel/ifs
+
 INTEL INTEGRATED SENSOR HUB DRIVER
 M:	Srinivas Pandruvada <[email protected]>
 M:	Jiri Kosina <[email protected]>
drivers/platform/x86/intel/Kconfig +1 -0
index 8e65086bb6c8..7339e7daf0a1 100644
@@ -4,6 +4,7 @@
 #
 
 source "drivers/platform/x86/intel/atomisp2/Kconfig"
+source "drivers/platform/x86/intel/ifs/Kconfig"
 source "drivers/platform/x86/intel/int1092/Kconfig"
 source "drivers/platform/x86/intel/int33fe/Kconfig"
 source "drivers/platform/x86/intel/int3472/Kconfig"
drivers/platform/x86/intel/Makefile +1 -0
index 35f2066578b2..bd7f2ef5e767 100644
@@ -5,6 +5,7 @@
 #
 
 obj-$(CONFIG_INTEL_ATOMISP2_PDX86)	+= atomisp2/
+obj-$(CONFIG_INTEL_IFS)			+= ifs/
 obj-$(CONFIG_INTEL_SAR_INT1092)		+= int1092/
 obj-$(CONFIG_INTEL_CHT_INT33FE)		+= int33fe/
 obj-$(CONFIG_INTEL_SKL_INT3472)		+= int3472/
drivers/platform/x86/intel/ifs/Kconfig new file +9 -0
new file mode 100644
index 000000000000..88e3d4fa1759
@@ -0,0 +1,9 @@
+config INTEL_IFS
+	tristate "Intel In Field Scan"
+	depends on X86 && 64BIT && SMP
+	help
+	  Enable support for In Field Scan in Intel CPU to perform core
+	  logic test in the field. To compile this driver as a module, choose
+	  M here. The module will be called intel_ifs.
+
+	  If unsure, say N.
drivers/platform/x86/intel/ifs/Makefile new file +3 -0
new file mode 100644
index 000000000000..c44305dff542
@@ -0,0 +1,3 @@
+obj-$(CONFIG_INTEL_IFS)			+= intel_ifs.o
+
+intel_ifs-objs				:= core.o
drivers/platform/x86/intel/ifs/core.c new file +44 -0

44 lines not on this page · raw message

drivers/platform/x86/intel/ifs/ifs.h new file +11 -0
new file mode 100644
index 000000000000..bb25a4cd3af6
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2022 Intel Corporation. */
+
+#ifndef _IFS_H_
+#define _IFS_H_
+
+/* These bits are in the IA32_CORE_CAPABILITIES MSR */
+#define MSR_IA32_CORE_CAPS_INTEGRITY_BIT	2
+#define MSR_IA32_CORE_CAPS_INTEGRITY		BIT(MSR_IA32_CORE_CAPS_INTEGRITY_BIT)
+
+#endif
Signature · 1 line
2.17.1
#6 lore raw

PATCH v2 4/10 platform/x86/intel/ifs: Load IFS Image

In reply to Jithu Joseph

IFS uses a scan image format that shares the same header as microcode updates and deployment approach for these images mirrors that of microcode update. Specifically, enable images to be deployed relative to a static symlink in /lib/firmware and then load into kernel memory via request_firmware().

The image is specific to a processor family, model and stepping. IFS requires that a test image be loaded before any ifs test is initiated. Load the image that matches processor signature. The IFS image is signed by Intel.

The IFS image file follows a similar naming convention as used for Intel CPU microcode files. The file must be located in the firmware directory where the microcode files are placed and named as {family/model /stepping}.scan as below:

/lib/firmware/intel/ifs/{ff-mm-ss}.scan

---
 drivers/platform/x86/intel/ifs/Makefile |  2 +-
 drivers/platform/x86/intel/ifs/core.c   | 62 ++++++++++++++++++++
 drivers/platform/x86/intel/ifs/ifs.h    | 15 +++++
 drivers/platform/x86/intel/ifs/load.c   | 76 +++++++++++++++++++++++++
 4 files changed, 154 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/load.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index c44305dff542..b69d026ca9da 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)			+= intel_ifs.o
 
-intel_ifs-objs				:= core.o
+intel_ifs-objs				:= core.o load.o
drivers/platform/x86/intel/ifs/core.c +62 -0

93 lines not on this page · raw message

drivers/platform/x86/intel/ifs/ifs.h +15 -0
index bb25a4cd3af6..e1c9c16cbadb 100644
@@ -8,4 +8,19 @@
 #define MSR_IA32_CORE_CAPS_INTEGRITY_BIT	2
 #define MSR_IA32_CORE_CAPS_INTEGRITY		BIT(MSR_IA32_CORE_CAPS_INTEGRITY_BIT)
 
+#define IFS_BLOB_REV_ERR_INJ			BIT(30)
+#define IFS_BLOB_REV_DEBUG			BIT(31)
+/**
+ * struct ifs_binary - attributes related to test binary
+ * @loaded_version: stores the currently loaded ifs image version.
+ * @loaded: If a valid test binary has been loaded into the memory
+ */
+struct ifs_binary {
+	int loaded_version;
+	bool loaded;
+};
+
+int load_ifs_binary(void);
+extern struct platform_device *ifs_pdev;
+extern struct ifs_binary ifs_binary;
 #endif
drivers/platform/x86/intel/ifs/load.c new file +76 -0

76 lines not on this page · raw message

Signature · 1 line
2.17.1
#7 lore raw

Re: [PATCH v2 04/10] platform/x86/intel/ifs: Load IFS Image

Quoted 11 lines · Jithu Joseph

IFS uses a scan image format that shares the same header as microcode updates and deployment approach for these images mirrors that of microcode update. Specifically, enable images to be deployed relative to a static symlink in /lib/firmware and then load into kernel memory via request_firmware().

The image is specific to a processor family, model and stepping. IFS requires that a test image be loaded before any ifs test is initiated. Load the image that matches processor signature. The IFS image is signed by Intel.

Quoted 6 lines

The IFS image file follows a similar naming convention as used for Intel CPU microcode files. The file must be located in the firmware directory where the microcode files are placed and named as {family/model /stepping}.scan as below:

/lib/firmware/intel/ifs/{ff-mm-ss}.scan

Is the firmware already submitted to the linux-firmware project for inclusion there?

If not, where should a user get it from?

thanks,

greg k-h

#8 lore raw

Re: [PATCH v2 04/10] platform/x86/intel/ifs: Load IFS Image

In reply to Jithu Joseph
Quoted 42 lines · Jithu Joseph

IFS uses a scan image format that shares the same header as microcode updates and deployment approach for these images mirrors that of microcode update. Specifically, enable images to be deployed relative to a static symlink in /lib/firmware and then load into kernel memory via request_firmware().

The image is specific to a processor family, model and stepping. IFS requires that a test image be loaded before any ifs test is initiated. Load the image that matches processor signature. The IFS image is signed by Intel.

The IFS image file follows a similar naming convention as used for Intel CPU microcode files. The file must be located in the firmware directory where the microcode files are placed and named as {family/model /stepping}.scan as below:

/lib/firmware/intel/ifs/{ff-mm-ss}.scan

---
 drivers/platform/x86/intel/ifs/Makefile |  2 +-
 drivers/platform/x86/intel/ifs/core.c   | 62 ++++++++++++++++++++
 drivers/platform/x86/intel/ifs/ifs.h    | 15 +++++
 drivers/platform/x86/intel/ifs/load.c   | 76 +++++++++++++++++++++++++
 4 files changed, 154 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/load.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index c44305dff542..b69d026ca9da 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)			+= intel_ifs.o
 
-intel_ifs-objs				:= core.o
+intel_ifs-objs				:= core.o load.o
drivers/platform/x86/intel/ifs/core.c +0 -0
index 87956623208f..716f333a064b 100644

drivers/platform/x86/intel/ifs/core.c line 11

Quoted 10 lines
drivers/platform/x86/intel/ifs/core.c +3 -0
@@ -2,10 +2,14 @@
 /* Copyright(c) 2022 Intel Corporation. */
 
 #include <linux/module.h>
+#include <linux/platform_device.h>
 #include <asm/cpu_device_id.h>
 
 #include "ifs.h"
 
+struct platform_device *ifs_pdev;
+struct ifs_binary ifs_binary;

Please no static memory. Use the driver model properly which does not want you to do this at all.

You should not need this at all. If you do, something is wrong as you are tying the lifecycle of the memory to the code, not to the device.

{sigh}

greg k-h

#9 lore raw

PATCH v2 5/10 platform/x86/intel/ifs: Check IFS Image sanity

In reply to Jithu Joseph

IFS image is designed specifically for a given family, model and stepping of the processor. Like Intel microcode header, the IFS image has the Processor Signature, Checksum and Processor Flags that must be matched with the information returned by the CPUID.

---
 drivers/platform/x86/intel/ifs/load.c | 67 +++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
drivers/platform/x86/intel/ifs/load.c +67 -0
index a1be4d6558a1..8f2735775f5b 100644
@@ -3,6 +3,7 @@
 
 #include <linux/firmware.h>
 #include <linux/platform_device.h>
+#include <asm/microcode_intel.h>
 
 #include "ifs.h"
 static const char *ifs_path = "intel/ifs/";
@@ -24,6 +25,67 @@ struct ifs_header {
 #define IFS_HEADER_SIZE	(sizeof(struct ifs_header))
 static struct ifs_header *ifs_header_ptr;	/* pointer to the ifs image header */
 static u64 ifs_hash_ptr;			/* Address of ifs metadata (hash) */
+static int ifs_sanity_check(void *mc)
+{
+	struct microcode_header_intel *mc_header = mc;
+	unsigned long total_size, data_size;
+	u32 sum, i;
+
+	total_size = get_totalsize(mc_header);
+	data_size = get_datasize(mc_header);
+
+	if ((data_size + MC_HEADER_SIZE > total_size) || (total_size % sizeof(u32))) {
+		dev_err(&ifs_pdev->dev, "bad ifs data file size.\n");
+		return -EINVAL;
+	}
+
+	if (mc_header->ldrver != 1 || mc_header->hdrver != 1) {
+		dev_err(&ifs_pdev->dev, "invalid/unknown ifs update format.\n");
+		return -EINVAL;
+	}
+
+	sum = 0;
+	i = total_size / sizeof(u32);
+	while (i--)
+		sum += ((u32 *)mc)[i];
+
+	if (sum) {
+		dev_err(&ifs_pdev->dev, "bad ifs data checksum, aborting.\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static bool find_ifs_matching_signature(struct ucode_cpu_info *uci, void *mc)
+{
+	struct microcode_header_intel *shdr;
+	unsigned int mc_size;
+
+	shdr = (struct microcode_header_intel *)mc;
+	mc_size = get_totalsize(shdr);
+
+	if (!mc_size || ifs_sanity_check(shdr) < 0) {
+		dev_err(&ifs_pdev->dev, "ifs sanity check failure\n");
+		return false;
+	}
+
+	if (!cpu_signatures_match(uci->cpu_sig.sig, uci->cpu_sig.pf, shdr->sig, shdr->pf)) {
+		dev_err(&ifs_pdev->dev, "ifs signature, pf not matching\n");
+		return false;
+	}
+
+	return true;
+}
+
+static bool ifs_image_sanity_check(void *data)
+{
+	struct ucode_cpu_info uci;
+
+	cpu_collect_info_early(&uci);
+
+	return find_ifs_matching_signature(&uci, data);
+}
 
 static const struct firmware *load_binary(const char *path)
 {
@@ -36,6 +98,11 @@ static const struct firmware *load_binary(const char *path)
 		goto out;
 	}
 
+	if (!ifs_image_sanity_check((void *)fw->data)) {
+		dev_err(&ifs_pdev->dev, "ifs header sanity check failed\n");
+		release_firmware(fw);
+		fw = NULL;
+	}
 out:
 
 	return fw;
Signature · 1 line
2.17.1
#10 lore raw

PATCH v2 6/10 platform/x86/intel/ifs: Authenticate and copy to secured memory

In reply to Jithu Joseph

The IFS image contains hashes that will be used to authenticate the ifs test chunks. First, use WRMSR to copy the hashes and enumerate the number of test chunks, chunk size and the maximum number of cores that can run scan test simultaneously.

Next, use WRMSR to authenticate each and every scan test chunk which is also stored in the IFS image. The CPU will check if the test chunks match the hashes, otherwise failure is indicated to system software. If the test chunk is authenticated, it is automatically copied to secured memory.

The ifs hash copy and authentication only needs to be done on the first logical cpu of each socket.

---
 drivers/platform/x86/intel/ifs/ifs.h  |  33 ++++++
 drivers/platform/x86/intel/ifs/load.c | 142 ++++++++++++++++++++++++++
 2 files changed, 175 insertions(+)
drivers/platform/x86/intel/ifs/ifs.h +33 -0
index e1c9c16cbadb..4d12f8e71c67 100644
@@ -10,13 +10,46 @@
 
 #define IFS_BLOB_REV_ERR_INJ			BIT(30)
 #define IFS_BLOB_REV_DEBUG			BIT(31)
+#define MSR_COPY_SCAN_HASHES			0x000002c2
+#define MSR_SCAN_HASHES_STATUS			0x000002c3
+#define MSR_AUTHENTICATE_AND_COPY_CHUNK		0x000002c4
+#define MSR_CHUNKS_AUTHENTICATION_STATUS	0x000002c5
+
+/* MSR_SCAN_HASHES_STATUS bit fields */
+union ifs_scan_hashes_status {
+	u64	data;
+	struct {
+		u64	chunk_size	:16;
+		u64	num_chunks	:8;
+		u64	rsvd1		:8;
+		u64	error_code	:8;
+		u64	rsvd2		:11;
+		u64	max_core_limit	:12;
+		u64	valid		:1;
+	};
+};
+
+/* MSR_CHUNKS_AUTH_STATUS bit fields */
+union ifs_chunks_auth_status {
+	u64	data;
+	struct {
+		u64	valid_chunks	:8;
+		u64	total_chunks	:8;
+		u64	rsvd1		:16;
+		u64	error_code	:8;
+		u64	rsvd2		:24;
+	};
+};
+
 /**
  * struct ifs_binary - attributes related to test binary
  * @loaded_version: stores the currently loaded ifs image version.
+ * @valid_chunks: number of chunks which could be validated.
  * @loaded: If a valid test binary has been loaded into the memory
  */
 struct ifs_binary {
 	int loaded_version;
+	int valid_chunks;
 	bool loaded;
 };
 
drivers/platform/x86/intel/ifs/load.c +142 -0

164 lines not on this page · raw message

Signature · 1 line
2.17.1
#11 lore raw

PATCH v2 7/10 platform/x86/intel/ifs: Add scan test support

In reply to Jithu Joseph

In a core, the scan engine is shared between sibling cpus.

When a Scan test (for a particular core) is triggered by the user, worker threads for each sibling cpus(belonging to that core) are queued to execute the scan test function in the Workqueue context.

All the siblings rendezvous before the test execution. The scan results are same for all siblings.

Scan may be aborted by some reasons. Scan test will be aborted in certain circumstances such as when interrupt occurred or cpu does not have enough power budget for scan. In this case, the kernel restart scan from the chunk where it stopped. Scan will also be aborted when the test is failed. In this case, the test is immediately stopped without retry.

---
 drivers/platform/x86/intel/ifs/Makefile  |   2 +-
 drivers/platform/x86/intel/ifs/core.c    |  14 ++
 drivers/platform/x86/intel/ifs/ifs.h     |  76 ++++++
 drivers/platform/x86/intel/ifs/runtest.c | 295 +++++++++++++++++++++++
 4 files changed, 386 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/runtest.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index b69d026ca9da..d5905e5d2de8 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)			+= intel_ifs.o
 
-intel_ifs-objs				:= core.o load.o
+intel_ifs-objs				:= core.o load.o runtest.o
drivers/platform/x86/intel/ifs/core.c +14 -0
index 716f333a064b..95847e00038b 100644
@@ -9,6 +9,9 @@
 
 struct platform_device *ifs_pdev;
 struct ifs_binary ifs_binary;
+struct ifs_test ifs_test;
+
+struct workqueue_struct *ifs_wq;
 
 #define X86_MATCH(model)					\
 	X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6,		\
@@ -86,6 +89,15 @@ static int __init ifs_init(void)
 		goto drv_unreg;
 	}
 
+	/* Flags are to keep all the sibling cpu worker threads (of a core) in close sync */
+	ifs_wq = alloc_workqueue("intel_ifs", (WQ_HIGHPRI | WQ_CPU_INTENSIVE), 1);
+	if (!ifs_wq) {
+		dev_err(&ifs_pdev->dev, "Failed to create work queue\n");
+		platform_device_unregister(ifs_pdev);
+		ret = -ENOMEM;
+		goto drv_unreg;
+	}
+	init_completion(&ifs_test.test_thread_done);
 	return 0;
 
 drv_unreg:
@@ -96,6 +108,8 @@ static int __init ifs_init(void)
 
 static void __exit ifs_exit(void)
 {
+	flush_workqueue(ifs_wq);
+	destroy_workqueue(ifs_wq);
 	platform_device_unregister(ifs_pdev);
 	platform_driver_unregister(&ifs_driver);
 }
drivers/platform/x86/intel/ifs/ifs.h +76 -0

95 lines not on this page · raw message

drivers/platform/x86/intel/ifs/runtest.c new file +295 -0

295 lines not on this page · raw message

Signature · 1 line
2.17.1
#12 lore raw

PATCH v2 8/10 platform/x86/intel/ifs: Add IFS sysfs interface

In reply to Jithu Joseph

Implement sysfs interface to trigger ifs test for a specific cpu. Additional interfaces related to checking the status of the scan test and seeing the version of the loaded IFS binary are also added.

The basic usage is as below.
- To start test, for example on cpu5:
echo 5 > /sys/devices/platform/intel_ifs/run_test
- To see the status of the last test
cat /sys/devices/platform/intel_ifs/status
- To see the version of the loaded scan binary cat /sys/devices/platform/intel_ifs/image_version

---
 drivers/platform/x86/intel/ifs/Makefile |   2 +-
 drivers/platform/x86/intel/ifs/core.c   |   1 +
 drivers/platform/x86/intel/ifs/ifs.h    |   2 +
 drivers/platform/x86/intel/ifs/sysfs.c  | 139 ++++++++++++++++++++++++
 4 files changed, 143 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/sysfs.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index d5905e5d2de8..93745fcdf652 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)			+= intel_ifs.o
 
-intel_ifs-objs				:= core.o load.o runtest.o
+intel_ifs-objs				:= core.o load.o runtest.o sysfs.o
drivers/platform/x86/intel/ifs/core.c +1 -0
index 95847e00038b..85442953d0f5 100644
@@ -82,6 +82,7 @@ static int __init ifs_init(void)
 		goto drv_unreg;
 	}
 
+	ifs_sysfs_add();
 	ret = platform_device_add(ifs_pdev);
 	if (ret) {
 		pr_err("intel_ifs: platform device add failed\n");
drivers/platform/x86/intel/ifs/ifs.h +2 -0
index 93cc1af4aea0..3200d9de4436 100644
@@ -127,6 +127,8 @@ struct ifs_test {
 
 int load_ifs_binary(void);
 int do_core_test(int cpu);
+void ifs_sysfs_add(void);
+
 extern struct platform_device *ifs_pdev;
 extern struct ifs_binary ifs_binary;
 extern struct ifs_test ifs_test;
drivers/platform/x86/intel/ifs/sysfs.c new file +139 -0

139 lines not on this page · raw message

Signature · 1 line
2.17.1
#13 lore raw

Re: [PATCH v2 08/10] platform/x86/intel/ifs: Add IFS sysfs interface

Quoted 79 lines · Jithu Joseph

Implement sysfs interface to trigger ifs test for a specific cpu. Additional interfaces related to checking the status of the scan test and seeing the version of the loaded IFS binary are also added.

The basic usage is as below.
- To start test, for example on cpu5:
echo 5 > /sys/devices/platform/intel_ifs/run_test
- To see the status of the last test
cat /sys/devices/platform/intel_ifs/status
- To see the version of the loaded scan binary cat /sys/devices/platform/intel_ifs/image_version

---
 drivers/platform/x86/intel/ifs/Makefile |   2 +-
 drivers/platform/x86/intel/ifs/core.c   |   1 +
 drivers/platform/x86/intel/ifs/ifs.h    |   2 +
 drivers/platform/x86/intel/ifs/sysfs.c  | 139 ++++++++++++++++++++++++
 4 files changed, 143 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/sysfs.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index d5905e5d2de8..93745fcdf652 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)			+= intel_ifs.o
 
-intel_ifs-objs				:= core.o load.o runtest.o
+intel_ifs-objs				:= core.o load.o runtest.o sysfs.o
drivers/platform/x86/intel/ifs/core.c +1 -0
index 95847e00038b..85442953d0f5 100644
@@ -82,6 +82,7 @@ static int __init ifs_init(void)
 		goto drv_unreg;
 	}
 
+	ifs_sysfs_add();
 	ret = platform_device_add(ifs_pdev);
 	if (ret) {
 		pr_err("intel_ifs: platform device add failed\n");
drivers/platform/x86/intel/ifs/ifs.h +2 -0
index 93cc1af4aea0..3200d9de4436 100644
@@ -127,6 +127,8 @@ struct ifs_test {
 
 int load_ifs_binary(void);
 int do_core_test(int cpu);
+void ifs_sysfs_add(void);
+
 extern struct platform_device *ifs_pdev;
 extern struct ifs_binary ifs_binary;
 extern struct ifs_test ifs_test;
drivers/platform/x86/intel/ifs/sysfs.c new file +16 -0
new file mode 100644
index 000000000000..f6decebbeae9
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright(c) 2022 Intel Corporation. */
+
+#include <linux/cpu.h>
+#include <linux/delay.h>
+#include <linux/fs.h>
+#include <linux/platform_device.h>
+#include <linux/semaphore.h>
+#include <linux/slab.h>
+
+#include "ifs.h"
+
+static DEFINE_SEMAPHORE(ifs_sem);
+
+/*
+ * The sysfs interface to check additional details of last test

drivers/platform/x86/intel/ifs/sysfs.c line 26

Quoted 10 lines
drivers/platform/x86/intel/ifs/sysfs.c new file +10 -0
+ * cat /sys/devices/system/platform/ifs/details
+ */
+static ssize_t details_show(struct device *dev,
+			    struct device_attribute *attr,
+			    char *buf)
+{
+	int ret;
+
+	if (down_trylock(&ifs_sem))
+		return -EBUSY;

Why do you care about locking here at all?

drivers/platform/x86/intel/ifs/sysfs.c line 29

Quoted 3 lines
drivers/platform/x86/intel/ifs/sysfs.c new file +3 -0
+
+	ret = sysfs_emit(buf, "%#llx\n", ifs_test.scan_details);
+	up(&ifs_sem);

What are you protecting? The value can change right after the lock is released, so who cares?

Quoted 43 lines
drivers/platform/x86/intel/ifs/sysfs.c new file +43 -0
+
+	return ret;
+}
+
+static DEVICE_ATTR_RO(details);
+
+static const char * const status_msg[] = {
+	[SCAN_NOT_TESTED] = "untested",
+	[SCAN_TEST_PASS] = "pass",
+	[SCAN_TEST_FAIL] = "fail"
+};
+
+/*
+ * The sysfs interface to check the test status:
+ * To check the status of last test
+ * cat /sys/devices/platform/ifs/status
+ */
+static ssize_t status_show(struct device *dev,
+			   struct device_attribute *attr,
+			   char *buf)
+{
+	int ret;
+
+	if (down_trylock(&ifs_sem))
+		return -EBUSY;
+
+	ret = sysfs_emit(buf, "%s\n", status_msg[ifs_test.status]);
+
+	up(&ifs_sem);
+
+	return ret;
+}
+
+static DEVICE_ATTR_RO(status);
+
+/*
+ * The sysfs interface for single core testing
+ * To start test, for example, cpu5
+ * echo 5 > /sys/devices/platform/ifs/run_test
+ * To check the result:
+ * cat /sys/devices/platform/ifs/result
+ * The sibling core gets tested at the same time.
+ */

drivers/platform/x86/intel/ifs/sysfs.c line 82

Quoted 10 lines
drivers/platform/x86/intel/ifs/sysfs.c new file +10 -0
+static ssize_t run_test_store(struct device *dev,
+			      struct device_attribute *attr,
+			      const char *buf, size_t count)
+{
+	unsigned int cpu;
+	int ret = count;
+	int rc;
+
+	if (!ifs_binary.loaded) {
+		dev_info(&ifs_pdev->dev, "Load scan binary using driver bind interface\n");

Do not allow userspace to spam kernel logs for no reason :(

sysfs files are not "help files" in the kernel.

Quoted 46 lines
drivers/platform/x86/intel/ifs/sysfs.c new file +46 -0
+		return -EPERM;
+	}
+
+	if (ifs_disabled)
+		return -ENXIO;
+
+	rc = kstrtouint(buf, 0, &cpu);
+	if (rc < 0 || cpu >= nr_cpu_ids)
+		return -EINVAL;
+
+	if (down_trylock(&ifs_sem))
+		return -EBUSY;
+
+	rc = do_core_test(cpu);
+	if (rc)
+		ret = rc;
+
+	up(&ifs_sem);
+
+	return ret;
+}
+
+static DEVICE_ATTR_WO(run_test);
+
+/*
+ * Currently loaded IFS image version.
+ */
+static ssize_t image_version_show(struct device *dev,
+				  struct device_attribute *attr, char *buf)
+{
+	return sysfs_emit(buf, "%#x\n", ifs_binary.loaded_version);
+}
+
+static DEVICE_ATTR_RO(image_version);
+
+/* global scan sysfs attributes */
+static struct attribute *plat_ifs_attrs[] = {
+	&dev_attr_image_version.attr,
+	&dev_attr_run_test.attr,
+	&dev_attr_status.attr,
+	&dev_attr_details.attr,
+	NULL
+};
+
+static const struct attribute_group plat_ifs_attr_group = {
+	.attrs = plat_ifs_attrs,

drivers/platform/x86/intel/ifs/sysfs.c line 138

Quoted 10 lines
drivers/platform/x86/intel/ifs/sysfs.c new file +10 -0
+};
+
+static const struct attribute_group *plat_ifs_groups[] = {
+	&plat_ifs_attr_group,
+	NULL
+};
+
+void ifs_sysfs_add(void)
+{
+	ifs_pdev->dev.groups = plat_ifs_groups;

Why do you have a single global structure?

{sigh}

#14 lore raw

PATCH v2 9/10 platform/x86/intel/ifs: add ABI documentation for IFS

In reply to Jithu Joseph

Add the sysfs attributes in ABI/testing for In-Field Scan.

---
 .../ABI/testing/sysfs-platform-intel-ifs      | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-ifs
Documentation/ABI/testing/sysfs-platform-intel-ifs new file +54 -0
new file mode 100644
index 000000000000..54dc6cd75484
@@ -0,0 +1,54 @@
+What:		/sys/devices/platform/intel_ifs/run_test
+Date:		April 07, 2022
+KernelVersion:	5.19.0
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	echo <cpu#> to trigger ifs test for all online cores.
+		For e.g to test cpu5 do echo 5 > /sys/devices/platform/intel_ifs/run_test
+
+What:		/sys/devices/platform/intel_ifs/status
+Date:		April 07, 2022
+KernelVersion:	5.19.0
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	The status of the last test. It can be one of "pass", "fail"
+		or "untested".
+
+What:		/sys/devices/system/cpu/cpu#/ifs/details
+Date:		April 07, 2022
+KernelVersion:	5.19.0
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Additional information regarding the last test. The details file reports
+		the hex value of the SCAN_STATUS MSR. Note that the error_code field
+		may contain driver defined software code not defined in the Intel SDM.
+
+What:		/sys/devices/platform/intel_ifs/image_version
+Date:		April 07, 2022
+KernelVersion:	5.19.0
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Version of loaded IFS binary image.
+
+What:		/sys/bus/platform/drivers/intel_ifs/bind
+Date:		April 07, 2022
+KernelVersion:	5.19.0
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	echo "intel_ifs" to reload IFS image.
+
+What:		/sys/module/intel_ifs/parameters/noirq
+Date:		April 07, 2022
+KernelVersion:	5.19.0
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	IFS tunable parameter that user can modify before
+		the scan run if they wish to override default value.
+
+		When set, system interrupts are not allowed to interrupt an IFS. The
+		default state for this parameter is set.
+
+What:		/sys/module/intel_ifs/parameters/retry
+Date:		April 07, 2022
+KernelVersion:	5.19.0
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	IFS tunable parameter that user can modify before scan run
+		if they wish to override default value.
+
+		Maximum retry counter when the test is not executed due to an
+		event such as interrupt. The default value is 5, it can be set to any
+		value from 1 to 20.
Signature · 1 line
2.17.1
#15 lore raw

Re: [PATCH v2 09/10] platform/x86/intel/ifs: add ABI documentation for IFS

Quoted 15 lines · Jithu Joseph

Add the sysfs attributes in ABI/testing for In-Field Scan.

---
 .../ABI/testing/sysfs-platform-intel-ifs      | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-ifs
Documentation/ABI/testing/sysfs-platform-intel-ifs new file +0 -0
new file mode 100644
index 000000000000..54dc6cd75484

Documentation/ABI/testing/sysfs-platform-intel-ifs line 3

Quoted 3 lines
Documentation/ABI/testing/sysfs-platform-intel-ifs new file +3 -0
@@ -0,0 +1,54 @@
+What:		/sys/devices/platform/intel_ifs/run_test
+Date:		April 07, 2022
+KernelVersion:	5.19.0

No need for ".0"

Documentation/ABI/testing/sysfs-platform-intel-ifs line 6

Quoted 3 lines
Documentation/ABI/testing/sysfs-platform-intel-ifs new file +3 -0
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	echo <cpu#> to trigger ifs test for all online cores.
+		For e.g to test cpu5 do echo 5 > /sys/devices/platform/intel_ifs/run_test

So core numbers are different than cpu numbers here? How are users going to map them?

Quoted 11 lines
Documentation/ABI/testing/sysfs-platform-intel-ifs new file +11 -0
+
+What:		/sys/devices/platform/intel_ifs/status
+Date:		April 07, 2022
+KernelVersion:	5.19.0
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	The status of the last test. It can be one of "pass", "fail"
+		or "untested".
+
+What:		/sys/devices/system/cpu/cpu#/ifs/details
+Date:		April 07, 2022
+KernelVersion:	5.19.0

Documentation/ABI/testing/sysfs-platform-intel-ifs line 27

Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-intel-ifs new file +10 -0
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Additional information regarding the last test. The details file reports
+		the hex value of the SCAN_STATUS MSR. Note that the error_code field
+		may contain driver defined software code not defined in the Intel SDM.
+
+What:		/sys/devices/platform/intel_ifs/image_version
+Date:		April 07, 2022
+KernelVersion:	5.19.0
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Version of loaded IFS binary image.

In what format?

Documentation/ABI/testing/sysfs-platform-intel-ifs line 33

Quoted 6 lines
Documentation/ABI/testing/sysfs-platform-intel-ifs new file +6 -0
+
+What:		/sys/bus/platform/drivers/intel_ifs/bind
+Date:		April 07, 2022
+KernelVersion:	5.19.0
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	echo "intel_ifs" to reload IFS image.

Huh? Why are you using a common sysfs file for this type of attribute? Please do not do so, make it "reload" or something like that.

Documentation/ABI/testing/sysfs-platform-intel-ifs line 40

Quoted 7 lines
Documentation/ABI/testing/sysfs-platform-intel-ifs new file +7 -0
+
+What:		/sys/module/intel_ifs/parameters/noirq
+Date:		April 07, 2022
+KernelVersion:	5.19.0
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	IFS tunable parameter that user can modify before
+		the scan run if they wish to override default value.

And where are those parameters documented? What are valid values here?

Documentation/ABI/testing/sysfs-platform-intel-ifs line 43

Quoted 2 lines
Documentation/ABI/testing/sysfs-platform-intel-ifs new file +2 -0
+		When set, system interrupts are not allowed to interrupt an IFS. The
+		default state for this parameter is set.

set to what?

Documentation/ABI/testing/sysfs-platform-intel-ifs line 54

Quoted 11 lines
Documentation/ABI/testing/sysfs-platform-intel-ifs new file +11 -0
+
+What:		/sys/module/intel_ifs/parameters/retry
+Date:		April 07, 2022
+KernelVersion:	5.19.0
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	IFS tunable parameter that user can modify before scan run
+		if they wish to override default value.
+
+		Maximum retry counter when the test is not executed due to an
+		event such as interrupt. The default value is 5, it can be set to any
+		value from 1 to 20.

Why would anyone ever want to change this value? Why doesn't it "just work" without needing anything tuned?

thanks,

greg k-h

#16 lore raw

PATCH v2 10/10 trace: platform/x86/intel/ifs: Add trace point to track Intel IFS operations

In reply to Jithu Joseph

From: Tony Luck <[email protected]>

Add tracing support which may be useful for debugging systems that fail to complete In Field Scan tests.

---
 drivers/platform/x86/intel/ifs/runtest.c |  5 ++++
 include/trace/events/intel_ifs.h         | 38 ++++++++++++++++++++++++
 2 files changed, 43 insertions(+)
 create mode 100644 include/trace/events/intel_ifs.h
drivers/platform/x86/intel/ifs/runtest.c +5 -0
index f9c98d84183f..b9fac2ac7107 100644
@@ -10,6 +10,9 @@
 
 #include "ifs.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/intel_ifs.h>
+
 bool ifs_disabled;
 
 static int ifs_retry_set(const char *val, const struct kernel_param *kp);
@@ -204,6 +207,8 @@ static void ifs_work_func(struct work_struct *work)
 
 		rdmsrl(MSR_SCAN_STATUS, status.data);
 
+		trace_ifs_status(activate, status);
+
 		/* Some cases can be retried, give up for others */
 		if (!can_restart(status))
 			break;
include/trace/events/intel_ifs.h new file +38 -0
new file mode 100644
index 000000000000..0611f370cb37
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM intel_ifs
+
+#if !defined(_TRACE_IFS_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_IFS_H
+
+#include <linux/ktime.h>
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(ifs_status,
+
+	TP_PROTO(union ifs_scan activate, union ifs_status status),
+
+	TP_ARGS(activate, status),
+
+	TP_STRUCT__entry(
+		__field(	u64,	status	)
+		__field(	u8,	start	)
+		__field(	u8,	stop	)
+	),
+
+	TP_fast_assign(
+		__entry->start	= activate.start;
+		__entry->stop	= activate.stop;
+		__entry->status	= status.data;
+	),
+
+	TP_printk("start: %.2x, stop: %.2x, status: %llx",
+		__entry->start,
+		__entry->stop,
+		__entry->status)
+);
+
+#endif /* _TRACE_IFS_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
Signature · 1 line
2.17.1
maintainer
#17 lore raw

v3 cover Introduce In Field Scan driver

In reply to Jithu Joseph

Longer description of what this does, and why it is useful in the v2 cover letter here:
https://lore.kernel.org/all/[email protected]/

But the TL;DR version is this driver loads scan test files that can check whether silicon in a CPU core is still running correctly. It is expected that these tests would be run several times per day to catch problems as silicon ages.

I'm posting this update because I missed many major issues when I added my review tag. So I have a moral obligation to fix up the things that I missed.

Changes since V2:

Dan Williams (offline):
----------------------
1) Provided the clue to split into a tiny driver that enumerates and registers the device. Then the IFS driver can attach to that an behave much more like a normal driver (original idea from Andy Lutomirski, used for pmem/nvdimms)

2 .. many) Lots more pointers, tips, and general good guidance to make both
the code and commit comments better and easier to understand.

Boris:
-----
1) Add "intel_" prefixes to the two functions moving to wider scope.

Done.

2) Move the declarations from <asm/microcode_intel.h> to <asm/cpu.h>

Done.

3) intel_cpu_signatures_match() is small enough to be "inline".

Done.

Greg:
----
1) Is the firmware already submitted to the linux-firmware project for inclusion there?
If not, where should a user get it from?

The scan files will be distributed by Intel on Github in much the same way that microcode is distributed today.

2) > +struct ifs_binary ifs_binary;

Please no static memory. Use the driver model properly which does not want you to do this at all.

You should not need this at all. If you do, something is wrong as you are tying the lifecycle of the memory to the code, not to the device.

Moved this (and ifs_test) to dynamic allocation using devm_kzalloc() and attaching the resulting pointer to the device with dev_set_drvdata().

3) > +static ssize_t details_show(struct device *dev,

Review

Quoted 7 lines
(quoted diff) +7 -0
+			    struct device_attribute *attr,
+			    char *buf)
+{
+	int ret;
+
+	if (down_trylock(&ifs_sem))
+		return -EBUSY;

Why do you care about locking here at all?

Review

Quoted 3 lines
(quoted diff) +3 -0
+
+	ret = sysfs_emit(buf, "%#llx\n", ifs_test.scan_details);
+	up(&ifs_sem);

What are you protecting? The value can change right after the lock is released, so who cares?

Removed locking from status and details show() functions. Running a test is synchronous. So:

  # echo 3 > run_test
  # cat status
  # cat details
will give the results of the core 3 test as expected. It is up to the user
to not do dumb things like reading status/details from another process in
parallel with running tests.

4) > + if (!ifs_binary.loaded) {

Review

Quoted 1 line
(quoted diff) +1 -0
+		dev_info(&ifs_pdev->dev, "Load scan binary using driver bind interface\n");

Do not allow userspace to spam kernel logs for no reason :(

sysfs files are not "help files" in the kernel.

Spam removed.

5) > +void ifs_sysfs_add(void)

Review

Quoted 2 lines
(quoted diff) +2 -0
+{
+	ifs_pdev->dev.groups = plat_ifs_groups;

Why do you have a single global structure?

All instances of the driver for different tests can use the same files and functions. They use "struct ifs_data *ifsd = dev_get_drvdata(dev);" to operate on the correct driver instance.

6) > +KernelVersion: 5.19.0

No need for ".0"

Removed.

7) > + For e.g to test cpu5 do echo 5 > /sys/devices/platform/intel_ifs/run_test

So core numbers are different than cpu numbers here? How are users going to map them?

Added some extra text here to say that tests are per core, but any thread on the core can be used to run the test. Should I also point people at /sys/devices/system/cpu/cpu#/topology/thread_siblings_list? It seems easy for users to get a list of cores with a script like:

$ cores=$(cat /sys/devices/system/cpu/cpu*/topology/thread_siblings_list | sed -e 's/,.*//' | sort -n | uniq)

8) > +Description: Version of loaded IFS binary image.

In what format?

Added "(hexadecimal)". Also added code (and Docs) to print "none" if the load of the scan file failed.

9) > +Description: echo "intel_ifs" to reload IFS image.

Huh? Why are you using a common sysfs file for this type of attribute? Please do not do so, make it "reload" or something like that.

Ok. Added a "reload" file like microcode. (Though using driver bind/unbind also works).

10) > +Description: IFS tunable parameter that user can modify before

Review

Quoted 1 line
(quoted diff) +1 -0
+		the scan run if they wish to override default value.

And where are those parameters documented? What are valid values here?

Dropped both the "noirq" and "retry" parameters. I think they now have sane defaults. If Jithu/Ashok have a good use case, they can send a patch to add them back.

-Tony

Jithu Joseph (7):
x86/microcode/intel: Expose collect_cpu_info_early() for IFS platform/x86/intel/ifs: Read IFS firmware image platform/x86/intel/ifs: Check IFS Image sanity platform/x86/intel/ifs: Authenticate and copy to secured memory platform/x86/intel/ifs: Add scan test support platform/x86/intel/ifs: Add IFS sysfs interface platform/x86/intel/ifs: add ABI documentation for IFS

Tony Luck (4):
Documentation: In-Field Scan
platform/x86/intel/ifs: Create device for Intel IFS (In Field Scan) platform/x86/intel/ifs: Add stub driver for In-Field Scan
trace: platform/x86/intel/ifs: Add trace point to track Intel IFS
operations

 .../ABI/testing/sysfs-platform-intel-ifs      |  39 ++
 Documentation/x86/ifs.rst                     | 101 ++++++
 Documentation/x86/index.rst                   |   1 +
 MAINTAINERS                                   |   8 +
 arch/x86/include/asm/cpu.h                    |  18 +
 arch/x86/kernel/cpu/intel.c                   |  32 ++
 arch/x86/kernel/cpu/microcode/intel.c         |  59 +---
 drivers/platform/x86/intel/Kconfig            |   1 +
 drivers/platform/x86/intel/Makefile           |   1 +
 drivers/platform/x86/intel/ifs/Kconfig        |  16 +
 drivers/platform/x86/intel/ifs/Makefile       |   5 +
 drivers/platform/x86/intel/ifs/core.c         |  74 ++++
 drivers/platform/x86/intel/ifs/ifs.h          | 103 ++++++
 .../platform/x86/intel/ifs/intel_ifs_device.c |  50 +++
 drivers/platform/x86/intel/ifs/load.c         | 265 ++++++++++++++
 drivers/platform/x86/intel/ifs/runtest.c      | 333 ++++++++++++++++++
 drivers/platform/x86/intel/ifs/sysfs.c        | 151 ++++++++
 include/trace/events/intel_ifs.h              |  38 ++
 18 files changed, 1243 insertions(+), 52 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-ifs
 create mode 100644 Documentation/x86/ifs.rst
 create mode 100644 drivers/platform/x86/intel/ifs/Kconfig
 create mode 100644 drivers/platform/x86/intel/ifs/Makefile
 create mode 100644 drivers/platform/x86/intel/ifs/core.c
 create mode 100644 drivers/platform/x86/intel/ifs/ifs.h
 create mode 100644 drivers/platform/x86/intel/ifs/intel_ifs_device.c
 create mode 100644 drivers/platform/x86/intel/ifs/load.c
 create mode 100644 drivers/platform/x86/intel/ifs/runtest.c
 create mode 100644 drivers/platform/x86/intel/ifs/sysfs.c
 create mode 100644 include/trace/events/intel_ifs.h

base-commit: b2d229d4ddb17db541098b83524d901257e93845

Signature · 1 line
2.35.1
maintainer
#18 lore raw

PATCH v3 1/11 x86/microcode/intel: Expose collect_cpu_info_early() for IFS

From: Jithu Joseph <[email protected]>

IFS is a CPU feature that allows a binary blob, similar to microcode, to be loaded and consumed to perform low level validation of CPU circuitry. In fact, it carries the same Processor Signature (family/model/stepping) details that are contained in Intel microcode blobs.

In support of an IFS driver to trigger loading, validation, and running of these tests blobs, make the functionality of cpu_signatures_match() and collect_cpu_info_early() available outside of the microcode driver.

Rename collect_cpu_info_early() to intel_cpu_collect_info_early() and EXPORT_SYMBOL_GPL() it. Add declaration to x86 <asm/cpu.h>

Make cpu_signatures_match() an inline function in x86 <asm/cpu.h>, and also give it an "intel_" prefix.

No functional change intended.

---
 arch/x86/include/asm/cpu.h            | 18 ++++++++
 arch/x86/kernel/cpu/intel.c           | 32 +++++++++++++++
 arch/x86/kernel/cpu/microcode/intel.c | 59 ++++-----------------------
 3 files changed, 57 insertions(+), 52 deletions(-)
arch/x86/include/asm/cpu.h +18 -0
index 86e5e4e26fcb..c245b2196657 100644
@@ -76,4 +76,22 @@ static inline void init_ia32_feat_ctl(struct cpuinfo_x86 *c) {}
 
 extern __noendbr void cet_disable(void);
 
+struct ucode_cpu_info;
+
+int intel_cpu_collect_info_early(struct ucode_cpu_info *uci);
+
+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;
+}
+
 #endif /* _ASM_X86_CPU_H */
arch/x86/kernel/cpu/intel.c +32 -0
index f7a5370a9b3b..bb717cd847b4 100644
@@ -181,6 +181,38 @@ static bool bad_spectre_microcode(struct cpuinfo_x86 *c)
 	return false;
 }
 
+int intel_cpu_collect_info_early(struct ucode_cpu_info *uci)
+{
+	unsigned int val[2];
+	unsigned int family, model;
+	struct cpu_signature csig = { 0 };
+	unsigned int eax, ebx, ecx, edx;
+
+	memset(uci, 0, sizeof(*uci));
+
+	eax = 0x00000001;
+	ecx = 0;
+	native_cpuid(&eax, &ebx, &ecx, &edx);
+	csig.sig = eax;
+
+	family = x86_family(eax);
+	model  = x86_model(eax);
+
+	if (model >= 5 || family > 6) {
+		/* get processor flags from MSR 0x17 */
+		native_rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]);
+		csig.pf = 1 << ((val[1] >> 18) & 7);
+	}
+
+	csig.rev = intel_get_microcode_revision();
+
+	uci->cpu_sig = csig;
+	uci->valid = 1;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(intel_cpu_collect_info_early);
+
 static void early_init_intel(struct cpuinfo_x86 *c)
 {
 	u64 misc_enable;
arch/x86/kernel/cpu/microcode/intel.c +7 -52

113 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#19 lore raw

PATCH v3 2/11 Documentation: In-Field Scan

In reply to Tony Luck

Add documentation for In-Field Scan (IFS). This documentation describes the basics of IFS, the loading IFS image, chunk authentication, running scan and how to check result via sysfs as well as tunable parameters.

The CORE_CAPABILITIES MSR enumerates whether IFS is supported.

The full github location for distributing the IFS images is still being decided. So just a placeholder included for now in the documentation.

Future CPUs will support more than one type of test. Plan for that now by using a ".0" suffix on the ABI directory names. Additional test types will use ".1", etc.

---
 Documentation/x86/ifs.rst   | 101 ++++++++++++++++++++++++++++++++++++
 Documentation/x86/index.rst |   1 +
 2 files changed, 102 insertions(+)
 create mode 100644 Documentation/x86/ifs.rst
Documentation/x86/ifs.rst new file +101 -0
new file mode 100644
index 000000000000..62f3c07d433a
@@ -0,0 +1,101 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=============
+In-Field Scan
+=============
+
+Introduction
+------------
+
+In Field Scan (IFS) is a hardware feature to run circuit level tests on
+a CPU core to detect problems that are not caught by parity or ECC checks.
+Future CPUs will support more than one type of test which will show up
+with a new platform-device instance-id, for now only .0 is exposed.
+
+
+IFS Image
+---------
+
+Intel provides a firmware file containing the scan tests via
+github [#f1]_.  Similar to microcode there is a separate file for each
+family-model-stepping.
+
+IFS Image Loading
+-----------------
+
+The driver loads the tests into memory reserved BIOS local to each CPU
+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::
+
+  # echo 1 > /sys/bus/platform/drivers/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
+
+Running tests
+-------------
+
+Tests are run by the driver synchronizing execution of all threads on a
+core and then writing to the ACTIVATE_SCAN MSR on all threads. Instruction
+execution continues when:
+
+1) All tests have completed.
+2) Execution was interrupted.
+3) A test detected a problem.
+
+In all cases reading the SCAN_STATUS MSR provides details on what
+happened. The driver makes the value of this MSR visible to applications
+via the "details" file (see below). Interrupted tests may be restarted.
+
+The IFS driver provides sysfs interfaces via /sys/devices/platform/intel_ifs.0/
+to control execution:
+
+Test a specific core::
+
+  # echo <cpu#> > /sys/devices/platform/intel_ifs.0/run_test
+
+when HT is enabled any of the sibling cpu# can be specified to test its
+corresponding physical core. Since the tests are per physical core, the
+result of testing any thread is same. It is only necessary to test one
+thread.
+
+For e.g. to test core corresponding to cpu5
+
+  # echo 5 > /sys/devices/platform/intel_ifs.0/run_test
+
+Results of the last test is provided in /sys::
+
+  $ cat /sys/devices/platform/intel_ifs.0/status
+  pass
+
+Status can be one of pass, fail, untested
+
+Additional details of the last test is provided by the details file::
+
+  $ cat /sys/devices/platform/intel_ifs.0/details
+  0x8081
+
+The details file reports the hex value of the SCAN_STATUS MSR.
+Hardware defined error codes are documented in volume 4 of the Intel
+Software Developer's Manual but the error_code field may contain one of
+the following driver defined software codes:
+
++------+--------------------+
+| 0xFD | Software timeout   |
++------+--------------------+
+| 0xFE | Partial completion |
++------+--------------------+
+
+Driver design choices
+---------------------
+
+1) The ACTIVATE_SCAN MSR allows for running any consecutive subrange of
+available tests. But the driver always tries to run all tests and only
+uses the subrange feature to restart an interrupted test.
+
+2) Hardware allows for some number of cores to be tested in parallel.
+The driver does not make use of this, it only tests one core at a time.
+
+.. [#f1] https://github.com/intel/TBD
Documentation/x86/index.rst +1 -0
index 91b2fa456618..9d8e8a73d57b 100644
@@ -35,6 +35,7 @@ x86-specific Documentation
    usb-legacy-support
    i386/index
    x86_64/index
+   ifs
    sva
    sgx
    features
Signature · 1 line
2.35.1
#20 lore raw

Re: [PATCH v3 02/11] Documentation: In-Field Scan

Quoted 90 lines · Tony Luck

Add documentation for In-Field Scan (IFS). This documentation describes the basics of IFS, the loading IFS image, chunk authentication, running scan and how to check result via sysfs as well as tunable parameters.

The CORE_CAPABILITIES MSR enumerates whether IFS is supported.

The full github location for distributing the IFS images is still being decided. So just a placeholder included for now in the documentation.

Future CPUs will support more than one type of test. Plan for that now by using a ".0" suffix on the ABI directory names. Additional test types will use ".1", etc.

---
 Documentation/x86/ifs.rst   | 101 ++++++++++++++++++++++++++++++++++++
 Documentation/x86/index.rst |   1 +
 2 files changed, 102 insertions(+)
 create mode 100644 Documentation/x86/ifs.rst
Documentation/x86/ifs.rst new file +61 -0
new file mode 100644
index 000000000000..62f3c07d433a
@@ -0,0 +1,101 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=============
+In-Field Scan
+=============
+
+Introduction
+------------
+
+In Field Scan (IFS) is a hardware feature to run circuit level tests on
+a CPU core to detect problems that are not caught by parity or ECC checks.
+Future CPUs will support more than one type of test which will show up
+with a new platform-device instance-id, for now only .0 is exposed.
+
+
+IFS Image
+---------
+
+Intel provides a firmware file containing the scan tests via
+github [#f1]_.  Similar to microcode there is a separate file for each
+family-model-stepping.
+
+IFS Image Loading
+-----------------
+
+The driver loads the tests into memory reserved BIOS local to each CPU
+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::
+
+  # echo 1 > /sys/bus/platform/drivers/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
+
+Running tests
+-------------
+
+Tests are run by the driver synchronizing execution of all threads on a
+core and then writing to the ACTIVATE_SCAN MSR on all threads. Instruction
+execution continues when:
+
+1) All tests have completed.
+2) Execution was interrupted.
+3) A test detected a problem.
+
+In all cases reading the SCAN_STATUS MSR provides details on what
+happened. The driver makes the value of this MSR visible to applications
+via the "details" file (see below). Interrupted tests may be restarted.
+
+The IFS driver provides sysfs interfaces via /sys/devices/platform/intel_ifs.0/
+to control execution:
+
+Test a specific core::
+
+  # echo <cpu#> > /sys/devices/platform/intel_ifs.0/run_test
+
+when HT is enabled any of the sibling cpu# can be specified to test its
+corresponding physical core. Since the tests are per physical core, the
+result of testing any thread is same. It is only necessary to test one

Documentation/x86/ifs.rst line 71

Quoted 10 lines
Documentation/x86/ifs.rst new file +10 -0
+thread.
+
+For e.g. to test core corresponding to cpu5
+
+  # echo 5 > /sys/devices/platform/intel_ifs.0/run_test
+
+Results of the last test is provided in /sys::
+
+  $ cat /sys/devices/platform/intel_ifs.0/status
+  pass

sysfs documentation belongs in Documentation/ABI/

And why not just include this whole thing in the driver itself and suck the documentation out of that? No need to have a separate file.

thanks,

greg k-h

#21 lore raw

Re: [PATCH v3 02/11] Documentation: In-Field Scan

Quoted 105 lines · Greg KH
Quoted 90 lines · Tony Luck

Add documentation for In-Field Scan (IFS). This documentation describes the basics of IFS, the loading IFS image, chunk authentication, running scan and how to check result via sysfs as well as tunable parameters.

The CORE_CAPABILITIES MSR enumerates whether IFS is supported.

The full github location for distributing the IFS images is still being decided. So just a placeholder included for now in the documentation.

Future CPUs will support more than one type of test. Plan for that now by using a ".0" suffix on the ABI directory names. Additional test types will use ".1", etc.

---
 Documentation/x86/ifs.rst   | 101 ++++++++++++++++++++++++++++++++++++
 Documentation/x86/index.rst |   1 +
 2 files changed, 102 insertions(+)
 create mode 100644 Documentation/x86/ifs.rst
Documentation/x86/ifs.rst new file +61 -0
new file mode 100644
index 000000000000..62f3c07d433a
@@ -0,0 +1,101 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=============
+In-Field Scan
+=============
+
+Introduction
+------------
+
+In Field Scan (IFS) is a hardware feature to run circuit level tests on
+a CPU core to detect problems that are not caught by parity or ECC checks.
+Future CPUs will support more than one type of test which will show up
+with a new platform-device instance-id, for now only .0 is exposed.
+
+
+IFS Image
+---------
+
+Intel provides a firmware file containing the scan tests via
+github [#f1]_.  Similar to microcode there is a separate file for each
+family-model-stepping.
+
+IFS Image Loading
+-----------------
+
+The driver loads the tests into memory reserved BIOS local to each CPU
+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::
+
+  # echo 1 > /sys/bus/platform/drivers/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
+
+Running tests
+-------------
+
+Tests are run by the driver synchronizing execution of all threads on a
+core and then writing to the ACTIVATE_SCAN MSR on all threads. Instruction
+execution continues when:
+
+1) All tests have completed.
+2) Execution was interrupted.
+3) A test detected a problem.
+
+In all cases reading the SCAN_STATUS MSR provides details on what
+happened. The driver makes the value of this MSR visible to applications
+via the "details" file (see below). Interrupted tests may be restarted.
+
+The IFS driver provides sysfs interfaces via /sys/devices/platform/intel_ifs.0/
+to control execution:
+
+Test a specific core::
+
+  # echo <cpu#> > /sys/devices/platform/intel_ifs.0/run_test
+
+when HT is enabled any of the sibling cpu# can be specified to test its
+corresponding physical core. Since the tests are per physical core, the
+result of testing any thread is same. It is only necessary to test one

Documentation/x86/ifs.rst line 71

Quoted 10 lines
Documentation/x86/ifs.rst new file +10 -0
+thread.
+
+For e.g. to test core corresponding to cpu5
+
+  # echo 5 > /sys/devices/platform/intel_ifs.0/run_test
+
+Results of the last test is provided in /sys::
+
+  $ cat /sys/devices/platform/intel_ifs.0/status
+  pass

sysfs documentation belongs in Documentation/ABI/

Quoted 2 lines

And why not just include this whole thing in the driver itself and suck the documentation out of that? No need to have a separate file.

At a minimum a separate file is needed to house the
---
.. kernel-doc:: $source_file
:doc: $header
---
...statements, but ok, I'll recommend that going forward to de-emphasize shipping content directly from Documentation/ when it can be ingested from "DOC:" source. I had been assuming DOC: blocks in the code were more for augmenting kernel-doc on driver internal ABIs and not longer theory of operation documentation that is an awkward fit for Documentation/ABI/.

#22 lore raw

Re: [PATCH v3 02/11] Documentation: In-Field Scan

Quoted 109 lines · Dan Williams
Quoted 105 lines · Greg KH
Quoted 90 lines · Tony Luck

Add documentation for In-Field Scan (IFS). This documentation describes the basics of IFS, the loading IFS image, chunk authentication, running scan and how to check result via sysfs as well as tunable parameters.

The CORE_CAPABILITIES MSR enumerates whether IFS is supported.

The full github location for distributing the IFS images is still being decided. So just a placeholder included for now in the documentation.

Future CPUs will support more than one type of test. Plan for that now by using a ".0" suffix on the ABI directory names. Additional test types will use ".1", etc.

---
 Documentation/x86/ifs.rst   | 101 ++++++++++++++++++++++++++++++++++++
 Documentation/x86/index.rst |   1 +
 2 files changed, 102 insertions(+)
 create mode 100644 Documentation/x86/ifs.rst
Documentation/x86/ifs.rst new file +61 -0
new file mode 100644
index 000000000000..62f3c07d433a
@@ -0,0 +1,101 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=============
+In-Field Scan
+=============
+
+Introduction
+------------
+
+In Field Scan (IFS) is a hardware feature to run circuit level tests on
+a CPU core to detect problems that are not caught by parity or ECC checks.
+Future CPUs will support more than one type of test which will show up
+with a new platform-device instance-id, for now only .0 is exposed.
+
+
+IFS Image
+---------
+
+Intel provides a firmware file containing the scan tests via
+github [#f1]_.  Similar to microcode there is a separate file for each
+family-model-stepping.
+
+IFS Image Loading
+-----------------
+
+The driver loads the tests into memory reserved BIOS local to each CPU
+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::
+
+  # echo 1 > /sys/bus/platform/drivers/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
+
+Running tests
+-------------
+
+Tests are run by the driver synchronizing execution of all threads on a
+core and then writing to the ACTIVATE_SCAN MSR on all threads. Instruction
+execution continues when:
+
+1) All tests have completed.
+2) Execution was interrupted.
+3) A test detected a problem.
+
+In all cases reading the SCAN_STATUS MSR provides details on what
+happened. The driver makes the value of this MSR visible to applications
+via the "details" file (see below). Interrupted tests may be restarted.
+
+The IFS driver provides sysfs interfaces via /sys/devices/platform/intel_ifs.0/
+to control execution:
+
+Test a specific core::
+
+  # echo <cpu#> > /sys/devices/platform/intel_ifs.0/run_test
+
+when HT is enabled any of the sibling cpu# can be specified to test its
+corresponding physical core. Since the tests are per physical core, the
+result of testing any thread is same. It is only necessary to test one

Documentation/x86/ifs.rst line 71

Quoted 10 lines
Documentation/x86/ifs.rst new file +10 -0
+thread.
+
+For e.g. to test core corresponding to cpu5
+
+  # echo 5 > /sys/devices/platform/intel_ifs.0/run_test
+
+Results of the last test is provided in /sys::
+
+  $ cat /sys/devices/platform/intel_ifs.0/status
+  pass

sysfs documentation belongs in Documentation/ABI/

Quoted 2 lines

And why not just include this whole thing in the driver itself and suck the documentation out of that? No need to have a separate file.

Quoted 11 lines

At a minimum a separate file is needed to house the
---
.. kernel-doc:: $source_file
:doc: $header
---
...statements, but ok, I'll recommend that going forward to de-emphasize shipping content directly from Documentation/ when it can be ingested from "DOC:" source. I had been assuming DOC: blocks in the code were more for augmenting kernel-doc on driver internal ABIs and not longer theory of operation documentation that is an awkward fit for Documentation/ABI/.

I don't know which is better, it's just that creating a whole new documentation file for a single tiny driver feels very odd as it will get out of date and is totally removed from the driver itself.

I'd prefer that drivers be self-contained, including the documentation, as it is much more obvious what is happening with that. Spreading stuff around the tree only causes stuff to get out of sync easier.

thanks,

greg k-h

maintainer
#23 lore raw

PATCH v3 3/11 platform/x86/intel/ifs: Create device for Intel IFS (In Field Scan)

In reply to Tony Luck

The initial implementation of IFS is model specific. Enumeration is via a combination of family-model-stepping and a check for a bit in the CORE_CAPABILITIES MSR.

Linux has handled this lack of enumeration before with a code stub to create a device. See arch/x86/kernel/pmem.c. Use the same approach here.

---
 MAINTAINERS                                   |  7 +++
 drivers/platform/x86/intel/Kconfig            |  1 +
 drivers/platform/x86/intel/Makefile           |  1 +
 drivers/platform/x86/intel/ifs/Kconfig        |  2 +
 drivers/platform/x86/intel/ifs/Makefile       |  1 +
 .../platform/x86/intel/ifs/intel_ifs_device.c | 50 +++++++++++++++++++
 6 files changed, 62 insertions(+)
 create mode 100644 drivers/platform/x86/intel/ifs/Kconfig
 create mode 100644 drivers/platform/x86/intel/ifs/Makefile
 create mode 100644 drivers/platform/x86/intel/ifs/intel_ifs_device.c
MAINTAINERS +7 -0
index 40fa1955ca3f..9e372a960fa5 100644
@@ -9861,6 +9861,13 @@ B:	https://bugzilla.kernel.org
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git
 F:	drivers/idle/intel_idle.c
 
+INTEL IN FIELD SCAN (IFS) DRIVER
+M:	Jithu Joseph <[email protected]>
+R:	Ashok Raj <[email protected]>
+R:	Tony Luck <[email protected]>
+S:	Maintained
+F:	drivers/platform/x86/intel/ifs
+
 INTEL INTEGRATED SENSOR HUB DRIVER
 M:	Srinivas Pandruvada <[email protected]>
 M:	Jiri Kosina <[email protected]>
drivers/platform/x86/intel/Kconfig +1 -0
index 1f01a8a23c57..794968bda115 100644
@@ -4,6 +4,7 @@
 #
 
 source "drivers/platform/x86/intel/atomisp2/Kconfig"
+source "drivers/platform/x86/intel/ifs/Kconfig"
 source "drivers/platform/x86/intel/int1092/Kconfig"
 source "drivers/platform/x86/intel/int3472/Kconfig"
 source "drivers/platform/x86/intel/pmc/Kconfig"
drivers/platform/x86/intel/Makefile +1 -0
index c61bc3e97121..10285d0fd16a 100644
@@ -5,6 +5,7 @@
 #
 
 obj-$(CONFIG_INTEL_ATOMISP2_PDX86)	+= atomisp2/
+obj-y					+= ifs/
 obj-$(CONFIG_INTEL_SAR_INT1092)		+= int1092/
 obj-$(CONFIG_INTEL_SKL_INT3472)		+= int3472/
 obj-$(CONFIG_INTEL_PMC_CORE)		+= pmc/
drivers/platform/x86/intel/ifs/Kconfig new file +2 -0
new file mode 100644
index 000000000000..51325b699563
@@ -0,0 +1,2 @@
+config INTEL_IFS_DEVICE
+	bool
drivers/platform/x86/intel/ifs/Makefile new file +1 -0
new file mode 100644
index 000000000000..12c2f5ce9925
@@ -0,0 +1 @@
+obj-$(CONFIG_INTEL_IFS_DEVICE)	+= intel_ifs_device.o
drivers/platform/x86/intel/ifs/intel_ifs_device.c new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
2.35.1
#24 lore raw

Re: [PATCH v3 03/11] platform/x86/intel/ifs: Create device for Intel IFS (In Field Scan)

Quoted 7 lines · Tony Luck

The initial implementation of IFS is model specific. Enumeration is via a combination of family-model-stepping and a check for a bit in the CORE_CAPABILITIES MSR.

Linux has handled this lack of enumeration before with a code stub to create a device. See arch/x86/kernel/pmem.c. Use the same approach here.

Ick, why? Why not just create a simple virtual device and use that? Do you really want to bind a driver to this? Or do you already "know" the only driver that you have will bind to this?

pmem.c should not be used as a good example of anything, sorry.

greg k-h

Quoted 116 lines
---
 MAINTAINERS                                   |  7 +++
 drivers/platform/x86/intel/Kconfig            |  1 +
 drivers/platform/x86/intel/Makefile           |  1 +
 drivers/platform/x86/intel/ifs/Kconfig        |  2 +
 drivers/platform/x86/intel/ifs/Makefile       |  1 +
 .../platform/x86/intel/ifs/intel_ifs_device.c | 50 +++++++++++++++++++
 6 files changed, 62 insertions(+)
 create mode 100644 drivers/platform/x86/intel/ifs/Kconfig
 create mode 100644 drivers/platform/x86/intel/ifs/Makefile
 create mode 100644 drivers/platform/x86/intel/ifs/intel_ifs_device.c
MAINTAINERS +7 -0
index 40fa1955ca3f..9e372a960fa5 100644
@@ -9861,6 +9861,13 @@ B:	https://bugzilla.kernel.org
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git
 F:	drivers/idle/intel_idle.c
 
+INTEL IN FIELD SCAN (IFS) DRIVER
+M:	Jithu Joseph <[email protected]>
+R:	Ashok Raj <[email protected]>
+R:	Tony Luck <[email protected]>
+S:	Maintained
+F:	drivers/platform/x86/intel/ifs
+
 INTEL INTEGRATED SENSOR HUB DRIVER
 M:	Srinivas Pandruvada <[email protected]>
 M:	Jiri Kosina <[email protected]>
drivers/platform/x86/intel/Kconfig +1 -0
index 1f01a8a23c57..794968bda115 100644
@@ -4,6 +4,7 @@
 #
 
 source "drivers/platform/x86/intel/atomisp2/Kconfig"
+source "drivers/platform/x86/intel/ifs/Kconfig"
 source "drivers/platform/x86/intel/int1092/Kconfig"
 source "drivers/platform/x86/intel/int3472/Kconfig"
 source "drivers/platform/x86/intel/pmc/Kconfig"
drivers/platform/x86/intel/Makefile +1 -0
index c61bc3e97121..10285d0fd16a 100644
@@ -5,6 +5,7 @@
 #
 
 obj-$(CONFIG_INTEL_ATOMISP2_PDX86)	+= atomisp2/
+obj-y					+= ifs/
 obj-$(CONFIG_INTEL_SAR_INT1092)		+= int1092/
 obj-$(CONFIG_INTEL_SKL_INT3472)		+= int3472/
 obj-$(CONFIG_INTEL_PMC_CORE)		+= pmc/
drivers/platform/x86/intel/ifs/Kconfig new file +2 -0
new file mode 100644
index 000000000000..51325b699563
@@ -0,0 +1,2 @@
+config INTEL_IFS_DEVICE
+	bool
drivers/platform/x86/intel/ifs/Makefile new file +1 -0
new file mode 100644
index 000000000000..12c2f5ce9925
@@ -0,0 +1 @@
+obj-$(CONFIG_INTEL_IFS_DEVICE)	+= intel_ifs_device.o
drivers/platform/x86/intel/ifs/intel_ifs_device.c new file +38 -0
new file mode 100644
index 000000000000..64a143871d72
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2022 Intel Corporation. */
+
+#include <linux/platform_device.h>
+#include <linux/init.h>
+#include <asm/cpu_device_id.h>
+
+#define MSR_IA32_CORE_CAPS_INTEGRITY_BIT	2
+#define MSR_IA32_CORE_CAPS_INTEGRITY		BIT(MSR_IA32_CORE_CAPS_INTEGRITY_BIT)
+
+#define X86_MATCH(model)					\
+	X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6,		\
+		INTEL_FAM6_##model, X86_FEATURE_CORE_CAPABILITIES, NULL)
+
+static const struct x86_cpu_id ifs_cpu_ids[] __initconst = {
+	X86_MATCH(SAPPHIRERAPIDS_X),
+	{}
+};
+
+static __init int register_ifs_device(void)
+{
+	struct platform_device *pdev;
+	const struct x86_cpu_id *m;
+	u64 ia32_core_caps;
+
+	m = x86_match_cpu(ifs_cpu_ids);
+	if (!m)
+		return -ENODEV;
+
+	if (rdmsrl_safe(MSR_IA32_CORE_CAPS, &ia32_core_caps))
+		return -ENODEV;
+
+	if (ia32_core_caps & MSR_IA32_CORE_CAPS_INTEGRITY) {
+		pdev = platform_device_alloc("intel_ifs", 0);
+		if (pdev) {
+			if (platform_device_add(pdev))
+				platform_device_put(pdev);
+		}

drivers/platform/x86/intel/ifs/intel_ifs_device.c line 48

Quoted 10 lines
drivers/platform/x86/intel/ifs/intel_ifs_device.c new file +10 -0
+	}
+
+	/*
+	 * Failure here will be visible by a missing device
+	 * in sysfs. Returning an error code would not make
+	 * that any easier to diagnose. Would also complicate
+	 * future implementations that may support a subset of
+	 * the types of tests.
+	 */
+	return 0;

So even if everything fails, you succeed? But you are failing above for some cases, so why is creating the device somehow special here that you should succeed no matter what?

thanks,

greg k-h

#25 lore raw

Re: [PATCH v3 03/11] platform/x86/intel/ifs: Create device for Intel IFS (In Field Scan)

Quoted 6 lines · Greg KH
Quoted 4 lines · Tony Luck

The initial implementation of IFS is model specific. Enumeration is via a combination of family-model-stepping and a check for a bit in the CORE_CAPABILITIES MSR.

Quoted 7 lines
Quoted 3 lines

Linux has handled this lack of enumeration before with a code stub to create a device. See arch/x86/kernel/pmem.c. Use the same approach here.

Ick, why? Why not just create a simple virtual device and use that? Do you really want to bind a driver to this? Or do you already "know" the only driver that you have will bind to this?

With the realization that there may be multiple instances of an IFS-like capability going forward, and that ideally those capabilities would move away from a CPU capability bit to an ACPI description, then it seemed to me that a simulated platform_device for this is a reasonable fit. I.e. when / if an ACPI _HID is assigned for this capability the same platform_driver can be reused for those instances.

Quoted 1 line

pmem.c should not be used as a good example of anything, sorry.

Yes, the arch/x86/kernel/pmem.c hack was supplanted by an ACPI device description. There is no ACPI device description for the IFS capability, yet.

So I saw these two cases as similar, that capabilities like this need enumeration besides a CPU-id bit or an E820 table entry, and when they move to an enumerable bus like ACPI a platform_driver is expected.

Quoted 126 lines

greg k-h

Quoted 122 lines
---
 MAINTAINERS                                   |  7 +++
 drivers/platform/x86/intel/Kconfig            |  1 +
 drivers/platform/x86/intel/Makefile           |  1 +
 drivers/platform/x86/intel/ifs/Kconfig        |  2 +
 drivers/platform/x86/intel/ifs/Makefile       |  1 +
 .../platform/x86/intel/ifs/intel_ifs_device.c | 50 +++++++++++++++++++
 6 files changed, 62 insertions(+)
 create mode 100644 drivers/platform/x86/intel/ifs/Kconfig
 create mode 100644 drivers/platform/x86/intel/ifs/Makefile
 create mode 100644 drivers/platform/x86/intel/ifs/intel_ifs_device.c
MAINTAINERS +7 -0
index 40fa1955ca3f..9e372a960fa5 100644
@@ -9861,6 +9861,13 @@ B:     https://bugzilla.kernel.org
 T:   git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git
 F:   drivers/idle/intel_idle.c
 
+INTEL IN FIELD SCAN (IFS) DRIVER
+M:   Jithu Joseph <[email protected]>
+R:   Ashok Raj <[email protected]>
+R:   Tony Luck <[email protected]>
+S:   Maintained
+F:   drivers/platform/x86/intel/ifs
+
 INTEL INTEGRATED SENSOR HUB DRIVER
 M:   Srinivas Pandruvada <[email protected]>
 M:   Jiri Kosina <[email protected]>
drivers/platform/x86/intel/Kconfig +1 -0
index 1f01a8a23c57..794968bda115 100644
@@ -4,6 +4,7 @@
 #
 
 source "drivers/platform/x86/intel/atomisp2/Kconfig"
+source "drivers/platform/x86/intel/ifs/Kconfig"
 source "drivers/platform/x86/intel/int1092/Kconfig"
 source "drivers/platform/x86/intel/int3472/Kconfig"
 source "drivers/platform/x86/intel/pmc/Kconfig"
drivers/platform/x86/intel/Makefile +1 -0
index c61bc3e97121..10285d0fd16a 100644
@@ -5,6 +5,7 @@
 #
 
 obj-$(CONFIG_INTEL_ATOMISP2_PDX86)   += atomisp2/
+obj-y                                        += ifs/
 obj-$(CONFIG_INTEL_SAR_INT1092)              += int1092/
 obj-$(CONFIG_INTEL_SKL_INT3472)              += int3472/
 obj-$(CONFIG_INTEL_PMC_CORE)         += pmc/
drivers/platform/x86/intel/ifs/Kconfig new file +2 -0
new file mode 100644
index 000000000000..51325b699563
@@ -0,0 +1,2 @@
+config INTEL_IFS_DEVICE
+     bool
drivers/platform/x86/intel/ifs/Makefile new file +1 -0
new file mode 100644
index 000000000000..12c2f5ce9925
@@ -0,0 +1 @@
+obj-$(CONFIG_INTEL_IFS_DEVICE)       += intel_ifs_device.o
drivers/platform/x86/intel/ifs/intel_ifs_device.c new file +44 -0
new file mode 100644
index 000000000000..64a143871d72
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2022 Intel Corporation. */
+
+#include <linux/platform_device.h>
+#include <linux/init.h>
+#include <asm/cpu_device_id.h>
+
+#define MSR_IA32_CORE_CAPS_INTEGRITY_BIT     2
+#define MSR_IA32_CORE_CAPS_INTEGRITY         BIT(MSR_IA32_CORE_CAPS_INTEGRITY_BIT)
+
+#define X86_MATCH(model)                                     \
+     X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6,            \
+             INTEL_FAM6_##model, X86_FEATURE_CORE_CAPABILITIES, NULL)
+
+static const struct x86_cpu_id ifs_cpu_ids[] __initconst = {
+     X86_MATCH(SAPPHIRERAPIDS_X),
+     {}
+};
+
+static __init int register_ifs_device(void)
+{
+     struct platform_device *pdev;
+     const struct x86_cpu_id *m;
+     u64 ia32_core_caps;
+
+     m = x86_match_cpu(ifs_cpu_ids);
+     if (!m)
+             return -ENODEV;
+
+     if (rdmsrl_safe(MSR_IA32_CORE_CAPS, &ia32_core_caps))
+             return -ENODEV;
+
+     if (ia32_core_caps & MSR_IA32_CORE_CAPS_INTEGRITY) {
+             pdev = platform_device_alloc("intel_ifs", 0);
+             if (pdev) {
+                     if (platform_device_add(pdev))
+                             platform_device_put(pdev);
+             }
+     }
+
+     /*
+      * Failure here will be visible by a missing device
+      * in sysfs. Returning an error code would not make
+      * that any easier to diagnose. Would also complicate
Quoted 8 lines

drivers/platform/x86/intel/ifs/intel_ifs_device.c line 48

Quoted 4 lines
drivers/platform/x86/intel/ifs/intel_ifs_device.c new file +4 -0
+      * future implementations that may support a subset of
+      * the types of tests.
+      */
+     return 0;

So even if everything fails, you succeed? But you are failing above for some cases, so why is creating the device somehow special here that you should succeed no matter what?

My bad, this failure is not fatal to init and test execution tooling will notice the missing device, but yes this can just return the initcall error to be logged.

#26 lore raw

Re: [PATCH v3 03/11] platform/x86/intel/ifs: Create device for Intel IFS (In Field Scan)

Quoted 16 lines · Dan Williams
Quoted 6 lines · Greg KH
Quoted 4 lines · Tony Luck

The initial implementation of IFS is model specific. Enumeration is via a combination of family-model-stepping and a check for a bit in the CORE_CAPABILITIES MSR.

Quoted 7 lines
Quoted 3 lines

Linux has handled this lack of enumeration before with a code stub to create a device. See arch/x86/kernel/pmem.c. Use the same approach here.

Ick, why? Why not just create a simple virtual device and use that? Do you really want to bind a driver to this? Or do you already "know" the only driver that you have will bind to this?

Quoted 6 lines

With the realization that there may be multiple instances of an IFS-like capability going forward, and that ideally those capabilities would move away from a CPU capability bit to an ACPI description, then it seemed to me that a simulated platform_device for this is a reasonable fit. I.e. when / if an ACPI _HID is assigned for this capability the same platform_driver can be reused for those instances.

Turns out the ACPI enumeration for this may not materialize, so this can indeed move to a simple / driver-less device.

#27 lore raw

Re: [PATCH v3 03/11] platform/x86/intel/ifs: Create device for Intel IFS (In Field Scan)

Quoted 24 lines · Dan Williams
Quoted 16 lines · Dan Williams
Quoted 6 lines · Greg KH
Quoted 4 lines · Tony Luck

The initial implementation of IFS is model specific. Enumeration is via a combination of family-model-stepping and a check for a bit in the CORE_CAPABILITIES MSR.

Quoted 7 lines
Quoted 3 lines

Linux has handled this lack of enumeration before with a code stub to create a device. See arch/x86/kernel/pmem.c. Use the same approach here.

Ick, why? Why not just create a simple virtual device and use that? Do you really want to bind a driver to this? Or do you already "know" the only driver that you have will bind to this?

Quoted 6 lines

With the realization that there may be multiple instances of an IFS-like capability going forward, and that ideally those capabilities would move away from a CPU capability bit to an ACPI description, then it seemed to me that a simulated platform_device for this is a reasonable fit. I.e. when / if an ACPI _HID is assigned for this capability the same platform_driver can be reused for those instances.

Quoted 2 lines

Turns out the ACPI enumeration for this may not materialize, so this can indeed move to a simple / driver-less device.

Hey, see, doing extra work now was not a good idea :)

#28 lore raw

Re: [PATCH v3 03/11] platform/x86/intel/ifs: Create device for Intel IFS (In Field Scan)

In reply to Dan Williams
Quoted 15 lines · Dan Williams
Quoted 6 lines · Greg KH
Quoted 4 lines · Tony Luck

The initial implementation of IFS is model specific. Enumeration is via a combination of family-model-stepping and a check for a bit in the CORE_CAPABILITIES MSR.

Quoted 7 lines
Quoted 3 lines

Linux has handled this lack of enumeration before with a code stub to create a device. See arch/x86/kernel/pmem.c. Use the same approach here.

Ick, why? Why not just create a simple virtual device and use that? Do you really want to bind a driver to this? Or do you already "know" the only driver that you have will bind to this?

Quoted 6 lines

With the realization that there may be multiple instances of an IFS-like capability going forward, and that ideally those capabilities would move away from a CPU capability bit to an ACPI description, then it seemed to me that a simulated platform_device for this is a reasonable fit. I.e. when / if an ACPI _HID is assigned for this capability the same platform_driver can be reused for those instances.

Don't write code today for stuff you do not have right now, you all know that. We can always revisit it in the future.

thanks,

greg k-h

maintainer
#29 lore raw

Re: [PATCH v3 03/11] platform/x86/intel/ifs: Create device for Intel IFS (In Field Scan)

Quoted 2 lines · Greg KH

Don't write code today for stuff you do not have right now, you all know that. We can always revisit it in the future.

Direction check on the virtual device option. Is this what you are asking for in "core.c"?

The second test type is happening internally right away ... so I put in some example code of how it can be added. Upstream submission will just have the one test that exists today.

Static definition of:

static struct ifs_data ifs_data[IFS_NUMTESTS];

keeps the code simpler (no need to have code to cleanup if dynamic allocation of this small structure fails). But if you feel strongly that all static allocation is bad, then I can kzallloc() per enumerated test type.

With this change it is no longer a platform driver. So maybe doesn't belong in drivers/platform/x86/intel/ifs/*

Any thoughts on where I should move it to?

-Tony

---- core.c ---

// SPDX-License-Identifier: GPL-2.0-only
/* Copyright(c) 2022 Intel Corporation. */

#include <linux/module.h>
#include <linux/device.h>
#include <linux/kdev_t.h>
#include <linux/semaphore.h>

#include <asm/cpu_device_id.h>

#include "ifs.h"

enum test_types {
IFS_SAF,
IFS_ANOTHER,
IFS_NUMTESTS
};

static struct class *ifs_class;
static struct ifs_data ifs_data[IFS_NUMTESTS];

#define MSR_IA32_CORE_CAPS_INTEGRITY_BIT 2
#define MSR_IA32_CORE_CAPS_INTEGRITY BIT(MSR_IA32_CORE_CAPS_INTEGRITY_BIT)

#define X86_MATCH(model)				\
	X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6,	\
		INTEL_FAM6_##model, X86_FEATURE_CORE_CAPABILITIES, NULL)
static const struct x86_cpu_id ifs_cpu_ids[] __initconst = {
	X86_MATCH(SAPPHIRERAPIDS_X),
	{}
};

MODULE_DEVICE_TABLE(x86cpu, ifs_cpu_ids);

static int ifs_device_unregister(struct device *dev, void *data)

{
	device_unregister(dev);

	return 0;
}

static int __init ifs_init(void)

{
	const struct x86_cpu_id *m;
	u64 ia32_core_caps;
	struct device *dev;
	int ndevices = 0;
	int ret = 0;

	m = x86_match_cpu(ifs_cpu_ids);
	if (!m)
		return -ENODEV;

	if (rdmsrl_safe(MSR_IA32_CORE_CAPS, &ia32_core_caps))
		return -ENODEV;

	ifs_class = class_create(THIS_MODULE, "intel_ifs");
	if (IS_ERR(ifs_class))
		return PTR_ERR(ifs_class);

	ret = ifs_setup_wq();
	if (ret)
		goto class_cleanup;

	if (ia32_core_caps & MSR_IA32_CORE_CAPS_INTEGRITY) {
		dev = device_create_with_groups(ifs_class, NULL, MKDEV(0, 0), &ifs_data[IFS_SAF],
					        plat_ifs_groups, "ifs%d", IFS_SAF);
		if (dev) {
			ndevices++;

			down(&ifs_sem);
			ifs_data[IFS_SAF].loaded = !ifs_load_firmware(dev);
			up(&ifs_sem);
		}
	}

	if (1) { // placeholder to test 2nd test
		dev = device_create_with_groups(ifs_class, NULL, MKDEV(0, 0), &ifs_data[IFS_ANOTHER],
					        plat_ifs_groups, "ifs%d", IFS_ANOTHER);
		if (dev)
			ndevices++;
	}

	if (ndevices)
		goto done;

	ret = -ENODEV;

	class_for_each_device(ifs_class, NULL, NULL, ifs_device_unregister);

class_cleanup:

	class_destroy(ifs_class);
done:
	return ret;
}

static void __exit ifs_exit(void)

{
	class_for_each_device(ifs_class, NULL, NULL, ifs_device_unregister);
	class_destroy(ifs_class);
	ifs_destroy_wq();
}

module_init(ifs_init);
module_exit(ifs_exit);

MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Intel In Field Scan (IFS) driver");

#30 lore raw

Re: [PATCH v3 03/11] platform/x86/intel/ifs: Create device for Intel IFS (In Field Scan)

Quoted 71 lines · Tony
Quoted 2 lines · Greg KH

Don't write code today for stuff you do not have right now, you all know that. We can always revisit it in the future.

Direction check on the virtual device option. Is this what you are asking for in "core.c"?

The second test type is happening internally right away ... so I put in some example code of how it can be added. Upstream submission will just have the one test that exists today.

Static definition of:

static struct ifs_data ifs_data[IFS_NUMTESTS];

keeps the code simpler (no need to have code to cleanup if dynamic allocation of this small structure fails). But if you feel strongly that all static allocation is bad, then I can kzallloc() per enumerated test type.

With this change it is no longer a platform driver. So maybe doesn't belong in drivers/platform/x86/intel/ifs/*

Any thoughts on where I should move it to?

-Tony

---- core.c ---

// SPDX-License-Identifier: GPL-2.0-only
/* Copyright(c) 2022 Intel Corporation. */

#include <linux/module.h>
#include <linux/device.h>
#include <linux/kdev_t.h>
#include <linux/semaphore.h>

#include <asm/cpu_device_id.h>

#include "ifs.h"

enum test_types {
IFS_SAF,
IFS_ANOTHER,
IFS_NUMTESTS
};

static struct class *ifs_class;
static struct ifs_data ifs_data[IFS_NUMTESTS];

#define MSR_IA32_CORE_CAPS_INTEGRITY_BIT 2
#define MSR_IA32_CORE_CAPS_INTEGRITY BIT(MSR_IA32_CORE_CAPS_INTEGRITY_BIT)

#define X86_MATCH(model)				\
	X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6,	\
		INTEL_FAM6_##model, X86_FEATURE_CORE_CAPABILITIES, NULL)
static const struct x86_cpu_id ifs_cpu_ids[] __initconst = {
	X86_MATCH(SAPPHIRERAPIDS_X),
	{}
};

MODULE_DEVICE_TABLE(x86cpu, ifs_cpu_ids);

static int ifs_device_unregister(struct device *dev, void *data)

{
	device_unregister(dev);

	return 0;
}

static int __init ifs_init(void)

Quoted 15 lines
{
	const struct x86_cpu_id *m;
	u64 ia32_core_caps;
	struct device *dev;
	int ndevices = 0;
	int ret = 0;

	m = x86_match_cpu(ifs_cpu_ids);
	if (!m)
		return -ENODEV;

	if (rdmsrl_safe(MSR_IA32_CORE_CAPS, &ia32_core_caps))
		return -ENODEV;

	ifs_class = class_create(THIS_MODULE, "intel_ifs");

Why do you need a class? Why not just use a misc device? Saves you loads of boilerplate code that is sometimes tricky to get correct.

thanks,

greg k-h

maintainer
#31 lore raw

RE: [PATCH v3 03/11] platform/x86/intel/ifs: Create device for Intel IFS (In Field Scan)

Quoted 4 lines
Quoted 1 line
	ifs_class = class_create(THIS_MODULE, "intel_ifs");

Why do you need a class? Why not just use a misc device? Saves you loads of boilerplate code that is sometimes tricky to get correct.

It didn't feel like a "ton" of boiler plate. Just class_create()/class_destroy() for the class itself. And

	class_for_each_device(ifs_class, NULL, NULL, ifs_device_unregister);

to clean up devices on exit (or error cleanup in init()).

I thought I needed a class to make a directory for my per-test directories to live in:

$ ls -l /sys/devices/virtual/intel_ifs
total 0
drwxr-xr-x 3 root root 0 Apr 20 13:36 ifs0
drwxr-xr-x 3 root root 0 Apr 20 13:36 ifs1

Can I do that with a misc device?

Or is it ok for them all to sit at the top level of /sys/devices/virtual?

-Tony

#32 lore raw

Re: [PATCH v3 03/11] platform/x86/intel/ifs: Create device for Intel IFS (In Field Scan)

Quoted 15 lines · Tony
Quoted 4 lines
Quoted 1 line
	ifs_class = class_create(THIS_MODULE, "intel_ifs");

Why do you need a class? Why not just use a misc device? Saves you loads of boilerplate code that is sometimes tricky to get correct.

It didn't feel like a "ton" of boiler plate. Just class_create()/class_destroy() for the class itself. And

	class_for_each_device(ifs_class, NULL, NULL, ifs_device_unregister);

to clean up devices on exit (or error cleanup in init()).

I thought I needed a class to make a directory for my per-test directories to live in:

Quoted 8 lines
$ ls -l /sys/devices/virtual/intel_ifs
total 0
drwxr-xr-x 3 root root 0 Apr 20 13:36 ifs0
drwxr-xr-x 3 root root 0 Apr 20 13:36 ifs1

Can I do that with a misc device?

Or is it ok for them all to sit at the top level of /sys/devices/virtual?

How many do you have?

And why is a directory needed for just one tiny driver type?

thanks,

greg k-h

maintainer
#33 lore raw

RE: [PATCH v3 03/11] platform/x86/intel/ifs: Create device for Intel IFS (In Field Scan)

Quoted 5 lines
Quoted 1 line

Or is it ok for them all to sit at the top level of /sys/devices/virtual?

How many do you have?

And why is a directory needed for just one tiny driver type?

One today. Two tomorrow (internally ... next gen CPU).

Three eventually (That's how many are on the roadmap that I can see).

-Tony

#34 lore raw

Re: [PATCH v3 03/11] platform/x86/intel/ifs: Create device for Intel IFS (In Field Scan)

Quoted 9 lines · Tony
Quoted 5 lines
Quoted 1 line

Or is it ok for them all to sit at the top level of /sys/devices/virtual?

How many do you have?

And why is a directory needed for just one tiny driver type?

One today. Two tomorrow (internally ... next gen CPU).

Three eventually (That's how many are on the roadmap that I can see).

Then just use a misc device, it's simple and saves you a ton of code.

maintainer
#35 lore raw

PATCH v3 4/11 platform/x86/intel/ifs: Add stub driver for In-Field Scan

In reply to Tony Luck

Cloud Service Providers that operate fleets of servers have reported
[1] occasions where they can detect that a CPU has gone bad due to effects like electromigration, or isolated manufacturing defects. However, that detection method is A/B testing seemingly random application failures looking for a pattern. In-Field Scan (IFS) is a driver for a platform capability to load a crafted 'scan image' to run targeted low level diagnostics outside of the CPU's architectural error detection capabilities.

[1]: https://www.youtube.com/watch?v=QMF3rqhjYuM

Kconfig for this driver selects CONFIG_INTEL_IFS_DEVICE so the base kernel will be built with code to create the device to which this driver will attach.

---
Not using module_platform_driver() for this simple stub because later patches need to add init()/exit() functions.

---
 drivers/platform/x86/intel/ifs/Kconfig  | 14 ++++++++++++
 drivers/platform/x86/intel/ifs/Makefile |  4 ++++
 drivers/platform/x86/intel/ifs/core.c   | 29 +++++++++++++++++++++++++
 3 files changed, 47 insertions(+)
 create mode 100644 drivers/platform/x86/intel/ifs/core.c
drivers/platform/x86/intel/ifs/Kconfig +14 -0
index 51325b699563..0aa5ecc5ef42 100644
@@ -1,2 +1,16 @@
 config INTEL_IFS_DEVICE
 	bool
+
+config INTEL_IFS
+	tristate "Intel In Field Scan"
+	depends on X86 && 64BIT && SMP
+	select INTEL_IFS_DEVICE
+	help
+	  Enable support for the In Field Scan capability in select
+	  CPUs. The capability allows for running low level tests via
+	  a scan image distributed by Intel via Github to validate CPU
+	  operation beyond baseline RAS capabilities. To compile this
+	  driver as a module, choose M here. The module will be called
+	  intel_ifs.
+
+	  If unsure, say N.
drivers/platform/x86/intel/ifs/Makefile +4 -0
index 12c2f5ce9925..bf8adc57892c 100644
@@ -1 +1,5 @@
 obj-$(CONFIG_INTEL_IFS_DEVICE)	+= intel_ifs_device.o
+
+obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
+
+intel_ifs-objs			:= core.o
drivers/platform/x86/intel/ifs/core.c new file +29 -0
new file mode 100644
index 000000000000..eb34b877dac0
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright(c) 2022 Intel Corporation. */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+static struct platform_driver intel_ifs_driver = {
+	.driver = {
+		.name = "intel_ifs",
+	},
+};
+
+static int __init ifs_init(void)
+{
+	return platform_driver_register(&intel_ifs_driver);
+}
+
+static void __exit ifs_exit(void)
+{
+	platform_driver_unregister(&intel_ifs_driver);
+}
+
+module_init(ifs_init);
+module_exit(ifs_exit);
+
+MODULE_ALIAS("platform:intel_ifs*");
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Intel In Field Scan (IFS) driver");
Signature · 1 line
2.35.1
maintainer
#36 lore raw

PATCH v3 5/11 platform/x86/intel/ifs: Read IFS firmware image

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

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.

---
 drivers/platform/x86/intel/ifs/Makefile |  2 +-
 drivers/platform/x86/intel/ifs/core.c   | 23 ++++++++++++++++++
 drivers/platform/x86/intel/ifs/ifs.h    | 19 +++++++++++++++
 drivers/platform/x86/intel/ifs/load.c   | 31 +++++++++++++++++++++++++
 4 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/ifs.h
 create mode 100644 drivers/platform/x86/intel/ifs/load.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index bf8adc57892c..eab0cc81f38e 100644
@@ -2,4 +2,4 @@ obj-$(CONFIG_INTEL_IFS_DEVICE)	+= intel_ifs_device.o
 
 obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
 
-intel_ifs-objs			:= core.o
+intel_ifs-objs			:= core.o load.o
drivers/platform/x86/intel/ifs/core.c +23 -0
index eb34b877dac0..139449f11a64 100644
@@ -4,7 +4,30 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 
+#include "ifs.h"
+
+static int ifs_probe(struct platform_device *pdev)
+{
+	struct ifs_data *ifsd;
+
+	ifsd = devm_kzalloc(&pdev->dev, sizeof(*ifsd), GFP_KERNEL);
+	if (!ifsd)
+		return -ENOMEM;
+
+	dev_set_drvdata(&pdev->dev, ifsd);
+
+	switch (pdev->id) {
+	case 0:
+		/* Load IFS binary to BIOS reserved memory area */
+		ifsd->loaded = !load_ifs_binary(&pdev->dev);
+		break;
+	}
+
+	return 0;
+}
+
 static struct platform_driver intel_ifs_driver = {
+	.probe = ifs_probe,
 	.driver = {
 		.name = "intel_ifs",
 	},
drivers/platform/x86/intel/ifs/ifs.h new file +19 -0
new file mode 100644
index 000000000000..dacc8b6ce159
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2022 Intel Corporation. */
+
+#ifndef _IFS_H_
+#define _IFS_H_
+
+/**
+ * struct ifs_data - attributes related to intel IFS driver
+ * @loaded_version: stores the currently loaded ifs image version.
+ * @loaded: If a valid test binary has been loaded into the memory
+ */
+struct ifs_data {
+	int loaded_version;
+	bool loaded;
+};
+
+int load_ifs_binary(struct device *dev);
+
+#endif
drivers/platform/x86/intel/ifs/load.c new file +31 -0
new file mode 100644
index 000000000000..fa6c64707a73
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright(c) 2022 Intel Corporation. */
+
+#include <linux/firmware.h>
+#include <linux/platform_device.h>
+
+static const char *ifs_path = "intel/ifs/";
+
+/*
+ * 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}.
+ */
+int load_ifs_binary(struct device *dev)
+{
+	const struct firmware *fw;
+	char scan_path[256];
+	int ret;
+
+	snprintf(scan_path, sizeof(scan_path), "%s%02x-%02x-%02x.scan", ifs_path,
+		 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 ret;
+	}
+
+	release_firmware(fw);
+
+	return ret;
+}
Signature · 1 line
2.35.1
#37 lore raw

Re: [PATCH v3 05/11] platform/x86/intel/ifs: Read IFS firmware image

drivers/platform/x86/intel/ifs/load.c line 13

Quoted 5 lines · Tony Luck
drivers/platform/x86/intel/ifs/load.c new file +5 -0
+/*
+ * 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}.
+ */
+int load_ifs_binary(struct device *dev)

Shouldn't all of your global symbols start with "ifs_"? Your other ones seem to, what went wrong here?

Also, how about "ifs_load_firmware()" makes more sense.

thanks,

greg "naming is hard" k-h

maintainer
#38 lore raw

PATCH v3 6/11 platform/x86/intel/ifs: Check IFS Image sanity

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

IFS image is designed specifically for a given family, model and stepping of the processor. Like Intel microcode header, the IFS image has the Processor Signature, Checksum and Processor Flags that must be matched with the information returned by the CPUID.

---
 drivers/platform/x86/intel/ifs/load.c | 69 +++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
drivers/platform/x86/intel/ifs/load.c +69 -0
index fa6c64707a73..b05d9055c391 100644
@@ -3,9 +3,73 @@
 
 #include <linux/firmware.h>
 #include <linux/platform_device.h>
+#include <asm/cpu.h>
+#include <asm/microcode_intel.h>
 
 static const char *ifs_path = "intel/ifs/";
 
+static int ifs_sanity_check(struct device *dev, void *mc)
+{
+	struct microcode_header_intel *mc_header = mc;
+	unsigned long total_size, data_size;
+	u32 sum, i;
+
+	total_size = get_totalsize(mc_header);
+	data_size = get_datasize(mc_header);
+
+	if ((data_size + MC_HEADER_SIZE > total_size) || (total_size % sizeof(u32))) {
+		dev_err(dev, "bad ifs data file size.\n");
+		return -EINVAL;
+	}
+
+	if (mc_header->ldrver != 1 || mc_header->hdrver != 1) {
+		dev_err(dev, "invalid/unknown ifs update format.\n");
+		return -EINVAL;
+	}
+
+	sum = 0;
+	i = total_size / sizeof(u32);
+	while (i--)
+		sum += ((u32 *)mc)[i];
+
+	if (sum) {
+		dev_err(dev, "bad ifs data checksum, aborting.\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static bool find_ifs_matching_signature(struct device *dev, struct ucode_cpu_info *uci, void *mc)
+{
+	struct microcode_header_intel *shdr;
+	unsigned int mc_size;
+
+	shdr = (struct microcode_header_intel *)mc;
+	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, void *data)
+{
+	struct ucode_cpu_info uci;
+
+	intel_cpu_collect_info_early(&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}.
@@ -25,6 +89,11 @@ int load_ifs_binary(struct device *dev)
 		return ret;
 	}
 
+	if (!ifs_image_sanity_check(dev, (void *)fw->data)) {
+		dev_err(dev, "ifs header sanity check failed\n");
+		ret = -ENOENT;
+	}
+
 	release_firmware(fw);
 
 	return ret;
Signature · 1 line
2.35.1
#39 lore raw

Re: [PATCH v3 06/11] platform/x86/intel/ifs: Check IFS Image sanity

Quoted 72 lines · Tony Luck

From: Jithu Joseph <[email protected]>

IFS image is designed specifically for a given family, model and stepping of the processor. Like Intel microcode header, the IFS image has the Processor Signature, Checksum and Processor Flags that must be matched with the information returned by the CPUID.

---
 drivers/platform/x86/intel/ifs/load.c | 69 +++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
drivers/platform/x86/intel/ifs/load.c +46 -0
index fa6c64707a73..b05d9055c391 100644
@@ -3,9 +3,73 @@
 
 #include <linux/firmware.h>
 #include <linux/platform_device.h>
+#include <asm/cpu.h>
+#include <asm/microcode_intel.h>
 
 static const char *ifs_path = "intel/ifs/";
 
+static int ifs_sanity_check(struct device *dev, void *mc)
+{
+	struct microcode_header_intel *mc_header = mc;
+	unsigned long total_size, data_size;
+	u32 sum, i;
+
+	total_size = get_totalsize(mc_header);
+	data_size = get_datasize(mc_header);
+
+	if ((data_size + MC_HEADER_SIZE > total_size) || (total_size % sizeof(u32))) {
+		dev_err(dev, "bad ifs data file size.\n");
+		return -EINVAL;
+	}
+
+	if (mc_header->ldrver != 1 || mc_header->hdrver != 1) {
+		dev_err(dev, "invalid/unknown ifs update format.\n");
+		return -EINVAL;
+	}
+
+	sum = 0;
+	i = total_size / sizeof(u32);
+	while (i--)
+		sum += ((u32 *)mc)[i];
+
+	if (sum) {
+		dev_err(dev, "bad ifs data checksum, aborting.\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static bool find_ifs_matching_signature(struct device *dev, struct ucode_cpu_info *uci, void *mc)
+{
+	struct microcode_header_intel *shdr;
+	unsigned int mc_size;
+
+	shdr = (struct microcode_header_intel *)mc;
+	mc_size = get_totalsize(shdr);
+
+	if (!mc_size || ifs_sanity_check(dev, shdr) < 0) {
+		dev_err(dev, "ifs sanity check failure\n");
+		return false;
+	}

drivers/platform/x86/intel/ifs/load.c line 64

Quoted 10 lines
drivers/platform/x86/intel/ifs/load.c +10 -0
+
+	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, void *data)

u8 *data?

Quoted 12 lines
drivers/platform/x86/intel/ifs/load.c +8 -0
+{
+	struct ucode_cpu_info uci;
+
+	intel_cpu_collect_info_early(&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}.

drivers/platform/x86/intel/ifs/load.c int load_ifs_binary(struct device *dev) · line 92

Quoted 4 lines
drivers/platform/x86/intel/ifs/load.c +1 -0
@@ -25,6 +89,11 @@ int load_ifs_binary(struct device *dev)
 		return ret;
 	}
 
+	if (!ifs_image_sanity_check(dev, (void *)fw->data)) {

It's not a void pointer, it's a pointer to u8. Why cast it away?

thanks,

greg k-h

maintainer
#40 lore raw

PATCH v3 7/11 platform/x86/intel/ifs: Authenticate and copy to secured memory

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

The IFS image contains hashes that will be used to authenticate the ifs test chunks. First, use WRMSR to copy the hashes and enumerate the number of test chunks, chunk size and the maximum number of cores that can run scan test simultaneously.

Next, use WRMSR to authenticate each and every scan test chunk which is also stored in the IFS image. The CPU will check if the test chunks match the hashes, otherwise failure is indicated to system software. If the test chunk is authenticated, it is automatically copied to secured memory.

The ifs hash copy and authentication only needs to be done on the first logical cpu of each socket.

---
 drivers/platform/x86/intel/ifs/ifs.h  |  33 ++++++
 drivers/platform/x86/intel/ifs/load.c | 165 ++++++++++++++++++++++++++
 2 files changed, 198 insertions(+)
drivers/platform/x86/intel/ifs/ifs.h +33 -0
index dacc8b6ce159..c51e285fc7ba 100644
@@ -4,14 +4,47 @@
 #ifndef _IFS_H_
 #define _IFS_H_
 
+#define MSR_COPY_SCAN_HASHES			0x000002c2
+#define MSR_SCAN_HASHES_STATUS			0x000002c3
+#define MSR_AUTHENTICATE_AND_COPY_CHUNK		0x000002c4
+#define MSR_CHUNKS_AUTHENTICATION_STATUS	0x000002c5
+
+/* MSR_SCAN_HASHES_STATUS bit fields */
+union ifs_scan_hashes_status {
+	u64	data;
+	struct {
+		u32	chunk_size	:16;
+		u32	num_chunks	:8;
+		u32	rsvd1		:8;
+		u32	error_code	:8;
+		u32	rsvd2		:11;
+		u32	max_core_limit	:12;
+		u32	valid		:1;
+	};
+};
+
+/* MSR_CHUNKS_AUTH_STATUS bit fields */
+union ifs_chunks_auth_status {
+	u64	data;
+	struct {
+		u32	valid_chunks	:8;
+		u32	total_chunks	:8;
+		u32	rsvd1		:16;
+		u32	error_code	:8;
+		u32	rsvd2		:24;
+	};
+};
+
 /**
  * struct ifs_data - attributes related to intel IFS driver
  * @loaded_version: stores the currently loaded ifs image version.
  * @loaded: If a valid test binary has been loaded into the memory
+ * @valid_chunks: number of chunks which could be validated.
  */
 struct ifs_data {
 	int loaded_version;
 	bool loaded;
+	int valid_chunks;
 };
 
 int load_ifs_binary(struct device *dev);
drivers/platform/x86/intel/ifs/load.c +165 -0

183 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#41 lore raw

PATCH v3 8/11 platform/x86/intel/ifs: Add scan test support

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

In a core, the scan engine is shared between sibling cpus.

When a Scan test (for a particular core) is triggered by the user, worker threads for each sibling cpus(belonging to that core) are queued to execute the scan test function in the Workqueue context.

All the siblings rendezvous before the test execution. The scan results are same for all siblings.

Scan may be aborted by some reasons. Scan test will be aborted in certain circumstances such as when interrupt occurred or cpu does not have enough power budget for scan. In this case, the kernel restart scan from the chunk where it stopped. Scan will also be aborted when the test is failed. In this case, the test is immediately stopped without retry.

---
 drivers/platform/x86/intel/ifs/Makefile  |   2 +-
 drivers/platform/x86/intel/ifs/core.c    |  15 +-
 drivers/platform/x86/intel/ifs/ifs.h     |  48 ++++
 drivers/platform/x86/intel/ifs/runtest.c | 321 +++++++++++++++++++++++
 4 files changed, 384 insertions(+), 2 deletions(-)
 create mode 100644 drivers/platform/x86/intel/ifs/runtest.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index eab0cc81f38e..7de27361b479 100644
@@ -2,4 +2,4 @@ obj-$(CONFIG_INTEL_IFS_DEVICE)	+= intel_ifs_device.o
 
 obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
 
-intel_ifs-objs			:= core.o load.o
+intel_ifs-objs			:= core.o load.o runtest.o
drivers/platform/x86/intel/ifs/core.c +14 -1
index 139449f11a64..0dc4cdda35ff 100644
@@ -35,11 +35,24 @@ static struct platform_driver intel_ifs_driver = {
 
 static int __init ifs_init(void)
 {
-	return platform_driver_register(&intel_ifs_driver);
+	int ret;
+
+	ret = platform_driver_register(&intel_ifs_driver);
+	if (ret)
+		return ret;
+
+	ret = ifs_setup_wq();
+	if (ret) {
+		platform_driver_unregister(&intel_ifs_driver);
+		return ret;
+	}
+
+	return 0;
 }
 
 static void __exit ifs_exit(void)
 {
+	ifs_destroy_wq();
 	platform_driver_unregister(&intel_ifs_driver);
 }
 
drivers/platform/x86/intel/ifs/ifs.h +48 -0

72 lines not on this page · raw message

drivers/platform/x86/intel/ifs/runtest.c new file +321 -0

321 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#42 lore raw

PATCH v3 9/11 platform/x86/intel/ifs: Add IFS sysfs interface

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

Implement sysfs interface to trigger ifs test for a specific cpu. Additional interfaces related to checking the status of the scan test and seeing the version of the loaded IFS binary are also added.

The basic usage is as below.
- To start test, for example on cpu5:
echo 5 > /sys/devices/platform/intel_ifs/run_test
- To see the status of the last test
cat /sys/devices/platform/intel_ifs/status
- To see the version of the loaded scan binary cat /sys/devices/platform/intel_ifs/image_version

---
 drivers/platform/x86/intel/ifs/Makefile  |   2 +-
 drivers/platform/x86/intel/ifs/core.c    |   9 ++
 drivers/platform/x86/intel/ifs/ifs.h     |   3 +
 drivers/platform/x86/intel/ifs/runtest.c |   7 ++
 drivers/platform/x86/intel/ifs/sysfs.c   | 151 +++++++++++++++++++++++
 5 files changed, 171 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/sysfs.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index 7de27361b479..dbbe0bf66987 100644
@@ -2,4 +2,4 @@ obj-$(CONFIG_INTEL_IFS_DEVICE)	+= intel_ifs_device.o
 
 obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
 
-intel_ifs-objs			:= core.o load.o runtest.o
+intel_ifs-objs			:= core.o load.o runtest.o sysfs.o
drivers/platform/x86/intel/ifs/core.c +9 -0
index 0dc4cdda35ff..f56cde0cdfd6 100644
@@ -3,6 +3,7 @@
 
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/semaphore.h>
 
 #include "ifs.h"
 
@@ -26,10 +27,18 @@ static int ifs_probe(struct platform_device *pdev)
 	return 0;
 }
 
+/*
+ * Note there is no need for a ->remove() call back. There isn't an
+ * "unload" operation to remove the scan binary from the BIOS reserved
+ * area. Also ".dev_groups" removal order will guarantee that any in
+ * flight tests have completed.
+ */
+
 static struct platform_driver intel_ifs_driver = {
 	.probe = ifs_probe,
 	.driver = {
 		.name = "intel_ifs",
+		.dev_groups = plat_ifs_groups,
 	},
 };
 
drivers/platform/x86/intel/ifs/ifs.h +3 -0
index f5e3636d709f..4e6662f2d2f8 100644
@@ -97,4 +97,7 @@ int ifs_setup_wq(void);
 void ifs_destroy_wq(void);
 int do_core_test(int cpu, struct device *dev);
 
+extern const struct attribute_group *plat_ifs_groups[];
+extern struct semaphore ifs_sem;
+
 #endif
drivers/platform/x86/intel/ifs/runtest.c +7 -0
index 7793a01f7b94..246eff250563 100644
@@ -10,6 +10,13 @@
 
 #include "ifs.h"
 
+/*
+ * Note all code and data in this file is protected by
+ * ifs_sem. On HT systems all threads on a core will
+ * execute together, but only the first thread on the
+ * core will update results of the test and indicate
+ * completion.
+ */
 static struct workqueue_struct *ifs_wq;
 static struct completion test_thread_done;
 static atomic_t siblings_in;
drivers/platform/x86/intel/ifs/sysfs.c new file +151 -0

151 lines not on this page · raw message

Signature · 1 line
2.35.1
#43 lore raw

Re: [PATCH v3 09/11] platform/x86/intel/ifs: Add IFS sysfs interface

Quoted 51 lines · Tony Luck

From: Jithu Joseph <[email protected]>

Implement sysfs interface to trigger ifs test for a specific cpu. Additional interfaces related to checking the status of the scan test and seeing the version of the loaded IFS binary are also added.

The basic usage is as below.
- To start test, for example on cpu5:
echo 5 > /sys/devices/platform/intel_ifs/run_test
- To see the status of the last test
cat /sys/devices/platform/intel_ifs/status
- To see the version of the loaded scan binary cat /sys/devices/platform/intel_ifs/image_version

---
 drivers/platform/x86/intel/ifs/Makefile  |   2 +-
 drivers/platform/x86/intel/ifs/core.c    |   9 ++
 drivers/platform/x86/intel/ifs/ifs.h     |   3 +
 drivers/platform/x86/intel/ifs/runtest.c |   7 ++
 drivers/platform/x86/intel/ifs/sysfs.c   | 151 +++++++++++++++++++++++
 5 files changed, 171 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/sysfs.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index 7de27361b479..dbbe0bf66987 100644
@@ -2,4 +2,4 @@ obj-$(CONFIG_INTEL_IFS_DEVICE)	+= intel_ifs_device.o
 
 obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
 
-intel_ifs-objs			:= core.o load.o runtest.o
+intel_ifs-objs			:= core.o load.o runtest.o sysfs.o
drivers/platform/x86/intel/ifs/core.c +1 -0
index 0dc4cdda35ff..f56cde0cdfd6 100644
@@ -3,6 +3,7 @@
 
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/semaphore.h>
 
 #include "ifs.h"
 

drivers/platform/x86/intel/ifs/core.c static int ifs_probe(struct platform_device *pdev) · line 35

Quoted 9 lines
drivers/platform/x86/intel/ifs/core.c +6 -0
@@ -26,10 +27,18 @@ static int ifs_probe(struct platform_device *pdev)
 	return 0;
 }
 
+/*
+ * Note there is no need for a ->remove() call back. There isn't an
+ * "unload" operation to remove the scan binary from the BIOS reserved
+ * area. Also ".dev_groups" removal order will guarantee that any in
+ * flight tests have completed.
+ */

So you are ok with the warning the kernel gives you when you unload the driver? That feels wrong :(

Quoted 136 lines
drivers/platform/x86/intel/ifs/core.c +2 -0
+
 static struct platform_driver intel_ifs_driver = {
 	.probe = ifs_probe,
 	.driver = {
 		.name = "intel_ifs",
+		.dev_groups = plat_ifs_groups,
 	},
 };
 
drivers/platform/x86/intel/ifs/ifs.h +3 -0
index f5e3636d709f..4e6662f2d2f8 100644
@@ -97,4 +97,7 @@ int ifs_setup_wq(void);
 void ifs_destroy_wq(void);
 int do_core_test(int cpu, struct device *dev);
 
+extern const struct attribute_group *plat_ifs_groups[];
+extern struct semaphore ifs_sem;
+
 #endif
drivers/platform/x86/intel/ifs/runtest.c +7 -0
index 7793a01f7b94..246eff250563 100644
@@ -10,6 +10,13 @@
 
 #include "ifs.h"
 
+/*
+ * Note all code and data in this file is protected by
+ * ifs_sem. On HT systems all threads on a core will
+ * execute together, but only the first thread on the
+ * core will update results of the test and indicate
+ * completion.
+ */
 static struct workqueue_struct *ifs_wq;
 static struct completion test_thread_done;
 static atomic_t siblings_in;
drivers/platform/x86/intel/ifs/sysfs.c new file +91 -0
new file mode 100644
index 000000000000..41db2a12fbc8
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright(c) 2022 Intel Corporation. */
+
+#include <linux/cpu.h>
+#include <linux/delay.h>
+#include <linux/fs.h>
+#include <linux/platform_device.h>
+#include <linux/semaphore.h>
+#include <linux/slab.h>
+
+#include "ifs.h"
+
+/*
+ * Protects against simultaneous tests on multiple cores, or
+ * reloading can file while a test is in progress
+ */
+DEFINE_SEMAPHORE(ifs_sem);
+
+/*
+ * The sysfs interface to check additional details of last test
+ * cat /sys/devices/system/platform/ifs/details
+ */
+static ssize_t details_show(struct device *dev,
+			    struct device_attribute *attr,
+			    char *buf)
+{
+	struct ifs_data *ifsd = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%#llx\n", ifsd->scan_details);
+}
+
+static DEVICE_ATTR_RO(details);
+
+static const char * const status_msg[] = {
+	[SCAN_NOT_TESTED] = "untested",
+	[SCAN_TEST_PASS] = "pass",
+	[SCAN_TEST_FAIL] = "fail"
+};
+
+/*
+ * The sysfs interface to check the test status:
+ * To check the status of last test
+ * cat /sys/devices/platform/ifs/status
+ */
+static ssize_t status_show(struct device *dev,
+			   struct device_attribute *attr,
+			   char *buf)
+{
+	struct ifs_data *ifsd = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%s\n", status_msg[ifsd->status]);
+}
+
+static DEVICE_ATTR_RO(status);
+
+/*
+ * The sysfs interface for single core testing
+ * To start test, for example, cpu5
+ * echo 5 > /sys/devices/platform/ifs/run_test
+ * To check the result:
+ * cat /sys/devices/platform/ifs/result
+ * The sibling core gets tested at the same time.
+ */
+static ssize_t run_test_store(struct device *dev,
+			      struct device_attribute *attr,
+			      const char *buf, size_t count)
+{
+	struct ifs_data *ifsd = dev_get_drvdata(dev);
+	unsigned int cpu;
+	int rc;
+
+	rc = kstrtouint(buf, 0, &cpu);
+	if (rc < 0 || cpu >= nr_cpu_ids)
+		return -EINVAL;
+
+	if (down_interruptible(&ifs_sem))
+		return -EINTR;
+
+	if (!ifsd->loaded)
+		rc = -EPERM;
+	else
+		rc = do_core_test(cpu, dev);
+
+	up(&ifs_sem);
+
+	return rc ? rc : count;
+}
+
+static DEVICE_ATTR_WO(run_test);
+
+/*

drivers/platform/x86/intel/ifs/sysfs.c line 101

Quoted 10 lines
drivers/platform/x86/intel/ifs/sysfs.c new file +10 -0
+ * Reload the IFS image. When user wants to install new IFS image
+ */
+static ssize_t reload_store(struct device *dev,
+			    struct device_attribute *attr,
+			    const char *buf, size_t count)
+{
+	struct ifs_data *ifsd = dev_get_drvdata(dev);
+	int rc;
+
+	if (!sysfs_streq(buf, "1"))

kstrtobool()?

Quoted 40 lines
drivers/platform/x86/intel/ifs/sysfs.c new file +40 -0
+		return -EINVAL;
+
+	if (down_interruptible(&ifs_sem))
+		return -EINTR;
+
+	rc = load_ifs_binary(dev);
+
+	ifsd->loaded = (rc == 0);
+
+	up(&ifs_sem);
+
+	return rc ? rc : count;
+}
+
+static DEVICE_ATTR_WO(reload);
+
+/*
+ * Display currently loaded IFS image version.
+ */
+static ssize_t image_version_show(struct device *dev,
+				  struct device_attribute *attr, char *buf)
+{
+	struct ifs_data *ifsd = dev_get_drvdata(dev);
+
+	if (!ifsd->loaded)
+		return sysfs_emit(buf, "%s\n", "none");
+	else
+		return sysfs_emit(buf, "%#x\n", ifsd->loaded_version);
+}
+
+static DEVICE_ATTR_RO(image_version);
+
+/* global scan sysfs attributes */
+static struct attribute *plat_ifs_attrs[] = {
+	&dev_attr_details.attr,
+	&dev_attr_status.attr,
+	&dev_attr_run_test.attr,
+	&dev_attr_reload.attr,
+	&dev_attr_image_version.attr,
+	NULL

drivers/platform/x86/intel/ifs/sysfs.c line 151

Quoted 10 lines
drivers/platform/x86/intel/ifs/sysfs.c new file +10 -0
+};
+
+static const struct attribute_group plat_ifs_attr_group = {
+	.attrs = plat_ifs_attrs,
+};
+
+const struct attribute_group *plat_ifs_groups[] = {
+	&plat_ifs_attr_group,
+	NULL
+};

ATTRIBUTE_GROUPS()?

thanks,

greg k-h

maintainer
#44 lore raw

Re: [PATCH v3 09/11] platform/x86/intel/ifs: Add IFS sysfs interface

Quoted 9 lines · Greg KH
Quoted 6 lines

+/*
+ * Note there is no need for a ->remove() call back. There isn't an
+ * "unload" operation to remove the scan binary from the BIOS reserved
+ * area. Also ".dev_groups" removal order will guarantee that any in
+ * flight tests have completed.
+ */

So you are ok with the warning the kernel gives you when you unload the driver? That feels wrong :(

What warning?

# dmesg | tail -5
[   38.084165] virbr0: port 1(virbr0-nic) entered listening state
[   38.149621] virbr0: port 1(virbr0-nic) entered disabled state
[   38.582054] broken atomic modeset userspace detected, disabling atomic
[   43.703321] igc 0000:01:00.0 enp1s0: NIC Link is Up 2500 Mbps Full Duplex, Flow Control: RX
[   43.703470] IPv6: ADDRCONF(NETDEV_CHANGE): enp1s0: link becomes ready
# modprobe intel_ifs
# ls /sys/devices/platform/intel_ifs.0/
details  driver_override  modalias  reload    status     uevent
driver   image_version    power     run_test  subsystem
# rmmod intel_ifs
# dmesg | tail -5
[   38.084165] virbr0: port 1(virbr0-nic) entered listening state
[   38.149621] virbr0: port 1(virbr0-nic) entered disabled state
[   38.582054] broken atomic modeset userspace detected, disabling atomic
[   43.703321] igc 0000:01:00.0 enp1s0: NIC Link is Up 2500 Mbps Full Duplex, Flow Control: RX
[   43.703470] IPv6: ADDRCONF(NETDEV_CHANGE): enp1s0: link becomes ready
#

-Tony

#45 lore raw

Re: [PATCH v3 09/11] platform/x86/intel/ifs: Add IFS sysfs interface

Quoted 23 lines · Tony
Quoted 9 lines · Greg KH
Quoted 6 lines

+/*
+ * Note there is no need for a ->remove() call back. There isn't an
+ * "unload" operation to remove the scan binary from the BIOS reserved
+ * area. Also ".dev_groups" removal order will guarantee that any in
+ * flight tests have completed.
+ */

So you are ok with the warning the kernel gives you when you unload the driver? That feels wrong :(

What warning?

# dmesg | tail -5
[   38.084165] virbr0: port 1(virbr0-nic) entered listening state
[   38.149621] virbr0: port 1(virbr0-nic) entered disabled state
[   38.582054] broken atomic modeset userspace detected, disabling atomic
[   43.703321] igc 0000:01:00.0 enp1s0: NIC Link is Up 2500 Mbps Full Duplex, Flow Control: RX
[   43.703470] IPv6: ADDRCONF(NETDEV_CHANGE): enp1s0: link becomes ready
# modprobe intel_ifs
# ls /sys/devices/platform/intel_ifs.0/
details  driver_override  modalias  reload    status     uevent
driver   image_version    power     run_test  subsystem
Quoted 8 lines
# rmmod intel_ifs
# dmesg | tail -5
[   38.084165] virbr0: port 1(virbr0-nic) entered listening state
[   38.149621] virbr0: port 1(virbr0-nic) entered disabled state
[   38.582054] broken atomic modeset userspace detected, disabling atomic
[   43.703321] igc 0000:01:00.0 enp1s0: NIC Link is Up 2500 Mbps Full Duplex, Flow Control: RX
[   43.703470] IPv6: ADDRCONF(NETDEV_CHANGE): enp1s0: link becomes ready
#

If there's no warning when the device goes away, why the crazy comment trying to justify the lack of a remove callback?

confused,

greg k-h

#46 lore raw

Re: [PATCH v3 09/11] platform/x86/intel/ifs: Add IFS sysfs interface

Quoted 34 lines · Greg KH
Quoted 23 lines · Tony
Quoted 9 lines · Greg KH
Quoted 6 lines

+/*
+ * Note there is no need for a ->remove() call back. There isn't an
+ * "unload" operation to remove the scan binary from the BIOS reserved
+ * area. Also ".dev_groups" removal order will guarantee that any in
+ * flight tests have completed.
+ */

So you are ok with the warning the kernel gives you when you unload the driver? That feels wrong :(

What warning?

# dmesg | tail -5
[   38.084165] virbr0: port 1(virbr0-nic) entered listening state
[   38.149621] virbr0: port 1(virbr0-nic) entered disabled state
[   38.582054] broken atomic modeset userspace detected, disabling atomic
[   43.703321] igc 0000:01:00.0 enp1s0: NIC Link is Up 2500 Mbps Full Duplex, Flow Control: RX
[   43.703470] IPv6: ADDRCONF(NETDEV_CHANGE): enp1s0: link becomes ready
# modprobe intel_ifs
# ls /sys/devices/platform/intel_ifs.0/
details  driver_override  modalias  reload    status     uevent
driver   image_version    power     run_test  subsystem
Quoted 8 lines
# rmmod intel_ifs
# dmesg | tail -5
[   38.084165] virbr0: port 1(virbr0-nic) entered listening state
[   38.149621] virbr0: port 1(virbr0-nic) entered disabled state
[   38.582054] broken atomic modeset userspace detected, disabling atomic
[   43.703321] igc 0000:01:00.0 enp1s0: NIC Link is Up 2500 Mbps Full Duplex, Flow Control: RX
[   43.703470] IPv6: ADDRCONF(NETDEV_CHANGE): enp1s0: link becomes ready
#
Quoted 2 lines

If there's no warning when the device goes away, why the crazy comment trying to justify the lack of a remove callback?

The comment clarifies the nuance that driver.dev_groups coordinates flushing access sysfs ops users before ->remove() is called. It can certainly be dropped.

#47 lore raw

Re: [PATCH v3 09/11] platform/x86/intel/ifs: Add IFS sysfs interface

In reply to Greg KH
Quoted 206 lines · Greg KH
Quoted 51 lines · Tony Luck

From: Jithu Joseph <[email protected]>

Implement sysfs interface to trigger ifs test for a specific cpu. Additional interfaces related to checking the status of the scan test and seeing the version of the loaded IFS binary are also added.

The basic usage is as below.
- To start test, for example on cpu5:
echo 5 > /sys/devices/platform/intel_ifs/run_test
- To see the status of the last test
cat /sys/devices/platform/intel_ifs/status
- To see the version of the loaded scan binary cat /sys/devices/platform/intel_ifs/image_version

---
 drivers/platform/x86/intel/ifs/Makefile  |   2 +-
 drivers/platform/x86/intel/ifs/core.c    |   9 ++
 drivers/platform/x86/intel/ifs/ifs.h     |   3 +
 drivers/platform/x86/intel/ifs/runtest.c |   7 ++
 drivers/platform/x86/intel/ifs/sysfs.c   | 151 +++++++++++++++++++++++
 5 files changed, 171 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/sysfs.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index 7de27361b479..dbbe0bf66987 100644
@@ -2,4 +2,4 @@ obj-$(CONFIG_INTEL_IFS_DEVICE)        += intel_ifs_device.o
 
 obj-$(CONFIG_INTEL_IFS)              += intel_ifs.o
 
-intel_ifs-objs                       := core.o load.o runtest.o
+intel_ifs-objs                       := core.o load.o runtest.o sysfs.o
drivers/platform/x86/intel/ifs/core.c +1 -0
index 0dc4cdda35ff..f56cde0cdfd6 100644
@@ -3,6 +3,7 @@
 
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/semaphore.h>
 
 #include "ifs.h"
 

drivers/platform/x86/intel/ifs/core.c static int ifs_probe(struct platform_device *pdev) · line 35

Quoted 9 lines
drivers/platform/x86/intel/ifs/core.c +6 -0
@@ -26,10 +27,18 @@ static int ifs_probe(struct platform_device *pdev)
      return 0;
 }
 
+/*
+ * Note there is no need for a ->remove() call back. There isn't an
+ * "unload" operation to remove the scan binary from the BIOS reserved
+ * area. Also ".dev_groups" removal order will guarantee that any in
+ * flight tests have completed.
+ */

So you are ok with the warning the kernel gives you when you unload the driver? That feels wrong :(

Quoted 140 lines
drivers/platform/x86/intel/ifs/core.c +2 -0
+
 static struct platform_driver intel_ifs_driver = {
      .probe = ifs_probe,
      .driver = {
              .name = "intel_ifs",
+             .dev_groups = plat_ifs_groups,
      },
 };
 
drivers/platform/x86/intel/ifs/ifs.h +3 -0
index f5e3636d709f..4e6662f2d2f8 100644
@@ -97,4 +97,7 @@ int ifs_setup_wq(void);
 void ifs_destroy_wq(void);
 int do_core_test(int cpu, struct device *dev);
 
+extern const struct attribute_group *plat_ifs_groups[];
+extern struct semaphore ifs_sem;
+
 #endif
drivers/platform/x86/intel/ifs/runtest.c +7 -0
index 7793a01f7b94..246eff250563 100644
@@ -10,6 +10,13 @@
 
 #include "ifs.h"
 
+/*
+ * Note all code and data in this file is protected by
+ * ifs_sem. On HT systems all threads on a core will
+ * execute together, but only the first thread on the
+ * core will update results of the test and indicate
+ * completion.
+ */
 static struct workqueue_struct *ifs_wq;
 static struct completion test_thread_done;
 static atomic_t siblings_in;
drivers/platform/x86/intel/ifs/sysfs.c new file +95 -0
new file mode 100644
index 000000000000..41db2a12fbc8
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright(c) 2022 Intel Corporation. */
+
+#include <linux/cpu.h>
+#include <linux/delay.h>
+#include <linux/fs.h>
+#include <linux/platform_device.h>
+#include <linux/semaphore.h>
+#include <linux/slab.h>
+
+#include "ifs.h"
+
+/*
+ * Protects against simultaneous tests on multiple cores, or
+ * reloading can file while a test is in progress
+ */
+DEFINE_SEMAPHORE(ifs_sem);
+
+/*
+ * The sysfs interface to check additional details of last test
+ * cat /sys/devices/system/platform/ifs/details
+ */
+static ssize_t details_show(struct device *dev,
+                         struct device_attribute *attr,
+                         char *buf)
+{
+     struct ifs_data *ifsd = dev_get_drvdata(dev);
+
+     return sysfs_emit(buf, "%#llx\n", ifsd->scan_details);
+}
+
+static DEVICE_ATTR_RO(details);
+
+static const char * const status_msg[] = {
+     [SCAN_NOT_TESTED] = "untested",
+     [SCAN_TEST_PASS] = "pass",
+     [SCAN_TEST_FAIL] = "fail"
+};
+
+/*
+ * The sysfs interface to check the test status:
+ * To check the status of last test
+ * cat /sys/devices/platform/ifs/status
+ */
+static ssize_t status_show(struct device *dev,
+                        struct device_attribute *attr,
+                        char *buf)
+{
+     struct ifs_data *ifsd = dev_get_drvdata(dev);
+
+     return sysfs_emit(buf, "%s\n", status_msg[ifsd->status]);
+}
+
+static DEVICE_ATTR_RO(status);
+
+/*
+ * The sysfs interface for single core testing
+ * To start test, for example, cpu5
+ * echo 5 > /sys/devices/platform/ifs/run_test
+ * To check the result:
+ * cat /sys/devices/platform/ifs/result
+ * The sibling core gets tested at the same time.
+ */
+static ssize_t run_test_store(struct device *dev,
+                           struct device_attribute *attr,
+                           const char *buf, size_t count)
+{
+     struct ifs_data *ifsd = dev_get_drvdata(dev);
+     unsigned int cpu;
+     int rc;
+
+     rc = kstrtouint(buf, 0, &cpu);
+     if (rc < 0 || cpu >= nr_cpu_ids)
+             return -EINVAL;
+
+     if (down_interruptible(&ifs_sem))
+             return -EINTR;
+
+     if (!ifsd->loaded)
+             rc = -EPERM;
+     else
+             rc = do_core_test(cpu, dev);
+
+     up(&ifs_sem);
+
+     return rc ? rc : count;
+}
+
+static DEVICE_ATTR_WO(run_test);
+
+/*
+ * Reload the IFS image. When user wants to install new IFS image
+ */
+static ssize_t reload_store(struct device *dev,
+                         struct device_attribute *attr,
Quoted 8 lines

drivers/platform/x86/intel/ifs/sysfs.c line 101

Quoted 6 lines
drivers/platform/x86/intel/ifs/sysfs.c new file +6 -0
+                         const char *buf, size_t count)
+{
+     struct ifs_data *ifsd = dev_get_drvdata(dev);
+     int rc;
+
+     if (!sysfs_streq(buf, "1"))

kstrtobool()?

I had asked them to drop kstrtobool() to save a line or 2, because this is a write-only attribute where "1" is the only valid value. Otherwise, no worries from me about supporting the other 'true' values.

Quoted 45 lines
Quoted 45 lines
drivers/platform/x86/intel/ifs/sysfs.c new file +44 -0
+             return -EINVAL;
+
+     if (down_interruptible(&ifs_sem))
+             return -EINTR;
+
+     rc = load_ifs_binary(dev);
+
+     ifsd->loaded = (rc == 0);
+
+     up(&ifs_sem);
+
+     return rc ? rc : count;
+}
+
+static DEVICE_ATTR_WO(reload);
+
+/*
+ * Display currently loaded IFS image version.
+ */
+static ssize_t image_version_show(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+     struct ifs_data *ifsd = dev_get_drvdata(dev);
+
+     if (!ifsd->loaded)
+             return sysfs_emit(buf, "%s\n", "none");
+     else
+             return sysfs_emit(buf, "%#x\n", ifsd->loaded_version);
+}
+
+static DEVICE_ATTR_RO(image_version);
+
+/* global scan sysfs attributes */
+static struct attribute *plat_ifs_attrs[] = {
+     &dev_attr_details.attr,
+     &dev_attr_status.attr,
+     &dev_attr_run_test.attr,
+     &dev_attr_reload.attr,
+     &dev_attr_image_version.attr,
+     NULL
+};
+
+static const struct attribute_group plat_ifs_attr_group = {
+     .attrs = plat_ifs_attrs,
Quoted 8 lines

drivers/platform/x86/intel/ifs/sysfs.c line 151

Quoted 6 lines
drivers/platform/x86/intel/ifs/sysfs.c new file +6 -0
+};
+
+const struct attribute_group *plat_ifs_groups[] = {
+     &plat_ifs_attr_group,
+     NULL
+};

ATTRIBUTE_GROUPS()?

Yeah, I should have caught that.

maintainer
#48 lore raw

PATCH v3 10/11 trace: platform/x86/intel/ifs: Add trace point to track Intel IFS operations

In reply to Tony Luck

Add tracing support which may be useful for debugging systems that fail to complete In Field Scan tests.

---
 MAINTAINERS                              |  1 +
 drivers/platform/x86/intel/ifs/runtest.c |  5 ++++
 include/trace/events/intel_ifs.h         | 38 ++++++++++++++++++++++++
 3 files changed, 44 insertions(+)
 create mode 100644 include/trace/events/intel_ifs.h
MAINTAINERS +1 -0
index 9e372a960fa5..b488ff628a43 100644
@@ -9867,6 +9867,7 @@ R:	Ashok Raj <[email protected]>
 R:	Tony Luck <[email protected]>
 S:	Maintained
 F:	drivers/platform/x86/intel/ifs
+F:	include/trace/events/intel_ifs.h
 
 INTEL INTEGRATED SENSOR HUB DRIVER
 M:	Srinivas Pandruvada <[email protected]>
drivers/platform/x86/intel/ifs/runtest.c +5 -0
index 246eff250563..c6fa9385dda0 100644
@@ -24,6 +24,9 @@ static atomic_t siblings_out;
 static int cpu_sibl_ct;
 static bool scan_enabled = true;
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/intel_ifs.h>
+
 struct ifs_work {
 	struct work_struct w;
 	struct device *dev;
@@ -217,6 +220,8 @@ static void ifs_work_func(struct work_struct *work)
 
 		rdmsrl(MSR_SCAN_STATUS, status.data);
 
+		trace_ifs_status(activate, status);
+
 		/* Some cases can be retried, give up for others */
 		if (!can_restart(status))
 			break;
include/trace/events/intel_ifs.h new file +38 -0
new file mode 100644
index 000000000000..0611f370cb37
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM intel_ifs
+
+#if !defined(_TRACE_IFS_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_IFS_H
+
+#include <linux/ktime.h>
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(ifs_status,
+
+	TP_PROTO(union ifs_scan activate, union ifs_status status),
+
+	TP_ARGS(activate, status),
+
+	TP_STRUCT__entry(
+		__field(	u64,	status	)
+		__field(	u8,	start	)
+		__field(	u8,	stop	)
+	),
+
+	TP_fast_assign(
+		__entry->start	= activate.start;
+		__entry->stop	= activate.stop;
+		__entry->status	= status.data;
+	),
+
+	TP_printk("start: %.2x, stop: %.2x, status: %llx",
+		__entry->start,
+		__entry->stop,
+		__entry->status)
+);
+
+#endif /* _TRACE_IFS_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
Signature · 1 line
2.35.1
maintainer
#49 lore raw

Re: [PATCH v3 10/11] trace: platform/x86/intel/ifs: Add trace point to track Intel IFS operations

include/trace/events/intel_ifs.h line 13

Quoted 3 lines · On Tue, 19 Apr 2022 09:38:58 -0700 Tony Luck <[email protected]> wrote:
include/trace/events/intel_ifs.h new file +3 -0
+TRACE_EVENT(ifs_status,
+
+	TP_PROTO(union ifs_scan activate, union ifs_status status),

Really, you want to pass the structure in by value, so that we have two copies? One to get to this function and then one to write to the ring buffer?

-- Steve

Quoted 22 lines
include/trace/events/intel_ifs.h new file +22 -0
+
+	TP_ARGS(activate, status),
+
+	TP_STRUCT__entry(
+		__field(	u64,	status	)
+		__field(	u8,	start	)
+		__field(	u8,	stop	)
+	),
+
+	TP_fast_assign(
+		__entry->start	= activate.start;
+		__entry->stop	= activate.stop;
+		__entry->status	= status.data;
+	),
+
+	TP_printk("start: %.2x, stop: %.2x, status: %llx",
+		__entry->start,
+		__entry->stop,
+		__entry->status)
+);
+
+#endif /* _TRACE_IFS_H */
maintainer
#50 lore raw

RE: [PATCH v3 10/11] trace: platform/x86/intel/ifs: Add trace point to track Intel IFS operations

Quoted 7 lines

include/trace/events/intel_ifs.h line 13

Quoted 3 lines
include/trace/events/intel_ifs.h new file +3 -0
+TRACE_EVENT(ifs_status,
+
+	TP_PROTO(union ifs_scan activate, union ifs_status status),

Really, you want to pass the structure in by value, so that we have two copies? One to get to this function and then one to write to the ring buffer?

These "structures" are just bitfield helpers for a u64 that is passed into WRMSR (in the case of activate) and received back from RDMSR in the case of status.

So this is really just a pair of u64 arguments, with the compiler handling the bit field extractions into the ring buffer.

Here are the definitions:

union ifs_scan {
        u64     data;
        struct {
                u32     start   :8;
                u32     stop    :8;
                u32     rsvd    :16;
                u32     delay   :31;
                u32     sigmce  :1;
        };
};
union ifs_status {
        u64     data;
        struct {
                u32     chunk_num               :8;
                u32     chunk_stop_index        :8;
                u32     rsvd1                   :16;
                u32     error_code              :8;
                u32     rsvd2                   :22;
                u32     control_error           :1;
                u32     signature_error         :1;
        };
};

Would it be better to do the bit extractions of the start/stop fields first?

-Tony

maintainer
#51 lore raw

Re: [PATCH v3 10/11] trace: platform/x86/intel/ifs: Add trace point to track Intel IFS operations

Quoted 8 lines · Tony
Quoted 7 lines

include/trace/events/intel_ifs.h line 13

Quoted 3 lines
include/trace/events/intel_ifs.h new file +3 -0
+TRACE_EVENT(ifs_status,
+
+	TP_PROTO(union ifs_scan activate, union ifs_status status),  

Really, you want to pass the structure in by value, so that we have two copies? One to get to this function and then one to write to the ring buffer?

Quoted 6 lines

These "structures" are just bitfield helpers for a u64 that is passed into WRMSR (in the case of activate) and received back from RDMSR in the case of status.

So this is really just a pair of u64 arguments, with the compiler handling the bit field extractions into the ring buffer.

I was just wondering if passing by reference would be better, but as you stated, they are just two u64 arguments.

Quoted 27 lines

Here are the definitions:

union ifs_scan {
        u64     data;
        struct {
                u32     start   :8;
                u32     stop    :8;
                u32     rsvd    :16;
                u32     delay   :31;
                u32     sigmce  :1;
        };
};
union ifs_status {
        u64     data;
        struct {
                u32     chunk_num               :8;
                u32     chunk_stop_index        :8;
                u32     rsvd1                   :16;
                u32     error_code              :8;
                u32     rsvd2                   :22;
                u32     control_error           :1;
                u32     signature_error         :1;
        };
};
Quoted 1 line

Would it be better to do the bit extractions of the start/stop fields first?

No, I'm just paranoid about passing structures / unions in by value and not reference. If you are fine with this, then I'm OK too.

-- Steve

maintainer
#52 lore raw

PATCH v3 11/11 platform/x86/intel/ifs: add ABI documentation for IFS

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

Add the sysfs attributes in ABI/testing for In-Field Scan.

---
 .../ABI/testing/sysfs-platform-intel-ifs      | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-ifs
Documentation/ABI/testing/sysfs-platform-intel-ifs new file +39 -0
new file mode 100644
index 000000000000..7a753c9f2dd7
@@ -0,0 +1,39 @@
+What:		/sys/devices/platform/intel_ifs.<N>/run_test
+Date:		April 13, 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Write <cpu#> to trigger IFS test for one online core.
+		Note that the test is per core. The cpu# can be
+		for any thread on the core. Running on one thread
+		completes the test for the core containing that thread.
+		Example: to test the core containing cpu5: echo 5 >
+		/sys/devices/platform/intel_ifs.<N>/run_test
+
+What:		/sys/devices/platform/intel_ifs.<N>/status
+Date:		April 13, 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	The status of the last test. It can be one of "pass", "fail"
+		or "untested".
+
+What:		/sys/devices/system/cpu/cpu#/ifs.<N>/details
+Date:		April 13, 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Additional information regarding the last test. The details file reports
+		the hex value of the SCAN_STATUS MSR. Note that the error_code field
+		may contain driver defined software code not defined in the Intel SDM.
+
+What:		/sys/devices/platform/intel_ifs.<N>/image_version
+Date:		April 13, 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Version (hexadecimal) of loaded IFS binary image. If no scan image
+		is loaded reports "none".
+
+What:		/sys/bus/platform/drivers/intel_ifs.<N>/reload
+Date:		April 13, 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Write "1" > reload to reload IFS image from
+		/lib/firmware/intel/ifs/ff-mm-ss.scan.
Signature · 1 line
2.35.1
maintainer
#53 lore raw

v4 cover Introduce In Field Scan driver

In reply to Tony Luck

TL;DR this driver loads scan test files that can check whether silicon in a CPU core is still running correctly. It is expected that these tests would be run several times per day to catch problems as silicon ages.

Changes since v3:

Thomas Gleixner:
----------------
1) intel_collect_cpu_info_early() ... function name doesn't make sense in context of this driver

True: Dropped the "_early" suffix from the name.

Greg Kroah-Hartman:
-------------------
1) "Ick, why?" and "pmem.c should not be used as a good example of anything" and "Why not just use a misc device?"

Now using a misc device.

2) "So even if everything fails, you succeed?"

This was w.r.t. the "pmem"-like driver, which is completely gone in v4. New driver succeeds if any of the test-types enumerate as present on the system. Fails with -ENODEV if no test types found.

3) "sysfs documentation belongs in Documentation/ABI/"

See patch 10 of this series.

4) "And why not just include this whole thing in the driver itself and suck the documentation out of that? No need to have a separate file."

Dropped Documentation/x86/ifs.rst from v4. People should be able to figure out how to use it from the ABI docs for the sysfs files. If that turns out to be wrong, we can revisit.

5) "int load_ifs_binary(struct device *dev)
Shouldn't all of your global symbols start with "ifs_"? Your other ones seem to, what went wrong here?
Also, how about "ifs_load_firmware()" makes more sense."

Changed name to ifs_load_firmware()

6) "static bool ifs_image_sanity_check(struct device *dev, void *data)

    u8 *data?"  and

"if (!ifs_image_sanity_check(dev, (void *)fw->data)) {
It's not a void pointer, it's a pointer to u8. Why cast it away?"

Changed the top of that call stack to cast to "(struct microcode_header_intel *) which is what the lower level functions all want.

7) "if (!sysfs_streq(buf, "1"))
kstrtobool()?

Changed from sysfs_streq() to kstrtobool()

8) "ATTRIBUTE_GROUPS()?"

Now using this macro.

Steven Rostedt:
---------------
1) "TP_PROTO(union ifs_scan activate, union ifs_status status),

Really, you want to pass the structure in by value, so that we have two copies? One to get to this function and then one to write to the ring buffer?"

Discussion on list resolved because these "pass by value" objects are just wrappers around a u64. Passing pointers wouldn't make any real difference. No code change.

Jithu Joseph (7):
x86/microcode/intel: Expose collect_cpu_info_early() for IFS platform/x86/intel/ifs: Read IFS firmware image platform/x86/intel/ifs: Check IFS Image sanity platform/x86/intel/ifs: Authenticate and copy to secured memory platform/x86/intel/ifs: Add scan test support platform/x86/intel/ifs: Add IFS sysfs interface platform/x86/intel/ifs: add ABI documentation for IFS

Tony Luck (3):
x86/msr-index: Define INTEGRITY_CAPABILITIES MSR platform/x86/intel/ifs: Add stub driver for In-Field Scan
trace: platform/x86/intel/ifs: Add trace point to track Intel IFS
operations

 .../ABI/testing/sysfs-platform-intel-ifs      |  39 ++
 MAINTAINERS                                   |   8 +
 arch/x86/include/asm/cpu.h                    |  18 +
 arch/x86/include/asm/msr-index.h              |   7 +
 arch/x86/kernel/cpu/intel.c                   |  32 ++
 arch/x86/kernel/cpu/microcode/intel.c         |  59 +---
 drivers/platform/x86/intel/Kconfig            |   1 +
 drivers/platform/x86/intel/Makefile           |   1 +
 drivers/platform/x86/intel/ifs/Kconfig        |  13 +
 drivers/platform/x86/intel/ifs/Makefile       |   3 +
 drivers/platform/x86/intel/ifs/core.c         |  97 +++++
 drivers/platform/x86/intel/ifs/ifs.h          | 123 +++++++
 drivers/platform/x86/intel/ifs/load.c         | 262 ++++++++++++++
 drivers/platform/x86/intel/ifs/runtest.c      | 332 ++++++++++++++++++
 drivers/platform/x86/intel/ifs/sysfs.c        | 147 ++++++++
 include/trace/events/intel_ifs.h              |  38 ++
 16 files changed, 1128 insertions(+), 52 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-ifs
 create mode 100644 drivers/platform/x86/intel/ifs/Kconfig
 create mode 100644 drivers/platform/x86/intel/ifs/Makefile
 create mode 100644 drivers/platform/x86/intel/ifs/core.c
 create mode 100644 drivers/platform/x86/intel/ifs/ifs.h
 create mode 100644 drivers/platform/x86/intel/ifs/load.c
 create mode 100644 drivers/platform/x86/intel/ifs/runtest.c
 create mode 100644 drivers/platform/x86/intel/ifs/sysfs.c
 create mode 100644 include/trace/events/intel_ifs.h

base-commit: b2d229d4ddb17db541098b83524d901257e93845

Signature · 1 line
2.35.1
maintainer
#54 lore raw

PATCH v4 1/10 x86/microcode/intel: Expose collect_cpu_info_early() for IFS

From: Jithu Joseph <[email protected]>

IFS is a CPU feature that allows a binary blob, similar to microcode, to be loaded and consumed to perform low level validation of CPU circuitry. In fact, it carries the same Processor Signature (family/model/stepping) details that are contained in Intel microcode blobs.

In support of an IFS driver to trigger loading, validation, and running of these tests blobs, make the functionality of cpu_signatures_match() and collect_cpu_info_early() available outside of the microcode driver.

Add an "intel_" prefix and drop the "_early" suffix from collect_cpu_info_early() and EXPORT_SYMBOL_GPL() it. Add declaration to x86 <asm/cpu.h>

Make cpu_signatures_match() an inline function in x86 <asm/cpu.h>, and also give it an "intel_" prefix.

No functional change intended.

---
 arch/x86/include/asm/cpu.h            | 18 ++++++++
 arch/x86/kernel/cpu/intel.c           | 32 +++++++++++++++
 arch/x86/kernel/cpu/microcode/intel.c | 59 ++++-----------------------
 3 files changed, 57 insertions(+), 52 deletions(-)
arch/x86/include/asm/cpu.h +18 -0
index 86e5e4e26fcb..990167357c34 100644
@@ -76,4 +76,22 @@ static inline void init_ia32_feat_ctl(struct cpuinfo_x86 *c) {}
 
 extern __noendbr void cet_disable(void);
 
+struct ucode_cpu_info;
+
+int intel_cpu_collect_info(struct ucode_cpu_info *uci);
+
+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;
+}
+
 #endif /* _ASM_X86_CPU_H */
arch/x86/kernel/cpu/intel.c +32 -0
index f7a5370a9b3b..94779146275d 100644
@@ -181,6 +181,38 @@ static bool bad_spectre_microcode(struct cpuinfo_x86 *c)
 	return false;
 }
 
+int intel_cpu_collect_info(struct ucode_cpu_info *uci)
+{
+	unsigned int val[2];
+	unsigned int family, model;
+	struct cpu_signature csig = { 0 };
+	unsigned int eax, ebx, ecx, edx;
+
+	memset(uci, 0, sizeof(*uci));
+
+	eax = 0x00000001;
+	ecx = 0;
+	native_cpuid(&eax, &ebx, &ecx, &edx);
+	csig.sig = eax;
+
+	family = x86_family(eax);
+	model  = x86_model(eax);
+
+	if (model >= 5 || family > 6) {
+		/* get processor flags from MSR 0x17 */
+		native_rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]);
+		csig.pf = 1 << ((val[1] >> 18) & 7);
+	}
+
+	csig.rev = intel_get_microcode_revision();
+
+	uci->cpu_sig = csig;
+	uci->valid = 1;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(intel_cpu_collect_info);
+
 static void early_init_intel(struct cpuinfo_x86 *c)
 {
 	u64 misc_enable;
arch/x86/kernel/cpu/microcode/intel.c +7 -52

113 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#55 lore raw

PATCH v4 2/10 x86/msr-index: Define INTEGRITY_CAPABILITIES MSR

In reply to Tony Luck

The INTEGRITY_CAPABILITIES MSR is enumerated by bit 2 of the CORE_CAPABILITIES MSR.

Add defines for the CORE_CAPS enumeration as well as for the integrity MSR.

---
 arch/x86/include/asm/msr-index.h | 7 +++++++
 1 file changed, 7 insertions(+)
arch/x86/include/asm/msr-index.h +7 -0
index ee15311b6be1..c3dc7ae32f1f 100644
@@ -76,6 +76,8 @@
 
 /* Abbreviated from Intel SDM name IA32_CORE_CAPABILITIES */
 #define MSR_IA32_CORE_CAPS			  0x000000cf
+#define MSR_IA32_CORE_CAPS_INTEGRITY_CAPS_BIT	  2
+#define MSR_IA32_CORE_CAPS_INTEGRITY_CAPS	  BIT(MSR_IA32_CORE_CAPS_INTEGRITY_CAPS_BIT)
 #define MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT_BIT  5
 #define MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT	  BIT(MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT_BIT)
 
@@ -154,6 +156,11 @@
 #define MSR_IA32_POWER_CTL		0x000001fc
 #define MSR_IA32_POWER_CTL_BIT_EE	19
 
+/* Abbreviated from Intel SDM name IA32_INTEGRITY_CAPABILITIES */
+#define MSR_INTEGRITY_CAPS			0x000002d9
+#define MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT	4
+#define MSR_INTEGRITY_CAPS_PERIODIC_BIST	BIT(MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT)
+
 #define MSR_LBR_NHM_FROM		0x00000680
 #define MSR_LBR_NHM_TO			0x000006c0
 #define MSR_LBR_CORE_FROM		0x00000040
Signature · 1 line
2.35.1
maintainer
#56 lore raw

PATCH v4 3/10 platform/x86/intel/ifs: Add stub driver for In-Field Scan

In reply to Tony Luck

Cloud Service Providers that operate fleets of servers have reported
[1] occasions where they can detect that a CPU has gone bad due to effects like electromigration, or isolated manufacturing defects. However, that detection method is A/B testing seemingly random application failures looking for a pattern. In-Field Scan (IFS) is a driver for a platform capability to load a crafted 'scan image' to run targeted low level diagnostics outside of the CPU's architectural error detection capabilities.

Stub version of driver just does initial part of check for the IFS feature. MSR_IA32_CORE_CAPS must enumerate the presence of the MSR_INTEGRITY_CAPS MSR.

[1]: https://www.youtube.com/watch?v=QMF3rqhjYuM

---
 MAINTAINERS                             |  7 ++++
 drivers/platform/x86/intel/Kconfig      |  1 +
 drivers/platform/x86/intel/Makefile     |  1 +
 drivers/platform/x86/intel/ifs/Kconfig  | 13 +++++++
 drivers/platform/x86/intel/ifs/Makefile |  3 ++
 drivers/platform/x86/intel/ifs/core.c   | 52 +++++++++++++++++++++++++
 6 files changed, 77 insertions(+)
 create mode 100644 drivers/platform/x86/intel/ifs/Kconfig
 create mode 100644 drivers/platform/x86/intel/ifs/Makefile
 create mode 100644 drivers/platform/x86/intel/ifs/core.c
MAINTAINERS +7 -0
index 40fa1955ca3f..d2ee63193ab3 100644
@@ -9861,6 +9861,13 @@ B:	https://bugzilla.kernel.org
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git
 F:	drivers/idle/intel_idle.c
 
+INTEL IN FIELD SCAN (IFS) DEVICE
+M:	Jithu Joseph <[email protected]>
+R:	Ashok Raj <[email protected]>
+R:	Tony Luck <[email protected]>
+S:	Maintained
+F:	drivers/platform/x86/intel/ifs
+
 INTEL INTEGRATED SENSOR HUB DRIVER
 M:	Srinivas Pandruvada <[email protected]>
 M:	Jiri Kosina <[email protected]>
drivers/platform/x86/intel/Kconfig +1 -0
index 1f01a8a23c57..794968bda115 100644
@@ -4,6 +4,7 @@
 #
 
 source "drivers/platform/x86/intel/atomisp2/Kconfig"
+source "drivers/platform/x86/intel/ifs/Kconfig"
 source "drivers/platform/x86/intel/int1092/Kconfig"
 source "drivers/platform/x86/intel/int3472/Kconfig"
 source "drivers/platform/x86/intel/pmc/Kconfig"
drivers/platform/x86/intel/Makefile +1 -0
index c61bc3e97121..717933dd0cfd 100644
@@ -5,6 +5,7 @@
 #
 
 obj-$(CONFIG_INTEL_ATOMISP2_PDX86)	+= atomisp2/
+obj-$(CONFIG_INTEL_IFS)			+= ifs/
 obj-$(CONFIG_INTEL_SAR_INT1092)		+= int1092/
 obj-$(CONFIG_INTEL_SKL_INT3472)		+= int3472/
 obj-$(CONFIG_INTEL_PMC_CORE)		+= pmc/
drivers/platform/x86/intel/ifs/Kconfig new file +13 -0
new file mode 100644
index 000000000000..d84491cfb0db
@@ -0,0 +1,13 @@
+config INTEL_IFS
+	tristate "Intel In Field Scan"
+	depends on X86 && 64BIT && SMP
+	select INTEL_IFS_DEVICE
+	help
+	  Enable support for the In Field Scan capability in select
+	  CPUs. The capability allows for running low level tests via
+	  a scan image distributed by Intel via Github to validate CPU
+	  operation beyond baseline RAS capabilities. To compile this
+	  support as a module, choose M here. The module will be called
+	  intel_ifs.
+
+	  If unsure, say N.
drivers/platform/x86/intel/ifs/Makefile new file +3 -0
new file mode 100644
index 000000000000..af904880e959
@@ -0,0 +1,3 @@
+obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
+
+intel_ifs-objs			:= core.o
drivers/platform/x86/intel/ifs/core.c new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#57 lore raw

PATCH v4 4/10 platform/x86/intel/ifs: Read IFS firmware image

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

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.

---
 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
drivers/platform/x86/intel/ifs/Makefile +1 -1
index af904880e959..98b6fde15689 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
 
-intel_ifs-objs			:= core.o
+intel_ifs-objs			:= core.o load.o
drivers/platform/x86/intel/ifs/core.c +35 -1
index 5713e6ee90f0..ed4ded6755b2 100644
@@ -6,6 +6,8 @@
 
 #include <asm/cpu_device_id.h>
 
+#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);
drivers/platform/x86/intel/ifs/ifs.h new file +25 -0
new file mode 100644
index 000000000000..9a0f8e2077e2
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2022 Intel Corporation. */
+
+#ifndef _IFS_H_
+#define _IFS_H_
+
+#include <linux/device.h>
+#include <linux/miscdevice.h>
+
+/**
+ * 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
drivers/platform/x86/intel/ifs/load.c new file +28 -0
new file mode 100644
index 000000000000..9fb71d38c819
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright(c) 2022 Intel Corporation. */
+
+#include <linux/firmware.h>
+
+#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);
+}
Signature · 1 line
2.35.1
#58 lore raw

Re: [PATCH v4 04/10] platform/x86/intel/ifs: Read IFS firmware image

Quoted 60 lines · Tony Luck

From: Jithu Joseph <[email protected]>

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.

---
 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
drivers/platform/x86/intel/ifs/Makefile +1 -1
index af904880e959..98b6fde15689 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
 
-intel_ifs-objs			:= core.o
+intel_ifs-objs			:= core.o load.o
drivers/platform/x86/intel/ifs/core.c +6 -0
index 5713e6ee90f0..ed4ded6755b2 100644
@@ -6,6 +6,8 @@
 
 #include <asm/cpu_device_id.h>
 
+#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,

drivers/platform/x86/intel/ifs/core.c static const struct x86_cpu_id ifs_cpu_ids[] __initconst = { · line 38

Quoted 10 lines
drivers/platform/x86/intel/ifs/core.c +10 -0
+		},
+		.misc = {
+			.name = "intel_ifs_0",
+			.nodename = "intel_ifs/0",
+			.minor = MISC_DYNAMIC_MINOR,
+		},
+	},
+};
+
+#define IFS_NUMTESTS ARRAY_SIZE(ifs_devices)

Cute way to do this, but I don't see you ever have any more devices added to this list in this series. Did I miss them?

If not, why all the overhead and complexity involved here for just a single misc device?

thanks,

greg k-h

maintainer
#59 lore raw

Re: [PATCH v4 04/10] platform/x86/intel/ifs: Read IFS firmware image

Quoted 5 lines · Greg KH
Quoted 4 lines · 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 +++++++++++++++++++

You haven't commented on the source tree location. With the change to use misc_register() this isn't a "platform" device anymore.

Should I move to "drivers/misc/"? Or is there some better spot that preseves the detail that this is an x86/intel driver in the path?

Quoted 9 lines
Quoted 9 lines
drivers/platform/x86/intel/ifs/core.c +9 -0
+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,
Quoted 8 lines

drivers/platform/x86/intel/ifs/core.c static const struct x86_cpu_id ifs_cpu_ids[] __initconst = { · line 38

Quoted 5 lines
drivers/platform/x86/intel/ifs/core.c +5 -0
+		},
+	},
+};
+
+#define IFS_NUMTESTS ARRAY_SIZE(ifs_devices)

Cute way to do this, but I don't see you ever have any more devices added to this list in this series. Did I miss them?

That's in part 11/10 ... I have hardware, so I'm pretty sure that this is a real thing. Just not ready to post until Intel announces the details of the new test type.

Quoted 2 lines

If not, why all the overhead and complexity involved here for just a single misc device?

It didn't seem like a lot of complexity here. It makes the changes to this file to add an extra test trivial (just a new name in the "enum" and a new initializer in ifs_devices[]).

Obviously some more code in load.c and runtest.c to handle the new test type.

If it really is too much now, I can rip it out from this submission and add it back when the second test is ready for public view.

-Tony

#60 lore raw

Re: [PATCH v4 04/10] platform/x86/intel/ifs: Read IFS firmware image

Quoted 7 lines · Tony
Quoted 5 lines · Greg KH
Quoted 4 lines · 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 +++++++++++++++++++
Quoted 5 lines

You haven't commented on the source tree location. With the change to use misc_register() this isn't a "platform" device anymore.

Should I move to "drivers/misc/"? Or is there some better spot that preseves the detail that this is an x86/intel driver in the path?

There's misc_register() users all over the tree, no need for it to be in drivers/misc/ at all, especially if this really is a platform device as this one is. It's fine here.

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
drivers/platform/x86/intel/ifs/core.c +9 -0
+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,
Quoted 8 lines

drivers/platform/x86/intel/ifs/core.c static const struct x86_cpu_id ifs_cpu_ids[] __initconst = { · line 38

Quoted 5 lines
drivers/platform/x86/intel/ifs/core.c +5 -0
+		},
+	},
+};
+
+#define IFS_NUMTESTS ARRAY_SIZE(ifs_devices)

Cute way to do this, but I don't see you ever have any more devices added to this list in this series. Did I miss them?

Quoted 3 lines

That's in part 11/10 ... I have hardware, so I'm pretty sure that this is a real thing. Just not ready to post until Intel announces the details of the new test type.

Let's not over-engineer for anything we can not review today please.

Quoted 7 lines
Quoted 2 lines

If not, why all the overhead and complexity involved here for just a single misc device?

It didn't seem like a lot of complexity here. It makes the changes to this file to add an extra test trivial (just a new name in the "enum" and a new initializer in ifs_devices[]).

Quoted 5 lines

Obviously some more code in load.c and runtest.c to handle the new test type.

If it really is too much now, I can rip it out from this submission and add it back when the second test is ready for public view.

Please do, thanks.

greg k-h

maintainer
#61 lore raw

Re: [PATCH v4 04/10] platform/x86/intel/ifs: Read IFS firmware image

Quoted 5 lines · Greg KH
Quoted 2 lines · Tony

If it really is too much now, I can rip it out from this submission and add it back when the second test is ready for public view.

Please do, thanks.

Hmmm ... maybe there were more bits than I thought.

 1 file changed, 19 insertions(+), 36 deletions(-)

core.c is now down to just 80 lines ... so that was a significant fraction of the file.

Net change below (I'll thread it back into the patch series before reposting).

Any other comments on the series?

-Tony

drivers/platform/x86/intel/ifs/core.c +19 -36
index 317ed3225307..489b77645b5e 100644
@@ -9,10 +9,6 @@
 
 #include "ifs.h"
 
-enum test_types {
-	IFS_SAF,
-};
-
 #define X86_MATCH(model)				\
 	X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6,	\
 		INTEL_FAM6_##model, X86_FEATURE_CORE_CAPABILITIES, NULL)
@@ -23,27 +19,21 @@ 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,
-		},
+static struct ifs_device ifs_device = {
+	.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)
@@ -61,32 +51,25 @@ static int __init ifs_init(void)
 	if (ifs_setup_wq())
 		return -ENOMEM;
 
-	for (i = 0; i < IFS_NUMTESTS; i++) {
-		if (!(msrval & BIT(ifs_devices[i].data.integrity_cap_bit)))
-			continue;
-
-		ifs_devices[i].misc.groups = ifs_get_groups();
-		if (!misc_register(&ifs_devices[i].misc)) {
-			ndevices++;
-			down(&ifs_sem);
-			ifs_load_firmware(ifs_devices[i].misc.this_device);
-			up(&ifs_sem);
-		}
-	}
+	ifs_device.misc.groups = ifs_get_groups();
 
-	if (!ndevices)
+	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);
+		up(&ifs_sem);
+	} else {
 		ifs_destroy_wq();
+		return -ENODEV;
+	}
 
-	return ndevices ? 0 : -ENODEV;
+	return 0;
 }
 
 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);
+	misc_deregister(&ifs_device.misc);
 	ifs_destroy_wq();
 }
 
Signature · 1 line
2.35.1
maintainer
#62 lore raw

PATCH v4 5/10 platform/x86/intel/ifs: Check IFS Image sanity

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

IFS image is designed specifically for a given family, model and stepping of the processor. Like Intel microcode header, the IFS image has the Processor Signature, Checksum and Processor Flags that must be matched with the information returned by the CPUID.

---
 drivers/platform/x86/intel/ifs/load.c | 68 +++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
drivers/platform/x86/intel/ifs/load.c +68 -0
index 9fb71d38c819..aece78d1c757 100644
@@ -2,9 +2,74 @@
 /* Copyright(c) 2022 Intel Corporation. */
 
 #include <linux/firmware.h>
+#include <asm/cpu.h>
+#include <asm/microcode_intel.h>
 
 #include "ifs.h"
 
+static int ifs_sanity_check(struct device *dev,
+			    const struct microcode_header_intel *mc_header)
+{
+	unsigned long total_size, data_size;
+	u32 sum, i;
+	u8 *mc;
+
+	total_size = get_totalsize(mc_header);
+	data_size = get_datasize(mc_header);
+
+	if ((data_size + MC_HEADER_SIZE > total_size) || (total_size % sizeof(u32))) {
+		dev_err(dev, "bad ifs data file size.\n");
+		return -EINVAL;
+	}
+
+	if (mc_header->ldrver != 1 || mc_header->hdrver != 1) {
+		dev_err(dev, "invalid/unknown ifs update format.\n");
+		return -EINVAL;
+	}
+
+	mc = (u8 *)mc_header;
+	sum = 0;
+	i = total_size / sizeof(u32);
+	while (i--)
+		sum += ((u32 *)mc)[i];
+
+	if (sum) {
+		dev_err(dev, "bad ifs data checksum, aborting.\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}.
@@ -24,5 +89,8 @@ void ifs_load_firmware(struct device *dev)
 		return;
 	}
 
+	if (!ifs_image_sanity_check(dev, (struct microcode_header_intel *)fw->data))
+		dev_err(dev, "ifs header sanity check failed\n");
+
 	release_firmware(fw);
 }
Signature · 1 line
2.35.1
maintainer
#63 lore raw

PATCH v4 6/10 platform/x86/intel/ifs: Authenticate and copy to secured memory

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

The IFS image contains hashes that will be used to authenticate the ifs test chunks. First, use WRMSR to copy the hashes and enumerate the number of test chunks, chunk size and the maximum number of cores that can run scan test simultaneously.

Next, use WRMSR to authenticate each and every scan test chunk which is also stored in the IFS image. The CPU will check if the test chunks match the hashes, otherwise failure is indicated to system software. If the test chunk is authenticated, it is automatically copied to secured memory.

The ifs hash copy and authentication only needs to be done on the first logical cpu of each socket.

---
 drivers/platform/x86/intel/ifs/ifs.h  |  47 +++++++
 drivers/platform/x86/intel/ifs/load.c | 170 +++++++++++++++++++++++++-
 2 files changed, 215 insertions(+), 2 deletions(-)
drivers/platform/x86/intel/ifs/ifs.h +47 -0
index 9a0f8e2077e2..a9e73346cd28 100644
@@ -7,12 +7,51 @@
 #include <linux/device.h>
 #include <linux/miscdevice.h>
 
+#define MSR_COPY_SCAN_HASHES			0x000002c2
+#define MSR_SCAN_HASHES_STATUS			0x000002c3
+#define MSR_AUTHENTICATE_AND_COPY_CHUNK		0x000002c4
+#define MSR_CHUNKS_AUTHENTICATION_STATUS	0x000002c5
+
+/* MSR_SCAN_HASHES_STATUS bit fields */
+union ifs_scan_hashes_status {
+	u64	data;
+	struct {
+		u32	chunk_size	:16;
+		u32	num_chunks	:8;
+		u32	rsvd1		:8;
+		u32	error_code	:8;
+		u32	rsvd2		:11;
+		u32	max_core_limit	:12;
+		u32	valid		:1;
+	};
+};
+
+/* MSR_CHUNKS_AUTH_STATUS bit fields */
+union ifs_chunks_auth_status {
+	u64	data;
+	struct {
+		u32	valid_chunks	:8;
+		u32	total_chunks	:8;
+		u32	rsvd1		:16;
+		u32	error_code	:8;
+		u32	rsvd2		:24;
+	};
+};
+
 /**
  * struct ifs_data - attributes related to intel IFS driver
  * @integrity_cap_bit - MSR_INTEGRITY_CAPS bit enumerating this test
+ * @loaded_version: stores the currently loaded ifs image version.
+ * @loaded: If a valid test binary has been loaded into the memory
+ * @loading_error: Error occurred on another CPU while loading image
+ * @valid_chunks: number of chunks which could be validated.
  */
 struct ifs_data {
 	int integrity_cap_bit;
+	int loaded_version;
+	bool loaded;
+	bool loading_error;
+	int valid_chunks;
 };
 
 struct ifs_device {
@@ -20,6 +59,14 @@ struct ifs_device {
 	struct miscdevice misc;
 };
 
+static inline struct ifs_data *ifs_get_data(struct device *dev)
+{
+	struct miscdevice *m = dev_get_drvdata(dev);
+	struct ifs_device *d = container_of(m, struct ifs_device, misc);
+
+	return &d->data;
+}
+
 void ifs_load_firmware(struct device *dev);
 
 #endif
drivers/platform/x86/intel/ifs/load.c +168 -2

195 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#64 lore raw

PATCH v4 7/10 platform/x86/intel/ifs: Add scan test support

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

In a core, the scan engine is shared between sibling cpus.

When a Scan test (for a particular core) is triggered by the user, worker threads for each sibling cpus(belonging to that core) are queued to execute the scan test function in the Workqueue context.

All the siblings rendezvous before the test execution. The scan results are same for all siblings.

Scan may be aborted by some reasons. Scan test will be aborted in certain circumstances such as when interrupt occurred or cpu does not have enough power budget for scan. In this case, the kernel restart scan from the chunk where it stopped. Scan will also be aborted when the test is failed. In this case, the test is immediately stopped without retry.

---
 drivers/platform/x86/intel/ifs/Makefile  |   2 +-
 drivers/platform/x86/intel/ifs/core.c    |   7 +
 drivers/platform/x86/intel/ifs/ifs.h     |  48 ++++
 drivers/platform/x86/intel/ifs/runtest.c | 327 +++++++++++++++++++++++
 4 files changed, 383 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/runtest.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index 98b6fde15689..cedcb103f860 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
 
-intel_ifs-objs			:= core.o load.o
+intel_ifs-objs			:= core.o load.o runtest.o
drivers/platform/x86/intel/ifs/core.c +7 -0
index ed4ded6755b2..fa4a6b13c1e2 100644
@@ -57,6 +57,9 @@ static int __init ifs_init(void)
 	if (rdmsrl_safe(MSR_INTEGRITY_CAPS, &msrval))
 		return -ENODEV;
 
+	if (ifs_setup_wq())
+		return -ENOMEM;
+
 	for (i = 0; i < IFS_NUMTESTS; i++) {
 		if (!(msrval & BIT(ifs_devices[i].data.integrity_cap_bit)))
 			continue;
@@ -67,6 +70,9 @@ static int __init ifs_init(void)
 		}
 	}
 
+	if (!ndevices)
+		ifs_destroy_wq();
+
 	return ndevices ? 0 : -ENODEV;
 }
 
@@ -77,6 +83,7 @@ static void __exit ifs_exit(void)
 	for (i = 0; i < IFS_NUMTESTS; i++)
 		if (ifs_devices[i].misc.this_device)
 			misc_deregister(&ifs_devices[i].misc);
+	ifs_destroy_wq();
 }
 
 module_init(ifs_init);
drivers/platform/x86/intel/ifs/ifs.h +48 -0

77 lines not on this page · raw message

drivers/platform/x86/intel/ifs/runtest.c new file +327 -0

327 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#65 lore raw

PATCH v4 8/10 platform/x86/intel/ifs: Add IFS sysfs interface

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

Implement sysfs interface to trigger ifs test for a specific cpu. Additional interfaces related to checking the status of the scan test and seeing the version of the loaded IFS binary are also added.

The basic usage is as below.
- To start test, for example on cpu5:
echo 5 > /sys/devices/platform/intel_ifs/run_test
- To see the status of the last test
cat /sys/devices/platform/intel_ifs/status
- To see the version of the loaded scan binary cat /sys/devices/platform/intel_ifs/image_version

---
 drivers/platform/x86/intel/ifs/Makefile |   2 +-
 drivers/platform/x86/intel/ifs/core.c   |   4 +
 drivers/platform/x86/intel/ifs/ifs.h    |   3 +
 drivers/platform/x86/intel/ifs/sysfs.c  | 147 ++++++++++++++++++++++++
 4 files changed, 155 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/sysfs.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index cedcb103f860..30f035ef5581 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
 
-intel_ifs-objs			:= core.o load.o runtest.o
+intel_ifs-objs			:= core.o load.o runtest.o sysfs.o
drivers/platform/x86/intel/ifs/core.c +4 -0
index fa4a6b13c1e2..317ed3225307 100644
@@ -3,6 +3,7 @@
 
 #include <linux/module.h>
 #include <linux/kdev_t.h>
+#include <linux/semaphore.h>
 
 #include <asm/cpu_device_id.h>
 
@@ -64,9 +65,12 @@ static int __init ifs_init(void)
 		if (!(msrval & BIT(ifs_devices[i].data.integrity_cap_bit)))
 			continue;
 
+		ifs_devices[i].misc.groups = ifs_get_groups();
 		if (!misc_register(&ifs_devices[i].misc)) {
 			ndevices++;
+			down(&ifs_sem);
 			ifs_load_firmware(ifs_devices[i].misc.this_device);
+			up(&ifs_sem);
 		}
 	}
 
drivers/platform/x86/intel/ifs/ifs.h +3 -0
index 1df796227ace..2ba03b21e2f8 100644
@@ -116,5 +116,8 @@ void ifs_load_firmware(struct device *dev);
 int ifs_setup_wq(void);
 void ifs_destroy_wq(void);
 int do_core_test(int cpu, struct device *dev);
+const struct attribute_group **ifs_get_groups(void);
+
+extern struct semaphore ifs_sem;
 
 #endif
drivers/platform/x86/intel/ifs/sysfs.c new file +147 -0

147 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#66 lore raw

PATCH v4 9/10 trace: platform/x86/intel/ifs: Add trace point to track Intel IFS operations

In reply to Tony Luck

Add tracing support which may be useful for debugging systems that fail to complete In Field Scan tests.

---
 MAINTAINERS                              |  1 +
 drivers/platform/x86/intel/ifs/runtest.c |  5 ++++
 include/trace/events/intel_ifs.h         | 38 ++++++++++++++++++++++++
 3 files changed, 44 insertions(+)
 create mode 100644 include/trace/events/intel_ifs.h
MAINTAINERS +1 -0
index d2ee63193ab3..abcf9b895ea8 100644
@@ -9867,6 +9867,7 @@ R:	Ashok Raj <[email protected]>
 R:	Tony Luck <[email protected]>
 S:	Maintained
 F:	drivers/platform/x86/intel/ifs
+F:	include/trace/events/intel_ifs.h
 
 INTEL INTEGRATED SENSOR HUB DRIVER
 M:	Srinivas Pandruvada <[email protected]>
drivers/platform/x86/intel/ifs/runtest.c +5 -0
index c30cc9c95b4f..d6cb5d9e44c2 100644
@@ -23,6 +23,9 @@ static atomic_t siblings_out;
 static int cpu_sibl_ct;
 static bool scan_enabled = true;
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/intel_ifs.h>
+
 struct ifs_work {
 	struct work_struct w;
 	struct device *dev;
@@ -216,6 +219,8 @@ static void ifs_work_func(struct work_struct *work)
 
 		rdmsrl(MSR_SCAN_STATUS, status.data);
 
+		trace_ifs_status(activate, status);
+
 		/* Some cases can be retried, give up for others */
 		if (!can_restart(status))
 			break;
include/trace/events/intel_ifs.h new file +38 -0
new file mode 100644
index 000000000000..0611f370cb37
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM intel_ifs
+
+#if !defined(_TRACE_IFS_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_IFS_H
+
+#include <linux/ktime.h>
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(ifs_status,
+
+	TP_PROTO(union ifs_scan activate, union ifs_status status),
+
+	TP_ARGS(activate, status),
+
+	TP_STRUCT__entry(
+		__field(	u64,	status	)
+		__field(	u8,	start	)
+		__field(	u8,	stop	)
+	),
+
+	TP_fast_assign(
+		__entry->start	= activate.start;
+		__entry->stop	= activate.stop;
+		__entry->status	= status.data;
+	),
+
+	TP_printk("start: %.2x, stop: %.2x, status: %llx",
+		__entry->start,
+		__entry->stop,
+		__entry->status)
+);
+
+#endif /* _TRACE_IFS_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
Signature · 1 line
2.35.1
maintainer Acked-by on v4 9/10
#67 lore raw

Re: [PATCH v4 09/10] trace: platform/x86/intel/ifs: Add trace point to track Intel IFS operations

Quoted 9 lines · On Fri, 22 Apr 2022 13:02:18 -0700 Tony Luck <[email protected]> wrote:

Add tracing support which may be useful for debugging systems that fail to complete In Field Scan tests.

---
 MAINTAINERS                              |  1 +
 drivers/platform/x86/intel/ifs/runtest.c |  5 ++++
 include/trace/events/intel_ifs.h         | 38 ++++++++++++++++++++++++

From the tracing POV:

-- Steve

maintainer
#68 lore raw

RE: [PATCH v4 09/10] trace: platform/x86/intel/ifs: Add trace point to track Intel IFS operations

Quoted 10 lines
Quoted 9 lines

Add tracing support which may be useful for debugging systems that fail to complete In Field Scan tests.

---
 MAINTAINERS                              |  1 +
 drivers/platform/x86/intel/ifs/runtest.c |  5 ++++
 include/trace/events/intel_ifs.h         | 38 ++++++++++++++++++++++++
Quoted 3 lines

From the tracing POV:

Question for the future of this driver. There are a couple more scan tools coming in the future. The interface is similar:

WRMSR to start a scan
RDMSR to get the results

For this first one, I made the trace code do some user friendly decoding of the WRMSR value to just show the two interesting fields (start & stop).

The future scan modes will have different fields.

I see two paths:

1) Create a new user friendly trace point for each new scan mode.
2) Just provide a generic one that dumps both the 64-bit WRMSR and RDMSR values.

Q: Are trace points "expensive" in some way ... so better to just have one than three?
Or are the cheap enough that decoding for the user is an OK thing?

Thanks

-Tony

maintainer
#69 lore raw

Re: [PATCH v4 09/10] trace: platform/x86/intel/ifs: Add trace point to track Intel IFS operations

Quoted 7 lines · Tony

I see two paths:

1) Create a new user friendly trace point for each new scan mode.
2) Just provide a generic one that dumps both the 64-bit WRMSR and RDMSR values.

Q: Are trace points "expensive" in some way ... so better to just have one than three?
Or are the cheap enough that decoding for the user is an OK thing?

Yes, they are expensive as each TRACE_EVENT() can add a few KB of text and data. But you can add a DECLARE_EVENT_CLASS() and then add "printk" differences that are less memory heavy.

See DEFINE_EVENT_PRINT().

-- Steve

maintainer
#70 lore raw

Re: [PATCH v4 09/10] trace: platform/x86/intel/ifs: Add trace point to track Intel IFS operations

Quoted 8 lines · Steven Rostedt
Quoted 5 lines · Tony

I see two paths:

1) Create a new user friendly trace point for each new scan mode.
2) Just provide a generic one that dumps both the 64-bit WRMSR and RDMSR values.

Quoted 8 lines
Quoted 2 lines

Q: Are trace points "expensive" in some way ... so better to just have one than three?
Or are the cheap enough that decoding for the user is an OK thing?

Yes, they are expensive as each TRACE_EVENT() can add a few KB of text and data. But you can add a DECLARE_EVENT_CLASS() and then add "printk" differences that are less memory heavy.

See DEFINE_EVENT_PRINT().

I looked at the examples in samples/trace_events/trace-events-sample.h and tried to use this. But I'm doing something wrong because the compiler barfs on something defined but not used.

Maybe my problem is the TP_printk() in the DECLARE_EVENT_CLASS() that is over-ridden by DEFINE_EVENT_PRINT(). I wasn't at all sure what to put here ... or how to use the base tracepoint that doesn't have the printk() over-ridden.

I think I need my class to just save both the u64 values to the trace buffer. Then the different trace points will extract the bits they want and print in a user friendly way. While this increases space used in the trace buffer, these events are not crazy high frequency. Usually one or two events per core with a gap 30 minutes or more between tests.

In my ".c" file the tracepoint looks like this using the name from DEFINE_EVENT_PRINT(), and now passing the full u64 values:

	trace_ifs_status_saf(activate.data, status.data);

and my #include file looks like this:

----------------------------------------------
/* SPDX-License-Identifier: GPL-2.0 */
#undef TRACE_SYSTEM
#define TRACE_SYSTEM intel_ifs

#if !defined(_TRACE_IFS_H) || defined(TRACE_HEADER_MULTI_READ) #define _TRACE_IFS_H

#include <linux/ktime.h>
#include <linux/tracepoint.h>

DECLARE_EVENT_CLASS(ifs_status,

	TP_PROTO(u64 activate, u64 status),

	TP_ARGS(activate, status),

	TP_STRUCT__entry(
		__field(	u64,	activate	)
		__field(	u64,	status		)
	),

	TP_fast_assign(
		__entry->activate = activate;
		__entry->status	= status;
	),

	TP_printk("activate: %llx status: %llx",
		__entry->activate,
		__entry->status)

);

DEFINE_EVENT_PRINT(ifs_status, ifs_status_saf,

	TP_PROTO(u64 activate, u64 status),
	TP_ARGS(activate, status),
	TP_printk("start: %.2x, stop: %.2x, status: %llx",
		((union ifs_scan *)&(__entry->activate))->start,
		((union ifs_scan *)&(__entry->activate))->stop,
		__entry->status)

);

#endif /* _TRACE_IFS_H */

/* This part must be outside protection */
#include <trace/define_trace.h>
-----------------------------------------------------

GCC messages:

CC [M] drivers/platform/x86/intel/ifs/runtest.o
In file included from /home/agluck/GIT/mywork/include/trace/define_trace.h:102,
from /home/agluck/GIT/mywork/include/trace/events/intel_ifs.h:44,
from /home/agluck/GIT/mywork/drivers/platform/x86/intel/ifs/runtest.c:27:
/home/agluck/GIT/mywork/include/trace/trace_events.h:426:13: warning: ‘print_fmt_ifs_status’ defined but not used [-Wunused-variable]

  426 | static char print_fmt_##call[] = print;                                 \
      |             ^~~~~~~~~~
/home/agluck/GIT/mywork/include/trace/events/intel_ifs.h:11:1: note: in expansion of macro ‘DECLARE_EVENT_CLASS’
   11 | DECLARE_EVENT_CLASS(ifs_status,
      | ^~~~~~~~~~~~~~~~~~~

In file included from /home/agluck/GIT/mywork/include/trace/define_trace.h:102,
from /home/agluck/GIT/mywork/include/trace/events/intel_ifs.h:44,
from /home/agluck/GIT/mywork/drivers/platform/x86/intel/ifs/runtest.c:27:
/home/agluck/GIT/mywork/include/trace/trace_events.h:207:37: warning: ‘trace_event_type_funcs_ifs_status’ defined but not used [-Wunused-variable]

  207 | static struct trace_event_functions trace_event_type_funcs_##call = {   \
      |                                     ^~~~~~~~~~~~~~~~~~~~~~~
/home/agluck/GIT/mywork/include/trace/events/intel_ifs.h:11:1: note: in expansion of macro ‘DECLARE_EVENT_CLASS’
   11 | DECLARE_EVENT_CLASS(ifs_status,
      | ^~~~~~~~~~~~~~~~~~~

make[1]: Leaving directory '/home/agluck/GIT/mywork/build/ifsv5-rc1'

-Tony

maintainer
#71 lore raw

Re: [PATCH v4 09/10] trace: platform/x86/intel/ifs: Add trace point to track Intel IFS operations

Quoted 9 lines · Tony

I looked at the examples in samples/trace_events/trace-events-sample.h and tried to use this. But I'm doing something wrong because the compiler barfs on something defined but not used.

Maybe my problem is the TP_printk() in the DECLARE_EVENT_CLASS() that is over-ridden by DEFINE_EVENT_PRINT(). I wasn't at all sure what to put here ... or how to use the base tracepoint that doesn't have the printk() over-ridden.

Yeah, that could be confusing.

Basically, TRACE_EVENT() is simply defined as:

DECLARE_EVENT_CLASS()
DEFINE_EVENT();

So technically you could create the class and event with the same name, and then you could create a second event on top of that. But I usually suggest people explicitly specify the DECLARE_EVENT_CLASS() and DEFINE_EVENT().

I would not do this until you have more than one event. The what you would do is create one event where the print matches the DECLARE_EVENT_CLASS() TP_printk(), and have that event defined with just DEFINE_EVENT(). Then create other events with the DEFINE_EVENT_PRINT().

Quoted 78 lines

I think I need my class to just save both the u64 values to the trace buffer. Then the different trace points will extract the bits they want and print in a user friendly way. While this increases space used in the trace buffer, these events are not crazy high frequency. Usually one or two events per core with a gap 30 minutes or more between tests.

In my ".c" file the tracepoint looks like this using the name from DEFINE_EVENT_PRINT(), and now passing the full u64 values:

	trace_ifs_status_saf(activate.data, status.data);

and my #include file looks like this:

----------------------------------------------
/* SPDX-License-Identifier: GPL-2.0 */
#undef TRACE_SYSTEM
#define TRACE_SYSTEM intel_ifs

#if !defined(_TRACE_IFS_H) || defined(TRACE_HEADER_MULTI_READ) #define _TRACE_IFS_H

#include <linux/ktime.h>
#include <linux/tracepoint.h>

DECLARE_EVENT_CLASS(ifs_status,

	TP_PROTO(u64 activate, u64 status),

	TP_ARGS(activate, status),

	TP_STRUCT__entry(
		__field(	u64,	activate	)
		__field(	u64,	status		)
	),

	TP_fast_assign(
		__entry->activate = activate;
		__entry->status	= status;
	),

	TP_printk("activate: %llx status: %llx",
		__entry->activate,
		__entry->status)

);

DEFINE_EVENT_PRINT(ifs_status, ifs_status_saf,

	TP_PROTO(u64 activate, u64 status),
	TP_ARGS(activate, status),
	TP_printk("start: %.2x, stop: %.2x, status: %llx",
		((union ifs_scan *)&(__entry->activate))->start,
		((union ifs_scan *)&(__entry->activate))->stop,
		__entry->status)

);

#endif /* _TRACE_IFS_H */

/* This part must be outside protection */
#include <trace/define_trace.h>
-----------------------------------------------------

GCC messages:

CC [M] drivers/platform/x86/intel/ifs/runtest.o
In file included from /home/agluck/GIT/mywork/include/trace/define_trace.h:102,
from /home/agluck/GIT/mywork/include/trace/events/intel_ifs.h:44,
from /home/agluck/GIT/mywork/drivers/platform/x86/intel/ifs/runtest.c:27:
/home/agluck/GIT/mywork/include/trace/trace_events.h:426:13: warning: ‘print_fmt_ifs_status’ defined but not used [-Wunused-variable]

  426 | static char print_fmt_##call[] = print;                                 \
      |             ^~~~~~~~~~
/home/agluck/GIT/mywork/include/trace/events/intel_ifs.h:11:1: note: in expansion of macro ‘DECLARE_EVENT_CLASS’
   11 | DECLARE_EVENT_CLASS(ifs_status,
      | ^~~~~~~~~~~~~~~~~~~

In file included from /home/agluck/GIT/mywork/include/trace/define_trace.h:102,
from /home/agluck/GIT/mywork/include/trace/events/intel_ifs.h:44,
from /home/agluck/GIT/mywork/drivers/platform/x86/intel/ifs/runtest.c:27:
/home/agluck/GIT/mywork/include/trace/trace_events.h:207:37: warning: ‘trace_event_type_funcs_ifs_status’ defined but not used [-Wunused-variable]

Quoted 7 lines
  207 | static struct trace_event_functions trace_event_type_funcs_##call = {   \
      |                                     ^~~~~~~~~~~~~~~~~~~~~~~
/home/agluck/GIT/mywork/include/trace/events/intel_ifs.h:11:1: note: in expansion of macro ‘DECLARE_EVENT_CLASS’
   11 | DECLARE_EVENT_CLASS(ifs_status,
      | ^~~~~~~~~~~~~~~~~~~

make[1]: Leaving directory '/home/agluck/GIT/mywork/build/ifsv5-rc1'

Yeah, because you don't have more than one event, so the DEFINE_EVENT_PRINT() does not make sense. You still need one DEFINE_EVENT() otherwise, you will get that static function not used warning.

-- Steve

maintainer
#72 lore raw

PATCH v4 10/10 platform/x86/intel/ifs: add ABI documentation for IFS

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

Add the sysfs attributes in ABI/testing for In-Field Scan.

---
 .../ABI/testing/sysfs-platform-intel-ifs      | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-ifs
Documentation/ABI/testing/sysfs-platform-intel-ifs new file +39 -0
new file mode 100644
index 000000000000..486d6d2ff8a0
@@ -0,0 +1,39 @@
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/run_test
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Write <cpu#> to trigger IFS test for one online core.
+		Note that the test is per core. The cpu# can be
+		for any thread on the core. Running on one thread
+		completes the test for the core containing that thread.
+		Example: to test the core containing cpu5: echo 5 >
+		/sys/devices/platform/intel_ifs.<N>/run_test
+
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/status
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	The status of the last test. It can be one of "pass", "fail"
+		or "untested".
+
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/details
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Additional information regarding the last test. The details file reports
+		the hex value of the SCAN_STATUS MSR. Note that the error_code field
+		may contain driver defined software code not defined in the Intel SDM.
+
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/image_version
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Version (hexadecimal) of loaded IFS binary image. If no scan image
+		is loaded reports "none".
+
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/reload
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Write "1" (or "y" or "Y") to reload the IFS image from
+		/lib/firmware/intel/ifs/ff-mm-ss.scan.
Signature · 1 line
2.35.1
maintainer
#73 lore raw

v5 cover Introduce In Field Scan driver

In reply to Tony Luck

Hopefully this is close enough to done to begin discussion on which maintainer tree will take this series.

Choices:
1) Hans/Mark take it into the platform-drivers tree Needs an Ack from x86 maintainers on parts 1 & 2
2) X86 maintainers take it into TIP
Needs Ack from Hans/Mark on parts 2-10

TL;DR this driver loads scan test files that can check whether silicon in a CPU core is still running correctly. It is expected that these tests would be run several times per day to catch problems as silicon ages.

Changes since v4:

Greg Kroah-Hartman
------------------
"Cute way to do this, but I don't see you ever have any more devices added to this list in this series."

Removed the enum, arrays, loops, and count of test types discovered. Now just check for enumeration of the single test type that is being deployed on Sapphire Rapids.

Jithu Joseph (7):
x86/microcode/intel: Expose collect_cpu_info_early() for IFS platform/x86/intel/ifs: Read IFS firmware image platform/x86/intel/ifs: Check IFS Image sanity platform/x86/intel/ifs: Authenticate and copy to secured memory platform/x86/intel/ifs: Add scan test support platform/x86/intel/ifs: Add IFS sysfs interface platform/x86/intel/ifs: add ABI documentation for IFS

Tony Luck (3):
x86/msr-index: Define INTEGRITY_CAPABILITIES MSR platform/x86/intel/ifs: Add stub driver for In-Field Scan
trace: platform/x86/intel/ifs: Add trace point to track Intel IFS
operations

 .../ABI/testing/sysfs-platform-intel-ifs      |  39 ++
 MAINTAINERS                                   |   8 +
 arch/x86/include/asm/cpu.h                    |  18 +
 arch/x86/include/asm/msr-index.h              |   7 +
 arch/x86/kernel/cpu/intel.c                   |  32 ++
 arch/x86/kernel/cpu/microcode/intel.c         |  59 +---
 drivers/platform/x86/intel/Kconfig            |   1 +
 drivers/platform/x86/intel/Makefile           |   1 +
 drivers/platform/x86/intel/ifs/Kconfig        |  13 +
 drivers/platform/x86/intel/ifs/Makefile       |   3 +
 drivers/platform/x86/intel/ifs/core.c         |  80 +++++
 drivers/platform/x86/intel/ifs/ifs.h          | 123 +++++++
 drivers/platform/x86/intel/ifs/load.c         | 262 ++++++++++++++
 drivers/platform/x86/intel/ifs/runtest.c      | 332 ++++++++++++++++++
 drivers/platform/x86/intel/ifs/sysfs.c        | 147 ++++++++
 include/trace/events/intel_ifs.h              |  38 ++
 16 files changed, 1111 insertions(+), 52 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-ifs
 create mode 100644 drivers/platform/x86/intel/ifs/Kconfig
 create mode 100644 drivers/platform/x86/intel/ifs/Makefile
 create mode 100644 drivers/platform/x86/intel/ifs/core.c
 create mode 100644 drivers/platform/x86/intel/ifs/ifs.h
 create mode 100644 drivers/platform/x86/intel/ifs/load.c
 create mode 100644 drivers/platform/x86/intel/ifs/runtest.c
 create mode 100644 drivers/platform/x86/intel/ifs/sysfs.c
 create mode 100644 include/trace/events/intel_ifs.h

base-commit: af2d861d4cd2a4da5137f795ee3509e6f944a25b

Signature · 1 line
2.35.1
maintainer
#74 lore raw

PATCH v5 1/10 x86/microcode/intel: Expose collect_cpu_info_early() for IFS

From: Jithu Joseph <[email protected]>

IFS is a CPU feature that allows a binary blob, similar to microcode, to be loaded and consumed to perform low level validation of CPU circuitry. In fact, it carries the same Processor Signature (family/model/stepping) details that are contained in Intel microcode blobs.

In support of an IFS driver to trigger loading, validation, and running of these tests blobs, make the functionality of cpu_signatures_match() and collect_cpu_info_early() available outside of the microcode driver.

Add an "intel_" prefix and drop the "_early" suffix from collect_cpu_info_early() and EXPORT_SYMBOL_GPL() it. Add declaration to x86 <asm/cpu.h>

Make cpu_signatures_match() an inline function in x86 <asm/cpu.h>, and also give it an "intel_" prefix.

No functional change intended.

---
 arch/x86/include/asm/cpu.h            | 18 ++++++++
 arch/x86/kernel/cpu/intel.c           | 32 +++++++++++++++
 arch/x86/kernel/cpu/microcode/intel.c | 59 ++++-----------------------
 3 files changed, 57 insertions(+), 52 deletions(-)
arch/x86/include/asm/cpu.h +18 -0
index 86e5e4e26fcb..990167357c34 100644
@@ -76,4 +76,22 @@ static inline void init_ia32_feat_ctl(struct cpuinfo_x86 *c) {}
 
 extern __noendbr void cet_disable(void);
 
+struct ucode_cpu_info;
+
+int intel_cpu_collect_info(struct ucode_cpu_info *uci);
+
+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;
+}
+
 #endif /* _ASM_X86_CPU_H */
arch/x86/kernel/cpu/intel.c +32 -0
index f7a5370a9b3b..94779146275d 100644
@@ -181,6 +181,38 @@ static bool bad_spectre_microcode(struct cpuinfo_x86 *c)
 	return false;
 }
 
+int intel_cpu_collect_info(struct ucode_cpu_info *uci)
+{
+	unsigned int val[2];
+	unsigned int family, model;
+	struct cpu_signature csig = { 0 };
+	unsigned int eax, ebx, ecx, edx;
+
+	memset(uci, 0, sizeof(*uci));
+
+	eax = 0x00000001;
+	ecx = 0;
+	native_cpuid(&eax, &ebx, &ecx, &edx);
+	csig.sig = eax;
+
+	family = x86_family(eax);
+	model  = x86_model(eax);
+
+	if (model >= 5 || family > 6) {
+		/* get processor flags from MSR 0x17 */
+		native_rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]);
+		csig.pf = 1 << ((val[1] >> 18) & 7);
+	}
+
+	csig.rev = intel_get_microcode_revision();
+
+	uci->cpu_sig = csig;
+	uci->valid = 1;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(intel_cpu_collect_info);
+
 static void early_init_intel(struct cpuinfo_x86 *c)
 {
 	u64 misc_enable;
arch/x86/kernel/cpu/microcode/intel.c +7 -52

113 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer Acked-by on v5 1/10
#75 lore raw

Re: [PATCH v5 01/10] x86/microcode/intel: Expose collect_cpu_info_early() for IFS

Quoted 25 lines · Tony Luck

From: Jithu Joseph <[email protected]>

IFS is a CPU feature that allows a binary blob, similar to microcode, to be loaded and consumed to perform low level validation of CPU circuitry. In fact, it carries the same Processor Signature (family/model/stepping) details that are contained in Intel microcode blobs.

In support of an IFS driver to trigger loading, validation, and running of these tests blobs, make the functionality of cpu_signatures_match() and collect_cpu_info_early() available outside of the microcode driver.

Add an "intel_" prefix and drop the "_early" suffix from collect_cpu_info_early() and EXPORT_SYMBOL_GPL() it. Add declaration to x86 <asm/cpu.h>

Make cpu_signatures_match() an inline function in x86 <asm/cpu.h>, and also give it an "intel_" prefix.

No functional change intended.

Quoted 5 lines
---
 arch/x86/include/asm/cpu.h            | 18 ++++++++
 arch/x86/kernel/cpu/intel.c           | 32 +++++++++++++++
 arch/x86/kernel/cpu/microcode/intel.c | 59 ++++-----------------------
 3 files changed, 57 insertions(+), 52 deletions(-)
Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
Reviewed-by on v5 1/10
#76 lore raw

Re: [PATCH v5 01/10] x86/microcode/intel: Expose collect_cpu_info_early() for IFS

In reply to Tony Luck
Quoted 19 lines · Tony Luck

From: Jithu Joseph <[email protected]>

IFS is a CPU feature that allows a binary blob, similar to microcode, to be loaded and consumed to perform low level validation of CPU circuitry. In fact, it carries the same Processor Signature (family/model/stepping) details that are contained in Intel microcode blobs.

In support of an IFS driver to trigger loading, validation, and running of these tests blobs, make the functionality of cpu_signatures_match() and collect_cpu_info_early() available outside of the microcode driver.

Add an "intel_" prefix and drop the "_early" suffix from collect_cpu_info_early() and EXPORT_SYMBOL_GPL() it. Add declaration to x86 <asm/cpu.h>

Make cpu_signatures_match() an inline function in x86 <asm/cpu.h>, and also give it an "intel_" prefix.

Quoted 6 lines

No functional change intended.

maintainer
#77 lore raw

PATCH v5 2/10 x86/msr-index: Define INTEGRITY_CAPABILITIES MSR

In reply to Tony Luck

The INTEGRITY_CAPABILITIES MSR is enumerated by bit 2 of the CORE_CAPABILITIES MSR.

Add defines for the CORE_CAPS enumeration as well as for the integrity MSR.

---
 arch/x86/include/asm/msr-index.h | 7 +++++++
 1 file changed, 7 insertions(+)
arch/x86/include/asm/msr-index.h +7 -0
index ee15311b6be1..c3dc7ae32f1f 100644
@@ -76,6 +76,8 @@
 
 /* Abbreviated from Intel SDM name IA32_CORE_CAPABILITIES */
 #define MSR_IA32_CORE_CAPS			  0x000000cf
+#define MSR_IA32_CORE_CAPS_INTEGRITY_CAPS_BIT	  2
+#define MSR_IA32_CORE_CAPS_INTEGRITY_CAPS	  BIT(MSR_IA32_CORE_CAPS_INTEGRITY_CAPS_BIT)
 #define MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT_BIT  5
 #define MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT	  BIT(MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT_BIT)
 
@@ -154,6 +156,11 @@
 #define MSR_IA32_POWER_CTL		0x000001fc
 #define MSR_IA32_POWER_CTL_BIT_EE	19
 
+/* Abbreviated from Intel SDM name IA32_INTEGRITY_CAPABILITIES */
+#define MSR_INTEGRITY_CAPS			0x000002d9
+#define MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT	4
+#define MSR_INTEGRITY_CAPS_PERIODIC_BIST	BIT(MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT)
+
 #define MSR_LBR_NHM_FROM		0x00000680
 #define MSR_LBR_NHM_TO			0x000006c0
 #define MSR_LBR_CORE_FROM		0x00000040
Signature · 1 line
2.35.1
maintainer
#78 lore raw

PATCH v5 3/10 platform/x86/intel/ifs: Add stub driver for In-Field Scan

In reply to Tony Luck

Cloud Service Providers that operate fleets of servers have reported
[1] occasions where they can detect that a CPU has gone bad due to effects like electromigration, or isolated manufacturing defects. However, that detection method is A/B testing seemingly random application failures looking for a pattern. In-Field Scan (IFS) is a driver for a platform capability to load a crafted 'scan image' to run targeted low level diagnostics outside of the CPU's architectural error detection capabilities.

Stub version of driver just does initial part of check for the IFS feature. MSR_IA32_CORE_CAPS must enumerate the presence of the MSR_INTEGRITY_CAPS MSR.

[1]: https://www.youtube.com/watch?v=QMF3rqhjYuM

---
 MAINTAINERS                             |  7 ++++
 drivers/platform/x86/intel/Kconfig      |  1 +
 drivers/platform/x86/intel/Makefile     |  1 +
 drivers/platform/x86/intel/ifs/Kconfig  | 13 +++++++
 drivers/platform/x86/intel/ifs/Makefile |  3 ++
 drivers/platform/x86/intel/ifs/core.c   | 48 +++++++++++++++++++++++++
 6 files changed, 73 insertions(+)
 create mode 100644 drivers/platform/x86/intel/ifs/Kconfig
 create mode 100644 drivers/platform/x86/intel/ifs/Makefile
 create mode 100644 drivers/platform/x86/intel/ifs/core.c
MAINTAINERS +7 -0
index 5e8c2f611766..bc902d0c64d2 100644
@@ -9859,6 +9859,13 @@ B:	https://bugzilla.kernel.org
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git
 F:	drivers/idle/intel_idle.c
 
+INTEL IN FIELD SCAN (IFS) DEVICE
+M:	Jithu Joseph <[email protected]>
+R:	Ashok Raj <[email protected]>
+R:	Tony Luck <[email protected]>
+S:	Maintained
+F:	drivers/platform/x86/intel/ifs
+
 INTEL INTEGRATED SENSOR HUB DRIVER
 M:	Srinivas Pandruvada <[email protected]>
 M:	Jiri Kosina <[email protected]>
drivers/platform/x86/intel/Kconfig +1 -0
index 1f01a8a23c57..794968bda115 100644
@@ -4,6 +4,7 @@
 #
 
 source "drivers/platform/x86/intel/atomisp2/Kconfig"
+source "drivers/platform/x86/intel/ifs/Kconfig"
 source "drivers/platform/x86/intel/int1092/Kconfig"
 source "drivers/platform/x86/intel/int3472/Kconfig"
 source "drivers/platform/x86/intel/pmc/Kconfig"
drivers/platform/x86/intel/Makefile +1 -0
index c61bc3e97121..717933dd0cfd 100644
@@ -5,6 +5,7 @@
 #
 
 obj-$(CONFIG_INTEL_ATOMISP2_PDX86)	+= atomisp2/
+obj-$(CONFIG_INTEL_IFS)			+= ifs/
 obj-$(CONFIG_INTEL_SAR_INT1092)		+= int1092/
 obj-$(CONFIG_INTEL_SKL_INT3472)		+= int3472/
 obj-$(CONFIG_INTEL_PMC_CORE)		+= pmc/
drivers/platform/x86/intel/ifs/Kconfig new file +13 -0
new file mode 100644
index 000000000000..d84491cfb0db
@@ -0,0 +1,13 @@
+config INTEL_IFS
+	tristate "Intel In Field Scan"
+	depends on X86 && 64BIT && SMP
+	select INTEL_IFS_DEVICE
+	help
+	  Enable support for the In Field Scan capability in select
+	  CPUs. The capability allows for running low level tests via
+	  a scan image distributed by Intel via Github to validate CPU
+	  operation beyond baseline RAS capabilities. To compile this
+	  support as a module, choose M here. The module will be called
+	  intel_ifs.
+
+	  If unsure, say N.
drivers/platform/x86/intel/ifs/Makefile new file +3 -0
new file mode 100644
index 000000000000..af904880e959
@@ -0,0 +1,3 @@
+obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
+
+intel_ifs-objs			:= core.o
drivers/platform/x86/intel/ifs/core.c new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.35.1
#79 lore raw

Re: [PATCH v5 03/10] platform/x86/intel/ifs: Add stub driver for In-Field Scan

drivers/platform/x86/intel/ifs/core.c line 14

Quoted 6 lines · Tony Luck
drivers/platform/x86/intel/ifs/core.c new file +6 -0
+#define X86_MATCH(model)				\
+	X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6,	\
+		INTEL_FAM6_##model, X86_FEATURE_CORE_CAPABILITIES, NULL)
+
+static const struct x86_cpu_id ifs_cpu_ids[] __initconst = {
+	X86_MATCH(SAPPHIRERAPIDS_X),

Why do we need a model match here? The core capabilities MSR is only available when X86_FEATURE_CORE_CAPABILITIES is set:

"If CPUID.(EAX=07H, ECX=0):EDX[30] = 1.
This MSR provides an architectural enumeration function for model-specific behavior."

So checking for Intel Fam6 ANYMODEL and X86_FEATURE_CORE_CAPABILITIES is sufficient, no?

We really don't need more match id tables with gazillions of CPU models.

Thanks,

tglx

maintainer
#80 lore raw

RE: [PATCH v5 03/10] platform/x86/intel/ifs: Add stub driver for In-Field Scan

Quoted 6 lines

drivers/platform/x86/intel/ifs/core.c line 14

Quoted 2 lines
drivers/platform/x86/intel/ifs/core.c new file +2 -0
+static const struct x86_cpu_id ifs_cpu_ids[] __initconst = {
+	X86_MATCH(SAPPHIRERAPIDS_X),

Why do we need a model match here? The core capabilities MSR is only available when X86_FEATURE_CORE_CAPABILITIES is set:

Quoted 6 lines

"If CPUID.(EAX=07H, ECX=0):EDX[30] = 1.
This MSR provides an architectural enumeration function for model-specific behavior."

So checking for Intel Fam6 ANYMODEL and X86_FEATURE_CORE_CAPABILITIES is sufficient, no?

IA32_CORE_CAPABILITES is a nightmare. Although it is an architectural register, the bits inside it are model specific.

In particular bit 2 (which we check here for the existence of the INTEGRITY MSR) has been assigned for other use on other models. See SDM volume 4 table 2-45 where bit 2 means FUSA supported on 06_8C and 06_8D (Tigerlake mobile and desktop). Ditto in table 2-46 (Alderlake and Raptorlake).

Quoted 1 line

We really don't need more match id tables with gazillions of CPU models.

Sadly we do :-(

-Tony

maintainer
#81 lore raw

Re: [PATCH v5 03/10] platform/x86/intel/ifs: Add stub driver for In-Field Scan

Quoted 3 lines · Tony
Quoted 1 line

We really don't need more match id tables with gazillions of CPU models.

Sadly we do :-(

So what was the reasoning about CPUID bits being so expensive so that we need to match models? Ditto for the splitlock situation - that thing is supported on a bunch of models but nope, not a CPUID bit in sight. What was the convincing argument that made hw folks give a CPUID bit to the PPIN thing? Perhaps we could use it there too. :)

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#82 lore raw

PATCH v5 4/10 platform/x86/intel/ifs: Read IFS firmware image

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

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.

---
 drivers/platform/x86/intel/ifs/Makefile |  2 +-
 drivers/platform/x86/intel/ifs/core.c   | 21 +++++++++++++++++++
 drivers/platform/x86/intel/ifs/ifs.h    | 25 ++++++++++++++++++++++
 drivers/platform/x86/intel/ifs/load.c   | 28 +++++++++++++++++++++++++
 4 files changed, 75 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/ifs.h
 create mode 100644 drivers/platform/x86/intel/ifs/load.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index af904880e959..98b6fde15689 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
 
-intel_ifs-objs			:= core.o
+intel_ifs-objs			:= core.o load.o
drivers/platform/x86/intel/ifs/core.c +21 -0
index e3623ac691b5..d4a54ff47447 100644
@@ -6,6 +6,8 @@
 
 #include <asm/cpu_device_id.h>
 
+#include "ifs.h"
+
 #define X86_MATCH(model)				\
 	X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6,	\
 		INTEL_FAM6_##model, X86_FEATURE_CORE_CAPABILITIES, NULL)
@@ -16,6 +18,17 @@ static const struct x86_cpu_id ifs_cpu_ids[] __initconst = {
 };
 MODULE_DEVICE_TABLE(x86cpu, ifs_cpu_ids);
 
+static struct ifs_device ifs_device = {
+	.data = {
+		.integrity_cap_bit = MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT,
+	},
+	.misc = {
+		.name = "intel_ifs_0",
+		.nodename = "intel_ifs/0",
+		.minor = MISC_DYNAMIC_MINOR,
+	},
+};
+
 static int __init ifs_init(void)
 {
 	const struct x86_cpu_id *m;
@@ -34,11 +47,19 @@ static int __init ifs_init(void)
 	if (rdmsrl_safe(MSR_INTEGRITY_CAPS, &msrval))
 		return -ENODEV;
 
+	if ((msrval & BIT(ifs_device.data.integrity_cap_bit)) &&
+	    !misc_register(&ifs_device.misc)) {
+		ifs_load_firmware(ifs_device.misc.this_device);
+	} else {
+		return -ENODEV;
+	}
+
 	return 0;
 }
 
 static void __exit ifs_exit(void)
 {
+	misc_deregister(&ifs_device.misc);
 }
 
 module_init(ifs_init);
drivers/platform/x86/intel/ifs/ifs.h new file +25 -0
new file mode 100644
index 000000000000..9a0f8e2077e2
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2022 Intel Corporation. */
+
+#ifndef _IFS_H_
+#define _IFS_H_
+
+#include <linux/device.h>
+#include <linux/miscdevice.h>
+
+/**
+ * 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
drivers/platform/x86/intel/ifs/load.c new file +28 -0
new file mode 100644
index 000000000000..9fb71d38c819
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright(c) 2022 Intel Corporation. */
+
+#include <linux/firmware.h>
+
+#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);
+}
Signature · 1 line
2.35.1
#83 lore raw

Re: [PATCH v5 04/10] platform/x86/intel/ifs: Read IFS firmware image

Quoted 7 lines · Tony Luck
drivers/platform/x86/intel/ifs/load.c new file +7 -0
+/*
+ * 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;

drivers/platform/x86/intel/ifs/load.c line 24

Quoted 10 lines
drivers/platform/x86/intel/ifs/load.c new file +10 -0
+	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;

Why is this not returning an error to the caller?

Thanks,

tglx

maintainer
#84 lore raw

RE: [PATCH v5 04/10] platform/x86/intel/ifs: Read IFS firmware image

Quoted 6 lines

drivers/platform/x86/intel/ifs/load.c line 24

Quoted 4 lines
drivers/platform/x86/intel/ifs/load.c new file +4 -0
+	ret = request_firmware_direct(&fw, scan_path, dev);
+	if (ret) {
+		dev_err(dev, "ifs file %s load failed\n", scan_path);
+		return;

Why is this not returning an error to the caller?

There are three call sequences that lead here:

1) CONFIG_INTEL_IFS=y
At boot this is pretty much guaranteed to fail (unless some crazy person includes the
scan file in the initramfs). In this case there isn't a useful caller to return the code to. In this case the driver init routine must ignore any error to make sure the sysfs reload file is present to load the scan file once the file system is available.

2) CONFIG_INTEL_IFS=m module load time
Same code path as built-in ... so must ignore a failed load here too (unless there is a way to distinguish the built-in vs. module execution environment).

3) echo 1 > reload
Hmmm. Some older revision did return an error ... but I seem to have factored it out
during cleanups. Limited to standard -E???? error codes. The reload_store() function can just check whether the load succeeded by looking at ifsd->loaded instead of a return value from ifs_load_firmware()

So, I will fix case 3. But probably by checking ifsd->loaded rather than by adding a return code to this function.

-Tony

maintainer
#85 lore raw

PATCH v5 5/10 platform/x86/intel/ifs: Check IFS Image sanity

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

IFS image is designed specifically for a given family, model and stepping of the processor. Like Intel microcode header, the IFS image has the Processor Signature, Checksum and Processor Flags that must be matched with the information returned by the CPUID.

---
 drivers/platform/x86/intel/ifs/load.c | 68 +++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
drivers/platform/x86/intel/ifs/load.c +68 -0
index 9fb71d38c819..aece78d1c757 100644
@@ -2,9 +2,74 @@
 /* Copyright(c) 2022 Intel Corporation. */
 
 #include <linux/firmware.h>
+#include <asm/cpu.h>
+#include <asm/microcode_intel.h>
 
 #include "ifs.h"
 
+static int ifs_sanity_check(struct device *dev,
+			    const struct microcode_header_intel *mc_header)
+{
+	unsigned long total_size, data_size;
+	u32 sum, i;
+	u8 *mc;
+
+	total_size = get_totalsize(mc_header);
+	data_size = get_datasize(mc_header);
+
+	if ((data_size + MC_HEADER_SIZE > total_size) || (total_size % sizeof(u32))) {
+		dev_err(dev, "bad ifs data file size.\n");
+		return -EINVAL;
+	}
+
+	if (mc_header->ldrver != 1 || mc_header->hdrver != 1) {
+		dev_err(dev, "invalid/unknown ifs update format.\n");
+		return -EINVAL;
+	}
+
+	mc = (u8 *)mc_header;
+	sum = 0;
+	i = total_size / sizeof(u32);
+	while (i--)
+		sum += ((u32 *)mc)[i];
+
+	if (sum) {
+		dev_err(dev, "bad ifs data checksum, aborting.\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}.
@@ -24,5 +89,8 @@ void ifs_load_firmware(struct device *dev)
 		return;
 	}
 
+	if (!ifs_image_sanity_check(dev, (struct microcode_header_intel *)fw->data))
+		dev_err(dev, "ifs header sanity check failed\n");
+
 	release_firmware(fw);
 }
Signature · 1 line
2.35.1
maintainer
#86 lore raw

PATCH v5 6/10 platform/x86/intel/ifs: Authenticate and copy to secured memory

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

The IFS image contains hashes that will be used to authenticate the ifs test chunks. First, use WRMSR to copy the hashes and enumerate the number of test chunks, chunk size and the maximum number of cores that can run scan test simultaneously.

Next, use WRMSR to authenticate each and every scan test chunk which is also stored in the IFS image. The CPU will check if the test chunks match the hashes, otherwise failure is indicated to system software. If the test chunk is authenticated, it is automatically copied to secured memory.

The ifs hash copy and authentication only needs to be done on the first logical cpu of each socket.

---
 drivers/platform/x86/intel/ifs/ifs.h  |  47 +++++++
 drivers/platform/x86/intel/ifs/load.c | 170 +++++++++++++++++++++++++-
 2 files changed, 215 insertions(+), 2 deletions(-)
drivers/platform/x86/intel/ifs/ifs.h +47 -0
index 9a0f8e2077e2..d985b4a50f46 100644
@@ -7,12 +7,51 @@
 #include <linux/device.h>
 #include <linux/miscdevice.h>
 
+#define MSR_COPY_SCAN_HASHES			0x000002c2
+#define MSR_SCAN_HASHES_STATUS			0x000002c3
+#define MSR_AUTHENTICATE_AND_COPY_CHUNK		0x000002c4
+#define MSR_CHUNKS_AUTHENTICATION_STATUS	0x000002c5
+
+/* MSR_SCAN_HASHES_STATUS bit fields */
+union ifs_scan_hashes_status {
+	u64	data;
+	struct {
+		u32	chunk_size	:16;
+		u32	num_chunks	:8;
+		u32	rsvd1		:8;
+		u32	error_code	:8;
+		u32	rsvd2		:11;
+		u32	max_core_limit	:12;
+		u32	valid		:1;
+	};
+};
+
+/* MSR_CHUNKS_AUTH_STATUS bit fields */
+union ifs_chunks_auth_status {
+	u64	data;
+	struct {
+		u32	valid_chunks	:8;
+		u32	total_chunks	:8;
+		u32	rsvd1		:16;
+		u32	error_code	:8;
+		u32	rsvd2		:24;
+	};
+};
+
 /**
  * struct ifs_data - attributes related to intel IFS driver
  * @integrity_cap_bit - MSR_INTEGRITY_CAPS bit enumerating this test
+ * @loaded_version: stores the currently loaded ifs image version.
+ * @loaded: If a valid test binary has been loaded into the memory
+ * @loading_error: Error occurred on another CPU while loading image
+ * @valid_chunks: number of chunks which could be validated.
  */
 struct ifs_data {
 	int integrity_cap_bit;
+	int loaded_version;
+	bool loaded;
+	bool loading_error;
+	int valid_chunks;
 };
 
 struct ifs_device {
@@ -20,6 +59,14 @@ struct ifs_device {
 	struct miscdevice misc;
 };
 
+static inline struct ifs_data *ifs_get_data(struct device *dev)
+{
+	struct miscdevice *m = dev_get_drvdata(dev);
+	struct ifs_device *d = container_of(m, struct ifs_device, misc);
+
+	return &d->data;
+}
+
 void ifs_load_firmware(struct device *dev);
 
 #endif
drivers/platform/x86/intel/ifs/load.c +168 -2

195 lines not on this page · raw message

Signature · 1 line
2.35.1
#87 lore raw

Re: [PATCH v5 06/10] platform/x86/intel/ifs: Authenticate and copy to secured memory

Quoted 7 lines · Tony Luck

The IFS image contains hashes that will be used to authenticate the ifs test chunks. First, use WRMSR to copy the hashes and enumerate the number of test chunks, chunk size and the maximum number of cores that can run scan test simultaneously.

Next, use WRMSR to authenticate each and every scan test chunk which is also stored in the IFS image. The CPU will check if the test chunks match

s/also// ?

Quoted 17 lines
drivers/platform/x86/intel/ifs/ifs.h +14 -0
+
+/* MSR_CHUNKS_AUTH_STATUS bit fields */
+union ifs_chunks_auth_status {
+	u64	data;
+	struct {
+		u32	valid_chunks	:8;
+		u32	total_chunks	:8;
+		u32	rsvd1		:16;
+		u32	error_code	:8;
+		u32	rsvd2		:24;
+	};
+};
+
 /**
  * struct ifs_data - attributes related to intel IFS driver
  * @integrity_cap_bit - MSR_INTEGRITY_CAPS bit enumerating this test
+ * @loaded_version: stores the currently loaded ifs image version.

drivers/platform/x86/intel/ifs/ifs.h line 54

Quoted 10 lines
drivers/platform/x86/intel/ifs/ifs.h +7 -0
+ * @loaded: If a valid test binary has been loaded into the memory
+ * @loading_error: Error occurred on another CPU while loading image
+ * @valid_chunks: number of chunks which could be validated.
  */
 struct ifs_data {
 	int integrity_cap_bit;
+	int loaded_version;
+	bool loaded;
+	bool loading_error;
+	int valid_chunks;

The above struct is nicely tabular. Can we have that here too please?

Quoted 31 lines
drivers/platform/x86/intel/ifs/load.c +31 -0
+/*
+ * IFS requires scan chunks authenticated per each socket in the platform.
+ * Once the test chunk is authenticated, it is automatically copied to secured memory
+ * and proceed the authentication for the next chunk.
+ */
+static int scan_chunks_sanity_check(struct device *dev)
+{
+	int metadata_size, curr_pkg, cpu, ret = -ENOMEM;
+	struct ifs_data *ifsd = ifs_get_data(dev);
+	bool *package_authenticated;
+	char *test_ptr;
+
+	package_authenticated = kcalloc(topology_max_packages(), sizeof(bool), GFP_KERNEL);
+	if (!package_authenticated)
+		return ret;
+
+	metadata_size = ifs_header_ptr->metadata_size;
+
+	/* 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;
+	ifsd->loading_error = false;
+

drivers/platform/x86/intel/ifs/load.c line 150

Quoted 10 lines
drivers/platform/x86/intel/ifs/load.c +10 -0
+	ifs_test_image_ptr = (u64)test_ptr;
+	ifsd->loaded_version = ifs_header_ptr->blob_revision;
+
+	/* copy the scan hash and authenticate per package */
+	cpus_read_lock();
+	for_each_online_cpu(cpu) {
+		curr_pkg = topology_physical_package_id(cpu);
+		if (package_authenticated[curr_pkg])
+			continue;
+		package_authenticated[curr_pkg] = 1;

Setting the authenticated indicator _before_ actually doing the authentication is just wrong. It does not matter in this case, but it's still making my eyes bleed.

drivers/platform/x86/intel/ifs/load.c line 152

Quoted 2 lines
drivers/platform/x86/intel/ifs/load.c +2 -0
+		ret = smp_call_function_single(cpu, copy_hashes_authenticate_chunks,
+					       dev, 1);

Why has this to be a smp function call? Just because it's conveniant? This is nothing urgent and no hotpath, so this really can use queue_work_on().

Thanks,

tglx

maintainer
#88 lore raw

PATCH v5 7/10 platform/x86/intel/ifs: Add scan test support

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

In a core, the scan engine is shared between sibling cpus.

When a Scan test (for a particular core) is triggered by the user, worker threads for each sibling cpus(belonging to that core) are queued to execute the scan test function in the Workqueue context.

All the siblings rendezvous before the test execution. The scan results are same for all siblings.

Scan may be aborted by some reasons. Scan test will be aborted in certain circumstances such as when interrupt occurred or cpu does not have enough power budget for scan. In this case, the kernel restart scan from the chunk where it stopped. Scan will also be aborted when the test is failed. In this case, the test is immediately stopped without retry.

---
 drivers/platform/x86/intel/ifs/Makefile  |   2 +-
 drivers/platform/x86/intel/ifs/core.c    |   5 +
 drivers/platform/x86/intel/ifs/ifs.h     |  48 ++++
 drivers/platform/x86/intel/ifs/runtest.c | 327 +++++++++++++++++++++++
 4 files changed, 381 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/runtest.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index 98b6fde15689..cedcb103f860 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
 
-intel_ifs-objs			:= core.o load.o
+intel_ifs-objs			:= core.o load.o runtest.o
drivers/platform/x86/intel/ifs/core.c +5 -0
index d4a54ff47447..d408290480c7 100644
@@ -47,10 +47,14 @@ static int __init ifs_init(void)
 	if (rdmsrl_safe(MSR_INTEGRITY_CAPS, &msrval))
 		return -ENODEV;
 
+	if (ifs_setup_wq())
+		return -ENOMEM;
+
 	if ((msrval & BIT(ifs_device.data.integrity_cap_bit)) &&
 	    !misc_register(&ifs_device.misc)) {
 		ifs_load_firmware(ifs_device.misc.this_device);
 	} else {
+		ifs_destroy_wq();
 		return -ENODEV;
 	}
 
@@ -60,6 +64,7 @@ static int __init ifs_init(void)
 static void __exit ifs_exit(void)
 {
 	misc_deregister(&ifs_device.misc);
+	ifs_destroy_wq();
 }
 
 module_init(ifs_init);
drivers/platform/x86/intel/ifs/ifs.h +48 -0

77 lines not on this page · raw message

drivers/platform/x86/intel/ifs/runtest.c new file +327 -0

327 lines not on this page · raw message

Signature · 1 line
2.35.1
#89 lore raw

Re: [PATCH v5 07/10] platform/x86/intel/ifs: Add scan test support

Quoted 47 lines · Tony Luck
drivers/platform/x86/intel/ifs/runtest.c new file +47 -0
+static bool wait_for_siblings(struct device *dev, struct ifs_data *ifsd, atomic_t *t, long long timeout)
+{
+	atomic_inc(t);
+	while (atomic_read(t) < cpu_sibl_ct) {
+		if (timeout < SPINUNIT) {
+			dev_err(dev,
+				"Timeout while waiting for CPUs rendezvous, remaining: %d\n",
+				cpu_sibl_ct - atomic_read(t));
+			return false;
+		}
+
+		ndelay(SPINUNIT);
+		timeout -= SPINUNIT;
+
+		touch_nmi_watchdog();
+	}
+
+	return true;
+}
+
+/*
+ * When a Scan test (for a particular core) is triggered by the user, worker threads
+ * for each sibling cpus(belonging to that core) are queued to execute this function in
+ * the Workqueue (ifs_wq) context.
+ * Wait for the sibling thread to join before the execution.
+ * Execute the scan test by running wrmsr(MSR_ACTIVATE_SCAN).
+ */
+static void ifs_work_func(struct work_struct *work)
+{
+	struct ifs_work *local_work = container_of(work, struct ifs_work, w);
+	int cpu = smp_processor_id();
+	union ifs_scan activate;
+	union ifs_status status;
+	unsigned long timeout;
+	struct ifs_data *ifsd;
+	struct device *dev;
+	int retries;
+	u32 first;
+
+	dev = local_work->dev;
+	ifsd = ifs_get_data(dev);
+
+	activate.rsvd = 0;
+	activate.delay = msec_to_tsc(THREAD_WAIT);
+	activate.sigmce = 0;
+
+	/*

drivers/platform/x86/intel/ifs/runtest.c line 191

Quoted 10 lines
drivers/platform/x86/intel/ifs/runtest.c new file +10 -0
+	 * Need to get (and keep) the threads on this core executing close together
+	 * so that the writes to MSR_ACTIVATE_SCAN below will succeed in entering
+	 * IFS test mode on this core. Interrupts on each thread are expected to be
+	 * brief. But preemption would be a problem.
+	 */
+	preempt_disable();
+
+	/* wait for the sibling threads to join */
+	first = cpumask_first(topology_sibling_cpumask(cpu));
+	if (!wait_for_siblings(dev, ifsd, &siblings_in, NSEC_PER_SEC)) {

Waiting for a second with preemption disabled? Seriously?

drivers/platform/x86/intel/ifs/runtest.c line 199

Quoted 8 lines
drivers/platform/x86/intel/ifs/runtest.c new file +8 -0
+		preempt_enable();
+		dev_err(dev, "cpu %d sibling did not join rendezvous\n", cpu);
+		goto out;
+	}
+
+	activate.start = 0;
+	activate.stop = ifsd->valid_chunks - 1;
+	timeout = jiffies + HZ / 2;

Plus another half a second with preemption disabled. That's just insane.

drivers/platform/x86/intel/ifs/runtest.c line 210

Quoted 11 lines
drivers/platform/x86/intel/ifs/runtest.c new file +11 -0
+	retries = MAX_IFS_RETRIES;
+
+	while (activate.start <= activate.stop) {
+		if (time_after(jiffies, timeout)) {
+			status.error_code = IFS_SW_TIMEOUT;
+			break;
+		}
+
+		local_irq_disable();
+		wrmsrl(MSR_ACTIVATE_SCAN, activate.data);
+		local_irq_enable();

That local_irq_disable() solves what?

drivers/platform/x86/intel/ifs/runtest.c line 217

Quoted 6 lines
drivers/platform/x86/intel/ifs/runtest.c new file +6 -0
+		/*
+		 * All logical CPUs on this core are now running IFS test. When it completes
+		 * execution or is interrupted, the following RDMSR gets the scan status.
+		 */
+
+		rdmsrl(MSR_SCAN_STATUS, status.data);

Wait. Is that rdmsrl() blocking execution until the scan completes?

If so, what's the stall time here? If not, how is the logic below supposed to work?

Quoted 48 lines
drivers/platform/x86/intel/ifs/runtest.c new file +48 -0
+		/* Some cases can be retried, give up for others */
+		if (!can_restart(status))
+			break;
+
+		if (status.chunk_num == activate.start) {
+			/* Check for forward progress */
+			if (retries-- == 0) {
+				if (status.error_code == IFS_NO_ERROR)
+					status.error_code = IFS_SW_PARTIAL_COMPLETION;
+				break;
+			}
+		} else {
+			retries = MAX_IFS_RETRIES;
+			activate.start = status.chunk_num;
+		}
+	}
+
+	preempt_enable();
+
+	if (cpu == first) {
+		/* Update status for this core */
+		ifsd->scan_details = status.data;
+
+		if (status.control_error || status.signature_error) {
+			ifsd->status = SCAN_TEST_FAIL;
+			message_fail(dev, cpu, status);
+		} else if (status.error_code) {
+			ifsd->status = SCAN_NOT_TESTED;
+			message_not_tested(dev, cpu, status);
+		} else {
+			ifsd->status = SCAN_TEST_PASS;
+		}
+	}
+
+	if (!wait_for_siblings(dev, ifsd, &siblings_out, NSEC_PER_SEC))
+		dev_err(dev, "cpu %d sibling did not exit rendezvous\n", cpu);
+
+out:
+	if (cpu == first)
+		complete(&test_thread_done);
+}
+
+/*
+ * Initiate per core test. It wakes up work queue threads on the target cpu and
+ * its sibling cpu. Once all sibling threads wake up, the scan test gets executed and
+ * wait for all sibling threads to finish the scan test.
+ */
+int do_core_test(int cpu, struct device *dev)

drivers/platform/x86/intel/ifs/runtest.c line 276

Quoted 10 lines
drivers/platform/x86/intel/ifs/runtest.c new file +10 -0
+{
+	struct ifs_work *local_work;
+	int sibling;
+	int ret = 0;
+	int i = 0;
+
+	if (!scan_enabled)
+		return -ENXIO;
+
+	cpu_hotplug_disable();

Why cpu_hotplug_disable()? Why is cpus_read_lock() not sufficient here?

drivers/platform/x86/intel/ifs/runtest.c line 288

Quoted 12 lines
drivers/platform/x86/intel/ifs/runtest.c new file +12 -0
+	if (!cpu_online(cpu)) {
+		dev_info(dev, "cannot test on the offline cpu %d\n", cpu);
+		ret = -EINVAL;
+		goto out;
+	}
+
+	reinit_completion(&test_thread_done);
+	atomic_set(&siblings_in, 0);
+	atomic_set(&siblings_out, 0);
+
+	cpu_sibl_ct = cpumask_weight(topology_sibling_cpumask(cpu));
+	local_work = kcalloc(cpu_sibl_ct, sizeof(*local_work), GFP_NOWAIT);

Why does this need GFP_NOWAIT?

drivers/platform/x86/intel/ifs/runtest.c line 314

Quoted 3 lines
drivers/platform/x86/intel/ifs/runtest.c new file +3 -0
+int ifs_setup_wq(void)
+{
+	/* Flags are to keep all the sibling cpu worker threads (of a core) in close sync */

I put that into the wishful thinking realm.

Is there anywhere a proper specification of this mechanism? The public available MSR list in the SDM is uselss.

Without proper documentation it's pretty much impossible to review this code and to think about the approach.

Thanks,

tglx

maintainer
#90 lore raw

Re: [PATCH v5 07/10] platform/x86/intel/ifs: Add scan test support

Quoted 7 lines · Thomas Gleixner

drivers/platform/x86/intel/ifs/runtest.c line 191

Quoted 4 lines · Tony Luck
drivers/platform/x86/intel/ifs/runtest.c new file +4 -0
+
+	/* wait for the sibling threads to join */
+	first = cpumask_first(topology_sibling_cpumask(cpu));
+	if (!wait_for_siblings(dev, ifsd, &siblings_in, NSEC_PER_SEC)) {

Waiting for a second with preemption disabled? Seriously?

Probably won't ever wait for a second. Any suggestions for a reasonable timeout for how long it might take before both threads on a core begin executing the target code after a pair of:

	queue_work_on(sibling, ifs_wq, &local_work[i].w);

that the request to check this core fired off?

Possibly this could be dropped, and just built into the allowable delay for the threads to execute the ACTIVATE_SCAN (31 bits of TSC cycles in the value written to the MSR). But a future scan feature doesn't include that user tuneable value.

Quoted 11 lines

drivers/platform/x86/intel/ifs/runtest.c line 199

Quoted 9 lines
drivers/platform/x86/intel/ifs/runtest.c new file +8 -0
+		preempt_enable();
+		dev_err(dev, "cpu %d sibling did not join rendezvous\n", cpu);
+		goto out;
+	}
+
+	activate.start = 0;
+	activate.stop = ifsd->valid_chunks - 1;
+	timeout = jiffies + HZ / 2;

Plus another half a second with preemption disabled. That's just insane.

Another rounded up value. Experimentally we are seeing the core scan test take aroun 50ms. The spec (I know, we haven't published the spec) says "up to 200ms".

Quoted 14 lines

drivers/platform/x86/intel/ifs/runtest.c line 210

Quoted 12 lines
drivers/platform/x86/intel/ifs/runtest.c new file +11 -0
+	retries = MAX_IFS_RETRIES;
+
+	while (activate.start <= activate.stop) {
+		if (time_after(jiffies, timeout)) {
+			status.error_code = IFS_SW_TIMEOUT;
+			break;
+		}
+
+		local_irq_disable();
+		wrmsrl(MSR_ACTIVATE_SCAN, activate.data);
+		local_irq_enable();

That local_irq_disable() solves what?

An interrupt will stop the currently running "chunk" of the scan. It is a restartable case. But the concern is that with high rate of interrupts the scan may not complete (or even make any forward progress).

Quoted 9 lines

drivers/platform/x86/intel/ifs/runtest.c line 217

Quoted 7 lines
drivers/platform/x86/intel/ifs/runtest.c new file +6 -0
+		/*
+		 * All logical CPUs on this core are now running IFS test. When it completes
+		 * execution or is interrupted, the following RDMSR gets the scan status.
+		 */
+
+		rdmsrl(MSR_SCAN_STATUS, status.data);

Wait. Is that rdmsrl() blocking execution until the scan completes?

The comment isn't quite accurate here (my fault). The WRMSR doesn't retire until the scan stops (either because it completed, or because some thing happend to stop before all chunks were processed).

So the two HT threads will continue after the WRMSR pretty much in lockstep and do the RDMSR to get the status. Both will see the same status in most cases.

Quoted 3 lines

If so, what's the stall time here? If not, how is the logic below supposed to work?

Exact time will depend how many chunks of the scan were completed, and how long they took. I see 50 ms total on current test system.

Quoted 20 lines
Quoted 18 lines
drivers/platform/x86/intel/ifs/runtest.c new file +17 -0
+		/* Some cases can be retried, give up for others */
+		if (!can_restart(status))
+			break;
+
+		if (status.chunk_num == activate.start) {
+			/* Check for forward progress */
+			if (retries-- == 0) {
+				if (status.error_code == IFS_NO_ERROR)
+					status.error_code = IFS_SW_PARTIAL_COMPLETION;
+				break;
+			}
+		} else {
+			retries = MAX_IFS_RETRIES;
+			activate.start = status.chunk_num;
+		}
+	}
+
Quoted 13 lines

drivers/platform/x86/intel/ifs/runtest.c line 276

Quoted 11 lines
drivers/platform/x86/intel/ifs/runtest.c new file +11 -0
+int do_core_test(int cpu, struct device *dev)
+{
+	struct ifs_work *local_work;
+	int sibling;
+	int ret = 0;
+	int i = 0;
+
+	if (!scan_enabled)
+		return -ENXIO;
+
+	cpu_hotplug_disable();

Why cpu_hotplug_disable()? Why is cpus_read_lock() not sufficient here?

May be left from earlier version. I'll check that cpus_read_lock() is enough.

Quoted 15 lines

drivers/platform/x86/intel/ifs/runtest.c line 288

Quoted 13 lines
drivers/platform/x86/intel/ifs/runtest.c new file +12 -0
+	if (!cpu_online(cpu)) {
+		dev_info(dev, "cannot test on the offline cpu %d\n", cpu);
+		ret = -EINVAL;
+		goto out;
+	}
+
+	reinit_completion(&test_thread_done);
+	atomic_set(&siblings_in, 0);
+	atomic_set(&siblings_out, 0);
+
+	cpu_sibl_ct = cpumask_weight(topology_sibling_cpumask(cpu));
+	local_work = kcalloc(cpu_sibl_ct, sizeof(*local_work), GFP_NOWAIT);

Why does this need GFP_NOWAIT?

It doesn't. Will fix.

Quoted 6 lines

drivers/platform/x86/intel/ifs/runtest.c line 314

Quoted 4 lines
drivers/platform/x86/intel/ifs/runtest.c new file +3 -0
+int ifs_setup_wq(void)
+{
+	/* Flags are to keep all the sibling cpu worker threads (of a core) in close sync */

I put that into the wishful thinking realm.

Can change to "... to try to keep ..."

Quoted 6 lines

Is there anywhere a proper specification of this mechanism? The public available MSR list in the SDM is uselss.

Without proper documentation it's pretty much impossible to review this code and to think about the approach.

Step 1 (at boot or driver load) is loading the scan tests into BIOS reserved memory. I will fix up the bits where you pointed out problems there.

Step 2 is the run time test of each core. That requires the near simultaneous execution of:

	wrmsrl(MSR_ACTIVATE_SCAN, activate.data);

on all HT threads on the core. Trivial on parts that do not support HT, or where it is disabled in BIOS. The above code is trying to achieve this "parallel" execution.
The follow-on :

	rdmsrl(MSR_SCAN_STATUS, status.data);

doesn't have to be synchronized ... but handy to do so for when not all chunks were processed and need to loop back to run another activate_scan to continue starting from the interrupted chunk. In the lab, this seems common ... when scanning all cores many of them complete all chunks in a single bite, but several take 2-3 times around the loop before completing.

As noted above I'm seeing a core test take around 50ms (but spec says up to 200ms). In some environments that doesn't require any special application or system reconfiguration. It's not much different from time-slicing when you are running more processes (or guests) than you have CPUs. So sysadmins in those environments can use this driver to cylce through cores testing each in turn without any extra steps.

You've pointed out that the driver disables preemption for insanely long amounts of time ... to use this driver to test cores on a system running applications where that is an issue will require additonal steps to migrate latency critical applications to a different core while the test is in progess, also re-direct interrupts. That seems well beyond the scope of what is possible in a driver without all the information about what workloads are running to pick a new temporary home for processes and interrupts while the core is being tested.

-Tony

#91 lore raw

Re: [PATCH v5 07/10] platform/x86/intel/ifs: Add scan test support

Quoted 9 lines · Tony
Quoted 7 lines · Thomas Gleixner

drivers/platform/x86/intel/ifs/runtest.c line 191

Quoted 4 lines · Tony Luck
drivers/platform/x86/intel/ifs/runtest.c new file +4 -0
+
+	/* wait for the sibling threads to join */
+	first = cpumask_first(topology_sibling_cpumask(cpu));
+	if (!wait_for_siblings(dev, ifsd, &siblings_in, NSEC_PER_SEC)) {

Waiting for a second with preemption disabled? Seriously?

Quoted 7 lines

Probably won't ever wait for a second. Any suggestions for a reasonable timeout for how long it might take before both threads on a core begin executing the target code after a pair of:

	queue_work_on(sibling, ifs_wq, &local_work[i].w);

that the request to check this core fired off?

The real question is why you try to rendevouz CPUs via work queues.

The kernel has a well established mechanism to do CPU rendevouz already:

stomp_machine()

We all hate it with a passion, but it is already doing what you are trying to achieve and as the stopper threads run with high priority they are not subject to arbitrary scheduling delays which make one CPU wait for a long time with preemption disabled.

Quoted 5 lines
Quoted 1 line

Plus another half a second with preemption disabled. That's just insane.

Another rounded up value. Experimentally we are seeing the core scan test take aroun 50ms. The spec (I know, we haven't published the spec) says "up to 200ms".

That's daft. Both the 200ms and the non-published spec, though the latter is worse because it's wasting everyones time.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/platform/x86/intel/ifs/runtest.c new file +5 -0
+	retries = MAX_IFS_RETRIES;
+
+	while (activate.start <= activate.stop) {
+		if (time_after(jiffies, timeout)) {
+			status.error_code = IFS_SW_TIMEOUT;
Quoted 8 lines

drivers/platform/x86/intel/ifs/runtest.c line 210

Quoted 6 lines
drivers/platform/x86/intel/ifs/runtest.c new file +6 -0
+			break;
+		}
+
+		local_irq_disable();
+		wrmsrl(MSR_ACTIVATE_SCAN, activate.data);
+		local_irq_enable();

That local_irq_disable() solves what?

Quoted 4 lines

An interrupt will stop the currently running "chunk" of the scan. It is a restartable case. But the concern is that with high rate of interrupts the scan may not complete (or even make any forward progress).

What about NMI/MCE? What happens if the scan triggers an MCE?

If the scan is stopped, will it be stopped on both hyperthreads?

What happens in the case, when one of the CPUs is slightly behind the other:

     CPU A                      CPU B
     local_irq_disable()
     wrmsrl(...);
                                <- Interrupt
                                   handle_irq();
                                local_irq_disable();
                                wrmsrl(...);

Will the interrupt which hit CPU B _after_ CPU A issued the MSR write stop the operation on CPU A and make it return?

If not, then how long is CPU A waiting for CPU B to join the party?

Quoted 9 lines
Quoted 8 lines

drivers/platform/x86/intel/ifs/runtest.c line 217

Quoted 6 lines
drivers/platform/x86/intel/ifs/runtest.c new file +6 -0
+		/*
+		 * All logical CPUs on this core are now running IFS test. When it completes
+		 * execution or is interrupted, the following RDMSR gets the scan status.
+		 */
+
+		rdmsrl(MSR_SCAN_STATUS, status.data);

Wait. Is that rdmsrl() blocking execution until the scan completes?

Quoted 3 lines

The comment isn't quite accurate here (my fault). The WRMSR doesn't retire until the scan stops (either because it completed, or because some thing happend to stop before all chunks were processed).

I suspected that due to the non-commented local_irq_disable() ...

Quoted 5 lines
Quoted 2 lines

If so, what's the stall time here? If not, how is the logic below supposed to work?

Exact time will depend how many chunks of the scan were completed, and how long they took. I see 50 ms total on current test system.

Per chunk or for all chunks? The interresting part is not the total time, the interresting part is the time per chunk.

Quoted 5 lines
Quoted 5 lines

Is there anywhere a proper specification of this mechanism? The public available MSR list in the SDM is uselss.

Without proper documentation it's pretty much impossible to review this code and to think about the approach.

...

Quoted 8 lines

Step 2 is the run time test of each core. That requires the near simultaneous execution of:

	wrmsrl(MSR_ACTIVATE_SCAN, activate.data);

on all HT threads on the core. Trivial on parts that do not support HT, or where it is disabled in BIOS. The above code is trying to achieve this "parallel" execution.

How is that supposed to work on a system which has HT enabled in BIOS, but disabled on the kernel command line or via /sys/..../smt/control or when a HT sibling is offlined temporarily?

I assume it cannot work, but I can't see anything which handles those cases.

Quoted 10 lines

The follow-on :

	rdmsrl(MSR_SCAN_STATUS, status.data);

doesn't have to be synchronized ... but handy to do so for when not all chunks were processed and need to loop back to run another activate_scan to continue starting from the interrupted chunk. In the lab, this seems common ... when scanning all cores many of them complete all chunks in a single bite, but several take 2-3 times around the loop before completing.

Is there a timeout for restarting an interrupted chunk?

Quoted 7 lines

As noted above I'm seeing a core test take around 50ms (but spec says up to 200ms). In some environments that doesn't require any special application or system reconfiguration. It's not much different from time-slicing when you are running more processes (or guests) than you have CPUs. So sysadmins in those environments can use this driver to cylce through cores testing each in turn without any extra steps.

Quoted 8 lines

You've pointed out that the driver disables preemption for insanely long amounts of time ... to use this driver to test cores on a system running applications where that is an issue will require additonal steps to migrate latency critical applications to a different core while the test is in progess, also re-direct interrupts. That seems well beyond the scope of what is possible in a driver without all the information about what workloads are running to pick a new temporary home for processes and interrupts while the core is being tested.

I assume that's all described in Documentation/x86/intel-ifs.rst, which was in patch 11/10 and unfortunately got lost in the intertubes.

Coming back to that rendevouz mechanism.

As far as I understand it, but of course my implementation of

   # pdforacle --remote=tony --condense sekrit-ifs-spec.pdf

might be suboptimal, the only hard requirement is to start the scan for a particular chunk on all HT threads roughly at the same time.

But there is no hard requirement that the individual chunks are started right after each other or that a restart of an for whatever reason interrupted chunk happens 'immediately'.

If that's the case and anything else would be an insanity, then you can do something like this:

static DEFINE_PER_CPU(struct ifs_status, ifs_status);

int do_test(int cpu, struct device *dev)

{
        const struct cpumask *mask;
        struct ifsdata data;

        cpus_read_lock();
        mask = topology_sibling_cpumask(cpu);
        if (!sane(mask))
        	goto fail;

        for_each_cpu(sibling, mask)
        	init_ifs_status(sibling);

        init_data(data, dev);

        while (data.chunk < data.max_chunks) {
        	ret = stomp_cpumask(mask, doscan, data);

                if (!ret) {
                        data.chunk++;
                	continue;
                }

                // Analyze per CPU ifs_status to either
                // restart or abort with proper information
                // about the reason to abort
                .....
        }
        ....

We don't have stomp_cpumask() today, but that's trivial enough to implement. Yes, we want to avoid expanding stomp_machine(), but trying to resemble stomp_machine() with work queues is worse by several orders of magnitude.

doscan() will boil down to:

    wrmsrl(RUN_SCAM, data->chunk);
    rdmsrl(STA_SCAM, status);
    this_cpu_write(ifs_status, status);
    return status ? -ECRAP : 0;

plus the required commentry which will be an order of magnitude more lines than the actual code above.

Thanks,

tglx

#92 lore raw

Re: [PATCH v5 07/10] platform/x86/intel/ifs: Add scan test support

Quoted 2 lines · Thomas Gleixner

We don't have stomp_cpumask() today, but that's trivial enough to implement.

I don't think we want to gift people a random cpumask stop_machine(), but here's one that stops a core. It runs the @fn on every cpu since I thought to have understood that was the requirement for this muck.

*completely* untestededed.

kernel/stop_machine.c +28 -0
index 6da7b91af353..2e7324e44e38 100644
@@ -631,6 +631,34 @@ int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus)
 }
 EXPORT_SYMBOL_GPL(stop_machine);
 
+/*
+ * stop_core_cpuslocked - stop_machine a core
+ * @cpu: any cpu in the targeted core
+ * @fn: the function to run
+ * @data: the data ptr for @fn()
+ *
+ * RETURNS:
+ * 0 if all executions of @fn returned 0, any non zero return value if any
+ * returned non zero.
+ */
+int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data)
+{
+	const struct cpumask *smt_mask = cpu_smt_mask(cpu);
+
+	struct multi_stop_data msdata = {
+		.fn = fn,
+		.data = data,
+		.num_threads = cpumask_weight(smt_mask);
+		.active_cpus = smt_mask,
+	};
+
+	lockdep_assert_cpus_held();
+
+	/* Set the initial state and stop all online cpus. */
+	set_state(&msdata, MULTI_STOP_PREPARE);
+	return stop_cpus(smt_mask, multi_cpu_stop, &msdata);
+}
+
 /**
  * stop_machine_from_inactive_cpu - stop_machine() from inactive CPU
  * @fn: the function to run
#93 lore raw

Re: [PATCH v5 07/10] platform/x86/intel/ifs: Add scan test support

Quoted 5 lines · Peter Zijlstra
Quoted 2 lines · Thomas Gleixner

We don't have stomp_cpumask() today, but that's trivial enough to implement.

I don't think we want to gift people a random cpumask stop_machine(),

Fair enough.

Quoted 2 lines

but here's one that stops a core. It runs the @fn on every cpu since I thought to have understood that was the requirement for this muck.

Yes.

Quoted 1 line

*completely* untestededed.

Looks about right neverthelessesseess.

maintainer
#94 lore raw

Re: [PATCH v5 07/10] platform/x86/intel/ifs: Add scan test support

Quoted 9 lines · Thomas Gleixner
Quoted 5 lines · Peter Zijlstra
Quoted 2 lines · Thomas Gleixner

We don't have stomp_cpumask() today, but that's trivial enough to implement.

I don't think we want to gift people a random cpumask stop_machine(),

Fair enough.

Quoted 8 lines
Quoted 2 lines

but here's one that stops a core. It runs the @fn on every cpu since I thought to have understood that was the requirement for this muck.

Yes.

Quoted 1 line

*completely* untestededed.

Looks about right neverthelessesseess.

Close enough. I made these changes:

1) Added EXPORT_SYMBOL_GPL()
2) Added protoype in <linux/stop_machine.h>
3) Moved the kerneldoc comment to the header (for some reason the other stop* functions document there).
4) Edited that kerneldoc a bit <<<< NEEDS REVIEW >>>
5) Changed a ';' to a ',' to make it compile.

With that it works, and will do exactly what I need (with less code in the IFS driver by the look of things).

A couple of thousand tests shows it works. The two threads arrive within 20 TSC cycles of each other 60% of the time, but I have some outliers up to 654 cycles ... which is plenty close enough.

Patch now looks like this. Author credit to Peter ... are you willing to add a Signed-off-by to stop checkpatch from whining at me?

There isn't a "Something-similar-suggested-by:" tag to credit Thomas with this. Perhaps "Inspired-by:"?

-Tony

From df5ca8024997d3d782978d154cfbff5147f451ad Mon Sep 17 00:00:00 2001
From: Peter Zijlstra <[email protected]>
Date: Thu, 5 May 2022 08:55:09 -0700
Subject: [PATCH] stop_machine: Add stop_core_cpuslocked() for per-core
operations

Hardware core level testing features require near simultaneous execution of WRMSR instructions on all threads of a core to initiate a test.

Provide a customized cut down version of stop_machine_cpuslocked() that just operates on the threads of a single core.

---
 include/linux/stop_machine.h | 16 ++++++++++++++++
 kernel/stop_machine.c        | 19 +++++++++++++++++++
 2 files changed, 35 insertions(+)
include/linux/stop_machine.h +16 -0
index 46fb3ebdd16e..ea7a74ea7389 100644
@@ -124,6 +124,22 @@ int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus);
  */
 int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus);
 
+/**
+ * stop_core_cpuslocked: - stop all threads on just one core
+ * @cpu: any cpu in the targeted core
+ * @fn: the function to run
+ * @data: the data ptr for @fn()
+ *
+ * Same as above, but instead of every CPU, only the logical CPUs of a
+ * single core are affected.
+ *
+ * Context: Must be called from within a cpus_read_lock() protected region.
+ *
+ * Return: 0 if all executions of @fn returned 0, any non zero return
+ * value if any returned non zero.
+ */
+int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data);
+
 int stop_machine_from_inactive_cpu(cpu_stop_fn_t fn, void *data,
 				   const struct cpumask *cpus);
 #else	/* CONFIG_SMP || CONFIG_HOTPLUG_CPU */
kernel/stop_machine.c +19 -0
index cbc30271ea4d..579761729836 100644
@@ -633,6 +633,25 @@ int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus)
 }
 EXPORT_SYMBOL_GPL(stop_machine);
 
+int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data)
+{
+	const struct cpumask *smt_mask = cpu_smt_mask(cpu);
+
+	struct multi_stop_data msdata = {
+		.fn = fn,
+		.data = data,
+		.num_threads = cpumask_weight(smt_mask),
+		.active_cpus = smt_mask,
+	};
+
+	lockdep_assert_cpus_held();
+
+	/* Set the initial state and stop all online cpus. */
+	set_state(&msdata, MULTI_STOP_PREPARE);
+	return stop_cpus(smt_mask, multi_cpu_stop, &msdata);
+}
+EXPORT_SYMBOL_GPL(stop_core_cpuslocked);
+
 /**
  * stop_machine_from_inactive_cpu - stop_machine() from inactive CPU
  * @fn: the function to run
Signature · 1 line
2.35.1
#95 lore raw

Re: [PATCH v5 07/10] platform/x86/intel/ifs: Add scan test support

Quoted 2 lines · Tony

Patch now looks like this. Author credit to Peter ... are you willing to add a Signed-off-by to stop checkpatch from whining at me?

sure, see below.

Quoted 2 lines

There isn't a "Something-similar-suggested-by:" tag to credit Thomas with this. Perhaps "Inspired-by:"?

I'm all for creative one off tags, there's some marvelous ones in the tree, but we always need more :-)

Quoted 9 lines

-Tony

From df5ca8024997d3d782978d154cfbff5147f451ad Mon Sep 17 00:00:00 2001
From: Peter Zijlstra <[email protected]>
Date: Thu, 5 May 2022 08:55:09 -0700
Subject: [PATCH] stop_machine: Add stop_core_cpuslocked() for per-core
operations

Quoted 6 lines

Hardware core level testing features require near simultaneous execution of WRMSR instructions on all threads of a core to initiate a test.

Provide a customized cut down version of stop_machine_cpuslocked() that just operates on the threads of a single core.

Quoted 66 lines
---
 include/linux/stop_machine.h | 16 ++++++++++++++++
 kernel/stop_machine.c        | 19 +++++++++++++++++++
 2 files changed, 35 insertions(+)
include/linux/stop_machine.h +16 -0
index 46fb3ebdd16e..ea7a74ea7389 100644
@@ -124,6 +124,22 @@ int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus);
  */
 int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus);
 
+/**
+ * stop_core_cpuslocked: - stop all threads on just one core
+ * @cpu: any cpu in the targeted core
+ * @fn: the function to run
+ * @data: the data ptr for @fn()
+ *
+ * Same as above, but instead of every CPU, only the logical CPUs of a
+ * single core are affected.
+ *
+ * Context: Must be called from within a cpus_read_lock() protected region.
+ *
+ * Return: 0 if all executions of @fn returned 0, any non zero return
+ * value if any returned non zero.
+ */
+int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data);
+
 int stop_machine_from_inactive_cpu(cpu_stop_fn_t fn, void *data,
 				   const struct cpumask *cpus);
 #else	/* CONFIG_SMP || CONFIG_HOTPLUG_CPU */
kernel/stop_machine.c +19 -0
index cbc30271ea4d..579761729836 100644
@@ -633,6 +633,25 @@ int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus)
 }
 EXPORT_SYMBOL_GPL(stop_machine);
 
+int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data)
+{
+	const struct cpumask *smt_mask = cpu_smt_mask(cpu);
+
+	struct multi_stop_data msdata = {
+		.fn = fn,
+		.data = data,
+		.num_threads = cpumask_weight(smt_mask),
+		.active_cpus = smt_mask,
+	};
+
+	lockdep_assert_cpus_held();
+
+	/* Set the initial state and stop all online cpus. */
+	set_state(&msdata, MULTI_STOP_PREPARE);
+	return stop_cpus(smt_mask, multi_cpu_stop, &msdata);
+}
+EXPORT_SYMBOL_GPL(stop_core_cpuslocked);
+
 /**
  * stop_machine_from_inactive_cpu - stop_machine() from inactive CPU
  * @fn: the function to run
Signature · 1 line
2.35.1
maintainer
#96 lore raw

PATCH v5 8/10 platform/x86/intel/ifs: Add IFS sysfs interface

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

Implement sysfs interface to trigger ifs test for a specific cpu. Additional interfaces related to checking the status of the scan test and seeing the version of the loaded IFS binary are also added.

The basic usage is as below.
- To start test, for example on cpu5:
echo 5 > /sys/devices/platform/intel_ifs/run_test
- To see the status of the last test
cat /sys/devices/platform/intel_ifs/status
- To see the version of the loaded scan binary cat /sys/devices/platform/intel_ifs/image_version

---
 drivers/platform/x86/intel/ifs/Makefile |   2 +-
 drivers/platform/x86/intel/ifs/core.c   |   6 +
 drivers/platform/x86/intel/ifs/ifs.h    |   3 +
 drivers/platform/x86/intel/ifs/sysfs.c  | 147 ++++++++++++++++++++++++
 4 files changed, 157 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/sysfs.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index cedcb103f860..30f035ef5581 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
 
-intel_ifs-objs			:= core.o load.o runtest.o
+intel_ifs-objs			:= core.o load.o runtest.o sysfs.o
drivers/platform/x86/intel/ifs/core.c +6 -0
index d408290480c7..489b77645b5e 100644
@@ -3,6 +3,7 @@
 
 #include <linux/module.h>
 #include <linux/kdev_t.h>
+#include <linux/semaphore.h>
 
 #include <asm/cpu_device_id.h>
 
@@ -50,9 +51,13 @@ static int __init ifs_init(void)
 	if (ifs_setup_wq())
 		return -ENOMEM;
 
+	ifs_device.misc.groups = ifs_get_groups();
+
 	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);
+		up(&ifs_sem);
 	} else {
 		ifs_destroy_wq();
 		return -ENODEV;
@@ -63,6 +68,7 @@ static int __init ifs_init(void)
 
 static void __exit ifs_exit(void)
 {
+
 	misc_deregister(&ifs_device.misc);
 	ifs_destroy_wq();
 }
drivers/platform/x86/intel/ifs/ifs.h +3 -0
index 31e58a36ab75..ddcdeda9016a 100644
@@ -116,5 +116,8 @@ void ifs_load_firmware(struct device *dev);
 int ifs_setup_wq(void);
 void ifs_destroy_wq(void);
 int do_core_test(int cpu, struct device *dev);
+const struct attribute_group **ifs_get_groups(void);
+
+extern struct semaphore ifs_sem;
 
 #endif
drivers/platform/x86/intel/ifs/sysfs.c new file +147 -0

147 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#97 lore raw

PATCH v5 9/10 trace: platform/x86/intel/ifs: Add trace point to track Intel IFS operations

In reply to Tony Luck

Add tracing support which may be useful for debugging systems that fail to complete In Field Scan tests.

---
 MAINTAINERS                              |  1 +
 drivers/platform/x86/intel/ifs/runtest.c |  5 ++++
 include/trace/events/intel_ifs.h         | 38 ++++++++++++++++++++++++
 3 files changed, 44 insertions(+)
 create mode 100644 include/trace/events/intel_ifs.h
MAINTAINERS +1 -0
index bc902d0c64d2..f024b8bf1053 100644
@@ -9865,6 +9865,7 @@ R:	Ashok Raj <[email protected]>
 R:	Tony Luck <[email protected]>
 S:	Maintained
 F:	drivers/platform/x86/intel/ifs
+F:	include/trace/events/intel_ifs.h
 
 INTEL INTEGRATED SENSOR HUB DRIVER
 M:	Srinivas Pandruvada <[email protected]>
drivers/platform/x86/intel/ifs/runtest.c +5 -0
index c30cc9c95b4f..d6cb5d9e44c2 100644
@@ -23,6 +23,9 @@ static atomic_t siblings_out;
 static int cpu_sibl_ct;
 static bool scan_enabled = true;
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/intel_ifs.h>
+
 struct ifs_work {
 	struct work_struct w;
 	struct device *dev;
@@ -216,6 +219,8 @@ static void ifs_work_func(struct work_struct *work)
 
 		rdmsrl(MSR_SCAN_STATUS, status.data);
 
+		trace_ifs_status(activate, status);
+
 		/* Some cases can be retried, give up for others */
 		if (!can_restart(status))
 			break;
include/trace/events/intel_ifs.h new file +38 -0
new file mode 100644
index 000000000000..0611f370cb37
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM intel_ifs
+
+#if !defined(_TRACE_IFS_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_IFS_H
+
+#include <linux/ktime.h>
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(ifs_status,
+
+	TP_PROTO(union ifs_scan activate, union ifs_status status),
+
+	TP_ARGS(activate, status),
+
+	TP_STRUCT__entry(
+		__field(	u64,	status	)
+		__field(	u8,	start	)
+		__field(	u8,	stop	)
+	),
+
+	TP_fast_assign(
+		__entry->start	= activate.start;
+		__entry->stop	= activate.stop;
+		__entry->status	= status.data;
+	),
+
+	TP_printk("start: %.2x, stop: %.2x, status: %llx",
+		__entry->start,
+		__entry->stop,
+		__entry->status)
+);
+
+#endif /* _TRACE_IFS_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
Signature · 1 line
2.35.1
maintainer
#98 lore raw

PATCH v5 10/10 platform/x86/intel/ifs: add ABI documentation for IFS

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

Add the sysfs attributes in ABI/testing for In-Field Scan.

---
 .../ABI/testing/sysfs-platform-intel-ifs      | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-ifs
Documentation/ABI/testing/sysfs-platform-intel-ifs new file +39 -0
new file mode 100644
index 000000000000..486d6d2ff8a0
@@ -0,0 +1,39 @@
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/run_test
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Write <cpu#> to trigger IFS test for one online core.
+		Note that the test is per core. The cpu# can be
+		for any thread on the core. Running on one thread
+		completes the test for the core containing that thread.
+		Example: to test the core containing cpu5: echo 5 >
+		/sys/devices/platform/intel_ifs.<N>/run_test
+
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/status
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	The status of the last test. It can be one of "pass", "fail"
+		or "untested".
+
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/details
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Additional information regarding the last test. The details file reports
+		the hex value of the SCAN_STATUS MSR. Note that the error_code field
+		may contain driver defined software code not defined in the Intel SDM.
+
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/image_version
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Version (hexadecimal) of loaded IFS binary image. If no scan image
+		is loaded reports "none".
+
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/reload
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Write "1" (or "y" or "Y") to reload the IFS image from
+		/lib/firmware/intel/ifs/ff-mm-ss.scan.
Signature · 1 line
2.35.1
#99 lore raw
In reply to Tony Luck
Quoted 9 lines · Tony Luck

Hopefully this is close enough to done to begin discussion on which maintainer tree will take this series.

Choices:
1) Hans/Mark take it into the platform-drivers tree Needs an Ack from x86 maintainers on parts 1 & 2
2) X86 maintainers take it into TIP
Needs Ack from Hans/Mark on parts 2-10

Quoted 3 lines

TL;DR this driver loads scan test files that can check whether silicon in a CPU core is still running correctly. It is expected that these tests would be run several times per day to catch problems as silicon ages.

Much nicer and simpler as compared to the first version submitted, thanks for sticking with it. The diff seems about 1/3 smaller from the first version sent out, peer-review works :)

maintainer
#100 lore raw
Quoted 5 lines

Much nicer and simpler as compared to the first version submitted, thanks for sticking with it. The diff seems about 1/3 smaller from the first version sent out, peer-review works :)

Thanks for your patience leading me to a much better driver.

-Tony

Acked-by on the v5 series
#101 lore raw
In reply to Tony Luck

Hi,

Quoted 8 lines · Tony Luck

Hopefully this is close enough to done to begin discussion on which maintainer tree will take this series.

Choices:
1) Hans/Mark take it into the platform-drivers tree Needs an Ack from x86 maintainers on parts 1 & 2
2) X86 maintainers take it into TIP
Needs Ack from Hans/Mark on parts 2-10

I've taken a quick look at the entire series and it looks good to me.

I'm fine with this entire series getting merged through the TIP tree, here is my ack for merging the drivers/platform/x86 bits through the TIP tree:

Regards,

Hans

Quoted 61 lines

TL;DR this driver loads scan test files that can check whether silicon in a CPU core is still running correctly. It is expected that these tests would be run several times per day to catch problems as silicon ages.

Changes since v4:

Greg Kroah-Hartman
------------------
"Cute way to do this, but I don't see you ever have any more devices added to this list in this series."

Removed the enum, arrays, loops, and count of test types discovered. Now just check for enumeration of the single test type that is being deployed on Sapphire Rapids.

Jithu Joseph (7):
x86/microcode/intel: Expose collect_cpu_info_early() for IFS platform/x86/intel/ifs: Read IFS firmware image platform/x86/intel/ifs: Check IFS Image sanity platform/x86/intel/ifs: Authenticate and copy to secured memory platform/x86/intel/ifs: Add scan test support platform/x86/intel/ifs: Add IFS sysfs interface platform/x86/intel/ifs: add ABI documentation for IFS

Tony Luck (3):
x86/msr-index: Define INTEGRITY_CAPABILITIES MSR platform/x86/intel/ifs: Add stub driver for In-Field Scan
trace: platform/x86/intel/ifs: Add trace point to track Intel IFS
operations

 .../ABI/testing/sysfs-platform-intel-ifs      |  39 ++
 MAINTAINERS                                   |   8 +
 arch/x86/include/asm/cpu.h                    |  18 +
 arch/x86/include/asm/msr-index.h              |   7 +
 arch/x86/kernel/cpu/intel.c                   |  32 ++
 arch/x86/kernel/cpu/microcode/intel.c         |  59 +---
 drivers/platform/x86/intel/Kconfig            |   1 +
 drivers/platform/x86/intel/Makefile           |   1 +
 drivers/platform/x86/intel/ifs/Kconfig        |  13 +
 drivers/platform/x86/intel/ifs/Makefile       |   3 +
 drivers/platform/x86/intel/ifs/core.c         |  80 +++++
 drivers/platform/x86/intel/ifs/ifs.h          | 123 +++++++
 drivers/platform/x86/intel/ifs/load.c         | 262 ++++++++++++++
 drivers/platform/x86/intel/ifs/runtest.c      | 332 ++++++++++++++++++
 drivers/platform/x86/intel/ifs/sysfs.c        | 147 ++++++++
 include/trace/events/intel_ifs.h              |  38 ++
 16 files changed, 1111 insertions(+), 52 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-ifs
 create mode 100644 drivers/platform/x86/intel/ifs/Kconfig
 create mode 100644 drivers/platform/x86/intel/ifs/Makefile
 create mode 100644 drivers/platform/x86/intel/ifs/core.c
 create mode 100644 drivers/platform/x86/intel/ifs/ifs.h
 create mode 100644 drivers/platform/x86/intel/ifs/load.c
 create mode 100644 drivers/platform/x86/intel/ifs/runtest.c
 create mode 100644 drivers/platform/x86/intel/ifs/sysfs.c
 create mode 100644 include/trace/events/intel_ifs.h

base-commit: af2d861d4cd2a4da5137f795ee3509e6f944a25b

maintainer
#102 lore raw
Quoted 7 lines

I've taken a quick look at the entire series and it looks good to me.

I'm fine with this entire series getting merged through the TIP tree, here is my ack for merging the drivers/platform/x86 bits through the TIP tree:

Hans,

Thanks for looking, and double thanks for the "Ack".

-Tony

maintainer
#103 lore raw
In reply to Hans de Goede
Quoted 2 lines · Hans de Goede

I'm fine with this entire series getting merged through the TIP tree,

Hmm, so looking at the diffstat - the majority of that is drivers/platform/x86/ so I guess your tree would be better suited for it...

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#104 lore raw
Quoted 3 lines

Hmm, so looking at the diffstat - the majority of that is drivers/platform/x86/ so I guess your tree would be better suited for it...

Can you check that I fixed the issues in part 01/10 that you reported in v3 of this series and give an Ack to Hans?

-Tony

maintainer
#105 lore raw
Quoted 2 lines

Can you check that I fixed the issues in part 01/10 that you reported in v3 of this series and give an Ack to Hans?

Oops ... reading e-mail out of order ... I see that you already gave the Ack. Thanks!

-Tony

#106 lore raw
In reply to Borislav Petkov

Hi,

Quoted 7 lines · Borislav Petkov
Quoted 2 lines · Hans de Goede

I'm fine with this entire series getting merged through the TIP tree,

Hmm, so looking at the diffstat - the majority of that is drivers/platform/x86/ so I guess your tree would be better suited for it...

Ok, that also works for me and I see that the few arch/x86 already have Ack-s / Reviewed-by-s from you / tglx .

I'll give it some more time for review for v6 and then pick up v6 (or v7 if review leads to more changes).

Regards,

Hans

maintainer
#107 lore raw
Quoted 2 lines

I'll give it some more time for review for v6 and then pick up v6 (or v7 if review leads to more changes).

Hans,

Thomas has found one substantive problem, and a few minor things (so far ... he still seems to be working through v6).

So there will be a v7. Likely early next week. Is that OK? Do you still take patches after -rc6?

-Tony

#108 lore raw

Hi,

Quoted 7 lines · Tony
Quoted 2 lines

I'll give it some more time for review for v6 and then pick up v6 (or v7 if review leads to more changes).

Hans,

Thomas has found one substantive problem, and a few minor things (so far ... he still seems to be working through v6).

Ok.

Quoted 1 line

So there will be a v7. Likely early next week. Is that OK?

That is fine.

Quoted 1 line

Do you still take patches after -rc6?

If the patches are send soon (1-2 days) after rc6 I can still take them.

Regards,

Hans

maintainer
#109 lore raw
Quoted 3 lines
Quoted 1 line

Do you still take patches after -rc6?

If the patches are send soon (1-2 days) after rc6 I can still take them.

Hans,

V7 was posted Friday. It survived my weekend testing, and another round of tglx scrutiny (ending with his "Reviewed-by" on the latter parts of the series.

Let me know if there is anything else you need to get them applied.

Thanks

-Tony

#110 lore raw

Hi,

Quoted 10 lines · Tony
Quoted 3 lines
Quoted 1 line

Do you still take patches after -rc6?

If the patches are send soon (1-2 days) after rc6 I can still take them.

Hans,

V7 was posted Friday. It survived my weekend testing, and another round of tglx scrutiny (ending with his "Reviewed-by" on the latter parts of the series.

Let me know if there is anything else you need to get them applied.

From my side everything looks good. I plan to merge this into my review-hans (*) branch coming Wednesday.

Regards,

Hans

*) And then from there move it to for-next once the build bots have had a chance to play with it

maintainer
#111 lore raw

v6 cover Introduce In Field Scan driver

In reply to Tony Luck

TL;DR this driver loads scan test files that can check whether silicon in a CPU core is still running correctly. It is expected that these tests would be run several times per day to catch problems as silicon ages.

Changes since v5:

Added various Reviewed tags. If anyone wants to take one or more back in the light of changes listed below, please speak up.

Thomas Gleixner
---------------
03 "So checking for Intel Fam6 ANYMODEL and X86_FEATURE_CORE_CAPABILITIES is
sufficient, no?"

Longer explanation in earlier e-mail ... but the family/model/stepping check is needed. No change.

04 "Why is ifs_load_firmware() not returning an error to the caller?"

In most cases the return isn't useful. But this did prompt a change to make sure "echo 1 > reload" does give an error if the load fails.

05 "The above struct is nicely tabular. Can we have that here too please?"

Added <TAB>s to ifs_data structure to make it equally pretty.

06 "Setting the authenticated indicator _before_ actually doing the authentication is just wrong. It does not matter in this case, but it's still making my eyes bleed."

Moved indicator to after success has been checked.

06 "Why has this to be a smp function call? Just because it's conveniant? This is nothing urgent and no hotpath, so this really can use queue_work_on()."

Even simpler is schedule_work_on() [since other changes mean that the driver no longer allocates a work queue.

07 "Waiting for a second with preemption disabled? Seriously?"
"Plus another half a second with preemption disabled. That's just insane." "That local_irq_disable() solves what?"
"Why cpu_hotplug_disable()? Why is cpus_read_lock() not sufficient here?" "Why does this need GFP_NOWAIT?"
"I put that into the wishful thinking realm"
"The real question is why you try to rendevouz CPUs via work queues." "pseudo-code to use stomp_machine()"

PeterZ contributed a neatly tailored for this usage "stop_core_cpuslocked()" function that works beautifully. See part 0003 of this new series. That meant all of the code that triggered the above comments has gone.

Tony Luck
---------
Noticed unnecessary casts from u8 to u32 in the checksum calculation in load.c. Fixed.

Changed the tracepoint to include the CPU number of the core being tested (the tracepoint otherwise just tells you which CPU is executing the driver code and executing "stop_core_cpuslocked()" to do the actual work on the target CPUs.

Dropped the msec_to_tsc() function that was used to initialize activate.delay. Just use a #define of 100000 cycles (two orders of magnitude bigger than I saw for the slew between the two threads executing the "stop_core_cpuslocked()" target function ... but not too insane so if the threads do not sync, we give up quickly).

Jithu Joseph (7):
x86/microcode/intel: Expose collect_cpu_info_early() for IFS platform/x86/intel/ifs: Read IFS firmware image platform/x86/intel/ifs: Check IFS Image sanity platform/x86/intel/ifs: Authenticate and copy to secured memory platform/x86/intel/ifs: Add scan test support platform/x86/intel/ifs: Add IFS sysfs interface platform/x86/intel/ifs: add ABI documentation for IFS

Peter Zijlstra (1):
stop_machine: Add stop_core_cpuslocked() for per-core operations

Tony Luck (3):
x86/msr-index: Define INTEGRITY_CAPABILITIES MSR platform/x86/intel/ifs: Add stub driver for In-Field Scan
trace: platform/x86/intel/ifs: Add trace point to track Intel IFS
operations

 .../ABI/testing/sysfs-platform-intel-ifs      |  39 +++
 MAINTAINERS                                   |   8 +
 arch/x86/include/asm/cpu.h                    |  18 ++
 arch/x86/include/asm/msr-index.h              |   7 +
 arch/x86/kernel/cpu/intel.c                   |  32 +++
 arch/x86/kernel/cpu/microcode/intel.c         |  59 +---
 drivers/platform/x86/intel/Kconfig            |   1 +
 drivers/platform/x86/intel/Makefile           |   1 +
 drivers/platform/x86/intel/ifs/Kconfig        |  13 +
 drivers/platform/x86/intel/ifs/Makefile       |   3 +
 drivers/platform/x86/intel/ifs/core.c         |  74 +++++
 drivers/platform/x86/intel/ifs/ifs.h          | 124 ++++++++
 drivers/platform/x86/intel/ifs/load.c         | 266 ++++++++++++++++++
 drivers/platform/x86/intel/ifs/runtest.c      | 255 +++++++++++++++++
 drivers/platform/x86/intel/ifs/sysfs.c        | 149 ++++++++++
 include/linux/stop_machine.h                  |  16 ++
 include/trace/events/intel_ifs.h              |  41 +++
 kernel/stop_machine.c                         |  19 ++
 18 files changed, 1073 insertions(+), 52 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-ifs
 create mode 100644 drivers/platform/x86/intel/ifs/Kconfig
 create mode 100644 drivers/platform/x86/intel/ifs/Makefile
 create mode 100644 drivers/platform/x86/intel/ifs/core.c
 create mode 100644 drivers/platform/x86/intel/ifs/ifs.h
 create mode 100644 drivers/platform/x86/intel/ifs/load.c
 create mode 100644 drivers/platform/x86/intel/ifs/runtest.c
 create mode 100644 drivers/platform/x86/intel/ifs/sysfs.c
 create mode 100644 include/trace/events/intel_ifs.h

base-commit: 672c0c5173427e6b3e2a9bbb7be51ceeec78093a

Signature · 1 line
2.35.1
maintainer
#112 lore raw

PATCH v6 1/11 x86/microcode/intel: Expose collect_cpu_info_early() for IFS

From: Jithu Joseph <[email protected]>

IFS is a CPU feature that allows a binary blob, similar to microcode, to be loaded and consumed to perform low level validation of CPU circuitry. In fact, it carries the same Processor Signature (family/model/stepping) details that are contained in Intel microcode blobs.

In support of an IFS driver to trigger loading, validation, and running of these tests blobs, make the functionality of cpu_signatures_match() and collect_cpu_info_early() available outside of the microcode driver.

Add an "intel_" prefix and drop the "_early" suffix from collect_cpu_info_early() and EXPORT_SYMBOL_GPL() it. Add declaration to x86 <asm/cpu.h>

Make cpu_signatures_match() an inline function in x86 <asm/cpu.h>, and also give it an "intel_" prefix.

No functional change intended.

---
 arch/x86/include/asm/cpu.h            | 18 ++++++++
 arch/x86/kernel/cpu/intel.c           | 32 +++++++++++++++
 arch/x86/kernel/cpu/microcode/intel.c | 59 ++++-----------------------
 3 files changed, 57 insertions(+), 52 deletions(-)
arch/x86/include/asm/cpu.h +18 -0
index 86e5e4e26fcb..990167357c34 100644
@@ -76,4 +76,22 @@ static inline void init_ia32_feat_ctl(struct cpuinfo_x86 *c) {}
 
 extern __noendbr void cet_disable(void);
 
+struct ucode_cpu_info;
+
+int intel_cpu_collect_info(struct ucode_cpu_info *uci);
+
+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;
+}
+
 #endif /* _ASM_X86_CPU_H */
arch/x86/kernel/cpu/intel.c +32 -0
index f7a5370a9b3b..94779146275d 100644
@@ -181,6 +181,38 @@ static bool bad_spectre_microcode(struct cpuinfo_x86 *c)
 	return false;
 }
 
+int intel_cpu_collect_info(struct ucode_cpu_info *uci)
+{
+	unsigned int val[2];
+	unsigned int family, model;
+	struct cpu_signature csig = { 0 };
+	unsigned int eax, ebx, ecx, edx;
+
+	memset(uci, 0, sizeof(*uci));
+
+	eax = 0x00000001;
+	ecx = 0;
+	native_cpuid(&eax, &ebx, &ecx, &edx);
+	csig.sig = eax;
+
+	family = x86_family(eax);
+	model  = x86_model(eax);
+
+	if (model >= 5 || family > 6) {
+		/* get processor flags from MSR 0x17 */
+		native_rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]);
+		csig.pf = 1 << ((val[1] >> 18) & 7);
+	}
+
+	csig.rev = intel_get_microcode_revision();
+
+	uci->cpu_sig = csig;
+	uci->valid = 1;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(intel_cpu_collect_info);
+
 static void early_init_intel(struct cpuinfo_x86 *c)
 {
 	u64 misc_enable;
arch/x86/kernel/cpu/microcode/intel.c +7 -52

113 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#113 lore raw

PATCH v6 2/11 x86/msr-index: Define INTEGRITY_CAPABILITIES MSR

In reply to Tony Luck

The INTEGRITY_CAPABILITIES MSR is enumerated by bit 2 of the CORE_CAPABILITIES MSR.

Add defines for the CORE_CAPS enumeration as well as for the integrity MSR.

---
 arch/x86/include/asm/msr-index.h | 7 +++++++
 1 file changed, 7 insertions(+)
arch/x86/include/asm/msr-index.h +7 -0
index ee15311b6be1..c3dc7ae32f1f 100644
@@ -76,6 +76,8 @@
 
 /* Abbreviated from Intel SDM name IA32_CORE_CAPABILITIES */
 #define MSR_IA32_CORE_CAPS			  0x000000cf
+#define MSR_IA32_CORE_CAPS_INTEGRITY_CAPS_BIT	  2
+#define MSR_IA32_CORE_CAPS_INTEGRITY_CAPS	  BIT(MSR_IA32_CORE_CAPS_INTEGRITY_CAPS_BIT)
 #define MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT_BIT  5
 #define MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT	  BIT(MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT_BIT)
 
@@ -154,6 +156,11 @@
 #define MSR_IA32_POWER_CTL		0x000001fc
 #define MSR_IA32_POWER_CTL_BIT_EE	19
 
+/* Abbreviated from Intel SDM name IA32_INTEGRITY_CAPABILITIES */
+#define MSR_INTEGRITY_CAPS			0x000002d9
+#define MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT	4
+#define MSR_INTEGRITY_CAPS_PERIODIC_BIST	BIT(MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT)
+
 #define MSR_LBR_NHM_FROM		0x00000680
 #define MSR_LBR_NHM_TO			0x000006c0
 #define MSR_LBR_CORE_FROM		0x00000040
Signature · 1 line
2.35.1
Reviewed-by on v6 2/11
#114 lore raw

Re: [PATCH v6 02/11] x86/msr-index: Define INTEGRITY_CAPABILITIES MSR

Quoted 9 lines · Tony Luck

The INTEGRITY_CAPABILITIES MSR is enumerated by bit 2 of the CORE_CAPABILITIES MSR.

Add defines for the CORE_CAPS enumeration as well as for the integrity MSR.

maintainer
#115 lore raw

PATCH v6 3/11 stop_machine: Add stop_core_cpuslocked() for per-core operations

In reply to Tony Luck

From: Peter Zijlstra <[email protected]>

Hardware core level testing features require near simultaneous execution of WRMSR instructions on all threads of a core to initiate a test.

Provide a customized cut down version of stop_machine_cpuslocked() that just operates on the threads of a single core.

---
 include/linux/stop_machine.h | 16 ++++++++++++++++
 kernel/stop_machine.c        | 19 +++++++++++++++++++
 2 files changed, 35 insertions(+)
include/linux/stop_machine.h +16 -0
index 46fb3ebdd16e..ea7a74ea7389 100644
@@ -124,6 +124,22 @@ int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus);
  */
 int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus);
 
+/**
+ * stop_core_cpuslocked: - stop all threads on just one core
+ * @cpu: any cpu in the targeted core
+ * @fn: the function to run
+ * @data: the data ptr for @fn()
+ *
+ * Same as above, but instead of every CPU, only the logical CPUs of a
+ * single core are affected.
+ *
+ * Context: Must be called from within a cpus_read_lock() protected region.
+ *
+ * Return: 0 if all executions of @fn returned 0, any non zero return
+ * value if any returned non zero.
+ */
+int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data);
+
 int stop_machine_from_inactive_cpu(cpu_stop_fn_t fn, void *data,
 				   const struct cpumask *cpus);
 #else	/* CONFIG_SMP || CONFIG_HOTPLUG_CPU */
kernel/stop_machine.c +19 -0
index cbc30271ea4d..579761729836 100644
@@ -633,6 +633,25 @@ int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus)
 }
 EXPORT_SYMBOL_GPL(stop_machine);
 
+int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data)
+{
+	const struct cpumask *smt_mask = cpu_smt_mask(cpu);
+
+	struct multi_stop_data msdata = {
+		.fn = fn,
+		.data = data,
+		.num_threads = cpumask_weight(smt_mask),
+		.active_cpus = smt_mask,
+	};
+
+	lockdep_assert_cpus_held();
+
+	/* Set the initial state and stop all online cpus. */
+	set_state(&msdata, MULTI_STOP_PREPARE);
+	return stop_cpus(smt_mask, multi_cpu_stop, &msdata);
+}
+EXPORT_SYMBOL_GPL(stop_core_cpuslocked);
+
 /**
  * stop_machine_from_inactive_cpu - stop_machine() from inactive CPU
  * @fn: the function to run
Signature · 1 line
2.35.1
Reviewed-by on v6 3/11
#116 lore raw

Re: [PATCH v6 03/11] stop_machine: Add stop_core_cpuslocked() for per-core operations

Quoted 11 lines · Tony Luck

From: Peter Zijlstra <[email protected]>

Hardware core level testing features require near simultaneous execution of WRMSR instructions on all threads of a core to initiate a test.

Provide a customized cut down version of stop_machine_cpuslocked() that just operates on the threads of a single core.

maintainer
#117 lore raw

PATCH v6 4/11 platform/x86/intel/ifs: Add stub driver for In-Field Scan

In reply to Tony Luck

Cloud Service Providers that operate fleets of servers have reported
[1] occasions where they can detect that a CPU has gone bad due to effects like electromigration, or isolated manufacturing defects. However, that detection method is A/B testing seemingly random application failures looking for a pattern. In-Field Scan (IFS) is a driver for a platform capability to load a crafted 'scan image' to run targeted low level diagnostics outside of the CPU's architectural error detection capabilities.

Stub version of driver just does initial part of check for the IFS feature. MSR_IA32_CORE_CAPS must enumerate the presence of the MSR_INTEGRITY_CAPS MSR.

[1]: https://www.youtube.com/watch?v=QMF3rqhjYuM

---
 MAINTAINERS                             |  7 ++++
 drivers/platform/x86/intel/Kconfig      |  1 +
 drivers/platform/x86/intel/Makefile     |  1 +
 drivers/platform/x86/intel/ifs/Kconfig  | 13 +++++++
 drivers/platform/x86/intel/ifs/Makefile |  3 ++
 drivers/platform/x86/intel/ifs/core.c   | 48 +++++++++++++++++++++++++
 6 files changed, 73 insertions(+)
 create mode 100644 drivers/platform/x86/intel/ifs/Kconfig
 create mode 100644 drivers/platform/x86/intel/ifs/Makefile
 create mode 100644 drivers/platform/x86/intel/ifs/core.c
MAINTAINERS +7 -0
index edc96cdb85e8..bb0c4ff25942 100644
@@ -9862,6 +9862,13 @@ B:	https://bugzilla.kernel.org
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git
 F:	drivers/idle/intel_idle.c
 
+INTEL IN FIELD SCAN (IFS) DEVICE
+M:	Jithu Joseph <[email protected]>
+R:	Ashok Raj <[email protected]>
+R:	Tony Luck <[email protected]>
+S:	Maintained
+F:	drivers/platform/x86/intel/ifs
+
 INTEL INTEGRATED SENSOR HUB DRIVER
 M:	Srinivas Pandruvada <[email protected]>
 M:	Jiri Kosina <[email protected]>
drivers/platform/x86/intel/Kconfig +1 -0
index 1f01a8a23c57..794968bda115 100644
@@ -4,6 +4,7 @@
 #
 
 source "drivers/platform/x86/intel/atomisp2/Kconfig"
+source "drivers/platform/x86/intel/ifs/Kconfig"
 source "drivers/platform/x86/intel/int1092/Kconfig"
 source "drivers/platform/x86/intel/int3472/Kconfig"
 source "drivers/platform/x86/intel/pmc/Kconfig"
drivers/platform/x86/intel/Makefile +1 -0
index c61bc3e97121..717933dd0cfd 100644
@@ -5,6 +5,7 @@
 #
 
 obj-$(CONFIG_INTEL_ATOMISP2_PDX86)	+= atomisp2/
+obj-$(CONFIG_INTEL_IFS)			+= ifs/
 obj-$(CONFIG_INTEL_SAR_INT1092)		+= int1092/
 obj-$(CONFIG_INTEL_SKL_INT3472)		+= int3472/
 obj-$(CONFIG_INTEL_PMC_CORE)		+= pmc/
drivers/platform/x86/intel/ifs/Kconfig new file +13 -0
new file mode 100644
index 000000000000..d84491cfb0db
@@ -0,0 +1,13 @@
+config INTEL_IFS
+	tristate "Intel In Field Scan"
+	depends on X86 && 64BIT && SMP
+	select INTEL_IFS_DEVICE
+	help
+	  Enable support for the In Field Scan capability in select
+	  CPUs. The capability allows for running low level tests via
+	  a scan image distributed by Intel via Github to validate CPU
+	  operation beyond baseline RAS capabilities. To compile this
+	  support as a module, choose M here. The module will be called
+	  intel_ifs.
+
+	  If unsure, say N.
drivers/platform/x86/intel/ifs/Makefile new file +3 -0
new file mode 100644
index 000000000000..af904880e959
@@ -0,0 +1,3 @@
+obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
+
+intel_ifs-objs			:= core.o
drivers/platform/x86/intel/ifs/core.c new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.35.1
Reviewed-by on v6 4/11
#118 lore raw

Re: [PATCH v6 04/11] platform/x86/intel/ifs: Add stub driver for In-Field Scan

drivers/platform/x86/intel/ifs/core.c line 14

Quoted 8 lines · Tony Luck
drivers/platform/x86/intel/ifs/core.c new file +8 -0
+#include <asm/cpu_device_id.h>
+
+#define X86_MATCH(model)				\
+	X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6,	\
+		INTEL_FAM6_##model, X86_FEATURE_CORE_CAPABILITIES, NULL)
+
+static const struct x86_cpu_id ifs_cpu_ids[] __initconst = {
+	X86_MATCH(SAPPHIRERAPIDS_X),

I still hate this with a passion. Nevertheless:

maintainer
#119 lore raw

PATCH v6 5/11 platform/x86/intel/ifs: Read IFS firmware image

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

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.

---
 drivers/platform/x86/intel/ifs/Makefile |  2 +-
 drivers/platform/x86/intel/ifs/core.c   | 22 ++++++++++++++++++-
 drivers/platform/x86/intel/ifs/ifs.h    | 25 ++++++++++++++++++++++
 drivers/platform/x86/intel/ifs/load.c   | 28 +++++++++++++++++++++++++
 4 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100644 drivers/platform/x86/intel/ifs/ifs.h
 create mode 100644 drivers/platform/x86/intel/ifs/load.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index af904880e959..98b6fde15689 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
 
-intel_ifs-objs			:= core.o
+intel_ifs-objs			:= core.o load.o
drivers/platform/x86/intel/ifs/core.c +21 -1
index e3623ac691b5..f62578dae8e9 100644
@@ -6,6 +6,8 @@
 
 #include <asm/cpu_device_id.h>
 
+#include "ifs.h"
+
 #define X86_MATCH(model)				\
 	X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6,	\
 		INTEL_FAM6_##model, X86_FEATURE_CORE_CAPABILITIES, NULL)
@@ -16,6 +18,17 @@ static const struct x86_cpu_id ifs_cpu_ids[] __initconst = {
 };
 MODULE_DEVICE_TABLE(x86cpu, ifs_cpu_ids);
 
+static struct ifs_device ifs_device = {
+	.data = {
+		.integrity_cap_bit = MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT,
+	},
+	.misc = {
+		.name = "intel_ifs_0",
+		.nodename = "intel_ifs/0",
+		.minor = MISC_DYNAMIC_MINOR,
+	},
+};
+
 static int __init ifs_init(void)
 {
 	const struct x86_cpu_id *m;
@@ -34,11 +47,18 @@ static int __init ifs_init(void)
 	if (rdmsrl_safe(MSR_INTEGRITY_CAPS, &msrval))
 		return -ENODEV;
 
-	return 0;
+	if ((msrval & BIT(ifs_device.data.integrity_cap_bit)) &&
+	    !misc_register(&ifs_device.misc)) {
+		ifs_load_firmware(ifs_device.misc.this_device);
+		return 0;
+	}
+
+	return -ENODEV;
 }
 
 static void __exit ifs_exit(void)
 {
+	misc_deregister(&ifs_device.misc);
 }
 
 module_init(ifs_init);
drivers/platform/x86/intel/ifs/ifs.h new file +25 -0
new file mode 100644
index 000000000000..47e5f8344fd8
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2022 Intel Corporation. */
+
+#ifndef _IFS_H_
+#define _IFS_H_
+
+#include <linux/device.h>
+#include <linux/miscdevice.h>
+
+/**
+ * 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
drivers/platform/x86/intel/ifs/load.c new file +28 -0
new file mode 100644
index 000000000000..9fb71d38c819
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright(c) 2022 Intel Corporation. */
+
+#include <linux/firmware.h>
+
+#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);
+}
Signature · 1 line
2.35.1
maintainer
#120 lore raw

PATCH v6 6/11 platform/x86/intel/ifs: Check IFS Image sanity

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

IFS image is designed specifically for a given family, model and stepping of the processor. Like Intel microcode header, the IFS image has the Processor Signature, Checksum and Processor Flags that must be matched with the information returned by the CPUID.

---
 drivers/platform/x86/intel/ifs/load.c | 66 +++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
drivers/platform/x86/intel/ifs/load.c +66 -0
index 9fb71d38c819..cfbf62494c89 100644
@@ -2,9 +2,72 @@
 /* Copyright(c) 2022 Intel Corporation. */
 
 #include <linux/firmware.h>
+#include <asm/cpu.h>
+#include <asm/microcode_intel.h>
 
 #include "ifs.h"
 
+static int ifs_sanity_check(struct device *dev,
+			    const struct microcode_header_intel *mc_header)
+{
+	unsigned long total_size, data_size;
+	u32 sum, *mc;
+
+	total_size = get_totalsize(mc_header);
+	data_size = get_datasize(mc_header);
+
+	if ((data_size + MC_HEADER_SIZE > total_size) || (total_size % sizeof(u32))) {
+		dev_err(dev, "bad ifs data file size.\n");
+		return -EINVAL;
+	}
+
+	if (mc_header->ldrver != 1 || mc_header->hdrver != 1) {
+		dev_err(dev, "invalid/unknown ifs update format.\n");
+		return -EINVAL;
+	}
+
+	mc = (u32 *)mc_header;
+	sum = 0;
+	for (int i = 0; i < total_size / sizeof(u32); i++)
+		sum += mc[i];
+
+	if (sum) {
+		dev_err(dev, "bad ifs data checksum, aborting.\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}.
@@ -24,5 +87,8 @@ void ifs_load_firmware(struct device *dev)
 		return;
 	}
 
+	if (!ifs_image_sanity_check(dev, (struct microcode_header_intel *)fw->data))
+		dev_err(dev, "ifs header sanity check failed\n");
+
 	release_firmware(fw);
 }
Signature · 1 line
2.35.1
maintainer
#121 lore raw

PATCH v6 7/11 platform/x86/intel/ifs: Authenticate and copy to secured memory

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

The IFS image contains hashes that will be used to authenticate the ifs test chunks. First, use WRMSR to copy the hashes and enumerate the number of test chunks, chunk size and the maximum number of cores that can run scan test simultaneously.

Next, use WRMSR to authenticate each and every scan test chunk which is stored in the IFS image. The CPU will check if the test chunks match the hashes, otherwise failure is indicated to system software. If the test chunk is authenticated, it is automatically copied to secured memory.

Use schedule_work_on() to perform the hash copy and authentication. Note this needs only be done on the first logical cpu of each socket.

---
 drivers/platform/x86/intel/ifs/ifs.h  |  52 ++++++++
 drivers/platform/x86/intel/ifs/load.c | 176 +++++++++++++++++++++++++-
 2 files changed, 226 insertions(+), 2 deletions(-)
drivers/platform/x86/intel/ifs/ifs.h +52 -0
index 47e5f8344fd8..1a606c999b12 100644
@@ -7,12 +7,56 @@
 #include <linux/device.h>
 #include <linux/miscdevice.h>
 
+#define MSR_COPY_SCAN_HASHES			0x000002c2
+#define MSR_SCAN_HASHES_STATUS			0x000002c3
+#define MSR_AUTHENTICATE_AND_COPY_CHUNK		0x000002c4
+#define MSR_CHUNKS_AUTHENTICATION_STATUS	0x000002c5
+
+/* MSR_SCAN_HASHES_STATUS bit fields */
+union ifs_scan_hashes_status {
+	u64	data;
+	struct {
+		u32	chunk_size	:16;
+		u32	num_chunks	:8;
+		u32	rsvd1		:8;
+		u32	error_code	:8;
+		u32	rsvd2		:11;
+		u32	max_core_limit	:12;
+		u32	valid		:1;
+	};
+};
+
+/* MSR_CHUNKS_AUTH_STATUS bit fields */
+union ifs_chunks_auth_status {
+	u64	data;
+	struct {
+		u32	valid_chunks	:8;
+		u32	total_chunks	:8;
+		u32	rsvd1		:16;
+		u32	error_code	:8;
+		u32	rsvd2		:24;
+	};
+};
+
 /**
  * struct ifs_data - attributes related to intel IFS driver
  * @integrity_cap_bit - MSR_INTEGRITY_CAPS bit enumerating this test
+ * @loaded_version: stores the currently loaded ifs image version.
+ * @loaded: If a valid test binary has been loaded into the memory
+ * @loading_error: Error occurred on another CPU while loading image
+ * @valid_chunks: number of chunks which could be validated.
  */
 struct ifs_data {
 	int	integrity_cap_bit;
+	int	loaded_version;
+	bool	loaded;
+	bool	loading_error;
+	int	valid_chunks;
+};
+
+struct ifs_work {
+	struct work_struct w;
+	struct device *dev;
 };
 
 struct ifs_device {
@@ -20,6 +64,14 @@ struct ifs_device {
 	struct miscdevice misc;
 };
 
+static inline struct ifs_data *ifs_get_data(struct device *dev)
+{
+	struct miscdevice *m = dev_get_drvdata(dev);
+	struct ifs_device *d = container_of(m, struct ifs_device, misc);
+
+	return &d->data;
+}
+
 void ifs_load_firmware(struct device *dev);
 
 #endif
drivers/platform/x86/intel/ifs/load.c +174 -2

201 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#122 lore raw

PATCH v6 8/11 platform/x86/intel/ifs: Add scan test support

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

In a core, the scan engine is shared between sibling cpus.

When a Scan test (for a particular core) is triggered by the user, the scan chunks are executed on all the threads on the core using stop_core_cpuslocked.

Scan may be aborted by some reasons. Scan test will be aborted in certain circumstances such as when interrupt occurred or cpu does not have enough power budget for scan. In this case, the kernel restart scan from the chunk where it stopped. Scan will also be aborted when the test is failed. In this case, the test is immediately stopped without retry.

---
 drivers/platform/x86/intel/ifs/Makefile  |   2 +-
 drivers/platform/x86/intel/ifs/ifs.h     |  44 ++++
 drivers/platform/x86/intel/ifs/runtest.c | 250 +++++++++++++++++++++++
 3 files changed, 295 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/runtest.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index 98b6fde15689..cedcb103f860 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
 
-intel_ifs-objs			:= core.o load.o
+intel_ifs-objs			:= core.o load.o runtest.o
drivers/platform/x86/intel/ifs/ifs.h +44 -0

73 lines not on this page · raw message

drivers/platform/x86/intel/ifs/runtest.c new file +250 -0

250 lines not on this page · raw message

Signature · 1 line
2.35.1
#123 lore raw

Re: [PATCH v6 08/11] platform/x86/intel/ifs: Add scan test support

drivers/platform/x86/intel/ifs/runtest.c line 19

Quoted 7 lines · Tony Luck
drivers/platform/x86/intel/ifs/runtest.c new file +7 -0
+/*
+ * Note all code and data in this file is protected by
+ * ifs_sem. On HT systems all threads on a core will
+ * execute together, but only the first thread on the
+ * core will update results of the test.
+ */
+struct workqueue_struct *ifs_wq;

Seems to be unused.

Quoted 1 line

+static bool oscan_enabled = true;

What changes this?

drivers/platform/x86/intel/ifs/runtest.c line 61

Quoted 3 lines
drivers/platform/x86/intel/ifs/runtest.c new file +3 -0
+static void message_not_tested(struct device *dev, int cpu, union ifs_status status)
+{
+	if (status.error_code < ARRAY_SIZE(scan_test_status))

Please add curly brackets as these are not one-line statements.

Quoted 5 lines
drivers/platform/x86/intel/ifs/runtest.c new file +5 -0
+		dev_info(dev, "CPU(s) %*pbl: SCAN operation did not start. %s\n",
+			 cpumask_pr_args(topology_sibling_cpumask(cpu)),
+			 scan_test_status[status.error_code]);
+/*
+ * Execute the scan. Called "simultaneously" on all threads of a core

drivers/platform/x86/intel/ifs/runtest.c line 138

Quoted 10 lines
drivers/platform/x86/intel/ifs/runtest.c new file +10 -0
+ * at high priority using the stop_cpus mechanism.
+ */
+static int doscan(void *data)
+{
+	int cpu = smp_processor_id();
+	u64 *msrs = data;
+	int first;
+
+	/* Only the first logical CPU on a core reports result */
+	first = cpumask_first(topology_sibling_cpumask(cpu));

Shouldn't that be cpu_smt_mask()?

drivers/platform/x86/intel/ifs/runtest.c line 145

Quoted 6 lines
drivers/platform/x86/intel/ifs/runtest.c new file +6 -0
+	/*
+	 * This WRMSR will wait for other HT threads to also write
+	 * to this MSR (at most for activate.delay cycles). Then it
+	 * starts scan of each requested chunk. The core scan happens
+	 * during the "execution" of the WRMSR. This instruction can
+	 * take up to 200 milliseconds before it retires.

200ms per test chunk?

Quoted 21 lines
drivers/platform/x86/intel/ifs/runtest.c new file +20 -0
+	 */
+	wrmsrl(MSR_ACTIVATE_SCAN, msrs[0]);
+
 
+	while (activate.start <= activate.stop) {
+		if (time_after(jiffies, timeout)) {
+			status.error_code = IFS_SW_TIMEOUT;
+			break;
+		}
+
+		msrvals[0] = activate.data;
+		stop_core_cpuslocked(cpu, doscan, msrvals);
+
+		status.data = msrvals[1];
+
+		/* Some cases can be retried, give up for others */
+		if (!can_restart(status))
+			break;
+
+		if (status.chunk_num == activate.start) {
+			/* Check for forward progress */

drivers/platform/x86/intel/ifs/runtest.c line 209

Quoted 10 lines
drivers/platform/x86/intel/ifs/runtest.c new file +10 -0
+			if (retries-- == 0) {
+				if (status.error_code == IFS_NO_ERROR)
+					status.error_code = IFS_SW_PARTIAL_COMPLETION;
+				break;
+			}
+		} else {
+			retries = MAX_IFS_RETRIES;
+			activate.start = status.chunk_num;
+		}
+	}

Looks way better now.

Quoted 11 lines
drivers/platform/x86/intel/ifs/runtest.c new file +11 -0
+}
+/*
+ * Initiate per core test. It wakes up work queue threads on the target cpu and
+ * its sibling cpu. Once all sibling threads wake up, the scan test gets executed and
+ * wait for all sibling threads to finish the scan test.
+ */
+int do_core_test(int cpu, struct device *dev)
+{
+	int ret = 0;
+
+	if (!scan_enabled)

drivers/platform/x86/intel/ifs/runtest.c line 244

Quoted 10 lines
drivers/platform/x86/intel/ifs/runtest.c new file +10 -0
+		return -ENXIO;
+
+	/* Prevent CPUs from being taken offline during the scan test */
+	cpus_read_lock();
+
+	if (!cpu_online(cpu)) {
+		dev_info(dev, "cannot test on the offline cpu %d\n", cpu);
+		ret = -EINVAL;
+		goto out;
+	}

Coming back to my points from the previous round:

1) How is that supposed to work on a system which has HT enabled in BIOS, but disabled on the kernel command line or via /sys/..../smt/control or when a HT sibling is offlined temporarily?

I assume it cannot work, but I can't see anything which handles those cases.

2) That documentation for the admin/user got eaten by the gremlins in the intertubes again.

Thanks,

tglx

maintainer
#124 lore raw

Re: [PATCH v6 08/11] platform/x86/intel/ifs: Add scan test support

Quoted 10 lines · Thomas Gleixner

drivers/platform/x86/intel/ifs/runtest.c line 19

Quoted 7 lines · Tony Luck
drivers/platform/x86/intel/ifs/runtest.c new file +7 -0
+/*
+ * Note all code and data in this file is protected by
+ * ifs_sem. On HT systems all threads on a core will
+ * execute together, but only the first thread on the
+ * core will update results of the test.
+ */
+struct workqueue_struct *ifs_wq;

Seems to be unused.

Missed deleting the definition after dropping all the users. Deleted now.

Quoted 3 lines
Quoted 1 line

+static bool oscan_enabled = true;

What changes this?

Code that changed this has been deleted (was to deal with a "can't happen" case where the kernel threads didn't set completion).

Variable (and the remaing place that checked it) now deleted.

Quoted 5 lines

drivers/platform/x86/intel/ifs/runtest.c line 61

Quoted 3 lines
drivers/platform/x86/intel/ifs/runtest.c new file +3 -0
+static void message_not_tested(struct device *dev, int cpu, union ifs_status status)
+{
+	if (status.error_code < ARRAY_SIZE(scan_test_status))

Please add curly brackets as these are not one-line statements.

Done.

Quoted 9 lines
Quoted 9 lines
drivers/platform/x86/intel/ifs/runtest.c new file +9 -0
+		dev_info(dev, "CPU(s) %*pbl: SCAN operation did not start. %s\n",
+			 cpumask_pr_args(topology_sibling_cpumask(cpu)),
+			 scan_test_status[status.error_code]);
+/*
+ * Execute the scan. Called "simultaneously" on all threads of a core
+ * at high priority using the stop_cpus mechanism.
+ */
+static int doscan(void *data)
+{
Quoted 8 lines

drivers/platform/x86/intel/ifs/runtest.c line 138

Quoted 6 lines
drivers/platform/x86/intel/ifs/runtest.c new file +6 -0
+	int cpu = smp_processor_id();
+	u64 *msrs = data;
+	int first;
+
+	/* Only the first logical CPU on a core reports result */
+	first = cpumask_first(topology_sibling_cpumask(cpu));

Shouldn't that be cpu_smt_mask()?

I guess so. It seems part of a maze of CONFIG options and #defines. The code worked because (except on power) cpu_smt_mask() is just an inline funtion that calls topology_sibling_cpumask().

I've changed this (and the other places that use topology_sibling_cpumask() to cpu_smt_mask(). Will probably save me from a randconfig build error some time in the future.

Quoted 8 lines

drivers/platform/x86/intel/ifs/runtest.c line 145

Quoted 6 lines
drivers/platform/x86/intel/ifs/runtest.c new file +6 -0
+	/*
+	 * This WRMSR will wait for other HT threads to also write
+	 * to this MSR (at most for activate.delay cycles). Then it
+	 * starts scan of each requested chunk. The core scan happens
+	 * during the "execution" of the WRMSR. This instruction can
+	 * take up to 200 milliseconds before it retires.

200ms per test chunk?

Updated comment to say that 200 ms is the time for all chunks.

Note that the loop that calls here tries to do all (remaining) chunks on each iteration. Doing them 1 at a time would reduce the time each spends in stomp_machine(), but not as much as you'd like. Each WRMSR(ACTIVATE_SCAN)) has to save/restore the whole state of the core (similar to a C6 entry+exit).

Quoted 25 lines
Quoted 25 lines
drivers/platform/x86/intel/ifs/runtest.c new file +24 -0
+	 */
+	wrmsrl(MSR_ACTIVATE_SCAN, msrs[0]);
+
 
+	while (activate.start <= activate.stop) {
+		if (time_after(jiffies, timeout)) {
+			status.error_code = IFS_SW_TIMEOUT;
+			break;
+		}
+
+		msrvals[0] = activate.data;
+		stop_core_cpuslocked(cpu, doscan, msrvals);
+
+		status.data = msrvals[1];
+
+		/* Some cases can be retried, give up for others */
+		if (!can_restart(status))
+			break;
+
+		if (status.chunk_num == activate.start) {
+			/* Check for forward progress */
+			if (retries-- == 0) {
+				if (status.error_code == IFS_NO_ERROR)
+					status.error_code = IFS_SW_PARTIAL_COMPLETION;
+				break;
Quoted 8 lines

drivers/platform/x86/intel/ifs/runtest.c line 209

Quoted 6 lines
drivers/platform/x86/intel/ifs/runtest.c new file +6 -0
+			}
+		} else {
+			retries = MAX_IFS_RETRIES;
+			activate.start = status.chunk_num;
+		}
+	}

Looks way better now.

Thanks to you!

Quoted 24 lines
Quoted 11 lines
drivers/platform/x86/intel/ifs/runtest.c new file +11 -0
+}
+/*
+ * Initiate per core test. It wakes up work queue threads on the target cpu and
+ * its sibling cpu. Once all sibling threads wake up, the scan test gets executed and
+ * wait for all sibling threads to finish the scan test.
+ */
+int do_core_test(int cpu, struct device *dev)
+{
+	int ret = 0;
+
+	if (!scan_enabled)

drivers/platform/x86/intel/ifs/runtest.c line 244

Quoted 10 lines
drivers/platform/x86/intel/ifs/runtest.c new file +10 -0
+		return -ENXIO;
+
+	/* Prevent CPUs from being taken offline during the scan test */
+	cpus_read_lock();
+
+	if (!cpu_online(cpu)) {
+		dev_info(dev, "cannot test on the offline cpu %d\n", cpu);
+		ret = -EINVAL;
+		goto out;
+	}

Coming back to my points from the previous round:

Quoted 6 lines

1) How is that supposed to work on a system which has HT enabled in BIOS, but disabled on the kernel command line or via /sys/..../smt/control or when a HT sibling is offlined temporarily?

I assume it cannot work, but I can't see anything which handles those cases.

Correct. If HT is disabled in BIOS, then there is no other thread, so core tests just use a single thread.

If a logical CPU is "offline" due to Linux actions, then core test will fail. In an earlier version we did attempt to detect this before trying to run the test. But we didn't find a simple way to determine that a core has one thread online, and another offline. Rather than a bunch of code to detect an operator error it seemed better to let it run & fail.

Here is what the user will see:

# echo 45 > run_test
# cat status
untested
# cat details
0x100008000

Console will see this message:
misc intel_ifs_0: CPU(s) 45: SCAN operation did not start. Other thread could not join.

If the user debugs using the trace point I included in the code they will see:

              sh-411499  [067] ..... 61260.698969: ifs_status: cpu: 45, start: 00, stop: 80, status: 100008000
              sh-411499  [067] ..... 61260.699968: ifs_status: cpu: 45, start: 00, stop: 80, status: 100008000
              sh-411499  [067] ..... 61260.700076: ifs_status: cpu: 45, start: 00, stop: 80, status: 100008000
              sh-411499  [067] ..... 61260.700187: ifs_status: cpu: 45, start: 00, stop: 80, status: 100008000
              sh-411499  [067] ..... 61260.700334: ifs_status: cpu: 45, start: 00, stop: 80, status: 100008000
              sh-411499  [067] ..... 61260.700437: ifs_status: cpu: 45, start: 00, stop: 80, status: 100008000

Hmmm ... looks like I have an off-by one error in the retry check.

/* Max retries on the same chunk */
#define MAX_IFS_RETRIES 5

But it tried SIX times before giving up. Will fix.

Quoted 2 lines

2) That documentation for the admin/user got eaten by the gremlins in the intertubes again.

GregKH wasn't a fan of this itty bitty driver cluttering up Documentation/x86. He said:

I don't know which is better, it's just that creating a whole new documentation file for a single tiny driver feels very odd as it will get out of date and is totally removed from the driver itself.

I'd prefer that drivers be self-contained, including the documentation, as it is much more obvious what is happening with that. Spreading stuff around the tree only causes stuff to get out of sync easier.

So the documentation patch was dropped after v3. Last version here:

https://lore.kernel.org/r/[email protected]

That doc would need pathnames updated to match the move from a platform device to a virtual misc device. But otherwise seems still accurate.

Does that cover what you want from documentation for this driver (wherever it gets located in the tree)? Are you looking for more?

-Tony

#125 lore raw

Re: [PATCH v6 08/11] platform/x86/intel/ifs: Add scan test support

Quoted 11 lines · Tony
Quoted 6 lines · Thomas Gleixner

1) How is that supposed to work on a system which has HT enabled in BIOS, but disabled on the kernel command line or via /sys/..../smt/control or when a HT sibling is offlined temporarily?

I assume it cannot work, but I can't see anything which handles those cases.

Correct. If HT is disabled in BIOS, then there is no other thread, so core tests just use a single thread.

Quoted 6 lines

If a logical CPU is "offline" due to Linux actions, then core test will fail. In an earlier version we did attempt to detect this before trying to run the test. But we didn't find a simple way to determine that a core has one thread online, and another offline. Rather than a bunch of code to detect an operator error it seemed better to let it run & fail.

Fair enough.

Quoted 10 lines

GregKH wasn't a fan of this itty bitty driver cluttering up Documentation/x86. He said:

I don't know which is better, it's just that creating a whole new documentation file for a single tiny driver feels very odd as it will get out of date and is totally removed from the driver itself.

I'd prefer that drivers be self-contained, including the documentation, as it is much more obvious what is happening with that. Spreading stuff around the tree only causes stuff to get out of sync easier.

Well, I agree to some extent, but the documentation which I want to see is documentation for admins. I'm not sure whether we want them to search the code. Those are consumers of Documentation/ AFAICT.

Quoted 9 lines

So the documentation patch was dropped after v3. Last version here:

https://lore.kernel.org/r/[email protected]

That doc would need pathnames updated to match the move from a platform device to a virtual misc device. But otherwise seems still accurate.

Does that cover what you want from documentation for this driver (wherever it gets located in the tree)? Are you looking for more?

It's pretty detailed on the inner workings, but lacks a big fat warning for the admin vs. the impact, i.e. that it makes the core go out for lunch for a while, which has consequences on workloads and interrupts directed at that core. Plus some explanation vs. the HT (SMT=off, soft offline) case above. Similar to what we have e.g. for buslocks.

Thanks,

tglx

maintainer
#126 lore raw

PATCH v6 9/11 platform/x86/intel/ifs: Add IFS sysfs interface

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

Implement sysfs interface to trigger ifs test for a specific cpu. Additional interfaces related to checking the status of the scan test and seeing the version of the loaded IFS binary are also added.

The basic usage is as below.
- To start test, for example on cpu5:
echo 5 > /sys/devices/platform/intel_ifs/run_test
- To see the status of the last test
cat /sys/devices/platform/intel_ifs/status
- To see the version of the loaded scan binary cat /sys/devices/platform/intel_ifs/image_version

---
 drivers/platform/x86/intel/ifs/Makefile |   2 +-
 drivers/platform/x86/intel/ifs/core.c   |   5 +
 drivers/platform/x86/intel/ifs/ifs.h    |   3 +
 drivers/platform/x86/intel/ifs/sysfs.c  | 149 ++++++++++++++++++++++++
 4 files changed, 158 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/sysfs.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index cedcb103f860..30f035ef5581 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
 
-intel_ifs-objs			:= core.o load.o runtest.o
+intel_ifs-objs			:= core.o load.o runtest.o sysfs.o
drivers/platform/x86/intel/ifs/core.c +5 -0
index f62578dae8e9..27204e3d674d 100644
@@ -3,6 +3,7 @@
 
 #include <linux/module.h>
 #include <linux/kdev_t.h>
+#include <linux/semaphore.h>
 
 #include <asm/cpu_device_id.h>
 
@@ -47,9 +48,13 @@ static int __init ifs_init(void)
 	if (rdmsrl_safe(MSR_INTEGRITY_CAPS, &msrval))
 		return -ENODEV;
 
+	ifs_device.misc.groups = ifs_get_groups();
+
 	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);
+		up(&ifs_sem);
 		return 0;
 	}
 
drivers/platform/x86/intel/ifs/ifs.h +3 -0
index 7435a5582df3..6606214773bc 100644
@@ -117,5 +117,8 @@ static inline struct ifs_data *ifs_get_data(struct device *dev)
 
 void ifs_load_firmware(struct device *dev);
 int do_core_test(int cpu, struct device *dev);
+const struct attribute_group **ifs_get_groups(void);
+
+extern struct semaphore ifs_sem;
 
 #endif
drivers/platform/x86/intel/ifs/sysfs.c new file +149 -0

149 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#127 lore raw

PATCH v6 10/11 trace: platform/x86/intel/ifs: Add trace point to track Intel IFS operations

In reply to Tony Luck

Add tracing support which may be useful for debugging systems that fail to complete In Field Scan tests.

---
 MAINTAINERS                              |  1 +
 drivers/platform/x86/intel/ifs/runtest.c |  5 +++
 include/trace/events/intel_ifs.h         | 41 ++++++++++++++++++++++++
 3 files changed, 47 insertions(+)
 create mode 100644 include/trace/events/intel_ifs.h
MAINTAINERS +1 -0
index bb0c4ff25942..6864fa039974 100644
@@ -9868,6 +9868,7 @@ R:	Ashok Raj <[email protected]>
 R:	Tony Luck <[email protected]>
 S:	Maintained
 F:	drivers/platform/x86/intel/ifs
+F:	include/trace/events/intel_ifs.h
 
 INTEL INTEGRATED SENSOR HUB DRIVER
 M:	Srinivas Pandruvada <[email protected]>
drivers/platform/x86/intel/ifs/runtest.c +5 -0
index fd3f5f3f31e5..cd25817ceda0 100644
@@ -19,6 +19,9 @@
 struct workqueue_struct *ifs_wq;
 static bool scan_enabled = true;
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/intel_ifs.h>
+
 /* Max retries on the same chunk */
 #define MAX_IFS_RETRIES  5
 
@@ -191,6 +194,8 @@ static void ifs_test_core(int cpu, struct device *dev)
 
 		status.data = msrvals[1];
 
+		trace_ifs_status(cpu, activate, status);
+
 		/* Some cases can be retried, give up for others */
 		if (!can_restart(status))
 			break;
include/trace/events/intel_ifs.h new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#128 lore raw

PATCH v6 11/11 platform/x86/intel/ifs: add ABI documentation for IFS

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

Add the sysfs attributes in ABI/testing for In-Field Scan.

---
 .../ABI/testing/sysfs-platform-intel-ifs      | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-ifs
Documentation/ABI/testing/sysfs-platform-intel-ifs new file +39 -0
new file mode 100644
index 000000000000..486d6d2ff8a0
@@ -0,0 +1,39 @@
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/run_test
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Write <cpu#> to trigger IFS test for one online core.
+		Note that the test is per core. The cpu# can be
+		for any thread on the core. Running on one thread
+		completes the test for the core containing that thread.
+		Example: to test the core containing cpu5: echo 5 >
+		/sys/devices/platform/intel_ifs.<N>/run_test
+
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/status
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	The status of the last test. It can be one of "pass", "fail"
+		or "untested".
+
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/details
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Additional information regarding the last test. The details file reports
+		the hex value of the SCAN_STATUS MSR. Note that the error_code field
+		may contain driver defined software code not defined in the Intel SDM.
+
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/image_version
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Version (hexadecimal) of loaded IFS binary image. If no scan image
+		is loaded reports "none".
+
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/reload
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Write "1" (or "y" or "Y") to reload the IFS image from
+		/lib/firmware/intel/ifs/ff-mm-ss.scan.
Signature · 1 line
2.35.1
maintainer
#129 lore raw

v7 cover Introduce In Field Scan driver

In reply to Tony Luck

TL;DR this driver loads scan test files that can check whether silicon in a CPU core is still running correctly. It is expected that these tests would be run several times per day to catch problems as silicon ages.

Changes since v6

Thomas Gleixner
---------------
"struct workqueue_struct *ifs_wq; Seems to be unused."

True. Deleted.

"static bool oscan_enabled = true; What changes this?"

Code that cleared it deleted. Drop this too.

"Please add curly brackets as these are not one-line statements"

Added

cpumask_first(topology_sibling_cpumask(cpu)); Shouldn't that be cpu_smt_mask()?"

Changed (and several other places)

"take up to 200 milliseconds before it retires. 200ms per test chunk?"

Updated comment to note that 200ms is for all chunks.

"Documentation lost in the intertubes"

Dredged up the version from v3 series and changed:
1) Fixed pathnames now this is a virtual misc device instead of platform device
2) Put all the text into a "/** DOC:" comment section in ifs.h with just a "kernel-doc:: drivers/platform/x86/intel/ifs/ifs.h" in the ifs.rst file under Documentation/x86.
3) Added a "big fat warning" (in all CAPS) pointing out that a core test can take up to 200 milliseconds. So admins must take extra steps if they are running latency sensitive workloads.
4) Added note that all HT threads of a core must be online to run a test.

Tony Luck
---------
Off-by-one on retries check (#define set to 5, but tried 6 times). Fixed Fixed kerneldoc description of "integrity_cap_bit" (was missing a ":")

Jithu Joseph (7):
x86/microcode/intel: Expose collect_cpu_info_early() for IFS platform/x86/intel/ifs: Read IFS firmware image platform/x86/intel/ifs: Check IFS Image sanity platform/x86/intel/ifs: Authenticate and copy to secured memory platform/x86/intel/ifs: Add scan test support platform/x86/intel/ifs: Add IFS sysfs interface platform/x86/intel/ifs: add ABI documentation for IFS

Peter Zijlstra (1):
stop_machine: Add stop_core_cpuslocked() for per-core operations

Tony Luck (4):
x86/msr-index: Define INTEGRITY_CAPABILITIES MSR platform/x86/intel/ifs: Add stub driver for In-Field Scan
trace: platform/x86/intel/ifs: Add trace point to track Intel IFS
operations
Documentation: In-Field Scan

 .../ABI/testing/sysfs-platform-intel-ifs      |  39 +++
 Documentation/x86/ifs.rst                     |   2 +
 Documentation/x86/index.rst                   |   1 +
 MAINTAINERS                                   |   8 +
 arch/x86/include/asm/cpu.h                    |  18 ++
 arch/x86/include/asm/msr-index.h              |   7 +
 arch/x86/kernel/cpu/intel.c                   |  32 +++
 arch/x86/kernel/cpu/microcode/intel.c         |  59 +---
 drivers/platform/x86/intel/Kconfig            |   1 +
 drivers/platform/x86/intel/Makefile           |   1 +
 drivers/platform/x86/intel/ifs/Kconfig        |  13 +
 drivers/platform/x86/intel/ifs/Makefile       |   3 +
 drivers/platform/x86/intel/ifs/core.c         |  73 +++++
 drivers/platform/x86/intel/ifs/ifs.h          | 234 +++++++++++++++
 drivers/platform/x86/intel/ifs/load.c         | 266 ++++++++++++++++++
 drivers/platform/x86/intel/ifs/runtest.c      | 252 +++++++++++++++++
 drivers/platform/x86/intel/ifs/sysfs.c        | 149 ++++++++++
 include/linux/stop_machine.h                  |  16 ++
 include/trace/events/intel_ifs.h              |  41 +++
 kernel/stop_machine.c                         |  19 ++
 20 files changed, 1182 insertions(+), 52 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-ifs
 create mode 100644 Documentation/x86/ifs.rst
 create mode 100644 drivers/platform/x86/intel/ifs/Kconfig
 create mode 100644 drivers/platform/x86/intel/ifs/Makefile
 create mode 100644 drivers/platform/x86/intel/ifs/core.c
 create mode 100644 drivers/platform/x86/intel/ifs/ifs.h
 create mode 100644 drivers/platform/x86/intel/ifs/load.c
 create mode 100644 drivers/platform/x86/intel/ifs/runtest.c
 create mode 100644 drivers/platform/x86/intel/ifs/sysfs.c
 create mode 100644 include/trace/events/intel_ifs.h

base-commit: 672c0c5173427e6b3e2a9bbb7be51ceeec78093a

Signature · 1 line
2.35.1
maintainer
#130 lore raw

PATCH v7 1/12 x86/microcode/intel: Expose collect_cpu_info_early() for IFS

From: Jithu Joseph <[email protected]>

IFS is a CPU feature that allows a binary blob, similar to microcode, to be loaded and consumed to perform low level validation of CPU circuitry. In fact, it carries the same Processor Signature (family/model/stepping) details that are contained in Intel microcode blobs.

In support of an IFS driver to trigger loading, validation, and running of these tests blobs, make the functionality of cpu_signatures_match() and collect_cpu_info_early() available outside of the microcode driver.

Add an "intel_" prefix and drop the "_early" suffix from collect_cpu_info_early() and EXPORT_SYMBOL_GPL() it. Add declaration to x86 <asm/cpu.h>

Make cpu_signatures_match() an inline function in x86 <asm/cpu.h>, and also give it an "intel_" prefix.

No functional change intended.

---
 arch/x86/include/asm/cpu.h            | 18 ++++++++
 arch/x86/kernel/cpu/intel.c           | 32 +++++++++++++++
 arch/x86/kernel/cpu/microcode/intel.c | 59 ++++-----------------------
 3 files changed, 57 insertions(+), 52 deletions(-)
arch/x86/include/asm/cpu.h +18 -0
index 86e5e4e26fcb..990167357c34 100644
@@ -76,4 +76,22 @@ static inline void init_ia32_feat_ctl(struct cpuinfo_x86 *c) {}
 
 extern __noendbr void cet_disable(void);
 
+struct ucode_cpu_info;
+
+int intel_cpu_collect_info(struct ucode_cpu_info *uci);
+
+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;
+}
+
 #endif /* _ASM_X86_CPU_H */
arch/x86/kernel/cpu/intel.c +32 -0
index f7a5370a9b3b..94779146275d 100644
@@ -181,6 +181,38 @@ static bool bad_spectre_microcode(struct cpuinfo_x86 *c)
 	return false;
 }
 
+int intel_cpu_collect_info(struct ucode_cpu_info *uci)
+{
+	unsigned int val[2];
+	unsigned int family, model;
+	struct cpu_signature csig = { 0 };
+	unsigned int eax, ebx, ecx, edx;
+
+	memset(uci, 0, sizeof(*uci));
+
+	eax = 0x00000001;
+	ecx = 0;
+	native_cpuid(&eax, &ebx, &ecx, &edx);
+	csig.sig = eax;
+
+	family = x86_family(eax);
+	model  = x86_model(eax);
+
+	if (model >= 5 || family > 6) {
+		/* get processor flags from MSR 0x17 */
+		native_rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]);
+		csig.pf = 1 << ((val[1] >> 18) & 7);
+	}
+
+	csig.rev = intel_get_microcode_revision();
+
+	uci->cpu_sig = csig;
+	uci->valid = 1;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(intel_cpu_collect_info);
+
 static void early_init_intel(struct cpuinfo_x86 *c)
 {
 	u64 misc_enable;
arch/x86/kernel/cpu/microcode/intel.c +7 -52

113 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#131 lore raw

PATCH v7 2/12 x86/msr-index: Define INTEGRITY_CAPABILITIES MSR

In reply to Tony Luck

The INTEGRITY_CAPABILITIES MSR is enumerated by bit 2 of the CORE_CAPABILITIES MSR.

Add defines for the CORE_CAPS enumeration as well as for the integrity MSR.

---
 arch/x86/include/asm/msr-index.h | 7 +++++++
 1 file changed, 7 insertions(+)
arch/x86/include/asm/msr-index.h +7 -0
index ee15311b6be1..c3dc7ae32f1f 100644
@@ -76,6 +76,8 @@
 
 /* Abbreviated from Intel SDM name IA32_CORE_CAPABILITIES */
 #define MSR_IA32_CORE_CAPS			  0x000000cf
+#define MSR_IA32_CORE_CAPS_INTEGRITY_CAPS_BIT	  2
+#define MSR_IA32_CORE_CAPS_INTEGRITY_CAPS	  BIT(MSR_IA32_CORE_CAPS_INTEGRITY_CAPS_BIT)
 #define MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT_BIT  5
 #define MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT	  BIT(MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT_BIT)
 
@@ -154,6 +156,11 @@
 #define MSR_IA32_POWER_CTL		0x000001fc
 #define MSR_IA32_POWER_CTL_BIT_EE	19
 
+/* Abbreviated from Intel SDM name IA32_INTEGRITY_CAPABILITIES */
+#define MSR_INTEGRITY_CAPS			0x000002d9
+#define MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT	4
+#define MSR_INTEGRITY_CAPS_PERIODIC_BIST	BIT(MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT)
+
 #define MSR_LBR_NHM_FROM		0x00000680
 #define MSR_LBR_NHM_TO			0x000006c0
 #define MSR_LBR_CORE_FROM		0x00000040
Signature · 1 line
2.35.1
maintainer
#132 lore raw

PATCH v7 3/12 stop_machine: Add stop_core_cpuslocked() for per-core operations

In reply to Tony Luck

From: Peter Zijlstra <[email protected]>

Hardware core level testing features require near simultaneous execution of WRMSR instructions on all threads of a core to initiate a test.

Provide a customized cut down version of stop_machine_cpuslocked() that just operates on the threads of a single core.

---
 include/linux/stop_machine.h | 16 ++++++++++++++++
 kernel/stop_machine.c        | 19 +++++++++++++++++++
 2 files changed, 35 insertions(+)
include/linux/stop_machine.h +16 -0
index 46fb3ebdd16e..ea7a74ea7389 100644
@@ -124,6 +124,22 @@ int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus);
  */
 int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus);
 
+/**
+ * stop_core_cpuslocked: - stop all threads on just one core
+ * @cpu: any cpu in the targeted core
+ * @fn: the function to run
+ * @data: the data ptr for @fn()
+ *
+ * Same as above, but instead of every CPU, only the logical CPUs of a
+ * single core are affected.
+ *
+ * Context: Must be called from within a cpus_read_lock() protected region.
+ *
+ * Return: 0 if all executions of @fn returned 0, any non zero return
+ * value if any returned non zero.
+ */
+int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data);
+
 int stop_machine_from_inactive_cpu(cpu_stop_fn_t fn, void *data,
 				   const struct cpumask *cpus);
 #else	/* CONFIG_SMP || CONFIG_HOTPLUG_CPU */
kernel/stop_machine.c +19 -0
index cbc30271ea4d..579761729836 100644
@@ -633,6 +633,25 @@ int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus)
 }
 EXPORT_SYMBOL_GPL(stop_machine);
 
+int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data)
+{
+	const struct cpumask *smt_mask = cpu_smt_mask(cpu);
+
+	struct multi_stop_data msdata = {
+		.fn = fn,
+		.data = data,
+		.num_threads = cpumask_weight(smt_mask),
+		.active_cpus = smt_mask,
+	};
+
+	lockdep_assert_cpus_held();
+
+	/* Set the initial state and stop all online cpus. */
+	set_state(&msdata, MULTI_STOP_PREPARE);
+	return stop_cpus(smt_mask, multi_cpu_stop, &msdata);
+}
+EXPORT_SYMBOL_GPL(stop_core_cpuslocked);
+
 /**
  * stop_machine_from_inactive_cpu - stop_machine() from inactive CPU
  * @fn: the function to run
Signature · 1 line
2.35.1
maintainer
#133 lore raw

PATCH v7 4/12 platform/x86/intel/ifs: Add stub driver for In-Field Scan

In reply to Tony Luck

Cloud Service Providers that operate fleets of servers have reported
[1] occasions where they can detect that a CPU has gone bad due to effects like electromigration, or isolated manufacturing defects. However, that detection method is A/B testing seemingly random application failures looking for a pattern. In-Field Scan (IFS) is a driver for a platform capability to load a crafted 'scan image' to run targeted low level diagnostics outside of the CPU's architectural error detection capabilities.

Stub version of driver just does initial part of check for the IFS feature. MSR_IA32_CORE_CAPS must enumerate the presence of the MSR_INTEGRITY_CAPS MSR.

[1]: https://www.youtube.com/watch?v=QMF3rqhjYuM

---
 MAINTAINERS                             |  7 ++++
 drivers/platform/x86/intel/Kconfig      |  1 +
 drivers/platform/x86/intel/Makefile     |  1 +
 drivers/platform/x86/intel/ifs/Kconfig  | 13 +++++++
 drivers/platform/x86/intel/ifs/Makefile |  3 ++
 drivers/platform/x86/intel/ifs/core.c   | 48 +++++++++++++++++++++++++
 6 files changed, 73 insertions(+)
 create mode 100644 drivers/platform/x86/intel/ifs/Kconfig
 create mode 100644 drivers/platform/x86/intel/ifs/Makefile
 create mode 100644 drivers/platform/x86/intel/ifs/core.c
MAINTAINERS +7 -0
index edc96cdb85e8..bb0c4ff25942 100644
@@ -9862,6 +9862,13 @@ B:	https://bugzilla.kernel.org
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git
 F:	drivers/idle/intel_idle.c
 
+INTEL IN FIELD SCAN (IFS) DEVICE
+M:	Jithu Joseph <[email protected]>
+R:	Ashok Raj <[email protected]>
+R:	Tony Luck <[email protected]>
+S:	Maintained
+F:	drivers/platform/x86/intel/ifs
+
 INTEL INTEGRATED SENSOR HUB DRIVER
 M:	Srinivas Pandruvada <[email protected]>
 M:	Jiri Kosina <[email protected]>
drivers/platform/x86/intel/Kconfig +1 -0
index 1f01a8a23c57..794968bda115 100644
@@ -4,6 +4,7 @@
 #
 
 source "drivers/platform/x86/intel/atomisp2/Kconfig"
+source "drivers/platform/x86/intel/ifs/Kconfig"
 source "drivers/platform/x86/intel/int1092/Kconfig"
 source "drivers/platform/x86/intel/int3472/Kconfig"
 source "drivers/platform/x86/intel/pmc/Kconfig"
drivers/platform/x86/intel/Makefile +1 -0
index c61bc3e97121..717933dd0cfd 100644
@@ -5,6 +5,7 @@
 #
 
 obj-$(CONFIG_INTEL_ATOMISP2_PDX86)	+= atomisp2/
+obj-$(CONFIG_INTEL_IFS)			+= ifs/
 obj-$(CONFIG_INTEL_SAR_INT1092)		+= int1092/
 obj-$(CONFIG_INTEL_SKL_INT3472)		+= int3472/
 obj-$(CONFIG_INTEL_PMC_CORE)		+= pmc/
drivers/platform/x86/intel/ifs/Kconfig new file +13 -0
new file mode 100644
index 000000000000..d84491cfb0db
@@ -0,0 +1,13 @@
+config INTEL_IFS
+	tristate "Intel In Field Scan"
+	depends on X86 && 64BIT && SMP
+	select INTEL_IFS_DEVICE
+	help
+	  Enable support for the In Field Scan capability in select
+	  CPUs. The capability allows for running low level tests via
+	  a scan image distributed by Intel via Github to validate CPU
+	  operation beyond baseline RAS capabilities. To compile this
+	  support as a module, choose M here. The module will be called
+	  intel_ifs.
+
+	  If unsure, say N.
drivers/platform/x86/intel/ifs/Makefile new file +3 -0
new file mode 100644
index 000000000000..af904880e959
@@ -0,0 +1,3 @@
+obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
+
+intel_ifs-objs			:= core.o
drivers/platform/x86/intel/ifs/core.c new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#134 lore raw

PATCH v7 5/12 platform/x86/intel/ifs: Read IFS firmware image

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

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.

---
 drivers/platform/x86/intel/ifs/Makefile |  2 +-
 drivers/platform/x86/intel/ifs/core.c   | 22 ++++++++++++++++++-
 drivers/platform/x86/intel/ifs/ifs.h    | 25 ++++++++++++++++++++++
 drivers/platform/x86/intel/ifs/load.c   | 28 +++++++++++++++++++++++++
 4 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100644 drivers/platform/x86/intel/ifs/ifs.h
 create mode 100644 drivers/platform/x86/intel/ifs/load.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index af904880e959..98b6fde15689 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
 
-intel_ifs-objs			:= core.o
+intel_ifs-objs			:= core.o load.o
drivers/platform/x86/intel/ifs/core.c +21 -1
index e3623ac691b5..f62578dae8e9 100644
@@ -6,6 +6,8 @@
 
 #include <asm/cpu_device_id.h>
 
+#include "ifs.h"
+
 #define X86_MATCH(model)				\
 	X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6,	\
 		INTEL_FAM6_##model, X86_FEATURE_CORE_CAPABILITIES, NULL)
@@ -16,6 +18,17 @@ static const struct x86_cpu_id ifs_cpu_ids[] __initconst = {
 };
 MODULE_DEVICE_TABLE(x86cpu, ifs_cpu_ids);
 
+static struct ifs_device ifs_device = {
+	.data = {
+		.integrity_cap_bit = MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT,
+	},
+	.misc = {
+		.name = "intel_ifs_0",
+		.nodename = "intel_ifs/0",
+		.minor = MISC_DYNAMIC_MINOR,
+	},
+};
+
 static int __init ifs_init(void)
 {
 	const struct x86_cpu_id *m;
@@ -34,11 +47,18 @@ static int __init ifs_init(void)
 	if (rdmsrl_safe(MSR_INTEGRITY_CAPS, &msrval))
 		return -ENODEV;
 
-	return 0;
+	if ((msrval & BIT(ifs_device.data.integrity_cap_bit)) &&
+	    !misc_register(&ifs_device.misc)) {
+		ifs_load_firmware(ifs_device.misc.this_device);
+		return 0;
+	}
+
+	return -ENODEV;
 }
 
 static void __exit ifs_exit(void)
 {
+	misc_deregister(&ifs_device.misc);
 }
 
 module_init(ifs_init);
drivers/platform/x86/intel/ifs/ifs.h new file +25 -0
new file mode 100644
index 000000000000..9d151324ae83
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2022 Intel Corporation. */
+
+#ifndef _IFS_H_
+#define _IFS_H_
+
+#include <linux/device.h>
+#include <linux/miscdevice.h>
+
+/**
+ * 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
drivers/platform/x86/intel/ifs/load.c new file +28 -0
new file mode 100644
index 000000000000..9fb71d38c819
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright(c) 2022 Intel Corporation. */
+
+#include <linux/firmware.h>
+
+#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);
+}
Signature · 1 line
2.35.1
Reviewed-by on v7 5/12
#135 lore raw

Re: [PATCH v7 05/12] platform/x86/intel/ifs: Read IFS firmware image

maintainer
#136 lore raw

PATCH v7 6/12 platform/x86/intel/ifs: Check IFS Image sanity

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

IFS image is designed specifically for a given family, model and stepping of the processor. Like Intel microcode header, the IFS image has the Processor Signature, Checksum and Processor Flags that must be matched with the information returned by the CPUID.

---
 drivers/platform/x86/intel/ifs/load.c | 66 +++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
drivers/platform/x86/intel/ifs/load.c +66 -0
index 9fb71d38c819..cfbf62494c89 100644
@@ -2,9 +2,72 @@
 /* Copyright(c) 2022 Intel Corporation. */
 
 #include <linux/firmware.h>
+#include <asm/cpu.h>
+#include <asm/microcode_intel.h>
 
 #include "ifs.h"
 
+static int ifs_sanity_check(struct device *dev,
+			    const struct microcode_header_intel *mc_header)
+{
+	unsigned long total_size, data_size;
+	u32 sum, *mc;
+
+	total_size = get_totalsize(mc_header);
+	data_size = get_datasize(mc_header);
+
+	if ((data_size + MC_HEADER_SIZE > total_size) || (total_size % sizeof(u32))) {
+		dev_err(dev, "bad ifs data file size.\n");
+		return -EINVAL;
+	}
+
+	if (mc_header->ldrver != 1 || mc_header->hdrver != 1) {
+		dev_err(dev, "invalid/unknown ifs update format.\n");
+		return -EINVAL;
+	}
+
+	mc = (u32 *)mc_header;
+	sum = 0;
+	for (int i = 0; i < total_size / sizeof(u32); i++)
+		sum += mc[i];
+
+	if (sum) {
+		dev_err(dev, "bad ifs data checksum, aborting.\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}.
@@ -24,5 +87,8 @@ void ifs_load_firmware(struct device *dev)
 		return;
 	}
 
+	if (!ifs_image_sanity_check(dev, (struct microcode_header_intel *)fw->data))
+		dev_err(dev, "ifs header sanity check failed\n");
+
 	release_firmware(fw);
 }
Signature · 1 line
2.35.1
maintainer
#138 lore raw

Re: [PATCH v7 06/12] platform/x86/intel/ifs: Check IFS Image sanity

In reply to Tony Luck
Quoted 6 lines · Tony Luck

From: Jithu Joseph <[email protected]>

IFS image is designed specifically for a given family, model and stepping of the processor. Like Intel microcode header, the IFS image has the Processor Signature, Checksum and Processor Flags that must be matched with the information returned by the CPUID.

Is the checksum the only protection against people loading arbitrary IFS images or are those things signed or encrypted, just like the microcode?

I'd hope they pass the same checks as microcode, when they get loaded, considering the similarity of how they're handled...

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#139 lore raw

RE: [PATCH v7 06/12] platform/x86/intel/ifs: Check IFS Image sanity

Quoted 5 lines

Is the checksum the only protection against people loading arbitrary IFS images or are those things signed or encrypted, just like the microcode?

I'd hope they pass the same checks as microcode, when they get loaded, considering the similarity of how they're handled...

The checksum is just a "did this file get corrupted check". The file contains SHA256 checksums for each of the chunks. These checksums are digitally signed. Checking of these is done by microcode when the file is loaded into BIOS reserved memory (where it is inaccessible to OS and I/O).

-Tony

maintainer
#140 lore raw

Re: [PATCH v7 06/12] platform/x86/intel/ifs: Check IFS Image sanity

Quoted 4 lines · Tony

The checksum is just a "did this file get corrupted check". The file contains SHA256 checksums for each of the chunks. These checksums are digitally signed. Checking of these is done by microcode when the file is loaded into BIOS reserved memory (where it is inaccessible to OS and I/O).

That sounds like something I was hoping to hear, good. :-)

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#141 lore raw

PATCH v7 7/12 platform/x86/intel/ifs: Authenticate and copy to secured memory

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

The IFS image contains hashes that will be used to authenticate the ifs test chunks. First, use WRMSR to copy the hashes and enumerate the number of test chunks, chunk size and the maximum number of cores that can run scan test simultaneously.

Next, use WRMSR to authenticate each and every scan test chunk which is stored in the IFS image. The CPU will check if the test chunks match the hashes, otherwise failure is indicated to system software. If the test chunk is authenticated, it is automatically copied to secured memory.

Use schedule_work_on() to perform the hash copy and authentication. Note this needs only be done on the first logical cpu of each socket.

---
 drivers/platform/x86/intel/ifs/ifs.h  |  52 ++++++++
 drivers/platform/x86/intel/ifs/load.c | 176 +++++++++++++++++++++++++-
 2 files changed, 226 insertions(+), 2 deletions(-)
drivers/platform/x86/intel/ifs/ifs.h +52 -0
index 9d151324ae83..bed70dc1e5b7 100644
@@ -7,12 +7,56 @@
 #include <linux/device.h>
 #include <linux/miscdevice.h>
 
+#define MSR_COPY_SCAN_HASHES			0x000002c2
+#define MSR_SCAN_HASHES_STATUS			0x000002c3
+#define MSR_AUTHENTICATE_AND_COPY_CHUNK		0x000002c4
+#define MSR_CHUNKS_AUTHENTICATION_STATUS	0x000002c5
+
+/* MSR_SCAN_HASHES_STATUS bit fields */
+union ifs_scan_hashes_status {
+	u64	data;
+	struct {
+		u32	chunk_size	:16;
+		u32	num_chunks	:8;
+		u32	rsvd1		:8;
+		u32	error_code	:8;
+		u32	rsvd2		:11;
+		u32	max_core_limit	:12;
+		u32	valid		:1;
+	};
+};
+
+/* MSR_CHUNKS_AUTH_STATUS bit fields */
+union ifs_chunks_auth_status {
+	u64	data;
+	struct {
+		u32	valid_chunks	:8;
+		u32	total_chunks	:8;
+		u32	rsvd1		:16;
+		u32	error_code	:8;
+		u32	rsvd2		:24;
+	};
+};
+
 /**
  * struct ifs_data - attributes related to intel IFS driver
  * @integrity_cap_bit: MSR_INTEGRITY_CAPS bit enumerating this test
+ * @loaded_version: stores the currently loaded ifs image version.
+ * @loaded: If a valid test binary has been loaded into the memory
+ * @loading_error: Error occurred on another CPU while loading image
+ * @valid_chunks: number of chunks which could be validated.
  */
 struct ifs_data {
 	int	integrity_cap_bit;
+	int	loaded_version;
+	bool	loaded;
+	bool	loading_error;
+	int	valid_chunks;
+};
+
+struct ifs_work {
+	struct work_struct w;
+	struct device *dev;
 };
 
 struct ifs_device {
@@ -20,6 +64,14 @@ struct ifs_device {
 	struct miscdevice misc;
 };
 
+static inline struct ifs_data *ifs_get_data(struct device *dev)
+{
+	struct miscdevice *m = dev_get_drvdata(dev);
+	struct ifs_device *d = container_of(m, struct ifs_device, misc);
+
+	return &d->data;
+}
+
 void ifs_load_firmware(struct device *dev);
 
 #endif
drivers/platform/x86/intel/ifs/load.c +174 -2

201 lines not on this page · raw message

Signature · 1 line
2.35.1
Reviewed-by on v7 7/12
#142 lore raw

Re: [PATCH v7 07/12] platform/x86/intel/ifs: Authenticate and copy to secured memory

Quoted 9 lines · Tony Luck

Use schedule_work_on() to perform the hash copy and authentication. Note this needs only be done on the first logical cpu of each socket.

maintainer
#143 lore raw

PATCH v7 8/12 platform/x86/intel/ifs: Add scan test support

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

In a core, the scan engine is shared between sibling cpus.

When a Scan test (for a particular core) is triggered by the user, the scan chunks are executed on all the threads on the core using stop_core_cpuslocked.

Scan may be aborted by some reasons. Scan test will be aborted in certain circumstances such as when interrupt occurred or cpu does not have enough power budget for scan. In this case, the kernel restart scan from the chunk where it stopped. Scan will also be aborted when the test is failed. In this case, the test is immediately stopped without retry.

---
 drivers/platform/x86/intel/ifs/Makefile  |   2 +-
 drivers/platform/x86/intel/ifs/ifs.h     |  44 ++++
 drivers/platform/x86/intel/ifs/runtest.c | 247 +++++++++++++++++++++++
 3 files changed, 292 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/runtest.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index 98b6fde15689..cedcb103f860 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
 
-intel_ifs-objs			:= core.o load.o
+intel_ifs-objs			:= core.o load.o runtest.o
drivers/platform/x86/intel/ifs/ifs.h +44 -0

73 lines not on this page · raw message

drivers/platform/x86/intel/ifs/runtest.c new file +247 -0

247 lines not on this page · raw message

Signature · 1 line
2.35.1
Reviewed-by on v7 8/12
#144 lore raw

Re: [PATCH v7 08/12] platform/x86/intel/ifs: Add scan test support

Quoted 14 lines · Tony Luck

From: Jithu Joseph <[email protected]>

In a core, the scan engine is shared between sibling cpus.

When a Scan test (for a particular core) is triggered by the user, the scan chunks are executed on all the threads on the core using stop_core_cpuslocked.

Scan may be aborted by some reasons. Scan test will be aborted in certain circumstances such as when interrupt occurred or cpu does not have enough power budget for scan. In this case, the kernel restart scan from the chunk where it stopped. Scan will also be aborted when the test is failed. In this case, the test is immediately stopped without retry.

Quoted 6 lines
maintainer
#145 lore raw

PATCH v7 9/12 platform/x86/intel/ifs: Add IFS sysfs interface

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

Implement sysfs interface to trigger ifs test for a specific cpu. Additional interfaces related to checking the status of the scan test and seeing the version of the loaded IFS binary are also added.

The basic usage is as below.
- To start test, for example on cpu5:
echo 5 > /sys/devices/platform/intel_ifs/run_test
- To see the status of the last test
cat /sys/devices/platform/intel_ifs/status
- To see the version of the loaded scan binary cat /sys/devices/platform/intel_ifs/image_version

---
 drivers/platform/x86/intel/ifs/Makefile |   2 +-
 drivers/platform/x86/intel/ifs/core.c   |   5 +
 drivers/platform/x86/intel/ifs/ifs.h    |   3 +
 drivers/platform/x86/intel/ifs/sysfs.c  | 149 ++++++++++++++++++++++++
 4 files changed, 158 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/intel/ifs/sysfs.c
drivers/platform/x86/intel/ifs/Makefile +1 -1
index cedcb103f860..30f035ef5581 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INTEL_IFS)		+= intel_ifs.o
 
-intel_ifs-objs			:= core.o load.o runtest.o
+intel_ifs-objs			:= core.o load.o runtest.o sysfs.o
drivers/platform/x86/intel/ifs/core.c +5 -0
index f62578dae8e9..27204e3d674d 100644
@@ -3,6 +3,7 @@
 
 #include <linux/module.h>
 #include <linux/kdev_t.h>
+#include <linux/semaphore.h>
 
 #include <asm/cpu_device_id.h>
 
@@ -47,9 +48,13 @@ static int __init ifs_init(void)
 	if (rdmsrl_safe(MSR_INTEGRITY_CAPS, &msrval))
 		return -ENODEV;
 
+	ifs_device.misc.groups = ifs_get_groups();
+
 	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);
+		up(&ifs_sem);
 		return 0;
 	}
 
drivers/platform/x86/intel/ifs/ifs.h +3 -0
index b648cccda3ec..720bd18a5e91 100644
@@ -117,5 +117,8 @@ static inline struct ifs_data *ifs_get_data(struct device *dev)
 
 void ifs_load_firmware(struct device *dev);
 int do_core_test(int cpu, struct device *dev);
+const struct attribute_group **ifs_get_groups(void);
+
+extern struct semaphore ifs_sem;
 
 #endif
drivers/platform/x86/intel/ifs/sysfs.c new file +149 -0

149 lines not on this page · raw message

Signature · 1 line
2.35.1
Reviewed-by on v7 9/12
#146 lore raw

Re: [PATCH v7 09/12] platform/x86/intel/ifs: Add IFS sysfs interface

Quoted 13 lines · Tony Luck

Implement sysfs interface to trigger ifs test for a specific cpu. Additional interfaces related to checking the status of the scan test and seeing the version of the loaded IFS binary are also added.

The basic usage is as below.
- To start test, for example on cpu5:
echo 5 > /sys/devices/platform/intel_ifs/run_test
- To see the status of the last test
cat /sys/devices/platform/intel_ifs/status
- To see the version of the loaded scan binary cat /sys/devices/platform/intel_ifs/image_version

Quoted 6 lines
maintainer
#147 lore raw

PATCH v7 10/12 trace: platform/x86/intel/ifs: Add trace point to track Intel IFS operations

In reply to Tony Luck

Add tracing support which may be useful for debugging systems that fail to complete In Field Scan tests.

---
 MAINTAINERS                              |  1 +
 drivers/platform/x86/intel/ifs/runtest.c |  5 +++
 include/trace/events/intel_ifs.h         | 41 ++++++++++++++++++++++++
 3 files changed, 47 insertions(+)
 create mode 100644 include/trace/events/intel_ifs.h
MAINTAINERS +1 -0
index bb0c4ff25942..6864fa039974 100644
@@ -9868,6 +9868,7 @@ R:	Ashok Raj <[email protected]>
 R:	Tony Luck <[email protected]>
 S:	Maintained
 F:	drivers/platform/x86/intel/ifs
+F:	include/trace/events/intel_ifs.h
 
 INTEL INTEGRATED SENSOR HUB DRIVER
 M:	Srinivas Pandruvada <[email protected]>
drivers/platform/x86/intel/ifs/runtest.c +5 -0
index 7efcce35e0e9..b2ca2bb4501f 100644
@@ -17,6 +17,9 @@
  * core will update results of the test.
  */
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/intel_ifs.h>
+
 /* Max retries on the same chunk */
 #define MAX_IFS_RETRIES  5
 
@@ -191,6 +194,8 @@ static void ifs_test_core(int cpu, struct device *dev)
 
 		status.data = msrvals[1];
 
+		trace_ifs_status(cpu, activate, status);
+
 		/* Some cases can be retried, give up for others */
 		if (!can_restart(status))
 			break;
include/trace/events/intel_ifs.h new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#148 lore raw

PATCH v7 11/12 platform/x86/intel/ifs: add ABI documentation for IFS

In reply to Tony Luck

From: Jithu Joseph <[email protected]>

Add the sysfs attributes in ABI/testing for In-Field Scan.

---
 .../ABI/testing/sysfs-platform-intel-ifs      | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-ifs
Documentation/ABI/testing/sysfs-platform-intel-ifs new file +39 -0
new file mode 100644
index 000000000000..486d6d2ff8a0
@@ -0,0 +1,39 @@
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/run_test
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Write <cpu#> to trigger IFS test for one online core.
+		Note that the test is per core. The cpu# can be
+		for any thread on the core. Running on one thread
+		completes the test for the core containing that thread.
+		Example: to test the core containing cpu5: echo 5 >
+		/sys/devices/platform/intel_ifs.<N>/run_test
+
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/status
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	The status of the last test. It can be one of "pass", "fail"
+		or "untested".
+
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/details
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Additional information regarding the last test. The details file reports
+		the hex value of the SCAN_STATUS MSR. Note that the error_code field
+		may contain driver defined software code not defined in the Intel SDM.
+
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/image_version
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Version (hexadecimal) of loaded IFS binary image. If no scan image
+		is loaded reports "none".
+
+What:		/sys/devices/virtual/misc/intel_ifs_<N>/reload
+Date:		April 21 2022
+KernelVersion:	5.19
+Contact:	"Jithu Joseph" <[email protected]>
+Description:	Write "1" (or "y" or "Y") to reload the IFS image from
+		/lib/firmware/intel/ifs/ff-mm-ss.scan.
Signature · 1 line
2.35.1
maintainer
#149 lore raw

PATCH v7 12/12 Documentation: In-Field Scan

In reply to Tony Luck

Add documentation for In-Field Scan (IFS). This documentation describes the basics of IFS, the loading IFS image, chunk authentication, running scan and how to check result via sysfs.

The CORE_CAPABILITIES MSR enumerates whether IFS is supported.

The full github location for distributing the IFS images is still being decided. So just a placeholder included for now in the documentation.

Future CPUs will support more than one type of test. Plan for that now by using a "_0" suffix on the ABI directory names. Additional test types will use "_1", etc.

---
 Documentation/x86/ifs.rst            |   2 +
 Documentation/x86/index.rst          |   1 +
 drivers/platform/x86/intel/ifs/ifs.h | 110 +++++++++++++++++++++++++++
 3 files changed, 113 insertions(+)
 create mode 100644 Documentation/x86/ifs.rst
Documentation/x86/ifs.rst new file +2 -0
new file mode 100644
index 000000000000..97abb696a680
@@ -0,0 +1,2 @@
+.. SPDX-License-Identifier: GPL-2.0
+.. kernel-doc:: drivers/platform/x86/intel/ifs/ifs.h
Documentation/x86/index.rst +1 -0
index 91b2fa456618..9d8e8a73d57b 100644
@@ -35,6 +35,7 @@ x86-specific Documentation
    usb-legacy-support
    i386/index
    x86_64/index
+   ifs
    sva
    sgx
    features
drivers/platform/x86/intel/ifs/ifs.h +110 -0

116 lines not on this page · raw message

Signature · 1 line
2.35.1
Reviewed-by on v7 12/12
#150 lore raw

Re: [PATCH v7 12/12] Documentation: In-Field Scan

Quoted 10 lines · Tony Luck

Add documentation for In-Field Scan (IFS). This documentation describes the basics of IFS, the loading IFS image, chunk authentication, running scan and how to check result via sysfs.

The CORE_CAPABILITIES MSR enumerates whether IFS is supported.

The full github location for distributing the IFS images is still being decided. So just a placeholder included for now in the documentation.

Quoted 6 lines

Future CPUs will support more than one type of test. Plan for that now by using a "_0" suffix on the ABI directory names. Additional test types will use "_1", etc.

#151 lore raw
In reply to Tony Luck

Hi,

Quoted 3 lines · Tony Luck

TL;DR this driver loads scan test files that can check whether silicon in a CPU core is still running correctly. It is expected that these tests would be run several times per day to catch problems as silicon ages.

Thank you for your patch-series, I've applied the series to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.

Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.

Regards,

Hans

Quoted 97 lines

Changes since v6

Thomas Gleixner
---------------
"struct workqueue_struct *ifs_wq; Seems to be unused."

True. Deleted.

"static bool oscan_enabled = true; What changes this?"

Code that cleared it deleted. Drop this too.

"Please add curly brackets as these are not one-line statements"

Added

cpumask_first(topology_sibling_cpumask(cpu)); Shouldn't that be cpu_smt_mask()?"

Changed (and several other places)

"take up to 200 milliseconds before it retires. 200ms per test chunk?"

Updated comment to note that 200ms is for all chunks.

"Documentation lost in the intertubes"

Dredged up the version from v3 series and changed:
1) Fixed pathnames now this is a virtual misc device instead of platform device
2) Put all the text into a "/** DOC:" comment section in ifs.h with just a "kernel-doc:: drivers/platform/x86/intel/ifs/ifs.h" in the ifs.rst file under Documentation/x86.
3) Added a "big fat warning" (in all CAPS) pointing out that a core test can take up to 200 milliseconds. So admins must take extra steps if they are running latency sensitive workloads.
4) Added note that all HT threads of a core must be online to run a test.

Tony Luck
---------
Off-by-one on retries check (#define set to 5, but tried 6 times). Fixed Fixed kerneldoc description of "integrity_cap_bit" (was missing a ":")

Jithu Joseph (7):
x86/microcode/intel: Expose collect_cpu_info_early() for IFS platform/x86/intel/ifs: Read IFS firmware image platform/x86/intel/ifs: Check IFS Image sanity platform/x86/intel/ifs: Authenticate and copy to secured memory platform/x86/intel/ifs: Add scan test support platform/x86/intel/ifs: Add IFS sysfs interface platform/x86/intel/ifs: add ABI documentation for IFS

Peter Zijlstra (1):
stop_machine: Add stop_core_cpuslocked() for per-core operations

Tony Luck (4):
x86/msr-index: Define INTEGRITY_CAPABILITIES MSR platform/x86/intel/ifs: Add stub driver for In-Field Scan
trace: platform/x86/intel/ifs: Add trace point to track Intel IFS
operations
Documentation: In-Field Scan

 .../ABI/testing/sysfs-platform-intel-ifs      |  39 +++
 Documentation/x86/ifs.rst                     |   2 +
 Documentation/x86/index.rst                   |   1 +
 MAINTAINERS                                   |   8 +
 arch/x86/include/asm/cpu.h                    |  18 ++
 arch/x86/include/asm/msr-index.h              |   7 +
 arch/x86/kernel/cpu/intel.c                   |  32 +++
 arch/x86/kernel/cpu/microcode/intel.c         |  59 +---
 drivers/platform/x86/intel/Kconfig            |   1 +
 drivers/platform/x86/intel/Makefile           |   1 +
 drivers/platform/x86/intel/ifs/Kconfig        |  13 +
 drivers/platform/x86/intel/ifs/Makefile       |   3 +
 drivers/platform/x86/intel/ifs/core.c         |  73 +++++
 drivers/platform/x86/intel/ifs/ifs.h          | 234 +++++++++++++++
 drivers/platform/x86/intel/ifs/load.c         | 266 ++++++++++++++++++
 drivers/platform/x86/intel/ifs/runtest.c      | 252 +++++++++++++++++
 drivers/platform/x86/intel/ifs/sysfs.c        | 149 ++++++++++
 include/linux/stop_machine.h                  |  16 ++
 include/trace/events/intel_ifs.h              |  41 +++
 kernel/stop_machine.c                         |  19 ++
 20 files changed, 1182 insertions(+), 52 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-ifs
 create mode 100644 Documentation/x86/ifs.rst
 create mode 100644 drivers/platform/x86/intel/ifs/Kconfig
 create mode 100644 drivers/platform/x86/intel/ifs/Makefile
 create mode 100644 drivers/platform/x86/intel/ifs/core.c
 create mode 100644 drivers/platform/x86/intel/ifs/ifs.h
 create mode 100644 drivers/platform/x86/intel/ifs/load.c
 create mode 100644 drivers/platform/x86/intel/ifs/runtest.c
 create mode 100644 drivers/platform/x86/intel/ifs/sysfs.c
 create mode 100644 include/trace/events/intel_ifs.h

base-commit: 672c0c5173427e6b3e2a9bbb7be51ceeec78093a