Skip to content

Commit 6f33a92

Browse files
jithu83jwrdegoede
authored andcommitted
platform/x86/intel/ifs: Add IFS sysfs interface
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 Reviewed-by: Dan Williams <[email protected]> Signed-off-by: Jithu Joseph <[email protected]> Co-developed-by: Tony Luck <[email protected]> Signed-off-by: Tony Luck <[email protected]> Acked-by: Hans de Goede <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Hans de Goede <[email protected]>
1 parent 2b40e65 commit 6f33a92

File tree

4 files changed

+158
-1
lines changed

4 files changed

+158
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
obj-$(CONFIG_INTEL_IFS) += intel_ifs.o
22

3-
intel_ifs-objs := core.o load.o runtest.o
3+
intel_ifs-objs := core.o load.o runtest.o sysfs.o

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <linux/module.h>
55
#include <linux/kdev_t.h>
6+
#include <linux/semaphore.h>
67

78
#include <asm/cpu_device_id.h>
89

@@ -47,9 +48,13 @@ static int __init ifs_init(void)
4748
if (rdmsrl_safe(MSR_INTEGRITY_CAPS, &msrval))
4849
return -ENODEV;
4950

51+
ifs_device.misc.groups = ifs_get_groups();
52+
5053
if ((msrval & BIT(ifs_device.data.integrity_cap_bit)) &&
5154
!misc_register(&ifs_device.misc)) {
55+
down(&ifs_sem);
5256
ifs_load_firmware(ifs_device.misc.this_device);
57+
up(&ifs_sem);
5358
return 0;
5459
}
5560

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,8 @@ static inline struct ifs_data *ifs_get_data(struct device *dev)
117117

118118
void ifs_load_firmware(struct device *dev);
119119
int do_core_test(int cpu, struct device *dev);
120+
const struct attribute_group **ifs_get_groups(void);
121+
122+
extern struct semaphore ifs_sem;
120123

121124
#endif
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/* Copyright(c) 2022 Intel Corporation. */
3+
4+
#include <linux/cpu.h>
5+
#include <linux/delay.h>
6+
#include <linux/fs.h>
7+
#include <linux/semaphore.h>
8+
#include <linux/slab.h>
9+
10+
#include "ifs.h"
11+
12+
/*
13+
* Protects against simultaneous tests on multiple cores, or
14+
* reloading can file while a test is in progress
15+
*/
16+
DEFINE_SEMAPHORE(ifs_sem);
17+
18+
/*
19+
* The sysfs interface to check additional details of last test
20+
* cat /sys/devices/system/platform/ifs/details
21+
*/
22+
static ssize_t details_show(struct device *dev,
23+
struct device_attribute *attr,
24+
char *buf)
25+
{
26+
struct ifs_data *ifsd = ifs_get_data(dev);
27+
28+
return sysfs_emit(buf, "%#llx\n", ifsd->scan_details);
29+
}
30+
31+
static DEVICE_ATTR_RO(details);
32+
33+
static const char * const status_msg[] = {
34+
[SCAN_NOT_TESTED] = "untested",
35+
[SCAN_TEST_PASS] = "pass",
36+
[SCAN_TEST_FAIL] = "fail"
37+
};
38+
39+
/*
40+
* The sysfs interface to check the test status:
41+
* To check the status of last test
42+
* cat /sys/devices/platform/ifs/status
43+
*/
44+
static ssize_t status_show(struct device *dev,
45+
struct device_attribute *attr,
46+
char *buf)
47+
{
48+
struct ifs_data *ifsd = ifs_get_data(dev);
49+
50+
return sysfs_emit(buf, "%s\n", status_msg[ifsd->status]);
51+
}
52+
53+
static DEVICE_ATTR_RO(status);
54+
55+
/*
56+
* The sysfs interface for single core testing
57+
* To start test, for example, cpu5
58+
* echo 5 > /sys/devices/platform/ifs/run_test
59+
* To check the result:
60+
* cat /sys/devices/platform/ifs/result
61+
* The sibling core gets tested at the same time.
62+
*/
63+
static ssize_t run_test_store(struct device *dev,
64+
struct device_attribute *attr,
65+
const char *buf, size_t count)
66+
{
67+
struct ifs_data *ifsd = ifs_get_data(dev);
68+
unsigned int cpu;
69+
int rc;
70+
71+
rc = kstrtouint(buf, 0, &cpu);
72+
if (rc < 0 || cpu >= nr_cpu_ids)
73+
return -EINVAL;
74+
75+
if (down_interruptible(&ifs_sem))
76+
return -EINTR;
77+
78+
if (!ifsd->loaded)
79+
rc = -EPERM;
80+
else
81+
rc = do_core_test(cpu, dev);
82+
83+
up(&ifs_sem);
84+
85+
return rc ? rc : count;
86+
}
87+
88+
static DEVICE_ATTR_WO(run_test);
89+
90+
/*
91+
* Reload the IFS image. When user wants to install new IFS image
92+
*/
93+
static ssize_t reload_store(struct device *dev,
94+
struct device_attribute *attr,
95+
const char *buf, size_t count)
96+
{
97+
struct ifs_data *ifsd = ifs_get_data(dev);
98+
bool res;
99+
100+
101+
if (kstrtobool(buf, &res))
102+
return -EINVAL;
103+
if (!res)
104+
return count;
105+
106+
if (down_interruptible(&ifs_sem))
107+
return -EINTR;
108+
109+
ifs_load_firmware(dev);
110+
111+
up(&ifs_sem);
112+
113+
return ifsd->loaded ? count : -ENODEV;
114+
}
115+
116+
static DEVICE_ATTR_WO(reload);
117+
118+
/*
119+
* Display currently loaded IFS image version.
120+
*/
121+
static ssize_t image_version_show(struct device *dev,
122+
struct device_attribute *attr, char *buf)
123+
{
124+
struct ifs_data *ifsd = ifs_get_data(dev);
125+
126+
if (!ifsd->loaded)
127+
return sysfs_emit(buf, "%s\n", "none");
128+
else
129+
return sysfs_emit(buf, "%#x\n", ifsd->loaded_version);
130+
}
131+
132+
static DEVICE_ATTR_RO(image_version);
133+
134+
/* global scan sysfs attributes */
135+
static struct attribute *plat_ifs_attrs[] = {
136+
&dev_attr_details.attr,
137+
&dev_attr_status.attr,
138+
&dev_attr_run_test.attr,
139+
&dev_attr_reload.attr,
140+
&dev_attr_image_version.attr,
141+
NULL
142+
};
143+
144+
ATTRIBUTE_GROUPS(plat_ifs);
145+
146+
const struct attribute_group **ifs_get_groups(void)
147+
{
148+
return plat_ifs_groups;
149+
}

0 commit comments

Comments
 (0)