mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Rene Herman <rene.herman@keyaccess.nl>,
	Adrian Bunk <bunk@kernel.org>, Yinghai Lu <yhlu.kernel@gmail.com>,
	Ingo Molnar <mingo@elte.hu>,
	Linux Kernel <linux-kernel@vger.kernel.org>,
	akpm@linux-foundation.org, Pavel Machek <pavel@suse.cz>
Subject: Re: [PATCH] x86: introduce a new Linux defined feature flag for PAT support
Date: Thu, 8 May 2008 14:49:19 +0200 (CEST)	[thread overview]
Message-ID: <alpine.LFD.1.10.0805081307520.3318@apollo.tec.linutronix.de> (raw)
In-Reply-To: <48226569.7010906@zytor.com>

On Wed, 7 May 2008, H. Peter Anvin wrote:
> Linus Torvalds wrote:
> > 
> > > *Certainly* I don't want anything like this crap:
> > > 
> > > > -    if (cpu_has_pat)
> > > > +    if (cpu_has_pat && cpu_has_pat_good)
> > 
> > This in fact is likely the best part of it.
> > 
> > Because that at least guarantees that we never say we have a good PAT when
> > the hardware doesn't even report it.
> > 
> > As it is, we seem to just blindly override hardware. It may be correct for
> > all the models we override, but still..
> > 
> 
> Yah, this is not good.  We should mask out the bit, but never, ever, set it if
> it was clear to begin with (unless we have it on really, *really*, good
> authority.)
> 
> I'm embarrassed to have let that slink by.

/me too.

Fix below.

Thanks,
	tglx

---------->
Subject: x86: cleanup PAT cpu validation
From: Thomas Gleixner <tglx@linutronix.de>
Date: Thu, 08 May 2008 09:18:43 +0200

Move the scattered checks for PAT support to a single function. Its
moved to addon_cpuid_features.c as this file is shared between 32 and
64 bit.

Remove the manipulation of the PAT feature bit and just disable PAT in
the PAT layer, based on the PAT bit provided by the CPU and the
current CPU version/model white list.

Change the boot CPU check so it works on Voyager somewhere in the
future as well :) Also panic, when a secondary has PAT disabled but
the primary one has alrady switched to PAT. We have no way to undo
that.

The white list is kept for now to ensure that we can rely on known to
work CPU types and concentrate on the software induced problems
instead of fighthing CPU erratas and subtle wreckage caused by not yet
verified CPUs. Once the PAT code has stabilized enough, we can remove
the white list and open the can of worms.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/kernel/cpu/addon_cpuid_features.c |   21 ++++++++++++
 arch/x86/kernel/cpu/common.c               |   27 +--------------
 arch/x86/kernel/setup_64.c                 |    9 +----
 arch/x86/mm/pat.c                          |   50 ++++++++++++-----------------
 include/asm-x86/pat.h                      |    8 ++++
 5 files changed, 55 insertions(+), 60 deletions(-)

Index: linux-2.6/arch/x86/kernel/cpu/addon_cpuid_features.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/cpu/addon_cpuid_features.c
+++ linux-2.6/arch/x86/kernel/cpu/addon_cpuid_features.c
@@ -6,6 +6,7 @@
 
 #include <linux/cpu.h>
 
+#include <asm/pat.h>
 #include <asm/processor.h>
 
 struct cpuid_bit {
@@ -48,3 +49,23 @@ void __cpuinit init_scattered_cpuid_feat
 			set_cpu_cap(c, cb->feature);
 	}
 }
+
+#ifdef CONFIG_X86_PAT
+void __cpuinit validate_pat_support(struct cpuinfo_x86 *c)
+{
+	switch (c->x86_vendor) {
+	case X86_VENDOR_AMD:
+		if (c->x86 >= 0xf && c->x86 <= 0x11)
+			return;
+		break;
+	case X86_VENDOR_INTEL:
+		if (c->x86 == 0xF || (c->x86 == 6 && c->x86_model >= 15))
+			return;
+		break;
+	}
+
+	pat_disable(cpu_has_pat ?
+		    "PAT disabled. Not yet verified on this CPU type." :
+		    "PAT not supported by CPU.");
+}
+#endif
Index: linux-2.6/arch/x86/kernel/cpu/common.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/cpu/common.c
+++ linux-2.6/arch/x86/kernel/cpu/common.c
@@ -12,6 +12,7 @@
 #include <asm/mmu_context.h>
 #include <asm/mtrr.h>
 #include <asm/mce.h>
+#include <asm/pat.h>
 #ifdef CONFIG_X86_LOCAL_APIC
 #include <asm/mpspec.h>
 #include <asm/apic.h>
@@ -308,19 +309,6 @@ static void __cpuinit early_get_cap(stru
 
 	}
 
-	clear_cpu_cap(c, X86_FEATURE_PAT);
-
-	switch (c->x86_vendor) {
-	case X86_VENDOR_AMD:
-		if (c->x86 >= 0xf && c->x86 <= 0x11)
-			set_cpu_cap(c, X86_FEATURE_PAT);
-		break;
-	case X86_VENDOR_INTEL:
-		if (c->x86 == 0xF || (c->x86 == 6 && c->x86_model >= 15))
-			set_cpu_cap(c, X86_FEATURE_PAT);
-		break;
-	}
-
 }
 
 /*
@@ -409,18 +397,6 @@ static void __cpuinit generic_identify(s
 		init_scattered_cpuid_features(c);
 	}
 
-	clear_cpu_cap(c, X86_FEATURE_PAT);
-
-	switch (c->x86_vendor) {
-	case X86_VENDOR_AMD:
-		if (c->x86 >= 0xf && c->x86 <= 0x11)
-			set_cpu_cap(c, X86_FEATURE_PAT);
-		break;
-	case X86_VENDOR_INTEL:
-		if (c->x86 == 0xF || (c->x86 == 6 && c->x86_model >= 15))
-			set_cpu_cap(c, X86_FEATURE_PAT);
-		break;
-	}
 }
 
 static void __cpuinit squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
@@ -651,6 +627,7 @@ void __init early_cpu_init(void)
 		cpu_devs[cvdev->vendor] = cvdev->cpu_dev;
 
 	early_cpu_detect();
+	validate_pat_support(&boot_cpu_data);
 }
 
 /* Make sure %fs is initialized properly in idle threads */
Index: linux-2.6/arch/x86/kernel/setup_64.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/setup_64.c
+++ linux-2.6/arch/x86/kernel/setup_64.c
@@ -70,6 +70,7 @@
 #include <asm/ds.h>
 #include <asm/topology.h>
 #include <asm/trampoline.h>
+#include <asm/pat.h>
 
 #include <mach_apic.h>
 #ifdef CONFIG_PARAVIRT
@@ -1063,25 +1064,19 @@ static void __cpuinit early_identify_cpu
 	if (c->extended_cpuid_level >= 0x80000007)
 		c->x86_power = cpuid_edx(0x80000007);
 
-
-	clear_cpu_cap(c, X86_FEATURE_PAT);
-
 	switch (c->x86_vendor) {
 	case X86_VENDOR_AMD:
 		early_init_amd(c);
-		if (c->x86 >= 0xf && c->x86 <= 0x11)
-			set_cpu_cap(c, X86_FEATURE_PAT);
 		break;
 	case X86_VENDOR_INTEL:
 		early_init_intel(c);
-		if (c->x86 == 0xF || (c->x86 == 6 && c->x86_model >= 15))
-			set_cpu_cap(c, X86_FEATURE_PAT);
 		break;
 	case X86_VENDOR_CENTAUR:
 		early_init_centaur(c);
 		break;
 	}
 
+	validate_pat_support(c);
 }
 
 /*
Index: linux-2.6/arch/x86/mm/pat.c
===================================================================
--- linux-2.6.orig/arch/x86/mm/pat.c
+++ linux-2.6/arch/x86/mm/pat.c
@@ -25,31 +25,24 @@
 #include <asm/mtrr.h>
 #include <asm/io.h>
 
-int pat_wc_enabled = 1;
+#ifdef CONFIG_X86_PAT
+int __read_mostly pat_wc_enabled = 1;
 
-static u64 __read_mostly boot_pat_state;
-
-static int nopat(char *str)
+void __init pat_disable(char *reason)
 {
 	pat_wc_enabled = 0;
-	printk(KERN_INFO "x86: PAT support disabled.\n");
-
-	return 0;
+	printk(KERN_INFO "%s\n", reason);
 }
-early_param("nopat", nopat);
 
-static int pat_known_cpu(void)
+static int nopat(char *str)
 {
-	if (!pat_wc_enabled)
-		return 0;
-
-	if (cpu_has_pat)
-		return 1;
-
-	pat_wc_enabled = 0;
-	printk(KERN_INFO "CPU and/or kernel does not support PAT.\n");
+	pat_disable("PAT support disabled.");
 	return 0;
 }
+early_param("nopat", nopat);
+#endif
+
+static u64 __read_mostly boot_pat_state;
 
 enum {
 	PAT_UC = 0,		/* uncached */
@@ -66,17 +59,19 @@ void pat_init(void)
 {
 	u64 pat;
 
-#ifndef CONFIG_X86_PAT
-	nopat(NULL);
-#endif
-
-	/* Boot CPU enables PAT based on CPU feature */
-	if (!smp_processor_id() && !pat_known_cpu())
+	if (!pat_wc_enabled)
 		return;
 
-	/* APs enable PAT iff boot CPU has enabled it before */
-	if (smp_processor_id() && !pat_wc_enabled)
-		return;
+	/* Paranoia check. */
+	if (!cpu_has_pat) {
+		printk(KERN_ERR "PAT enabled, but CPU feature cleared\n");
+		/*
+		 * Panic if this happens on the secondary CPU, and we
+		 * switched to PAT on the boot CPU. We have no way to
+		 * undo PAT.
+		*/
+		BUG_ON(boot_pat_state);
+	}
 
 	/* Set PWT to Write-Combining. All other bits stay the same */
 	/*
@@ -95,9 +90,8 @@ void pat_init(void)
 	      PAT(4,WB) | PAT(5,WC) | PAT(6,UC_MINUS) | PAT(7,UC);
 
 	/* Boot CPU check */
-	if (!smp_processor_id()) {
+	if (!boot_pat_state)
 		rdmsrl(MSR_IA32_CR_PAT, boot_pat_state);
-	}
 
 	wrmsrl(MSR_IA32_CR_PAT, pat);
 	printk(KERN_INFO "x86 PAT enabled: cpu %d, old 0x%Lx, new 0x%Lx\n",
Index: linux-2.6/include/asm-x86/pat.h
===================================================================
--- linux-2.6.orig/include/asm-x86/pat.h
+++ linux-2.6/include/asm-x86/pat.h
@@ -4,7 +4,13 @@
 
 #include <linux/types.h>
 
+#ifdef CONFIG_X86_PAT
 extern int pat_wc_enabled;
+extern void validate_pat_support(struct cpuinfo_x86 *c);
+#else
+# define pat_wc_enabled		(0)
+static inline void validate_pat_support(struct cpuinfo_x86 *c) { }
+#endif
 
 extern void pat_init(void);
 
@@ -12,5 +18,7 @@ extern int reserve_memtype(u64 start, u6
 		unsigned long req_type, unsigned long *ret_type);
 extern int free_memtype(u64 start, u64 end);
 
+extern void pat_disable(char *reason);
+
 #endif
 

  reply	other threads:[~2008-05-08 12:50 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-07  1:48 2.6.26, PAT and AMD family 6 Rene Herman
2008-05-07  2:39 ` Yinghai Lu
2008-05-07 12:46   ` Undocumented and duplicated code Adrian Bunk
2008-05-07 13:14     ` Rene Herman
2008-05-07 20:52     ` 2.6.26, PAT and AMD family 6 Thomas Gleixner
2008-05-07 20:59       ` Pavel Machek
2008-05-07 21:10       ` Rene Herman
2008-05-07 21:41         ` Thomas Gleixner
2008-05-07 21:46           ` Adrian Bunk
2008-05-07 22:08             ` Thomas Gleixner
2008-05-07 22:29               ` Pavel Machek
2008-05-07 22:04           ` Rene Herman
2008-05-07 22:23             ` Rene Herman
2008-05-07 22:31           ` Yinghai Lu
2008-05-07 22:57         ` H. Peter Anvin
2008-05-08  0:02           ` Rene Herman
2008-05-08  0:03             ` H. Peter Anvin
2008-05-08  0:10               ` Rene Herman
2008-05-08  0:19                 ` Linus Torvalds
2008-05-08  0:28                   ` Rene Herman
2008-05-08  1:57                     ` [PATCH] x86: introduce a new Linux defined feature flag for PAT support Rene Herman
2008-05-08  1:58                       ` Linus Torvalds
2008-05-08  2:11                         ` H. Peter Anvin
2008-05-08  2:17                           ` Rene Herman
2008-05-08  2:24                           ` Linus Torvalds
2008-05-08  2:28                             ` H. Peter Anvin
2008-05-08 12:49                               ` Thomas Gleixner [this message]
2008-05-08 13:08                                 ` Ingo Molnar
2008-05-08 16:44                                   ` H. Peter Anvin
2008-05-08 13:11                                 ` Adrian Bunk
2008-05-08 13:33                                   ` Thomas Gleixner
2008-05-08 14:44                                 ` Rene Herman
2008-05-08 14:53                                   ` Thomas Gleixner
2008-05-08 16:48                                     ` H. Peter Anvin
2008-05-08 16:53                                       ` Rene Herman
2008-05-08  2:04                       ` [PATCH] x86: enable PAT support on AMD Duron model 7 Rene Herman
2008-05-08  2:08                         ` Arjan van de Ven
2008-05-08  2:12                           ` Rene Herman
2008-05-08 10:19                       ` [PATCH] x86: introduce a new Linux defined feature flag for PAT support Andi Kleen
2008-05-08 12:40                         ` Rene Herman
2008-05-08 13:39                           ` Andi Kleen
2008-05-08 15:32                             ` Alan Cox
2008-05-08 16:51                               ` H. Peter Anvin
2008-05-08  0:21                 ` 2.6.26, PAT and AMD family 6 Thomas Gleixner
2008-05-08  0:30                   ` Rene Herman
2008-05-08  0:15               ` Linus Torvalds
2008-05-08  0:31                 ` H. Peter Anvin
2008-05-08 10:14                   ` Andi Kleen
2008-05-08 16:43                     ` H. Peter Anvin
2008-05-07 21:23       ` Adrian Bunk
2008-05-07 21:54         ` Thomas Gleixner
2008-05-07 22:09           ` Adrian Bunk
2008-05-07 22:14           ` Pavel Machek
2008-05-07 22:22             ` Yinghai Lu
2008-05-07 22:37               ` Pavel Machek
2008-05-07 22:40                 ` Yinghai Lu
2008-05-07 23:02                   ` Pavel Machek
2008-05-07 23:02                 ` Thomas Gleixner
2008-05-07 23:10                   ` Pavel Machek
2008-05-07 23:46                     ` Thomas Gleixner
2008-05-07 22:23             ` Yinghai Lu
2008-05-07 22:39               ` Pavel Machek
2008-05-07 22:45                 ` Yinghai Lu
2008-05-07 23:06                   ` Pavel Machek
2008-05-07 23:01               ` H. Peter Anvin
2008-05-07 22:26             ` Yinghai Lu
2008-05-07 22:30               ` Rene Herman
2008-05-07 22:58             ` Thomas Gleixner
2008-05-07 13:00   ` Rene Herman
2008-05-07 13:42     ` Arjan van de Ven
2008-05-07 14:09       ` Rene Herman
2008-05-07 14:24         ` Arjan van de Ven
2008-05-07 19:08           ` Rene Herman
2008-05-07 22:17             ` Arjan van de Ven
2008-05-07 19:39     ` Daniel Hazelton
2008-05-07 20:06       ` Rene Herman
2008-05-07 20:16         ` Yinghai Lu
2008-05-07 20:18           ` Yinghai Lu
2008-05-08  4:06             ` H. Peter Anvin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.1.10.0805081307520.3318@apollo.tec.linutronix.de \
    --to=tglx@linutronix.de \
    --cc=akpm@linux-foundation.org \
    --cc=bunk@kernel.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=pavel@suse.cz \
    --cc=rene.herman@keyaccess.nl \
    --cc=torvalds@linux-foundation.org \
    --cc=yhlu.kernel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®