Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3228456imw; Mon, 11 Jul 2022 04:46:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s21XWmZGcK2Fe+tzF4I4ROhEky8XGzVAKqJA4V9hXW88wTJ1s7ae8pGLvCYOiGY2rUERBt X-Received: by 2002:a17:902:ea0f:b0:16c:134:a247 with SMTP id s15-20020a170902ea0f00b0016c0134a247mr17874820plg.86.1657539986800; Mon, 11 Jul 2022 04:46:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657539986; cv=none; d=google.com; s=arc-20160816; b=pWKmCr1AEoppEH18WoB0fjtAsSlpgGEzd7A1RbD8+kzrFZp4fc4Slsu721q8feATo1 IMQ1LvKXczYNxLdiqpfhmEb324GmQ+NTcUMrASK8moL+VhcIXlcxGQxCwK7OKIPxG3xq 8fvDLchAfc3yXNJtbhqCDuZ6BYn15bkRyHhKzb3dDMowl5xfoWgpjWTO9OAmjZAzmB4n zi1IZJ9I+BeoN3l4f16cR70z/Xa9G84CvMhYdSIZ5dt4ZDHNMK2PwGMCICosCMRgcGZv pm3fexIK4fDfrAlyrzjUvL6N7kMzP2TFPzOqsEYlg4/LArfg1R6DmoTpVhstyPEsoiGg 00LQ== 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=w/ukMm5iwQWAeG3BAhYL3RaptUVhXqOYbZbqYfz4OBM=; b=COvKPRbcXQ8w2nS9LalAHXTeWosSLuF9za3BygKghw5p7/ieDdV1Ufucd1R0VAn1jH QyvMj2+hPw37yRO5g3wn8OtjYQUDqVyjq1zAxAw5GYGs6YQcI5jwLKdMWO0sMiSANUfk YEZSRAysKyPfhwkt9CbI1jVjqHBgw0kbhx8hV/HC8P45Aas1pZwWO1Vq77NKukEnzcDk N6mEj9xmRnNdGLsl6Y0NrvOwJxBdbLWSMmy2Cwp5aVVPyyX2UVVKWe18sglzCRGgz+dS EFQnb9kWlhdoHAO0s+/TpEnRv9gI5TnafH1+Lu8NQ0UH7lAqOZwM/W2VT+bkxaX5dBQq C3BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netscape.net header.s=a2048 header.b=sigCv5Nt; 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 v2-20020a655682000000b00415be6739b0si8857798pgs.240.2022.07.11.04.46.14; Mon, 11 Jul 2022 04:46:26 -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=sigCv5Nt; 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 S229581AbiGKLns (ORCPT + 99 others); Mon, 11 Jul 2022 07:43:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231405AbiGKLnE (ORCPT ); Mon, 11 Jul 2022 07:43:04 -0400 Received: from sonic312-23.consmr.mail.gq1.yahoo.com (sonic312-23.consmr.mail.gq1.yahoo.com [98.137.69.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1FCECE00 for ; Mon, 11 Jul 2022 04:38:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netscape.net; s=a2048; t=1657539521; bh=w/ukMm5iwQWAeG3BAhYL3RaptUVhXqOYbZbqYfz4OBM=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=sigCv5NtbCmuRMFy8E9TL10fWV6Mh6L/vwwQTQzX/S4+tju4GRDtGa5QKcHjQ6efV82JsKcLjJqsKtIU/oOZv7nURu2iW7ehYTlG12JSSZCmCQwA8UD4oOxvEJK59LW9w3erLeZ3sxBOFgHkNyat4pNRCrsORwMafAMgG0TCBsYaAV8EM2sJTYbJfIpmsxu6bNOpWHjagHX4j1sySB8Rife2POZjuVAiLVVcONsdJfoxZXs93yNP5JaE73yyrf+XxlAUn/6/CQKi1mcqE+LcYtOlg34L8qsW0cA2WrsbG7T72q4d10Q7d+s4GX/fttnnzJv26l65jk2obmkuEPpaag== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1657539521; bh=mGozHT5h7zDYiUQg4KfZcbWrKhfFoSRR5f34X62/Xhn=; h=X-Sonic-MF:Date:Subject:To:From:From:Subject; b=kWCMBTqGUo34tUjsJTDbrjJxNVoKXiTyjOejeuiioasfOcRPe6QUoXITih8zqmrb2at9+lEg2TAQmtCGgARANfvA+h4R6gKmRCXmq2KA8hl8sRxTxPzPgGq1M73RVqMAAFN08gz1zXcNHXA1D9oBGgHi50mYjuDpwNjyglHjZ4OeCFcJiomxeb0I79TFOdfaqVHLi9gz0etLsk/ZO7VbDSH2D08O29kjz9H4cbP/NeP2m+fvBCm/zHIR4jyuV8QpQn1gE/6XPMIUiOYMxmmwNpbbQ3nSllqUYX4QcHKEQUiXoYu7ZmR1hyNXlHlEhO50OZS4JT1GZI7GpzB5EEgdKw== X-YMail-OSG: Ynrj1a0VM1kbZ5mDA11QppCioN22lv89ZLTgz652Y2gBXOBdaO2Ji8sovCmqZbY 6imIkVY.eDlrBXJAE_1uEP6r2gqGKo1tDMy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irJZG_A4trI2auXipXRVwts6zlj1 VfcVfk6de4Q-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.gq1.yahoo.com with HTTP; Mon, 11 Jul 2022 11:38:41 +0000 Received: by hermes--production-bf1-58957fb66f-dd4hs (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8f307d8659d7a819d3d711f175c166e1; Mon, 11 Jul 2022 11:38:37 +0000 (UTC) Message-ID: Date: Mon, 11 Jul 2022 07:38:35 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] x86/PAT: have pat_enabled() properly reflect state when running on e.g. Xen Content-Language: en-US To: Borislav Petkov , Jan Beulich Cc: Andrew Lutomirski , "dave.hansen@linux.intel.com" , Peter Zijlstra , lkml , "xen-devel@lists.xenproject.org" References: <9385fa60-fa5d-f559-a137-6608408f88b0@suse.com> <016d281b-7e40-f1bd-66ee-c19c3cc56efe@suse.com> From: Chuck Zmudzinski In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailer: WebService/1.1.20381 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, 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/5/22 12:14 PM, Borislav Petkov wrote: > On Tue, Jul 05, 2022 at 05:56:36PM +0200, Jan Beulich wrote: > > Re-using pat_disabled like you do in your suggestion below won't > > work, because mtrr_bp_init() calls pat_disable() when MTRRs > > appear to be disabled (from the kernel's view). The goal is to > > honor "nopat" without honoring any other calls to pat_disable(). I think Jan is speaking of the narrow goal of the patch that is causing the regression at hand: Commit bdd8b6c98239cad3a976d6f197afc2c794d3cef8 ("drm/i915: replace X86_FEATURE_PAT with pat_enabled()") The author of that commit expressed the desire to more readily handle the nopat option in Linux in an architecture-independent way. in the commit message. The patch was not intended to cause a functional change, but it did - it caused a regression in Xen Dom0s running certain Intel graphics devices. > > Actually, the current goal is to adjust Xen dom0 because: > > 1. it uses the PAT code > > 2. but then it does something special and hides the MTRRs > > which is not something real hardware does. > > So this one-off thing should be prominent, visible and not get in the > way. Actually, this is probably the most insightful comment in all the words that have been written about this regression. This is a one-off thing, peculiar to Xen PV, but it is not visible enough and gets overlooked when changes are made. I guess I agree it should not get in the way either, and it doesn't, except when the lack of visibility of this one-off thing causes the author of a patch to overlook it and cause unforeseen problems for users of Xen on Linux. That is precisely what happened five years ago with commit 99c13b8c8896d7bcb92753bf ("x86/mm/pat: Don't report PAT on CPUs that don't support it") Have you looked at that patch? That is the one that introduced the regression that causes pat_enabled() to return a false negative on Xen Dom0 today, and it hid in the code for four and a half years and was only exposed as a regression with commit bdd8b6c98239cad3a9 last December, which again was written in a way that caused the regression on Xen because this one-off thing that Xen does was not visible enough to the author of the recent patch from last December that exposed this problem as a regression with Xen PV domains and certain Intel graphics adpapters. That patch did not take into account this not-visible-enough Xen case when MTRR is disabled but PAT is still supported by the CPU in Xen PV domains. So the proper way to fix this regression is by fixing that commit from five years ago. It is very simple. After some code re-factoring and other changes, today that commit can be fixed by something like: --- a/arch/x86/mm/pat/memtype.c    2022-06-16 07:32:05.000000000 -0400 +++ b/arch/x86/mm/pat/memtype.c    2022-07-09 17:51:56.783050765 -0400 @@ -315,6 +315,20 @@                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);  }   Like Jan's approach, it implements the fix in init_cache_modes(), but unlike Jan's approach, it only sets pat_bp_enabled and pat_bp_initialized to true if boot_cpu_has(X86_FEATURE_PAT) is true and rdmsrl(MSR_IA32_CR_PAT, pat) returns a valid value. No need to check for a hypervisor, just check if the CPU supports PAT here and that PAT MSR returns something valid here. If both are true, then set pat_bp_enabled to true. Regression solved. And that leaves the bigger goal of dealing with this one-off thing that Xen does in a more sane way for another day. I am working on a patch series that attempts to start the process by first re-factoring the currently confusing pat_disable functions and variables that will hopefully make this one-off Xen thing more visible and easier to understand so when someone wants to play around with the current way of deciding whether or not PAT is enabled on X86, no regression will occur on Xen or in any other environment. Best Regards, Chuck