Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp274154imw; Tue, 12 Jul 2022 19:50:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uL5fhLmtiKY1uKBVL1V76gFJYfb5EV/KGppI04gQrjvRnUlFLWjdFiQ48u+AHZ9lmbJOMz X-Received: by 2002:a17:90a:c088:b0:1ef:b85c:576b with SMTP id o8-20020a17090ac08800b001efb85c576bmr7802079pjs.237.1657680624111; Tue, 12 Jul 2022 19:50:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657680624; cv=none; d=google.com; s=arc-20160816; b=k+AObfJnGMm4yVvbV6q5qQG3j3uKfSXAt0Hu9t7DlgMDay9JBp37WD3FAKAtpX4H9f NAeo3YM9mHv1dAd8Y1tTCmOCowyeSbHUvQHR1GcYUiKXVUu8Nb00KARy0EcfNCE9e3sU U2KUgskwk92D01T4us2tVwfIIkF94xEjrj284gJBSgroHODIvrXYzfX4E24ViuO3cUH7 +e2LJnX0qDZZPbHhsLH9tWYDnGTus5okjnXqRaPgkmlItvcONZaN6t8Yatpg4WiAWAiV OkjpQw/qc1gtnVb/S7DqevBBRpsaTEHYU1UWZs0qvICzHCytmsvRGCASDuftukXT1ebL JNyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=ilQ63Qlh/pxWEmqxuxayijK2KJ9t+TQhVpcbdyvIRRY=; b=yDQmxG7cMhy6/1LhCoIQZ3WOrkb3cYmNJlB2FaQVtHRxOcoKsujtc/NRPCDPcDfYWZ 53IQqlqEntSoXmFZGTZ+mJiYiAUxR9aQUCnuN5E8ziRHsKu9sJkf/5viQInlZw004qQT f2m6Zvu4MdcF8APAumJ82xeLnSoimFMqwl1DzgKjedp1uWcROgxmkPsXIEw5Btho2etT Jrep4ZLIJFh0En9rz1P05rBKnqAw2KsvQ8YXq2Q4mhCIWkUxn8Mioyr31Cfx7R6pcaLl gY3AryVZp3ZQ0F0Xv18l6AZaZmGAyoC3Kj1LBOz3EgDKxvYLZN7FEWe7NZdh/U8+WkyO myiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@aol.com header.s=a2048 header.b=PCONkz1s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=aol.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jc2-20020a17090325c200b0016bf01a662asi13696378plb.499.2022.07.12.19.50.11; Tue, 12 Jul 2022 19:50:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@aol.com header.s=a2048 header.b=PCONkz1s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=aol.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233674AbiGMBgj (ORCPT + 99 others); Tue, 12 Jul 2022 21:36:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229775AbiGMBgi (ORCPT ); Tue, 12 Jul 2022 21:36:38 -0400 Received: from sonic307-8.consmr.mail.gq1.yahoo.com (sonic307-8.consmr.mail.gq1.yahoo.com [98.137.64.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0035CC7B8 for ; Tue, 12 Jul 2022 18:36:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1657676196; bh=ilQ63Qlh/pxWEmqxuxayijK2KJ9t+TQhVpcbdyvIRRY=; h=From:To:Cc:Subject:Date:References:From:Subject:Reply-To; b=PCONkz1sV3u1EryJ5YBSI/Vg3MtWr6jEa9qOBNKYeqP/Pu6ltZV6+rChsMyx2fJ0XNHhav48mVNbeMzN2giGWwr+L1ybbfbkWPwYQcyWgKV3jZHBEEDo6+j9k+Qx0uP/h4TIw2yb876mthUEMZiFnB1mVhLAVEid1wCr7BlYoeVoZ8SOMWaJwnJab8YfxRZdb3lfqDKdQ6ApQOVEc2QaxkV6HxRjRtlzjzKWri1C63iYeC0DZm3gZ+5lXCT1+6VBF7a1Agox/psCN8YXf2DWtq67jCV00N2BvL4BtXzU2Y9P7f+eHK53Kucx0Hdosg2tCpiFqZnZ4MLBz7NjzKJTfA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1657676196; bh=CfK7C2itV8VfkLP5ECLS/mYB/CEjf8Zzcx3VvW/HYW9=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=tgZea/8XuqvZi2f1BW+Srlk2njPyiMDabqbEwXkgH0gX6YGvIpBueBL3stkKGhgDn7D0bNNQvjlyl8uJSInpr5AN/9dPEyXlksyOwCwE5BD0DJjwoBzvUzaVCVamanpTe3xea8CJRLEhyRvPO3Msj4I0cx876o1GiM2L9dKw/ZTGUjzVGwG9fahmE+9qUSXxVgg/tgDsYxoCjBE9uBZTYs4GstjDlRN8A9aEsXmEy7E5IHgdIhRbIwlgTnocHEFm4cctb/0i9vMDONq5m+dkBPYJfEppqnnY9BAQ6T1mQsiz0/vh6P7Zm3/rofVHmpZDcInIQMbvXQrawdDZd7v0AQ== X-YMail-OSG: wumnrFAVM1nJcpCj0FRu7OkeKPNBfKyNn3Z3Xi7QLjW.NGYqi6U1HzPu3JduYmS M08rb_OnmfwSrtLELFpb2Vg_BaA3lskWK9BQbt_OE0hAQuOHqVF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-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic307.consmr.mail.gq1.yahoo.com with HTTP; Wed, 13 Jul 2022 01:36:36 +0000 Received: by hermes--production-ne1-7864dcfd54-jt2sh (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 103a284e887da164b6a51a28e1ee36f6; Wed, 13 Jul 2022 01:36:33 +0000 (UTC) From: Chuck Zmudzinski To: linux-kernel@vger.kernel.org Cc: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Dan Williams , "Kirill A. Shutemov" , Tom Lendacky , Jane Chu , Tianyu Lan , Randy Dunlap , Sean Christopherson , Jan Beulich , Juergen Gross , xen-devel@lists.xenproject.org, stable@vger.kernel.org Subject: [PATCH v2] Subject: x86/PAT: Report PAT on CPUs that support PAT without MTRR Date: Tue, 12 Jul 2022 21:36:12 -0400 Message-Id: <9d5070ae4f3e956a95d3f50e24f1a93488b9ff52.1657671676.git.brchuckz@aol.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit References: <9d5070ae4f3e956a95d3f50e24f1a93488b9ff52.1657671676.git.brchuckz.ref@aol.com> X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The commit 99c13b8c8896d7bcb92753bf ("x86/mm/pat: Don't report PAT on CPUs that don't support it") incorrectly failed to account for the case in init_cache_modes() when CPUs do support PAT and falsely reported PAT to be disabled when in fact PAT is enabled. In some environments, notably in Xen PV domains, MTRR is disabled but PAT is still enabled, and that is the case that the aforementioned commit failed to account for. As an unfortunate consequnce, the pat_enabled() function currently does not correctly report that PAT is enabled in such environments. The fix is implemented in init_cache_modes() by setting pat_bp_enabled to true in init_cache_modes() for the case that commit 99c13b8c8896d7bcb92753bf ("x86/mm/pat: Don't report PAT on CPUs that don't support it") failed to account for. This approach arranges for pat_enabled() to return true in the Xen PV environment without undermining the rest of PAT MSR management logic that considers PAT to be disabled: Specifically, no writes to the PAT MSR should occur. This patch fixes a regression that some users are experiencing with Linux as a Xen Dom0 driving particular Intel graphics devices by correctly reporting to the Intel i915 driver that PAT is enabled where previously it was falsely reporting that PAT is disabled. Some users are experiencing system hangs in Xen PV Dom0 and all users on Xen PV Dom0 are experiencing reduced graphics performance because 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 are quite a bit less performant than possible without this patch. Also, with the current code, in the Xen PV environment, PAT will not be disabled if the administrator sets the "nopat" boot option. Introduce a new boolean variable, pat_force_disable, to forcibly disable PAT when the administrator sets the "nopat" option to override the default behavior of using the PAT configuration that Xen has provided. 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). Fixes: 99c13b8c8896d7bcb92753bf ("x86/mm/pat: Don't report PAT on CPUs that don't support it") Co-developed-by: Jan Beulich Cc: stable@vger.kernel.org Signed-off-by: Chuck Zmudzinski --- v2: *Add force_pat_disabled variable to fix "nopat" on Xen PV (Jan Beulich) *Add the necessary code to incorporate the "nopat" fix *void init_cache_modes(void) -> void __init init_cache_modes(void) *Add Jan Beulich as Co-developer (Jan has not signed off yet) *Expand the commit message to include relevant parts of the commit message of Jan Beulich's proposed patch for this problem *Fix 'else if ... {' placement and indentation *Remove indication the backport to stable branches is only back to 5.17.y I think these changes address all the comments on the original patch I added Jan Beulich as a Co-developer because Juergen Gross asked me to include Jan's idea for fixing "nopat" that was missing from the first version of the patch. The patch has been tested, it works as expected with and without nopat in the Xen PV Dom0 environment. That is, "nopat" causes the system to exhibit the effects and problems that lack of PAT support causes. arch/x86/mm/pat/memtype.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index d5ef64ddd35e..10a37d309d23 100644 --- 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; @@ -292,7 +294,7 @@ void init_cache_modes(void) rdmsrl(MSR_IA32_CR_PAT, pat); } - if (!pat) { + if (!pat || pat_force_disabled) { /* * No PAT. Emulate the PAT table that corresponds to the two * cache bits, PWT (Write Through) and PCD (Cache Disable). @@ -313,6 +315,16 @@ 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_bp_enabled) { + /* + * In some environments, specifically Xen PV, PAT + * initialization is skipped because MTRRs are disabled even + * though PAT is available. In such environments, set PAT to + * enabled to correctly indicate to callers of pat_enabled() + * that CPU support for PAT is available. + */ + pat_bp_enabled = true; + pr_info("x86/PAT: PAT enabled by init_cache_modes\n"); } __init_cache_modes(pat); -- 2.36.1