* [RFC PATCH 0/4] x86, cpu: Expand ->x86_capability flags with bugs bitvector
@ 2013-02-11 11:18 Borislav Petkov
2013-02-11 11:18 ` [RFC PATCH 1/4] x86, cpu: Expand cpufeature facility to include cpu bugs Borislav Petkov
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Borislav Petkov @ 2013-02-11 11:18 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: X86 ML, LKML, Borislav Petkov
From: Borislav Petkov <bp@suse.de>
Hi,
so this is a rough first version to collect some initial comments. It is
lightly tested in kvm.
Thanks.
Borislav Petkov (4):
x86, cpu: Expand cpufeature facility to include cpu bugs
x86, cpu: Convert F00F bug detection
x86, cpu: Convert FDIV bug detection
x86, cpu: Convert Cyrix coma bug detection
arch/x86/include/asm/cpufeature.h | 38 ++++++++++++++++++++++++++++++++++++++
arch/x86/include/asm/processor.h | 6 +-----
arch/x86/kernel/alternative.c | 2 +-
arch/x86/kernel/cpu/bugs.c | 5 +++--
arch/x86/kernel/cpu/common.c | 4 ++++
arch/x86/kernel/cpu/cyrix.c | 5 +++--
arch/x86/kernel/cpu/intel.c | 4 ++--
arch/x86/kernel/cpu/proc.c | 6 +++---
arch/x86/mm/fault.c | 2 +-
9 files changed, 56 insertions(+), 16 deletions(-)
--
1.8.1.3.535.ga923c31
^ permalink raw reply [flat|nested] 6+ messages in thread
* [RFC PATCH 1/4] x86, cpu: Expand cpufeature facility to include cpu bugs
2013-02-11 11:18 [RFC PATCH 0/4] x86, cpu: Expand ->x86_capability flags with bugs bitvector Borislav Petkov
@ 2013-02-11 11:18 ` Borislav Petkov
2013-02-13 23:23 ` H. Peter Anvin
2013-02-11 11:18 ` [RFC PATCH 2/4] x86, cpu: Convert F00F bug detection Borislav Petkov
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Borislav Petkov @ 2013-02-11 11:18 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: X86 ML, LKML, Borislav Petkov
From: Borislav Petkov <bp@suse.de>
We add another 32-bit vector at the end of the ->x86_capability
bitvector which collects bugs present in CPUs. After all, a CPU bug is a
kind of a capability, albeit a strange one.
Signed-off-by: Borislav Petkov <bp@suse.de>
---
arch/x86/include/asm/cpufeature.h | 34 ++++++++++++++++++++++++++++++++++
arch/x86/include/asm/processor.h | 2 +-
arch/x86/kernel/alternative.c | 2 +-
arch/x86/kernel/cpu/common.c | 4 ++++
4 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index 2d9075e863a0..68daf877dad5 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -9,6 +9,7 @@
#endif
#define NCAPINTS 10 /* N 32-bit words worth of info */
+#define NBUGINTS 1 /* N 32-bit bug flags */
/*
* Note: If the comment begins with a quoted string, that string is used
@@ -399,6 +400,39 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
#define static_cpu_has(bit) boot_cpu_has(bit)
#endif
+#define __BUG_CHECK_BIT(bit) \
+({ \
+ WARN_ON(bit >> 5 < NCAPINTS); \
+ bit; \
+})
+
+#define cpu_has_bug(c, bit) \
+({ \
+ unsigned __bit = __BUG_CHECK_BIT((bit)); \
+ cpu_has(c, __bit); \
+})
+
+#define boot_cpu_has_bug(bit) \
+ cpu_has_bug(&boot_cpu_data, (bit))
+
+#define static_cpu_has_bug(bit) \
+({ \
+ unsigned __bit = __BUG_CHECK_BIT((bit)); \
+ static_cpu_has(__bit); \
+})
+
+#define set_cpu_bug(c, bit) \
+({ \
+ unsigned __bit = __BUG_CHECK_BIT((bit)); \
+ set_cpu_cap(c, __bit); \
+})
+
+#define clear_cpu_bug(c, bit) \
+({ \
+ unsigned __bit = __BUG_CHECK_BIT((bit)); \
+ clear_cpu_cap(c, __bit); \
+})
+
#endif /* defined(__KERNEL__) && !defined(__ASSEMBLY__) */
#endif /* _ASM_X86_CPUFEATURE_H */
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 439f27a41ee8..67721c634bf0 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -108,7 +108,7 @@ struct cpuinfo_x86 {
__u32 extended_cpuid_level;
/* Maximum supported CPUID level, -1=no CPUID: */
int cpuid_level;
- __u32 x86_capability[NCAPINTS];
+ __u32 x86_capability[NCAPINTS + NBUGINTS];
char x86_vendor_id[16];
char x86_model_id[64];
/* in KB - valid for CPUS which support this call: */
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index ef5ccca79a6c..c15cf9a25e27 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -271,7 +271,7 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
replacement = (u8 *)&a->repl_offset + a->repl_offset;
BUG_ON(a->replacementlen > a->instrlen);
BUG_ON(a->instrlen > sizeof(insnbuf));
- BUG_ON(a->cpuid >= NCAPINTS*32);
+ BUG_ON(a->cpuid >= (NCAPINTS + NBUGINTS) * 32);
if (!boot_cpu_has(a->cpuid))
continue;
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index d814772c5bed..22018f70a671 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -920,6 +920,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
/* AND the already accumulated flags with these */
for (i = 0; i < NCAPINTS; i++)
boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
+
+ /* OR, i.e. replicate the bug flags */
+ for (i = NCAPINTS; i < NCAPINTS + NBUGINTS; i++)
+ c->x86_capability[i] |= boot_cpu_data.x86_capability[i];
}
/* Init Machine Check Exception if available. */
--
1.8.1.3.535.ga923c31
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [RFC PATCH 2/4] x86, cpu: Convert F00F bug detection
2013-02-11 11:18 [RFC PATCH 0/4] x86, cpu: Expand ->x86_capability flags with bugs bitvector Borislav Petkov
2013-02-11 11:18 ` [RFC PATCH 1/4] x86, cpu: Expand cpufeature facility to include cpu bugs Borislav Petkov
@ 2013-02-11 11:18 ` Borislav Petkov
2013-02-11 11:18 ` [RFC PATCH 3/4] x86, cpu: Convert FDIV " Borislav Petkov
2013-02-11 11:18 ` [RFC PATCH 4/4] x86, cpu: Convert Cyrix coma " Borislav Petkov
3 siblings, 0 replies; 6+ messages in thread
From: Borislav Petkov @ 2013-02-11 11:18 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: X86 ML, LKML, Borislav Petkov
From: Borislav Petkov <bp@suse.de>
... to using the new facility and drop the cpuinfo_x86 member.
Signed-off-by: Borislav Petkov <bp@suse.de>
---
arch/x86/include/asm/cpufeature.h | 2 ++
arch/x86/include/asm/processor.h | 1 -
arch/x86/kernel/cpu/intel.c | 4 ++--
arch/x86/kernel/cpu/proc.c | 2 +-
arch/x86/mm/fault.c | 2 +-
5 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index 68daf877dad5..22107c57c0e4 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -216,6 +216,8 @@
#define X86_FEATURE_ADX (9*32+19) /* The ADCX and ADOX instructions */
#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
+#define X86_BUG_F00F (NCAPINTS*32+ 0) /* Intel F00F bug */
+
#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
#include <asm/asm.h>
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 67721c634bf0..60b21f132ae4 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -93,7 +93,6 @@ struct cpuinfo_x86 {
char hard_math;
char rfu;
char fdiv_bug;
- char f00f_bug;
char coma_bug;
char pad0;
#else
diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
index 1905ce98bee0..1acdd42d86d1 100644
--- a/arch/x86/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
@@ -209,11 +209,11 @@ static void __cpuinit intel_workarounds(struct cpuinfo_x86 *c)
* system.
* Note that the workaround only should be initialized once...
*/
- c->f00f_bug = 0;
+ clear_cpu_bug(c, X86_BUG_F00F);
if (!paravirt_enabled() && c->x86 == 5) {
static int f00f_workaround_enabled;
- c->f00f_bug = 1;
+ set_cpu_bug(c, X86_BUG_F00F);
if (!f00f_workaround_enabled) {
trap_init_f00f_bug();
printk(KERN_NOTICE "Intel Pentium with F0 0F bug - workaround enabled.\n");
diff --git a/arch/x86/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c
index 3286a92e662a..debb8826589b 100644
--- a/arch/x86/kernel/cpu/proc.c
+++ b/arch/x86/kernel/cpu/proc.c
@@ -37,7 +37,7 @@ static void show_cpuinfo_misc(struct seq_file *m, struct cpuinfo_x86 *c)
"wp\t\t: %s\n",
c->fdiv_bug ? "yes" : "no",
c->hlt_works_ok ? "no" : "yes",
- c->f00f_bug ? "yes" : "no",
+ static_cpu_has_bug(X86_BUG_F00F) ? "yes" : "no",
c->coma_bug ? "yes" : "no",
c->hard_math ? "yes" : "no",
c->hard_math ? "yes" : "no",
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index fb674fd3fc22..aaaf6931ff0b 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -555,7 +555,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
/*
* Pentium F0 0F C7 C8 bug workaround:
*/
- if (boot_cpu_data.f00f_bug) {
+ if (boot_cpu_has_bug(X86_BUG_F00F)) {
nr = (address - idt_descr.address) >> 3;
if (nr == 6) {
--
1.8.1.3.535.ga923c31
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [RFC PATCH 3/4] x86, cpu: Convert FDIV bug detection
2013-02-11 11:18 [RFC PATCH 0/4] x86, cpu: Expand ->x86_capability flags with bugs bitvector Borislav Petkov
2013-02-11 11:18 ` [RFC PATCH 1/4] x86, cpu: Expand cpufeature facility to include cpu bugs Borislav Petkov
2013-02-11 11:18 ` [RFC PATCH 2/4] x86, cpu: Convert F00F bug detection Borislav Petkov
@ 2013-02-11 11:18 ` Borislav Petkov
2013-02-11 11:18 ` [RFC PATCH 4/4] x86, cpu: Convert Cyrix coma " Borislav Petkov
3 siblings, 0 replies; 6+ messages in thread
From: Borislav Petkov @ 2013-02-11 11:18 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: X86 ML, LKML, Borislav Petkov
From: Borislav Petkov <bp@suse.de>
... to the new facility.
Signed-off-by: Borislav Petkov <bp@suse.de>
---
arch/x86/include/asm/cpufeature.h | 1 +
arch/x86/include/asm/processor.h | 1 -
arch/x86/kernel/cpu/bugs.c | 5 +++--
arch/x86/kernel/cpu/proc.c | 2 +-
4 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index 22107c57c0e4..6be6fab3dced 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -217,6 +217,7 @@
#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
#define X86_BUG_F00F (NCAPINTS*32+ 0) /* Intel F00F bug */
+#define X86_BUG_FDIV (NCAPINTS*32+ 1) /* FPU FDIV bug */
#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 60b21f132ae4..d18dedf333aa 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -92,7 +92,6 @@ struct cpuinfo_x86 {
char hlt_works_ok;
char hard_math;
char rfu;
- char fdiv_bug;
char coma_bug;
char pad0;
#else
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 92dfec986a48..3ca8ab0001bc 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -84,9 +84,10 @@ static void __init check_fpu(void)
kernel_fpu_end();
- boot_cpu_data.fdiv_bug = fdiv_bug;
- if (boot_cpu_data.fdiv_bug)
+ if (fdiv_bug) {
+ set_cpu_bug(&boot_cpu_data, X86_BUG_FDIV);
pr_warn("Hmm, FPU with FDIV bug\n");
+ }
}
static void __init check_hlt(void)
diff --git a/arch/x86/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c
index debb8826589b..de41600664da 100644
--- a/arch/x86/kernel/cpu/proc.c
+++ b/arch/x86/kernel/cpu/proc.c
@@ -35,7 +35,7 @@ static void show_cpuinfo_misc(struct seq_file *m, struct cpuinfo_x86 *c)
"fpu_exception\t: %s\n"
"cpuid level\t: %d\n"
"wp\t\t: %s\n",
- c->fdiv_bug ? "yes" : "no",
+ static_cpu_has_bug(X86_BUG_FDIV) ? "yes" : "no",
c->hlt_works_ok ? "no" : "yes",
static_cpu_has_bug(X86_BUG_F00F) ? "yes" : "no",
c->coma_bug ? "yes" : "no",
--
1.8.1.3.535.ga923c31
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [RFC PATCH 4/4] x86, cpu: Convert Cyrix coma bug detection
2013-02-11 11:18 [RFC PATCH 0/4] x86, cpu: Expand ->x86_capability flags with bugs bitvector Borislav Petkov
` (2 preceding siblings ...)
2013-02-11 11:18 ` [RFC PATCH 3/4] x86, cpu: Convert FDIV " Borislav Petkov
@ 2013-02-11 11:18 ` Borislav Petkov
3 siblings, 0 replies; 6+ messages in thread
From: Borislav Petkov @ 2013-02-11 11:18 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: X86 ML, LKML, Borislav Petkov
From: Borislav Petkov <bp@suse.de>
... to the new facility. Drop the padding too since it becomes
unnecessary now.
Signed-off-by: Borislav Petkov <bp@suse.de>
---
arch/x86/include/asm/cpufeature.h | 1 +
arch/x86/include/asm/processor.h | 2 --
arch/x86/kernel/cpu/cyrix.c | 5 +++--
arch/x86/kernel/cpu/proc.c | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index 6be6fab3dced..62b9affc0948 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -218,6 +218,7 @@
#define X86_BUG_F00F (NCAPINTS*32+ 0) /* Intel F00F bug */
#define X86_BUG_FDIV (NCAPINTS*32+ 1) /* FPU FDIV bug */
+#define X86_BUG_COMA (NCAPINTS*32+ 2) /* Cyrix 6x86 coma */
#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index d18dedf333aa..c7f1066bd93a 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -92,8 +92,6 @@ struct cpuinfo_x86 {
char hlt_works_ok;
char hard_math;
char rfu;
- char coma_bug;
- char pad0;
#else
/* Number of 4K pages in DTLB/ITLB combined(in pages): */
int x86_tlbsize;
diff --git a/arch/x86/kernel/cpu/cyrix.c b/arch/x86/kernel/cpu/cyrix.c
index 4fbd384fb645..ef060edeb68e 100644
--- a/arch/x86/kernel/cpu/cyrix.c
+++ b/arch/x86/kernel/cpu/cyrix.c
@@ -249,7 +249,7 @@ static void __cpuinit init_cyrix(struct cpuinfo_x86 *c)
/* Emulate MTRRs using Cyrix's ARRs. */
set_cpu_cap(c, X86_FEATURE_CYRIX_ARR);
/* 6x86's contain this bug */
- c->coma_bug = 1;
+ set_cpu_bug(c, X86_BUG_COMA);
break;
case 4: /* MediaGX/GXm or Geode GXM/GXLV/GX1 */
@@ -317,7 +317,8 @@ static void __cpuinit init_cyrix(struct cpuinfo_x86 *c)
/* Enable MMX extensions (App note 108) */
setCx86_old(CX86_CCR7, getCx86_old(CX86_CCR7)|1);
} else {
- c->coma_bug = 1; /* 6x86MX, it has the bug. */
+ /* 6x86MX, it has the bug. */
+ set_cpu_bug(c, X86_BUG_COMA);
}
tmp = (!(dir0_lsn & 7) || dir0_lsn & 1) ? 2 : 0;
Cx86_cb[tmp] = cyrix_model_mult2[dir0_lsn & 7];
diff --git a/arch/x86/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c
index de41600664da..7497d1eb6053 100644
--- a/arch/x86/kernel/cpu/proc.c
+++ b/arch/x86/kernel/cpu/proc.c
@@ -38,7 +38,7 @@ static void show_cpuinfo_misc(struct seq_file *m, struct cpuinfo_x86 *c)
static_cpu_has_bug(X86_BUG_FDIV) ? "yes" : "no",
c->hlt_works_ok ? "no" : "yes",
static_cpu_has_bug(X86_BUG_F00F) ? "yes" : "no",
- c->coma_bug ? "yes" : "no",
+ static_cpu_has_bug(X86_BUG_COMA) ? "yes" : "no",
c->hard_math ? "yes" : "no",
c->hard_math ? "yes" : "no",
c->cpuid_level,
--
1.8.1.3.535.ga923c31
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [RFC PATCH 1/4] x86, cpu: Expand cpufeature facility to include cpu bugs
2013-02-11 11:18 ` [RFC PATCH 1/4] x86, cpu: Expand cpufeature facility to include cpu bugs Borislav Petkov
@ 2013-02-13 23:23 ` H. Peter Anvin
0 siblings, 0 replies; 6+ messages in thread
From: H. Peter Anvin @ 2013-02-13 23:23 UTC (permalink / raw)
To: Borislav Petkov; +Cc: X86 ML, LKML, Borislav Petkov
On 02/11/2013 03:18 AM, Borislav Petkov wrote:
>
> +#define __BUG_CHECK_BIT(bit) \
> +({ \
> + WARN_ON(bit >> 5 < NCAPINTS); \
> + bit; \
> +})
> +
Do we need this? Either way, if we do, I would suggest doing something
like:
if (__builtin_constant_p(bit))
bad_bug_number();
... and flag bad_bug_number as a compile time error, since the vast
majority of the time the bit number will be constant.
However, I don't think it is necessary. In order for this to ever
trigger someone must have known they were testing for a bug, and yet not
used the X86_BUG_ macros, which seems very unlikely.
> #define X86_BUG_F00F (NCAPINTS*32+ 0) /* Intel F00F bug */
> #define X86_BUG_FDIV (NCAPINTS*32+ 1) /* FPU FDIV bug */
> +#define X86_BUG_COMA (NCAPINTS*32+ 2) /* Cyrix 6x86 coma */
Just to make it a bit cleaner once we have more than one word of bug
tests, I would suggest macroizing this:
#define X86_BUG(x) (NCAPINTS*32 + (x))
... and then just ...
#define X86_BUG_F00F X86_BUG(0)
#define X86_BUG_FDIV X86_BUG(1)
... and so on.
The only reason we *don't* do that with the features is that they tend
to come chunkwise in the form of CPUID words.
-hpa
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-02-13 23:24 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-11 11:18 [RFC PATCH 0/4] x86, cpu: Expand ->x86_capability flags with bugs bitvector Borislav Petkov
2013-02-11 11:18 ` [RFC PATCH 1/4] x86, cpu: Expand cpufeature facility to include cpu bugs Borislav Petkov
2013-02-13 23:23 ` H. Peter Anvin
2013-02-11 11:18 ` [RFC PATCH 2/4] x86, cpu: Convert F00F bug detection Borislav Petkov
2013-02-11 11:18 ` [RFC PATCH 3/4] x86, cpu: Convert FDIV " Borislav Petkov
2013-02-11 11:18 ` [RFC PATCH 4/4] x86, cpu: Convert Cyrix coma " Borislav Petkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).