Skip to content

Commit 646b658

Browse files
Mikulas Patockagregkh
authored andcommitted
x86/mm/pat: Don't report PAT on CPUs that don't support it
commit 99c13b8c8896d7bcb92753bf0c63a8de4326e78d upstream. The pat_enabled() logic is broken on CPUs which do not support PAT and where the initialization code fails to call pat_init(). Due to that the enabled flag stays true and pat_enabled() returns true wrongfully. As a consequence the mappings, e.g. for Xorg, are set up with the wrong caching mode and the required MTRR setups are omitted. To cure this the following changes are required: 1) Make pat_enabled() return true only if PAT initialization was invoked and successful. 2) Invoke init_cache_modes() unconditionally in setup_arch() and remove the extra callsites in pat_disable() and the pat disabled code path in pat_init(). Also rename __pat_enabled to pat_disabled to reflect the real purpose of this variable. Fixes: 9cd25aa ("x86/mm/pat: Emulate PAT when it is disabled") Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Bernhard Held <berny156@gmx.de> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Brian Gerst <brgerst@gmail.com> Cc: "Luis R. Rodriguez" <mcgrof@suse.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Andy Lutomirski <luto@kernel.org> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: http://lkml.kernel.org/r/alpine.LRH.2.02.1707041749300.3456@file01.intranet.prod.int.rdu2.redhat.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ad5a88c commit 646b658

3 files changed

Lines changed: 20 additions & 16 deletions

File tree

arch/x86/include/asm/pat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
bool pat_enabled(void);
88
void pat_disable(const char *reason);
99
extern void pat_init(void);
10+
extern void init_cache_modes(void);
1011

1112
extern int reserve_memtype(u64 start, u64 end,
1213
enum page_cache_mode req_pcm, enum page_cache_mode *ret_pcm);

arch/x86/kernel/setup.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,13 @@ void __init setup_arch(char **cmdline_p)
10481048
if (mtrr_trim_uncached_memory(max_pfn))
10491049
max_pfn = e820_end_of_ram_pfn();
10501050

1051+
/*
1052+
* This call is required when the CPU does not support PAT. If
1053+
* mtrr_bp_init() invoked it already via pat_init() the call has no
1054+
* effect.
1055+
*/
1056+
init_cache_modes();
1057+
10511058
#ifdef CONFIG_X86_32
10521059
/* max_low_pfn get updated here */
10531060
find_low_pfn_range();

arch/x86/mm/pat.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,23 @@
3636
#undef pr_fmt
3737
#define pr_fmt(fmt) "" fmt
3838

39-
static bool boot_cpu_done;
40-
41-
static int __read_mostly __pat_enabled = IS_ENABLED(CONFIG_X86_PAT);
42-
static void init_cache_modes(void);
39+
static bool __read_mostly boot_cpu_done;
40+
static bool __read_mostly pat_disabled = !IS_ENABLED(CONFIG_X86_PAT);
41+
static bool __read_mostly pat_initialized;
42+
static bool __read_mostly init_cm_done;
4343

4444
void pat_disable(const char *reason)
4545
{
46-
if (!__pat_enabled)
46+
if (pat_disabled)
4747
return;
4848

4949
if (boot_cpu_done) {
5050
WARN_ONCE(1, "x86/PAT: PAT cannot be disabled after initialization\n");
5151
return;
5252
}
5353

54-
__pat_enabled = 0;
54+
pat_disabled = true;
5555
pr_info("x86/PAT: %s\n", reason);
56-
57-
init_cache_modes();
5856
}
5957

6058
static int __init nopat(char *str)
@@ -66,7 +64,7 @@ early_param("nopat", nopat);
6664

6765
bool pat_enabled(void)
6866
{
69-
return !!__pat_enabled;
67+
return pat_initialized;
7068
}
7169
EXPORT_SYMBOL_GPL(pat_enabled);
7270

@@ -204,6 +202,8 @@ static void __init_cache_modes(u64 pat)
204202
update_cache_mode_entry(i, cache);
205203
}
206204
pr_info("x86/PAT: Configuration [0-7]: %s\n", pat_msg);
205+
206+
init_cm_done = true;
207207
}
208208

209209
#define PAT(x, y) ((u64)PAT_ ## y << ((x)*8))
@@ -224,6 +224,7 @@ static void pat_bsp_init(u64 pat)
224224
}
225225

226226
wrmsrl(MSR_IA32_CR_PAT, pat);
227+
pat_initialized = true;
227228

228229
__init_cache_modes(pat);
229230
}
@@ -241,10 +242,9 @@ static void pat_ap_init(u64 pat)
241242
wrmsrl(MSR_IA32_CR_PAT, pat);
242243
}
243244

244-
static void init_cache_modes(void)
245+
void init_cache_modes(void)
245246
{
246247
u64 pat = 0;
247-
static int init_cm_done;
248248

249249
if (init_cm_done)
250250
return;
@@ -286,8 +286,6 @@ static void init_cache_modes(void)
286286
}
287287

288288
__init_cache_modes(pat);
289-
290-
init_cm_done = 1;
291289
}
292290

293291
/**
@@ -305,10 +303,8 @@ void pat_init(void)
305303
u64 pat;
306304
struct cpuinfo_x86 *c = &boot_cpu_data;
307305

308-
if (!pat_enabled()) {
309-
init_cache_modes();
306+
if (pat_disabled)
310307
return;
311-
}
312308

313309
if ((c->x86_vendor == X86_VENDOR_INTEL) &&
314310
(((c->x86 == 0x6) && (c->x86_model <= 0xd)) ||

0 commit comments

Comments
 (0)