-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARM: report Spectre v2 status through sysfs
As per other architectures, add support for reporting the Spectre vulnerability status via sysfs CPU. Acked-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
- Loading branch information
Russell King (Oracle)
committed
Mar 5, 2022
1 parent
df0cc57
commit 9dd7819
Showing
5 changed files
with
187 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
|
||
#ifndef __ASM_SPECTRE_H | ||
#define __ASM_SPECTRE_H | ||
|
||
enum { | ||
SPECTRE_UNAFFECTED, | ||
SPECTRE_MITIGATED, | ||
SPECTRE_VULNERABLE, | ||
}; | ||
|
||
enum { | ||
__SPECTRE_V2_METHOD_BPIALL, | ||
__SPECTRE_V2_METHOD_ICIALLU, | ||
__SPECTRE_V2_METHOD_SMC, | ||
__SPECTRE_V2_METHOD_HVC, | ||
}; | ||
|
||
enum { | ||
SPECTRE_V2_METHOD_BPIALL = BIT(__SPECTRE_V2_METHOD_BPIALL), | ||
SPECTRE_V2_METHOD_ICIALLU = BIT(__SPECTRE_V2_METHOD_ICIALLU), | ||
SPECTRE_V2_METHOD_SMC = BIT(__SPECTRE_V2_METHOD_SMC), | ||
SPECTRE_V2_METHOD_HVC = BIT(__SPECTRE_V2_METHOD_HVC), | ||
}; | ||
|
||
void spectre_v2_update_state(unsigned int state, unsigned int methods); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
#include <linux/cpu.h> | ||
#include <linux/device.h> | ||
|
||
#include <asm/spectre.h> | ||
|
||
ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, | ||
char *buf) | ||
{ | ||
return sprintf(buf, "Mitigation: __user pointer sanitization\n"); | ||
} | ||
|
||
static unsigned int spectre_v2_state; | ||
static unsigned int spectre_v2_methods; | ||
|
||
void spectre_v2_update_state(unsigned int state, unsigned int method) | ||
{ | ||
if (state > spectre_v2_state) | ||
spectre_v2_state = state; | ||
spectre_v2_methods |= method; | ||
} | ||
|
||
ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, | ||
char *buf) | ||
{ | ||
const char *method; | ||
|
||
if (spectre_v2_state == SPECTRE_UNAFFECTED) | ||
return sprintf(buf, "%s\n", "Not affected"); | ||
|
||
if (spectre_v2_state != SPECTRE_MITIGATED) | ||
return sprintf(buf, "%s\n", "Vulnerable"); | ||
|
||
switch (spectre_v2_methods) { | ||
case SPECTRE_V2_METHOD_BPIALL: | ||
method = "Branch predictor hardening"; | ||
break; | ||
|
||
case SPECTRE_V2_METHOD_ICIALLU: | ||
method = "I-cache invalidation"; | ||
break; | ||
|
||
case SPECTRE_V2_METHOD_SMC: | ||
case SPECTRE_V2_METHOD_HVC: | ||
method = "Firmware call"; | ||
break; | ||
|
||
default: | ||
method = "Multiple mitigations"; | ||
break; | ||
} | ||
|
||
return sprintf(buf, "Mitigation: %s\n", method); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters