Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp21285imw; Thu, 14 Jul 2022 19:29:04 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tDWRhNy14l0aOvfBQARw9Q7pW3Xuc1ZawHJYSuCT3+B5kTHUuPfYdHAKM71MYUpjRZLyDf X-Received: by 2002:a17:906:5512:b0:726:be2c:a2e5 with SMTP id r18-20020a170906551200b00726be2ca2e5mr11327702ejp.88.1657852144302; Thu, 14 Jul 2022 19:29:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657852144; cv=none; d=google.com; s=arc-20160816; b=pWhIfVsP53T0Cw23O+cemFo3OJ+jG8Nm7gWgK3j71SgGyvYxjIW9OYFfR/5BwDpUKB rPYejN3ySnXs+3Cn0Opm5XHhxbQYq0kC2p5nOoNyoqfwtUnLp6qf9+jVaN+FyYME1C4h 63PoGypGOP/tKMe2X9qoEQhHslxKrBHxA+TY306c5M1EMmFnxXOuTRzMwafKn4KsjsI/ UuQXLDTGNKKk+RIk1R4Suho1XhDeVQAOVlbDvz+h5hGczPRtb5aLT6jPx2DKj9wSUVZc l2YAalZWeda7HtxkzTcdW0QWm5uQw4CNhNGUXauy8jjQ5KvbgXacKyOLte0gsdXXuItF qGcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=ikYj4oGExaqVUjXEqqwrkniGmBXQdtogeu3jz7ioOUw=; b=vV5QBsS27Yv10M1jgITCmrRTTs3WdNBh9EiT0E/RgJeG9O85oLu2lU8GLFEMqYtghO 6uyy56waqINY1LHlz7DlKG5qOxMmqkxhLWhclGrt6XpHFDX/BygoxSkurIHIrx6G4JWd oPYzRppUUtOa+21TirXrncOkz3UPDF5uJoVo80vrVZcBpRGeq/64p9xWexo2tLVzdnCb iFZeQfuuX4Dbm7DfpuRSiXbjAY13Z3LgxqLKs6V3B8phFX9FZitJh077dScq1iaPEjHv 696J3ccm4btsnNmGX0qtV3lcHKuMp6SMjIOOye9YAdXzR8GhqnylJfVBss8Qt6MCD6rf CRHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netscape.net header.s=a2048 header.b=QFOscrCN; 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=netscape.net Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z3-20020a05640240c300b004397f76c865si4067890edb.466.2022.07.14.19.28.39; Thu, 14 Jul 2022 19:29:04 -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=@netscape.net header.s=a2048 header.b=QFOscrCN; 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=netscape.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232690AbiGOCTu (ORCPT + 99 others); Thu, 14 Jul 2022 22:19:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229541AbiGOCTs (ORCPT ); Thu, 14 Jul 2022 22:19:48 -0400 Received: from sonic308-8.consmr.mail.gq1.yahoo.com (sonic308-8.consmr.mail.gq1.yahoo.com [98.137.68.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C68229C80 for ; Thu, 14 Jul 2022 19:19:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netscape.net; s=a2048; t=1657851587; bh=ikYj4oGExaqVUjXEqqwrkniGmBXQdtogeu3jz7ioOUw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=QFOscrCN2oVaeycP2RbKLtRi7bImemzW671zFZhpnbsqWt4HC9FMMzPey6mMQwIJEN5/WabaadMuotMims7n3yiLh4VQvJZiVGsTlMUgnGKQv3j7jDb7wfKn/2jBbO4VHE56C/DNKmpPx2Muc1+fYhjGlCpR8Ubsh2EXt0Ei9PPyXMtZL1ALWt6M9zkRkfDQpYzILKE0m4PfxW8vjwlIjGZyhXWtCYFIl2ewpWJY5lrsjls/qWA2frSnD4XmmnVx0xeUwz6X7Kq0eVVtFInX2L6YPvEh8zDqUbkr7pHSsQrmJT60WhxA1hLrFGwwOwSiBl1SrHeQSzXuG4aaoDsEtg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1657851587; bh=2tvmpiwH/jUC7q1rvaoVWpN60yRmZ3/H7HpMVZ0HX6u=; h=X-Sonic-MF:Date:Subject:To:From:From:Subject; b=qBQ5x2hvSABvVUR9T6tfp5kzDs4vIUHpmjJukK6R1D293SOiSXflauNRC8h8V7yGA5NUIGjpd9kOasV9Uyo1o+sH2HPxnKlJQGH0NGdtgISVl0IEJ7tZrAV6pXZnNxPQqkgR1uOliRQxaPJd8Ou/O2lKnEM+0XcJZEe2z3tqYGvsTbJtr7XkBc1oQBYxCPW0d6/e9lHn2D5F7tay+QP3/gNc1Ptw+gYTAwZLKFV4KhcGS/JfUdqJm2SvmKQaMdpWWjUqRJo0jPmCQS7zCMNK8B8gp/ZbP/r7JtF9Ejj7R2yNKGIzWnJQwgjTpw6TO7fGfdq/rDFqiYWWDRXO1Iw7jg== X-YMail-OSG: ApqVZPQVM1m.wsDXoGVxxoB9DGoFc4flSA7teL_IGd3AKzWtk3YLgQV_I29qiDi KIdhvF8By5OGwCsQhwz88fQWE4Xyg5Yp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szjSRGRY1deIV.B2j.MQObec2QN3IY5qCiZ n8Ac- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.gq1.yahoo.com with HTTP; Fri, 15 Jul 2022 02:19:47 +0000 Received: by hermes--production-ne1-7864dcfd54-xmlhn (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID ba0ca635c88d8bc86fe3ed38195e495d; Fri, 15 Jul 2022 02:19:44 +0000 (UTC) Message-ID: Date: Thu, 14 Jul 2022 22:19:40 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v2] Subject: x86/PAT: Report PAT on CPUs that support PAT without MTRR Content-Language: en-US To: Juergen Gross , Chuck Zmudzinski , 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 , xen-devel@lists.xenproject.org, stable@vger.kernel.org References: <9d5070ae4f3e956a95d3f50e24f1a93488b9ff52.1657671676.git.brchuckz.ref@aol.com> <9d5070ae4f3e956a95d3f50e24f1a93488b9ff52.1657671676.git.brchuckz@aol.com> From: Chuck Zmudzinski In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Mailer: WebService/1.1.20407 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.aol 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,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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 On 7/14/2022 1:40 AM, Juergen Gross wrote: > On 13.07.22 03:36, Chuck Zmudzinski wrote: > > 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) { > > Can we just remove this modification and ... > > > /* > > * 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) { > > ... use > > + } else if (!pat_bp_enabled && !pat_force_disabled) { > > here? > > This will result in the desired outcome in all cases IMO: If PAT wasn't > disabled via "nopat" and the PAT MSR has a non-zero value (from BIOS or > Hypervisor) and PAT has been disabled implicitly (e.g. due to lack of > MTRR), then PAT will be set to "enabled" again. With that, you can also completely remove the new Boolean - it will be a meaningless variable wasting memory. This will also make my patch more or less do what Jan's patch does - the "nopat" option will not cause the situation when the PAT MSR does not match the software view. So you are basically proposing just going back to my original patch, after fixing the style problems, of course. That also would solve the problem of needing Jan's S-o-b. I am inclined, however, to wait for a maintainer who has power to actually do the commit, to make a comment. Your R-b to my v2 did not have much clout with the actual maintainers, as far as I can tell. I am somewhat annoyed that it was at your suggestion that my v2 ended up confusing the main issue, the regression, with the red herring of the "nopat" option. Chuck > > + /* > > + * 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); > > > Juergen