[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] x86/PAT: have pat_enabled() properly reflect state when running on e.g. Xen


  • To: Andrew Lutomirski <luto@xxxxxxxxxx>, "dave.hansen@xxxxxxxxxxxxxxx" <dave.hansen@xxxxxxxxxxxxxxx>, Peter Zijlstra <peterz@xxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 28 Apr 2022 16:50:29 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=A8stDmbfCiVRa3vsDBlpsWtwv/Zq4Potk7/5iOXXUcg=; b=YYOBJkdWb0WXvvko1jgTtbzyftqORJnlMdP6V3gIhrxe/Fx28W7Tmb5GqU9N+X7r5P5lHaBVS8JcKZvsRDE0sdOYeWBzKPYxIXst6p5eVskC8eXcTztJ2HVaW67NQxiMLSLTUZmJzIQjDqbeFi/hnRrFzr/hBo/dlwTOrZjJoZsllUpSYfJ1KNP+WbG6IxeE09EqpWmpJ3p3w2o7pgBqvaEhbsEiL3B25vWfg1+WjAjg/PcDcWldOz9qv7Xn4gDmvXXj5ogx92MjTQCvCe4b7JYS1PDJ35PFhxbWdo0j1op2qFMr3yyyJE+lJxx3FASn5KiSFpQsVhCpfW6iPLh4DA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m2h+kAAQPHL4xIewzr3NRvSjnLptGoM7xR11LrxyaADvdA1u39WLRPJxqr26w2U575LvsaZR0fyorsgyZXLbMMzV598LcPK4As3bneo8/gbauhqa5L7UadX6fJuNA3bX1KmT9s+huEL/gfA4wla8QCycP9yWFczcyLs8aoBX53l8iBa/6xSmv/l/kPVvMXIfS74qAPjfCpe+w1X36t0Zurnkes6V6ukqxEABPPxx8MKKR2nRUZhzhZ8ri3UAeJ+eXG3J3LW6dtgFVAbQGqdslRQEn0s2T7ug71rcLQHYwS1ESgKiSbmL/f67ubL0aV/V5tyz5TOWpOcyPQDGf6avkg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: lkml <linux-kernel@xxxxxxxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Thu, 28 Apr 2022 14:50:44 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The latest with commit bdd8b6c98239 ("drm/i915: replace X86_FEATURE_PAT
with pat_enabled()") pat_enabled() returning false (because of PAT
initialization being suppressed in the absence of MTRRs being announced
to be available) 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
performant 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).

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
On the system where I observed the issue, a knock-on effect of driver
initialization failing was that the SATA-controller also started to
report failures.

--- a/arch/x86/mm/pat/memtype.c
+++ b/arch/x86/mm/pat/memtype.c
@@ -62,6 +62,7 @@
 
 static bool __read_mostly pat_bp_initialized;
 static bool __read_mostly pat_disabled = !IS_ENABLED(CONFIG_X86_PAT);
+static bool __initdata pat_force_disabled = !IS_ENABLED(CONFIG_X86_PAT);
 static bool __read_mostly pat_bp_enabled;
 static bool __read_mostly pat_cm_initialized;
 
@@ -86,6 +87,7 @@ void pat_disable(const char *msg_reason)
 static int __init nopat(char *str)
 {
        pat_disable("PAT support disabled via boot option.");
+       pat_force_disabled = true;
        return 0;
 }
 early_param("nopat", nopat);
@@ -272,7 +274,7 @@ static void pat_ap_init(u64 pat)
        wrmsrl(MSR_IA32_CR_PAT, pat);
 }
 
-void init_cache_modes(void)
+void __init init_cache_modes(void)
 {
        u64 pat = 0;
 
@@ -313,6 +315,13 @@ void init_cache_modes(void)
                 */
                pat = PAT(0, WB) | PAT(1, WT) | PAT(2, UC_MINUS) | PAT(3, UC) |
                      PAT(4, WB) | PAT(5, WT) | PAT(6, UC_MINUS) | PAT(7, UC);
+       } else if (!pat_force_disabled &&
+                  boot_cpu_has(X86_FEATURE_HYPERVISOR)) {
+               /*
+                * Clearly PAT is enabled underneath. Allow pat_enabled() to
+                * reflect this.
+                */
+               pat_bp_enabled = true;
        }
 
        __init_cache_modes(pat);




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.