public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/cpufeatures: make bits in cpu_caps_cleared[] and cpu_cpus_set[] exclusive
@ 2020-03-18  6:16 Xiaoyao Li
  2020-03-18 10:32 ` Borislav Petkov
  0 siblings, 1 reply; 3+ messages in thread
From: Xiaoyao Li @ 2020-03-18  6:16 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin
  Cc: xiaoyao.li, x86, linux-kernel

In apply_forced_caps(), cpu_caps_set[] overrides cpu_caps_cleared[], so
that setup_clear_cpu_cap() cannot clear one cap if setup_force_cpu_cap()
sets the cap before it.

Explicitly clear the bit in cpu_caps_cleared[] when set it in
cpu_caps_set[], and vice versa, can fix this.

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
 arch/x86/include/asm/cpufeature.h | 1 +
 arch/x86/kernel/cpu/cpuid-deps.c  | 1 +
 2 files changed, 2 insertions(+)

diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index 59bf91c57aa8..f6d976b05d2c 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -144,6 +144,7 @@ extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit);
 #define setup_force_cpu_cap(bit) do { \
 	set_cpu_cap(&boot_cpu_data, bit);	\
 	set_bit(bit, (unsigned long *)cpu_caps_set);	\
+	clear_bit(bit, (unsigned long *)cpu_caps_cleared);	\
 } while (0)
 
 #define setup_force_cpu_bug(bit) setup_force_cpu_cap(bit)
diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c
index 3cbe24ca80ab..e16c36094e6c 100644
--- a/arch/x86/kernel/cpu/cpuid-deps.c
+++ b/arch/x86/kernel/cpu/cpuid-deps.c
@@ -82,6 +82,7 @@ static inline void clear_feature(struct cpuinfo_x86 *c, unsigned int feature)
 	if (!c) {
 		clear_cpu_cap(&boot_cpu_data, feature);
 		set_bit(feature, (unsigned long *)cpu_caps_cleared);
+		clear_bit(feature, (unsigned long *)cpu_caps_set);
 	} else {
 		clear_bit(feature, (unsigned long *)c->x86_capability);
 	}
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/cpufeatures: make bits in cpu_caps_cleared[] and cpu_cpus_set[] exclusive
  2020-03-18  6:16 [PATCH] x86/cpufeatures: make bits in cpu_caps_cleared[] and cpu_cpus_set[] exclusive Xiaoyao Li
@ 2020-03-18 10:32 ` Borislav Petkov
  2020-03-18 12:57   ` Xiaoyao Li
  0 siblings, 1 reply; 3+ messages in thread
From: Borislav Petkov @ 2020-03-18 10:32 UTC (permalink / raw)
  To: Xiaoyao Li
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, linux-kernel

On Wed, Mar 18, 2020 at 02:16:24PM +0800, Xiaoyao Li wrote:
> In apply_forced_caps(), cpu_caps_set[] overrides cpu_caps_cleared[], so
> that setup_clear_cpu_cap() cannot clear one cap if setup_force_cpu_cap()
> sets the cap before it.

Context pls: what is the observation, what are you trying to do,
reproducer, etc?

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/cpufeatures: make bits in cpu_caps_cleared[] and cpu_cpus_set[] exclusive
  2020-03-18 10:32 ` Borislav Petkov
@ 2020-03-18 12:57   ` Xiaoyao Li
  0 siblings, 0 replies; 3+ messages in thread
From: Xiaoyao Li @ 2020-03-18 12:57 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, linux-kernel

On 3/18/2020 6:32 PM, Borislav Petkov wrote:
> On Wed, Mar 18, 2020 at 02:16:24PM +0800, Xiaoyao Li wrote:
>> In apply_forced_caps(), cpu_caps_set[] overrides cpu_caps_cleared[], so
>> that setup_clear_cpu_cap() cannot clear one cap if setup_force_cpu_cap()
>> sets the cap before it.
> 
> Context pls: what is the observation, what are you trying to do,
> reproducer, etc?

Well. I use setup_force_cup_cap(XXX) to set one flag, XXX, during early 
boot. And use setup_clear_cpu_cap(XXX) to clear this flag when something 
wrong later. However, it turns out that the flag is still set when I use 
cpu_has(c, XXX) to check when init each AP. I have to clear the flag XXX 
explicitly using clear_cpu_cap(c, XXX). However, in /proc/cpuinfo, this 
XXX flag still presents on every CPU.

> Thx.
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-18 12:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-18  6:16 [PATCH] x86/cpufeatures: make bits in cpu_caps_cleared[] and cpu_cpus_set[] exclusive Xiaoyao Li
2020-03-18 10:32 ` Borislav Petkov
2020-03-18 12:57   ` Xiaoyao Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox