Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/mm/pat: Use 7th PAT MSR slot for Write-Through PAT type

Assign Write-Through type to the PA7 slot in the PAT MSR when
the processor is not affected by PAT errata. The PA7 slot is
chosen to improve robustness in the presence of errata that
might cause the high PAT bit to be ignored. This way a buggy PA7
slot access will hit the PA3 slot, which is UC, so at worst we
lose performance without causing a correctness issue.

The following Intel processors are affected by the PAT errata.

Errata CPUID
----------------------------------------------------
Pentium 2, A52 family 0x6, model 0x5
Pentium 3, E27 family 0x6, model 0x7, 0x8
Pentium 3 Xenon, G26 family 0x6, model 0x7, 0x8, 0xa
Pentium M, Y26 family 0x6, model 0x9
Pentium M 90nm, X9 family 0x6, model 0xd
Pentium 4, N46 family 0xf, model 0x0

Instead of making sharp boundary checks, we remain conservative
and exclude all Pentium 2, 3, M and 4 family processors. For
those, _PAGE_CACHE_MODE_WT is redirected to UC- per the default
setup in __cachemode2pte_tbl[].

Signed-off-by: Toshi Kani <toshi.kani@hp.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Elliott@hp.com
Cc: H. Peter Anvin <hpa@zytor.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: arnd@arndb.de
Cc: hch@lst.de
Cc: hmh@hmh.eng.br
Cc: jgross@suse.com
Cc: konrad.wilk@oracle.com
Cc: linux-mm <linux-mm@kvack.org>
Cc: linux-nvdimm@lists.01.org
Cc: stefan.bader@canonical.com
Cc: yigal@plexistor.com
Link: https://lkml.kernel.org/r/1433187393-22688-2-git-send-email-toshi.kani@hp.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Toshi Kani and committed by
Ingo Molnar
d79a40ca 7202fdb1

+50 -9
+50 -9
arch/x86/mm/pat.c
··· 235 235 void pat_init(void) 236 236 { 237 237 u64 pat; 238 + struct cpuinfo_x86 *c = &boot_cpu_data; 238 239 239 240 if (!pat_enabled()) { 240 241 /* ··· 245 244 * has PAT but the "nopat" boot option has been specified. This 246 245 * emulated PAT table is used when MSR_IA32_CR_PAT returns 0. 247 246 * 248 - * PTE encoding used: 247 + * PTE encoding: 249 248 * 250 249 * PCD 251 250 * |PWT PAT ··· 260 259 */ 261 260 pat = PAT(0, WB) | PAT(1, WT) | PAT(2, UC_MINUS) | PAT(3, UC) | 262 261 PAT(4, WB) | PAT(5, WT) | PAT(6, UC_MINUS) | PAT(7, UC); 263 - } else { 262 + 263 + } else if ((c->x86_vendor == X86_VENDOR_INTEL) && 264 + (((c->x86 == 0x6) && (c->x86_model <= 0xd)) || 265 + ((c->x86 == 0xf) && (c->x86_model <= 0x6)))) { 264 266 /* 265 - * PTE encoding used in Linux: 267 + * PAT support with the lower four entries. Intel Pentium 2, 268 + * 3, M, and 4 are affected by PAT errata, which makes the 269 + * upper four entries unusable. To be on the safe side, we don't 270 + * use those. 271 + * 272 + * PTE encoding: 266 273 * PAT 267 274 * |PCD 268 - * ||PWT 269 - * ||| 270 - * 000 WB _PAGE_CACHE_WB 271 - * 001 WC _PAGE_CACHE_WC 272 - * 010 UC- _PAGE_CACHE_UC_MINUS 273 - * 011 UC _PAGE_CACHE_UC 275 + * ||PWT PAT 276 + * ||| slot 277 + * 000 0 WB : _PAGE_CACHE_MODE_WB 278 + * 001 1 WC : _PAGE_CACHE_MODE_WC 279 + * 010 2 UC-: _PAGE_CACHE_MODE_UC_MINUS 280 + * 011 3 UC : _PAGE_CACHE_MODE_UC 274 281 * PAT bit unused 282 + * 283 + * NOTE: When WT or WP is used, it is redirected to UC- per 284 + * the default setup in __cachemode2pte_tbl[]. 275 285 */ 276 286 pat = PAT(0, WB) | PAT(1, WC) | PAT(2, UC_MINUS) | PAT(3, UC) | 277 287 PAT(4, WB) | PAT(5, WC) | PAT(6, UC_MINUS) | PAT(7, UC); 288 + } else { 289 + /* 290 + * Full PAT support. We put WT in slot 7 to improve 291 + * robustness in the presence of errata that might cause 292 + * the high PAT bit to be ignored. This way, a buggy slot 7 293 + * access will hit slot 3, and slot 3 is UC, so at worst 294 + * we lose performance without causing a correctness issue. 295 + * Pentium 4 erratum N46 is an example for such an erratum, 296 + * although we try not to use PAT at all on affected CPUs. 297 + * 298 + * PTE encoding: 299 + * PAT 300 + * |PCD 301 + * ||PWT PAT 302 + * ||| slot 303 + * 000 0 WB : _PAGE_CACHE_MODE_WB 304 + * 001 1 WC : _PAGE_CACHE_MODE_WC 305 + * 010 2 UC-: _PAGE_CACHE_MODE_UC_MINUS 306 + * 011 3 UC : _PAGE_CACHE_MODE_UC 307 + * 100 4 WB : Reserved 308 + * 101 5 WC : Reserved 309 + * 110 6 UC-: Reserved 310 + * 111 7 WT : _PAGE_CACHE_MODE_WT 311 + * 312 + * The reserved slots are unused, but mapped to their 313 + * corresponding types in the presence of PAT errata. 314 + */ 315 + pat = PAT(0, WB) | PAT(1, WC) | PAT(2, UC_MINUS) | PAT(3, UC) | 316 + PAT(4, WB) | PAT(5, WC) | PAT(6, UC_MINUS) | PAT(7, WT); 278 317 } 279 318 280 319 if (!boot_cpu_done) {