Skip to content

Commit 72cbc8f

Browse files
jbeulichsuryasaimadhu
authored andcommitted
x86/PAT: Have pat_enabled() properly reflect state when running on Xen
After commit ID in the Fixes: tag, pat_enabled() returns false (because of PAT initialization being suppressed in the absence of MTRRs being announced to be available). This has become a problem: the i915 driver now fails to initialize when running PV on Xen (i915_gem_object_pin_map() is where I located the induced failure), and its error handling is flaky enough to (at least sometimes) result in a hung system. Yet even beyond that problem the keying of the use of WC mappings to pat_enabled() (see arch_can_pci_mmap_wc()) means that in particular graphics frame buffer accesses would have been quite a bit less optimal than possible. Arrange for the function to return true in such environments, without undermining the rest of PAT MSR management logic considering PAT to be disabled: specifically, no writes to the PAT MSR should occur. For the new boolean to live in .init.data, init_cache_modes() also needs moving to .init.text (where it could/should have lived already before). [ bp: This is the "small fix" variant for stable. It'll get replaced with a proper PAT and MTRR detection split upstream but that is too involved for a stable backport. - additional touchups to commit msg. Use cpu_feature_enabled(). ] Fixes: bdd8b6c ("drm/i915: replace X86_FEATURE_PAT with pat_enabled()") Signed-off-by: Jan Beulich <jbeulich@suse.com> Signed-off-by: Borislav Petkov <bp@suse.de> Acked-by: Ingo Molnar <mingo@kernel.org> Cc: <stable@vger.kernel.org> Cc: Juergen Gross <jgross@suse.com> Cc: Lucas De Marchi <lucas.demarchi@intel.com> Link: https://lore.kernel.org/r/9385fa60-fa5d-f559-a137-6608408f88b0@suse.com
1 parent 568035b commit 72cbc8f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

arch/x86/mm/pat/memtype.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
static bool __read_mostly pat_bp_initialized;
6464
static bool __read_mostly pat_disabled = !IS_ENABLED(CONFIG_X86_PAT);
65+
static bool __initdata pat_force_disabled = !IS_ENABLED(CONFIG_X86_PAT);
6566
static bool __read_mostly pat_bp_enabled;
6667
static bool __read_mostly pat_cm_initialized;
6768

@@ -86,6 +87,7 @@ void pat_disable(const char *msg_reason)
8687
static int __init nopat(char *str)
8788
{
8889
pat_disable("PAT support disabled via boot option.");
90+
pat_force_disabled = true;
8991
return 0;
9092
}
9193
early_param("nopat", nopat);
@@ -272,7 +274,7 @@ static void pat_ap_init(u64 pat)
272274
wrmsrl(MSR_IA32_CR_PAT, pat);
273275
}
274276

275-
void init_cache_modes(void)
277+
void __init init_cache_modes(void)
276278
{
277279
u64 pat = 0;
278280

@@ -313,6 +315,12 @@ void init_cache_modes(void)
313315
*/
314316
pat = PAT(0, WB) | PAT(1, WT) | PAT(2, UC_MINUS) | PAT(3, UC) |
315317
PAT(4, WB) | PAT(5, WT) | PAT(6, UC_MINUS) | PAT(7, UC);
318+
} else if (!pat_force_disabled && cpu_feature_enabled(X86_FEATURE_HYPERVISOR)) {
319+
/*
320+
* Clearly PAT is enabled underneath. Allow pat_enabled() to
321+
* reflect this.
322+
*/
323+
pat_bp_enabled = true;
316324
}
317325

318326
__init_cache_modes(pat);

0 commit comments

Comments
 (0)