Skip to content

Commit 87590ce

Browse files
committed
sysfs/cpu: Add vulnerability folder
As the meltdown/spectre problem affects several CPU architectures, it makes sense to have common way to express whether a system is affected by a particular vulnerability or not. If affected the way to express the mitigation should be common as well. Create /sys/devices/system/cpu/vulnerabilities folder and files for meltdown, spectre_v1 and spectre_v2. Allow architectures to override the show function. Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Reviewed-by: Konrad Rzeszutek Wilk <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Will Deacon <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: David Woodhouse <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 99c6fa2 commit 87590ce

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

Documentation/ABI/testing/sysfs-devices-system-cpu

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,19 @@ Contact: Linux kernel mailing list <[email protected]>
373373
Description: information about CPUs heterogeneity.
374374

375375
cpu_capacity: capacity of cpu#.
376+
377+
What: /sys/devices/system/cpu/vulnerabilities
378+
/sys/devices/system/cpu/vulnerabilities/meltdown
379+
/sys/devices/system/cpu/vulnerabilities/spectre_v1
380+
/sys/devices/system/cpu/vulnerabilities/spectre_v2
381+
Date: Januar 2018
382+
Contact: Linux kernel mailing list <[email protected]>
383+
Description: Information about CPU vulnerabilities
384+
385+
The files are named after the code names of CPU
386+
vulnerabilities. The output of those files reflects the
387+
state of the CPUs in the system. Possible output values:
388+
389+
"Not affected" CPU is not affected by the vulnerability
390+
"Vulnerable" CPU is affected and no mitigation in effect
391+
"Mitigation: $M" CPU is affetcted and mitigation $M is in effect

drivers/base/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ config GENERIC_CPU_DEVICES
235235
config GENERIC_CPU_AUTOPROBE
236236
bool
237237

238+
config GENERIC_CPU_VULNERABILITIES
239+
bool
240+
238241
config SOC_BUS
239242
bool
240243
select GLOB

drivers/base/cpu.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,58 @@ static void __init cpu_dev_register_generic(void)
501501
#endif
502502
}
503503

504+
#ifdef CONFIG_GENERIC_CPU_VULNERABILITIES
505+
506+
ssize_t __weak cpu_show_meltdown(struct device *dev,
507+
struct device_attribute *attr, char *buf)
508+
{
509+
return sprintf(buf, "Not affected\n");
510+
}
511+
512+
ssize_t __weak cpu_show_spectre_v1(struct device *dev,
513+
struct device_attribute *attr, char *buf)
514+
{
515+
return sprintf(buf, "Not affected\n");
516+
}
517+
518+
ssize_t __weak cpu_show_spectre_v2(struct device *dev,
519+
struct device_attribute *attr, char *buf)
520+
{
521+
return sprintf(buf, "Not affected\n");
522+
}
523+
524+
static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL);
525+
static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL);
526+
static DEVICE_ATTR(spectre_v2, 0444, cpu_show_spectre_v2, NULL);
527+
528+
static struct attribute *cpu_root_vulnerabilities_attrs[] = {
529+
&dev_attr_meltdown.attr,
530+
&dev_attr_spectre_v1.attr,
531+
&dev_attr_spectre_v2.attr,
532+
NULL
533+
};
534+
535+
static const struct attribute_group cpu_root_vulnerabilities_group = {
536+
.name = "vulnerabilities",
537+
.attrs = cpu_root_vulnerabilities_attrs,
538+
};
539+
540+
static void __init cpu_register_vulnerabilities(void)
541+
{
542+
if (sysfs_create_group(&cpu_subsys.dev_root->kobj,
543+
&cpu_root_vulnerabilities_group))
544+
pr_err("Unable to register CPU vulnerabilities\n");
545+
}
546+
547+
#else
548+
static inline void cpu_register_vulnerabilities(void) { }
549+
#endif
550+
504551
void __init cpu_dev_init(void)
505552
{
506553
if (subsys_system_register(&cpu_subsys, cpu_root_attr_groups))
507554
panic("Failed to register CPU subsystem");
508555

509556
cpu_dev_register_generic();
557+
cpu_register_vulnerabilities();
510558
}

include/linux/cpu.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ extern void cpu_remove_dev_attr(struct device_attribute *attr);
4747
extern int cpu_add_dev_attr_group(struct attribute_group *attrs);
4848
extern void cpu_remove_dev_attr_group(struct attribute_group *attrs);
4949

50+
extern ssize_t cpu_show_meltdown(struct device *dev,
51+
struct device_attribute *attr, char *buf);
52+
extern ssize_t cpu_show_spectre_v1(struct device *dev,
53+
struct device_attribute *attr, char *buf);
54+
extern ssize_t cpu_show_spectre_v2(struct device *dev,
55+
struct device_attribute *attr, char *buf);
56+
5057
extern __printf(4, 5)
5158
struct device *cpu_device_create(struct device *parent, void *drvdata,
5259
const struct attribute_group **groups,

0 commit comments

Comments
 (0)