-
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.
Follow the patterns of the other architectures that use GENERIC_CPU_VULNERABILITIES for riscv to introduce the ghostwrite vulnerability and mitigation. The mitigation is to disable all vector which is accomplished by clearing the bit from the cpufeature field. Ghostwrite only affects thead c9xx CPUs that impelment xtheadvector, so the vulerability will only be mitigated on these CPUs. Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> Tested-by: Yangyu Chen <cyy@cyyself.name> Link: https://lore.kernel.org/r/20241113-xtheadvector-v11-14-236c22791ef9@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
- Loading branch information
Charlie Jenkins
authored and
Palmer Dabbelt
committed
Jan 18, 2025
1 parent
c384c5d
commit 4bf9706
Showing
9 changed files
with
138 additions
and
2 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
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,22 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
/* | ||
* Interface for managing mitigations for riscv vulnerabilities. | ||
* | ||
* Copyright (C) 2024 Rivos Inc. | ||
*/ | ||
|
||
#ifndef __ASM_BUGS_H | ||
#define __ASM_BUGS_H | ||
|
||
/* Watch out, ordering is important here. */ | ||
enum mitigation_state { | ||
UNAFFECTED, | ||
MITIGATED, | ||
VULNERABLE, | ||
}; | ||
|
||
void ghostwrite_set_vulnerable(void); | ||
bool ghostwrite_enable_mitigation(void); | ||
enum mitigation_state ghostwrite_get_state(void); | ||
|
||
#endif /* __ASM_BUGS_H */ |
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
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,60 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* Copyright (C) 2024 Rivos Inc. | ||
*/ | ||
|
||
#include <linux/cpu.h> | ||
#include <linux/device.h> | ||
#include <linux/sprintf.h> | ||
|
||
#include <asm/bugs.h> | ||
#include <asm/vendor_extensions/thead.h> | ||
|
||
static enum mitigation_state ghostwrite_state; | ||
|
||
void ghostwrite_set_vulnerable(void) | ||
{ | ||
ghostwrite_state = VULNERABLE; | ||
} | ||
|
||
/* | ||
* Vendor extension alternatives will use the value set at the time of boot | ||
* alternative patching, thus this must be called before boot alternatives are | ||
* patched (and after extension probing) to be effective. | ||
* | ||
* Returns true if mitgated, false otherwise. | ||
*/ | ||
bool ghostwrite_enable_mitigation(void) | ||
{ | ||
if (IS_ENABLED(CONFIG_RISCV_ISA_XTHEADVECTOR) && | ||
ghostwrite_state == VULNERABLE && !cpu_mitigations_off()) { | ||
disable_xtheadvector(); | ||
ghostwrite_state = MITIGATED; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
enum mitigation_state ghostwrite_get_state(void) | ||
{ | ||
return ghostwrite_state; | ||
} | ||
|
||
ssize_t cpu_show_ghostwrite(struct device *dev, struct device_attribute *attr, char *buf) | ||
{ | ||
if (IS_ENABLED(CONFIG_RISCV_ISA_XTHEADVECTOR)) { | ||
switch (ghostwrite_state) { | ||
case UNAFFECTED: | ||
return sprintf(buf, "Not affected\n"); | ||
case MITIGATED: | ||
return sprintf(buf, "Mitigation: xtheadvector disabled\n"); | ||
case VULNERABLE: | ||
fallthrough; | ||
default: | ||
return sprintf(buf, "Vulnerable\n"); | ||
} | ||
} else { | ||
return sprintf(buf, "Not affected\n"); | ||
} | ||
} |
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
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