mirror of
https://github.com/torvalds/linux.git
synced 2024-12-26 12:52:30 +00:00
e4a84be6f0
The Intel(R) Xeon Phi(TM) Processor x200 Family (codename: Knights Landing) has an erratum where a processor thread setting the Accessed or Dirty bits may not do so atomically against its checks for the Present bit. This may cause a thread (which is about to page fault) to set A and/or D, even though the Present bit had already been atomically cleared. These bits are truly "stray". In the case of the Dirty bit, the thread associated with the stray set was *not* allowed to write to the page. This means that we do not have to launder the bit(s); we can simply ignore them. If the PTE is used for storing a swap index or a NUMA migration index, the A bit could be misinterpreted as part of the swap type. The stray bits being set cause a software-cleared PTE to be interpreted as a swap entry. In some cases (like when the swap index ends up being for a non-existent swapfile), the kernel detects the stray value and WARN()s about it, but there is no guarantee that the kernel can always detect it. When we have 64-bit PTEs (64-bit mode or 32-bit PAE), we were able to move the swap PTE format around to avoid these troublesome bits. But, 32-bit non-PAE is tight on bits. So, disallow it from running on this hardware. I can't imagine anyone wanting to run 32-bit non-highmem kernels on this hardware, but disallowing them from running entirely is surely the safe thing to do. Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Dave Hansen <dave@sr71.net> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Luis R. Rodriguez <mcgrof@suse.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Toshi Kani <toshi.kani@hp.com> Cc: dave.hansen@intel.com Cc: linux-mm@kvack.org Cc: mhocko@suse.com Link: http://lkml.kernel.org/r/20160708001914.D0B50110@viggo.jf.intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
121 lines
2.6 KiB
C
121 lines
2.6 KiB
C
#include <linux/types.h>
|
|
#include "bitops.h"
|
|
|
|
#include <asm/processor-flags.h>
|
|
#include <asm/required-features.h>
|
|
#include <asm/msr-index.h>
|
|
#include "cpuflags.h"
|
|
|
|
struct cpu_features cpu;
|
|
u32 cpu_vendor[3];
|
|
|
|
static bool loaded_flags;
|
|
|
|
static int has_fpu(void)
|
|
{
|
|
u16 fcw = -1, fsw = -1;
|
|
unsigned long cr0;
|
|
|
|
asm volatile("mov %%cr0,%0" : "=r" (cr0));
|
|
if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
|
|
cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
|
|
asm volatile("mov %0,%%cr0" : : "r" (cr0));
|
|
}
|
|
|
|
asm volatile("fninit ; fnstsw %0 ; fnstcw %1"
|
|
: "+m" (fsw), "+m" (fcw));
|
|
|
|
return fsw == 0 && (fcw & 0x103f) == 0x003f;
|
|
}
|
|
|
|
/*
|
|
* For building the 16-bit code we want to explicitly specify 32-bit
|
|
* push/pop operations, rather than just saying 'pushf' or 'popf' and
|
|
* letting the compiler choose. But this is also included from the
|
|
* compressed/ directory where it may be 64-bit code, and thus needs
|
|
* to be 'pushfq' or 'popfq' in that case.
|
|
*/
|
|
#ifdef __x86_64__
|
|
#define PUSHF "pushfq"
|
|
#define POPF "popfq"
|
|
#else
|
|
#define PUSHF "pushfl"
|
|
#define POPF "popfl"
|
|
#endif
|
|
|
|
int has_eflag(unsigned long mask)
|
|
{
|
|
unsigned long f0, f1;
|
|
|
|
asm volatile(PUSHF " \n\t"
|
|
PUSHF " \n\t"
|
|
"pop %0 \n\t"
|
|
"mov %0,%1 \n\t"
|
|
"xor %2,%1 \n\t"
|
|
"push %1 \n\t"
|
|
POPF " \n\t"
|
|
PUSHF " \n\t"
|
|
"pop %1 \n\t"
|
|
POPF
|
|
: "=&r" (f0), "=&r" (f1)
|
|
: "ri" (mask));
|
|
|
|
return !!((f0^f1) & mask);
|
|
}
|
|
|
|
/* Handle x86_32 PIC using ebx. */
|
|
#if defined(__i386__) && defined(__PIC__)
|
|
# define EBX_REG "=r"
|
|
#else
|
|
# define EBX_REG "=b"
|
|
#endif
|
|
|
|
static inline void cpuid(u32 id, u32 *a, u32 *b, u32 *c, u32 *d)
|
|
{
|
|
asm volatile(".ifnc %%ebx,%3 ; movl %%ebx,%3 ; .endif \n\t"
|
|
"cpuid \n\t"
|
|
".ifnc %%ebx,%3 ; xchgl %%ebx,%3 ; .endif \n\t"
|
|
: "=a" (*a), "=c" (*c), "=d" (*d), EBX_REG (*b)
|
|
: "a" (id)
|
|
);
|
|
}
|
|
|
|
void get_cpuflags(void)
|
|
{
|
|
u32 max_intel_level, max_amd_level;
|
|
u32 tfms;
|
|
u32 ignored;
|
|
|
|
if (loaded_flags)
|
|
return;
|
|
loaded_flags = true;
|
|
|
|
if (has_fpu())
|
|
set_bit(X86_FEATURE_FPU, cpu.flags);
|
|
|
|
if (has_eflag(X86_EFLAGS_ID)) {
|
|
cpuid(0x0, &max_intel_level, &cpu_vendor[0], &cpu_vendor[2],
|
|
&cpu_vendor[1]);
|
|
|
|
if (max_intel_level >= 0x00000001 &&
|
|
max_intel_level <= 0x0000ffff) {
|
|
cpuid(0x1, &tfms, &ignored, &cpu.flags[4],
|
|
&cpu.flags[0]);
|
|
cpu.level = (tfms >> 8) & 15;
|
|
cpu.family = cpu.level;
|
|
cpu.model = (tfms >> 4) & 15;
|
|
if (cpu.level >= 6)
|
|
cpu.model += ((tfms >> 16) & 0xf) << 4;
|
|
}
|
|
|
|
cpuid(0x80000000, &max_amd_level, &ignored, &ignored,
|
|
&ignored);
|
|
|
|
if (max_amd_level >= 0x80000001 &&
|
|
max_amd_level <= 0x8000ffff) {
|
|
cpuid(0x80000001, &ignored, &ignored, &cpu.flags[6],
|
|
&cpu.flags[1]);
|
|
}
|
|
}
|
|
}
|