[PATCH] LoongArch: Enable generic CPU vulnerabilites support

Tiezhu Yang posted 1 patch 2 months ago
arch/loongarch/Kconfig | 1 +
1 file changed, 1 insertion(+)
[PATCH] LoongArch: Enable generic CPU vulnerabilites support
Posted by Tiezhu Yang 2 months ago
Currently, many architectures support generic CPU vulnerabilites,
such as x86, arm64 and riscv:

  commit 61dc0f555b5c ("x86/cpu: Implement CPU vulnerabilites sysfs functions")
  commit 61ae1321f06c ("arm64: enable generic CPU vulnerabilites support")
  commit 0e3f3649d44b ("riscv: Enable generic CPU vulnerabilites support")

All LoongArch CPUs (not only LS3A5000) implement a special mechanism
in the processor core to prevent "Spectre" and "Meltdown" attacks, so
it can enable generic CPU vulnerabilites support for LoongArch too.

Without this patch, there are no user interfaces of vulnerabilities
to check on LoongArch. The output of those files reflects the state
of the CPUs in the system, the output value "Not affected" means
"CPU is not affected by the vulnerability".

Before:

  # cat /sys/devices/system/cpu/vulnerabilities/spec_rstack_overflow
  cat: /sys/devices/system/cpu/vulnerabilities/spec_rstack_overflow: No such file or directory
  # cat /sys/devices/system/cpu/vulnerabilities/spec_store_bypass
  cat: /sys/devices/system/cpu/vulnerabilities/spec_store_bypass: No such file or directory
  # cat /sys/devices/system/cpu/vulnerabilities/meltdown
  cat: /sys/devices/system/cpu/vulnerabilities/meltdown: No such file or directory

After:

  # cat /sys/devices/system/cpu/vulnerabilities/spec_rstack_overflow
  Not affected
  # cat /sys/devices/system/cpu/vulnerabilities/spec_store_bypass
  Not affected
  # cat /sys/devices/system/cpu/vulnerabilities/meltdown
  Not affected

Link: https://www.loongson.cn/EN/news/show?id=633
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 arch/loongarch/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
index 6d68c5020307..4b02b0492c3b 100644
--- a/arch/loongarch/Kconfig
+++ b/arch/loongarch/Kconfig
@@ -84,6 +84,7 @@ config LOONGARCH
 	select GENERIC_CMOS_UPDATE
 	select GENERIC_CPU_AUTOPROBE
 	select GENERIC_CPU_DEVICES
+	select GENERIC_CPU_VULNERABILITIES
 	select GENERIC_ENTRY
 	select GENERIC_GETTIMEOFDAY
 	select GENERIC_IOREMAP if !ARCH_IOREMAP
-- 
2.42.0
Re: [PATCH] LoongArch: Enable generic CPU vulnerabilites support
Posted by Xi Ruoyao 2 months ago
On Tue, 2024-09-24 at 14:20 +0800, Tiezhu Yang wrote:
> Currently, many architectures support generic CPU vulnerabilites,
> such as x86, arm64 and riscv:
> 
>   commit 61dc0f555b5c ("x86/cpu: Implement CPU vulnerabilites sysfs functions")
>   commit 61ae1321f06c ("arm64: enable generic CPU vulnerabilites support")
>   commit 0e3f3649d44b ("riscv: Enable generic CPU vulnerabilites support")
> 
> All LoongArch CPUs (not only LS3A5000)

There will be other LoongArch CPUs (some may be even not designed by
Loongson Technology).  So to me we should match the CPUCFG.PRID value
and report "Unknown: No mitigations" for unknown models, instead of
being too optimistic and report "Not Affected" for them.

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University