* [PATCH 0/6] arm64: add support for generic cpu vulnerabilities
@ 2018-08-07 18:14 Mian Yousaf Kaukab
2018-08-07 18:14 ` [PATCH 1/6] arm64: kpti: move check for non-vulnerable CPUs to a function Mian Yousaf Kaukab
` (5 more replies)
0 siblings, 6 replies; 12+ messages in thread
From: Mian Yousaf Kaukab @ 2018-08-07 18:14 UTC (permalink / raw)
To: linux-arm-kernel
GENERIC_CPU_VULNERABILITIES provide a common way to figure out if a
system is affected by vulnerabilities like meltdown and other variants
of spectre. This small series adds support for it in arm64.
Thank you,
Best regards,
Yousaf
Mian Yousaf Kaukab (6):
arm64: kpti: move check for non-vulnerable CPUs to a function
arm64: add sysfs vulnerability show for meltdown
arm64: add sysfs vulnerability show for spectre v1
arm64: add sysfs vulnerability show for spectre v2
arm64: add sysfs vulnerability show for speculative store bypass
arm64: enable generic CPU vulnerabilites support
arch/arm64/Kconfig | 1 +
arch/arm64/include/asm/cpufeature.h | 16 +++++++
arch/arm64/kernel/cpu_errata.c | 84 ++++++++++++++++++++++++++++++++++++-
arch/arm64/kernel/cpufeature.c | 9 +---
4 files changed, 101 insertions(+), 9 deletions(-)
--
2.11.0
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH 1/6] arm64: kpti: move check for non-vulnerable CPUs to a function 2018-08-07 18:14 [PATCH 0/6] arm64: add support for generic cpu vulnerabilities Mian Yousaf Kaukab @ 2018-08-07 18:14 ` Mian Yousaf Kaukab 2018-08-07 18:14 ` [PATCH 2/6] arm64: add sysfs vulnerability show for meltdown Mian Yousaf Kaukab ` (4 subsequent siblings) 5 siblings, 0 replies; 12+ messages in thread From: Mian Yousaf Kaukab @ 2018-08-07 18:14 UTC (permalink / raw) To: linux-arm-kernel Prepare to call it in generic cpu vulnerabilities support. Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de> --- arch/arm64/include/asm/cpufeature.h | 16 ++++++++++++++++ arch/arm64/kernel/cpufeature.c | 9 +-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 1717ba1db35d..0b0b5b3e36ba 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -530,6 +530,22 @@ void arm64_set_ssbd_mitigation(bool state); static inline void arm64_set_ssbd_mitigation(bool state) {} #endif +static inline bool is_cpu_meltdown_safe(void) +{ + /* List of CPUs that are not vulnerable and don't need KPTI */ + static const struct midr_range kpti_safe_list[] = { + MIDR_ALL_VERSIONS(MIDR_CAVIUM_THUNDERX2), + MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN), + { /* sentinel */ } + }; + + /* Don't force KPTI for CPUs that are not vulnerable */ + if (is_midr_in_range_list(read_cpuid_id(), kpti_safe_list)) + return true; + + return false; +} + #endif /* __ASSEMBLY__ */ #endif diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index e238b7932096..6a94f8bce35a 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -865,12 +865,6 @@ static int __kpti_forced; /* 0: not forced, >0: forced on, <0: forced off */ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, int scope) { - /* List of CPUs that are not vulnerable and don't need KPTI */ - static const struct midr_range kpti_safe_list[] = { - MIDR_ALL_VERSIONS(MIDR_CAVIUM_THUNDERX2), - MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN), - { /* sentinel */ } - }; char const *str = "command line option"; /* @@ -894,8 +888,7 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) return true; - /* Don't force KPTI for CPUs that are not vulnerable */ - if (is_midr_in_range_list(read_cpuid_id(), kpti_safe_list)) + if (is_cpu_meltdown_safe()) return false; /* Defer to CPU feature registers */ -- 2.11.0 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/6] arm64: add sysfs vulnerability show for meltdown 2018-08-07 18:14 [PATCH 0/6] arm64: add support for generic cpu vulnerabilities Mian Yousaf Kaukab 2018-08-07 18:14 ` [PATCH 1/6] arm64: kpti: move check for non-vulnerable CPUs to a function Mian Yousaf Kaukab @ 2018-08-07 18:14 ` Mian Yousaf Kaukab 2018-08-07 18:14 ` [PATCH 3/6] arm64: add sysfs vulnerability show for spectre v1 Mian Yousaf Kaukab ` (3 subsequent siblings) 5 siblings, 0 replies; 12+ messages in thread From: Mian Yousaf Kaukab @ 2018-08-07 18:14 UTC (permalink / raw) To: linux-arm-kernel Checking CSV3 support directly in case CONFIG_UNMAP_KERNEL_AT_EL0 is not enabled. Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de> --- arch/arm64/kernel/cpu_errata.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index dec10898d688..996edb4e18ad 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -22,6 +22,7 @@ #include <asm/cpu.h> #include <asm/cputype.h> #include <asm/cpufeature.h> +#include <asm/mmu.h> static bool __maybe_unused is_affected_midr_range(const struct arm64_cpu_capabilities *entry, int scope) @@ -683,3 +684,26 @@ const struct arm64_cpu_capabilities arm64_errata[] = { { } }; + +#ifdef CONFIG_GENERIC_CPU_VULNERABILITIES + +ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, + char *buf) +{ + u64 pfr0; + u32 csv3; + + if (arm64_kernel_unmapped_at_el0()) + return sprintf(buf, "Mitigation: KPTI\n"); + + pfr0 = read_cpuid(ID_AA64PFR0_EL1); + csv3 = cpuid_feature_extract_unsigned_field(pfr0, + ID_AA64PFR0_CSV3_SHIFT); + + if (csv3 || is_cpu_meltdown_safe()) + return sprintf(buf, "Not affected\n"); + + return sprintf(buf, "Vulnerable\n"); +} + +#endif -- 2.11.0 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/6] arm64: add sysfs vulnerability show for spectre v1 2018-08-07 18:14 [PATCH 0/6] arm64: add support for generic cpu vulnerabilities Mian Yousaf Kaukab 2018-08-07 18:14 ` [PATCH 1/6] arm64: kpti: move check for non-vulnerable CPUs to a function Mian Yousaf Kaukab 2018-08-07 18:14 ` [PATCH 2/6] arm64: add sysfs vulnerability show for meltdown Mian Yousaf Kaukab @ 2018-08-07 18:14 ` Mian Yousaf Kaukab 2018-08-07 18:14 ` [PATCH 4/6] arm64: add sysfs vulnerability show for spectre v2 Mian Yousaf Kaukab ` (2 subsequent siblings) 5 siblings, 0 replies; 12+ messages in thread From: Mian Yousaf Kaukab @ 2018-08-07 18:14 UTC (permalink / raw) To: linux-arm-kernel Hard-coded since patches are merged and there are no configuration options. Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de> --- arch/arm64/kernel/cpu_errata.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 996edb4e18ad..92616431ae4e 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -706,4 +706,10 @@ ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, return sprintf(buf, "Vulnerable\n"); } +ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return sprintf(buf, "Mitigation: __user pointer sanitization\n"); +} + #endif -- 2.11.0 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 4/6] arm64: add sysfs vulnerability show for spectre v2 2018-08-07 18:14 [PATCH 0/6] arm64: add support for generic cpu vulnerabilities Mian Yousaf Kaukab ` (2 preceding siblings ...) 2018-08-07 18:14 ` [PATCH 3/6] arm64: add sysfs vulnerability show for spectre v1 Mian Yousaf Kaukab @ 2018-08-07 18:14 ` Mian Yousaf Kaukab 2018-08-07 18:14 ` [PATCH 5/6] arm64: add sysfs vulnerability show for speculative store bypass Mian Yousaf Kaukab 2018-08-07 18:14 ` [PATCH 6/6] arm64: enable generic CPU vulnerabilites support Mian Yousaf Kaukab 5 siblings, 0 replies; 12+ messages in thread From: Mian Yousaf Kaukab @ 2018-08-07 18:14 UTC (permalink / raw) To: linux-arm-kernel Only report mitigation present if hardening callback has been successfully installed. Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de> --- arch/arm64/kernel/cpu_errata.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 92616431ae4e..8469d3be7b15 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -481,7 +481,8 @@ multi_entry_cap_cpu_enable(const struct arm64_cpu_capabilities *entry) caps->cpu_enable(caps); } -#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR +#if defined(CONFIG_HARDEN_BRANCH_PREDICTOR) || \ + defined(CONFIG_GENERIC_CPU_VULNERABILITIES) /* * List of CPUs where we need to issue a psci call to @@ -712,4 +713,35 @@ ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, return sprintf(buf, "Mitigation: __user pointer sanitization\n"); } +ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, + char *buf) +{ + u64 pfr0; + struct bp_hardening_data *data; + + pfr0 = read_cpuid(ID_AA64PFR0_EL1); + if (cpuid_feature_extract_unsigned_field(pfr0, ID_AA64PFR0_CSV2_SHIFT)) + return sprintf(buf, "Not affected\n"); + + if (cpus_have_const_cap(ARM64_HARDEN_BRANCH_PREDICTOR)) { + /* + * Hardware is vulnerable. Lets check if bp hardening callback + * has been successfully installed + */ + data = arm64_get_bp_hardening_data(); + if (data && data->fn) + return sprintf(buf, + "Mitigation: Branch predictor hardening"); + else + /* For example SMCCC_VERSION_1_0 */ + return sprintf(buf, "Vulnerable\n"); + } + + /* In case CONFIG_HARDEN_BRANCH_PREDICTOR is not enabled */ + if (is_midr_in_range_list(read_cpuid_id(), arm64_bp_harden_smccc_cpus)) + return sprintf(buf, "Vulnerable\n"); + + return sprintf(buf, "Not affected\n"); +} + #endif -- 2.11.0 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 5/6] arm64: add sysfs vulnerability show for speculative store bypass 2018-08-07 18:14 [PATCH 0/6] arm64: add support for generic cpu vulnerabilities Mian Yousaf Kaukab ` (3 preceding siblings ...) 2018-08-07 18:14 ` [PATCH 4/6] arm64: add sysfs vulnerability show for spectre v2 Mian Yousaf Kaukab @ 2018-08-07 18:14 ` Mian Yousaf Kaukab 2018-08-07 18:14 ` [PATCH 6/6] arm64: enable generic CPU vulnerabilites support Mian Yousaf Kaukab 5 siblings, 0 replies; 12+ messages in thread From: Mian Yousaf Kaukab @ 2018-08-07 18:14 UTC (permalink / raw) To: linux-arm-kernel Return status based no ssbd_state. Return string "Unknown" in case CONFIG_ARM64_SSBD is disabled or arch workaround2 is not available in the firmware. Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de> --- arch/arm64/kernel/cpu_errata.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 8469d3be7b15..8b60aa30a3fa 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -744,4 +744,24 @@ ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, return sprintf(buf, "Not affected\n"); } +ssize_t cpu_show_spec_store_bypass(struct device *dev, + struct device_attribute *attr, char *buf) +{ + switch (arm64_get_ssbd_state()) { + case ARM64_SSBD_MITIGATED: + return sprintf(buf, "Not affected\n"); + + case ARM64_SSBD_KERNEL: + case ARM64_SSBD_FORCE_ENABLE: + return sprintf(buf, + "Mitigation: Speculative Store Bypass disabled"); + + case ARM64_SSBD_FORCE_DISABLE: + return sprintf(buf, "Vulnerable\n"); + + default: /* ARM64_SSBD_UNKNOWN*/ + return sprintf(buf, "Unknown\n"); + } +} + #endif -- 2.11.0 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 6/6] arm64: enable generic CPU vulnerabilites support 2018-08-07 18:14 [PATCH 0/6] arm64: add support for generic cpu vulnerabilities Mian Yousaf Kaukab ` (4 preceding siblings ...) 2018-08-07 18:14 ` [PATCH 5/6] arm64: add sysfs vulnerability show for speculative store bypass Mian Yousaf Kaukab @ 2018-08-07 18:14 ` Mian Yousaf Kaukab 5 siblings, 0 replies; 12+ messages in thread From: Mian Yousaf Kaukab @ 2018-08-07 18:14 UTC (permalink / raw) To: linux-arm-kernel Enable CPU vulnerabilty show functions for spectre_v1, spectre_v2, meltdown and store-bypass. Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de> --- arch/arm64/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 0dec01a0c81c..ffd97bc0f5d5 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -84,6 +84,7 @@ config ARM64 select GENERIC_CLOCKEVENTS select GENERIC_CLOCKEVENTS_BROADCAST select GENERIC_CPU_AUTOPROBE + select GENERIC_CPU_VULNERABILITIES select GENERIC_EARLY_IOREMAP select GENERIC_IDLE_POLL_SETUP select GENERIC_IRQ_MULTI_HANDLER -- 2.11.0 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 0/6] add system vulnerability sysfs entries @ 2018-12-06 23:44 Jeremy Linton 2018-12-06 23:44 ` [PATCH 2/6] arm64: add sysfs vulnerability show for meltdown Jeremy Linton 0 siblings, 1 reply; 12+ messages in thread From: Jeremy Linton @ 2018-12-06 23:44 UTC (permalink / raw) To: linux-arm-kernel Cc: mark.rutland, suzuki.poulose, marc.zyngier, catalin.marinas, will.deacon, linux-kernel, Jeremy Linton, ykaukab, dave.martin, shankerd Part of this series was originally by Mian Yousaf Kaukab. Arm64 machines should be displaying a human readable vulnerability status to speculative execution attacks in /sys/devices/system/cpu/vulnerabilities This series enables that behavior by providing the expected functions. Those functions expose the cpu errata and feature states, as well as whether firmware is responding appropriately to display the overall machine status. This means that in a heterogeneous machine we will only claim the machine is mitigated or safe if we are confident all booted cores are safe or mitigated. Otherwise, we will display unknown or unsafe depending on how much of the machine configuration can be assured. Jeremy Linton (2): arm64: add sysfs vulnerability show for meltdown arm64: add sysfs vulnerability show for spectre v2 Mian Yousaf Kaukab (4): arm64: kpti: move check for non-vulnerable CPUs to a function arm64: add sysfs vulnerability show for spectre v1 arm64: add sysfs vulnerability show for speculative store bypass arm64: enable generic CPU vulnerabilites support arch/arm64/Kconfig | 1 + arch/arm64/kernel/cpu_errata.c | 110 +++++++++++++++++++++++++++++++-- arch/arm64/kernel/cpufeature.c | 45 +++++++++++--- 3 files changed, 143 insertions(+), 13 deletions(-) -- 2.17.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 2/6] arm64: add sysfs vulnerability show for meltdown 2018-12-06 23:44 [PATCH 0/6] add system vulnerability sysfs entries Jeremy Linton @ 2018-12-06 23:44 ` Jeremy Linton 2018-12-13 9:23 ` Julien Thierry 0 siblings, 1 reply; 12+ messages in thread From: Jeremy Linton @ 2018-12-06 23:44 UTC (permalink / raw) To: linux-arm-kernel Cc: mark.rutland, suzuki.poulose, marc.zyngier, catalin.marinas, will.deacon, linux-kernel, Jeremy Linton, ykaukab, dave.martin, shankerd Add a simple state machine which will track whether all the online cores in a machine are vulnerable. Once that is done we have a fairly authoritative view of the machine vulnerability, which allows us to make a judgment about machine safety if it hasn't been mitigated. Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> --- arch/arm64/kernel/cpufeature.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 242898395f68..bea9adfef7fa 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -905,6 +905,8 @@ has_useable_cnp(const struct arm64_cpu_capabilities *entry, int scope) return has_cpuid_feature(entry, scope); } +static enum { A64_MELT_UNSET, A64_MELT_SAFE, A64_MELT_UNKN } __meltdown_safe = A64_MELT_UNSET; + #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 static int __kpti_forced; /* 0: not forced, >0: forced on, <0: forced off */ @@ -928,6 +930,15 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, { char const *str = "command line option"; + bool meltdown_safe = is_cpu_meltdown_safe() || + has_cpuid_feature(entry, scope); + + /* Only safe if all booted cores are known safe */ + if (meltdown_safe && __meltdown_safe == A64_MELT_UNSET) + __meltdown_safe = A64_MELT_SAFE; + else if (!meltdown_safe) + __meltdown_safe = A64_MELT_UNKN; + /* * For reasons that aren't entirely clear, enabling KPTI on Cavium * ThunderX leads to apparent I-cache corruption of kernel text, which @@ -949,11 +960,7 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) return true; - if (is_cpu_meltdown_safe()) - return false; - - /* Defer to CPU feature registers */ - return !has_cpuid_feature(entry, scope); + return !meltdown_safe; } static void @@ -1920,3 +1927,17 @@ static int __init enable_mrs_emulation(void) } core_initcall(enable_mrs_emulation); + +#ifdef CONFIG_GENERIC_CPU_VULNERABILITIES +ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, + char *buf) +{ + if (arm64_kernel_unmapped_at_el0()) + return sprintf(buf, "Mitigation: KPTI\n"); + + if (__meltdown_safe == A64_MELT_SAFE) + return sprintf(buf, "Not affected\n"); + + return sprintf(buf, "Unknown\n"); +} +#endif -- 2.17.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 2/6] arm64: add sysfs vulnerability show for meltdown 2018-12-06 23:44 ` [PATCH 2/6] arm64: add sysfs vulnerability show for meltdown Jeremy Linton @ 2018-12-13 9:23 ` Julien Thierry 2018-12-13 10:46 ` Julien Thierry 0 siblings, 1 reply; 12+ messages in thread From: Julien Thierry @ 2018-12-13 9:23 UTC (permalink / raw) To: Jeremy Linton, linux-arm-kernel Cc: mark.rutland, suzuki.poulose, marc.zyngier, catalin.marinas, will.deacon, linux-kernel, ykaukab, dave.martin, shankerd Hi Jeremy, On 06/12/2018 23:44, Jeremy Linton wrote: > Add a simple state machine which will track whether > all the online cores in a machine are vulnerable. > > Once that is done we have a fairly authoritative view > of the machine vulnerability, which allows us to make a > judgment about machine safety if it hasn't been mitigated. > > Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> > --- > arch/arm64/kernel/cpufeature.c | 31 ++++++++++++++++++++++++++----- > 1 file changed, 26 insertions(+), 5 deletions(-) > > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > index 242898395f68..bea9adfef7fa 100644 > --- a/arch/arm64/kernel/cpufeature.c > +++ b/arch/arm64/kernel/cpufeature.c > @@ -905,6 +905,8 @@ has_useable_cnp(const struct arm64_cpu_capabilities *entry, int scope) > return has_cpuid_feature(entry, scope); > } > > +static enum { A64_MELT_UNSET, A64_MELT_SAFE, A64_MELT_UNKN } __meltdown_safe = A64_MELT_UNSET; > + I'm wondering, do we really need that tri state? Can't we consider that we are safe an move to unsafe/unkown if any cpu during bring up is not in the safe list? The only user of this is cpu_show_meltdown, but I don't imagine it'll get called before unmap_kernel_at_el0() is called for the boot CPU which should initialise that state. Or is there another reason for having that UNSET state? Thanks, > #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 > static int __kpti_forced; /* 0: not forced, >0: forced on, <0: forced off */ > > @@ -928,6 +930,15 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, > { > char const *str = "command line option"; > > + bool meltdown_safe = is_cpu_meltdown_safe() || > + has_cpuid_feature(entry, scope); > + > + /* Only safe if all booted cores are known safe */ > + if (meltdown_safe && __meltdown_safe == A64_MELT_UNSET) > + __meltdown_safe = A64_MELT_SAFE; > + else if (!meltdown_safe) > + __meltdown_safe = A64_MELT_UNKN; > + > /* > * For reasons that aren't entirely clear, enabling KPTI on Cavium > * ThunderX leads to apparent I-cache corruption of kernel text, which > @@ -949,11 +960,7 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, > if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) > return true; > > - if (is_cpu_meltdown_safe()) > - return false; > - > - /* Defer to CPU feature registers */ > - return !has_cpuid_feature(entry, scope); > + return !meltdown_safe; > } > > static void > @@ -1920,3 +1927,17 @@ static int __init enable_mrs_emulation(void) > } > > core_initcall(enable_mrs_emulation); > + > +#ifdef CONFIG_GENERIC_CPU_VULNERABILITIES > +ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, > + char *buf) > +{ > + if (arm64_kernel_unmapped_at_el0()) > + return sprintf(buf, "Mitigation: KPTI\n"); > + > + if (__meltdown_safe == A64_MELT_SAFE) > + return sprintf(buf, "Not affected\n"); > + > + return sprintf(buf, "Unknown\n"); > +} > +#endif > -- Julien Thierry _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/6] arm64: add sysfs vulnerability show for meltdown 2018-12-13 9:23 ` Julien Thierry @ 2018-12-13 10:46 ` Julien Thierry 2018-12-12 14:49 ` Jeremy Linton 0 siblings, 1 reply; 12+ messages in thread From: Julien Thierry @ 2018-12-13 10:46 UTC (permalink / raw) To: Jeremy Linton, linux-arm-kernel Cc: mark.rutland, suzuki.poulose, marc.zyngier, catalin.marinas, will.deacon, linux-kernel, ykaukab, dave.martin, shankerd On 13/12/2018 09:23, Julien Thierry wrote: > Hi Jeremy, > > On 06/12/2018 23:44, Jeremy Linton wrote: >> Add a simple state machine which will track whether >> all the online cores in a machine are vulnerable. >> >> Once that is done we have a fairly authoritative view >> of the machine vulnerability, which allows us to make a >> judgment about machine safety if it hasn't been mitigated. >> >> Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> >> --- >> arch/arm64/kernel/cpufeature.c | 31 ++++++++++++++++++++++++++----- >> 1 file changed, 26 insertions(+), 5 deletions(-) >> >> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c >> index 242898395f68..bea9adfef7fa 100644 >> --- a/arch/arm64/kernel/cpufeature.c >> +++ b/arch/arm64/kernel/cpufeature.c >> @@ -905,6 +905,8 @@ has_useable_cnp(const struct arm64_cpu_capabilities *entry, int scope) >> return has_cpuid_feature(entry, scope); >> } >> >> +static enum { A64_MELT_UNSET, A64_MELT_SAFE, A64_MELT_UNKN } __meltdown_safe = A64_MELT_UNSET; >> + > > I'm wondering, do we really need that tri state? > > Can't we consider that we are safe an move to unsafe/unkown if any cpu > during bring up is not in the safe list? > > The only user of this is cpu_show_meltdown, but I don't imagine it'll > get called before unmap_kernel_at_el0() is called for the boot CPU which > should initialise that state. > > Or is there another reason for having that UNSET state? > Ok, I think I get the point of the UNSET as #ifndef CONFIG_UNMAP_KERNEL_AT_EL0 we don't set the state. But does that mean we always fall in the "Unknown" case when we don't build kpti in? Is that desirable? If so, I'd suggest replacing the tri-state with the following change: >> + >> +#ifdef CONFIG_GENERIC_CPU_VULNERABILITIES >> +ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, >> + char *buf) >> +{ >> + if (arm64_kernel_unmapped_at_el0()) >> + return sprintf(buf, "Mitigation: KPTI\n"); >> + if (!IS_ENABLED(UNMAP_KERNEL_AT_EL0) || !meltdown_safe) sprintf(buf, "Unknown\n"); else sprintf(buf, "Not affected\n"); Thanks, -- Julien Thierry _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/6] arm64: add sysfs vulnerability show for meltdown 2018-12-13 10:46 ` Julien Thierry @ 2018-12-12 14:49 ` Jeremy Linton 2018-12-14 8:55 ` Julien Thierry 0 siblings, 1 reply; 12+ messages in thread From: Jeremy Linton @ 2018-12-12 14:49 UTC (permalink / raw) To: Julien Thierry, linux-arm-kernel Cc: mark.rutland, suzuki.poulose, marc.zyngier, catalin.marinas, will.deacon, linux-kernel, ykaukab, dave.martin, shankerd Hi Julien, Thanks for taking a look at this! On 12/13/2018 04:46 AM, Julien Thierry wrote: > > > On 13/12/2018 09:23, Julien Thierry wrote: >> Hi Jeremy, >> >> On 06/12/2018 23:44, Jeremy Linton wrote: >>> Add a simple state machine which will track whether >>> all the online cores in a machine are vulnerable. >>> >>> Once that is done we have a fairly authoritative view >>> of the machine vulnerability, which allows us to make a >>> judgment about machine safety if it hasn't been mitigated. >>> >>> Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> >>> --- >>> arch/arm64/kernel/cpufeature.c | 31 ++++++++++++++++++++++++++----- >>> 1 file changed, 26 insertions(+), 5 deletions(-) >>> >>> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c >>> index 242898395f68..bea9adfef7fa 100644 >>> --- a/arch/arm64/kernel/cpufeature.c >>> +++ b/arch/arm64/kernel/cpufeature.c >>> @@ -905,6 +905,8 @@ has_useable_cnp(const struct arm64_cpu_capabilities *entry, int scope) >>> return has_cpuid_feature(entry, scope); >>> } >>> >>> +static enum { A64_MELT_UNSET, A64_MELT_SAFE, A64_MELT_UNKN } __meltdown_safe = A64_MELT_UNSET; >>> + >> >> I'm wondering, do we really need that tri state? >> >> Can't we consider that we are safe an move to unsafe/unkown if any cpu >> during bring up is not in the safe list? >> >> The only user of this is cpu_show_meltdown, but I don't imagine it'll >> get called before unmap_kernel_at_el0() is called for the boot CPU which >> should initialise that state. >> >> Or is there another reason for having that UNSET state? >> > > Ok, I think I get the point of the UNSET as #ifndef > CONFIG_UNMAP_KERNEL_AT_EL0 we don't set the state. But does that mean we > always fall in the "Unknown" case when we don't build kpti in? Is that > desirable? > > If so, I'd suggest replacing the tri-state with the following change: > > >>> + >>> +#ifdef CONFIG_GENERIC_CPU_VULNERABILITIES >>> +ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, >>> + char *buf) >>> +{ >>> + if (arm64_kernel_unmapped_at_el0()) >>> + return sprintf(buf, "Mitigation: KPTI\n"); >>> + > > if (!IS_ENABLED(UNMAP_KERNEL_AT_EL0) || !meltdown_safe) > sprintf(buf, "Unknown\n"); > else > sprintf(buf, "Not affected\n"); If I'm understanding what your suggesting: Isn't this only checking the current core, rather than the whole machine? IIRC that was the fundamental complaint with the original set. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/6] arm64: add sysfs vulnerability show for meltdown 2018-12-12 14:49 ` Jeremy Linton @ 2018-12-14 8:55 ` Julien Thierry 0 siblings, 0 replies; 12+ messages in thread From: Julien Thierry @ 2018-12-14 8:55 UTC (permalink / raw) To: Jeremy Linton, linux-arm-kernel Cc: mark.rutland, suzuki.poulose, marc.zyngier, catalin.marinas, will.deacon, linux-kernel, ykaukab, dave.martin, shankerd Hi Jeremy, On 12/12/2018 14:49, Jeremy Linton wrote: > Hi Julien, > > Thanks for taking a look at this! > > On 12/13/2018 04:46 AM, Julien Thierry wrote: >> >> >> On 13/12/2018 09:23, Julien Thierry wrote: >>> Hi Jeremy, >>> >>> On 06/12/2018 23:44, Jeremy Linton wrote: >>>> Add a simple state machine which will track whether >>>> all the online cores in a machine are vulnerable. >>>> >>>> Once that is done we have a fairly authoritative view >>>> of the machine vulnerability, which allows us to make a >>>> judgment about machine safety if it hasn't been mitigated. >>>> >>>> Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> >>>> --- >>>> arch/arm64/kernel/cpufeature.c | 31 ++++++++++++++++++++++++++----- >>>> 1 file changed, 26 insertions(+), 5 deletions(-) >>>> >>>> diff --git a/arch/arm64/kernel/cpufeature.c >>>> b/arch/arm64/kernel/cpufeature.c >>>> index 242898395f68..bea9adfef7fa 100644 >>>> --- a/arch/arm64/kernel/cpufeature.c >>>> +++ b/arch/arm64/kernel/cpufeature.c >>>> @@ -905,6 +905,8 @@ has_useable_cnp(const struct >>>> arm64_cpu_capabilities *entry, int scope) >>>> return has_cpuid_feature(entry, scope); >>>> } >>>> +static enum { A64_MELT_UNSET, A64_MELT_SAFE, A64_MELT_UNKN } >>>> __meltdown_safe = A64_MELT_UNSET; >>>> + >>> >>> I'm wondering, do we really need that tri state? >>> >>> Can't we consider that we are safe an move to unsafe/unkown if any cpu >>> during bring up is not in the safe list? >>> >>> The only user of this is cpu_show_meltdown, but I don't imagine it'll >>> get called before unmap_kernel_at_el0() is called for the boot CPU which >>> should initialise that state. >>> >>> Or is there another reason for having that UNSET state? >>> >> >> Ok, I think I get the point of the UNSET as #ifndef >> CONFIG_UNMAP_KERNEL_AT_EL0 we don't set the state. But does that mean we >> always fall in the "Unknown" case when we don't build kpti in? Is that >> desirable? >> >> If so, I'd suggest replacing the tri-state with the following change: >> >> >>>> + >>>> +#ifdef CONFIG_GENERIC_CPU_VULNERABILITIES >>>> +ssize_t cpu_show_meltdown(struct device *dev, struct >>>> device_attribute *attr, >>>> + char *buf) >>>> +{ >>>> + if (arm64_kernel_unmapped_at_el0()) >>>> + return sprintf(buf, "Mitigation: KPTI\n"); >>>> + >> >> if (!IS_ENABLED(UNMAP_KERNEL_AT_EL0) || !meltdown_safe) >> sprintf(buf, "Unknown\n"); >> else >> sprintf(buf, "Not affected\n"); > > If I'm understanding what your suggesting: > > Isn't this only checking the current core, rather than the whole > machine? IIRC that was the fundamental complaint with the original set. > Sorry, yes, I meant to check "!__meltdown_safe". Basically my suggestion is to replace the static enum variable with a static bool and handle the "UNSET" case on whether we built the mitigation. Does that make sense? However, there's still the same issue as with patch 4. If we don't build the mitigation, we say that we don't know the status of the system. I think it would be nice to be able to say that a system is safe even when the mitigation is not built. People knowing they have a safe system might be inclined to not build additional stuff they don't need. Cheers. -- Julien Thierry _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2018-12-14 8:55 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-08-07 18:14 [PATCH 0/6] arm64: add support for generic cpu vulnerabilities Mian Yousaf Kaukab 2018-08-07 18:14 ` [PATCH 1/6] arm64: kpti: move check for non-vulnerable CPUs to a function Mian Yousaf Kaukab 2018-08-07 18:14 ` [PATCH 2/6] arm64: add sysfs vulnerability show for meltdown Mian Yousaf Kaukab 2018-08-07 18:14 ` [PATCH 3/6] arm64: add sysfs vulnerability show for spectre v1 Mian Yousaf Kaukab 2018-08-07 18:14 ` [PATCH 4/6] arm64: add sysfs vulnerability show for spectre v2 Mian Yousaf Kaukab 2018-08-07 18:14 ` [PATCH 5/6] arm64: add sysfs vulnerability show for speculative store bypass Mian Yousaf Kaukab 2018-08-07 18:14 ` [PATCH 6/6] arm64: enable generic CPU vulnerabilites support Mian Yousaf Kaukab -- strict thread matches above, loose matches on Subject: below -- 2018-12-06 23:44 [PATCH 0/6] add system vulnerability sysfs entries Jeremy Linton 2018-12-06 23:44 ` [PATCH 2/6] arm64: add sysfs vulnerability show for meltdown Jeremy Linton 2018-12-13 9:23 ` Julien Thierry 2018-12-13 10:46 ` Julien Thierry 2018-12-12 14:49 ` Jeremy Linton 2018-12-14 8:55 ` Julien Thierry
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox