Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3290280imw; Mon, 11 Jul 2022 06:00:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1shhLrvx4CTApZbz20EXGVdhS1sFVYRK2PyZVHCU3spIlyxzeshPi9cVl9/arWPtVuFyBLi X-Received: by 2002:a17:903:234d:b0:16c:3e90:12f5 with SMTP id c13-20020a170903234d00b0016c3e9012f5mr8486183plh.82.1657544416583; Mon, 11 Jul 2022 06:00:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657544416; cv=none; d=google.com; s=arc-20160816; b=iqWjYBKCA5J3Dz8cw1JW/v0DCYXvFGEhlshtW/+iOSne9UwkIavfx2R9RuS+aDyQ+M JOMTKa1lx7b81ETeHA8z9bQpcpVvOyN4hXcvRwLHnu6zBZRbLlxhXVcNIacDF06aSJB5 bDvxEq9o1azKH83i3XncNuhVsDZQ1dCa1e1HPriaptLuOwc1TSGpanpiUPz+aqmqenuz raFsKXTZmEj+pq/logwfoARUwr1G4hGahWTqK6o42KaCav2rRoKRR4+KQZeeNMH4xOUz vzWG0KGewFD7iZPT2X1ucMh+43PTH1+Q/rjIHHcRw1x/g/JZZ2uA2gtiL1rfVN0nG1Gf K7yQ== 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 :content-language:references:cc:to:subject:from:user-agent :mime-version:date:message-id:dkim-signature; bh=bkyH/2yEtsetdxmue4dlbWNa1NmKY5t/YHv6BZ96HxY=; b=ElB2JjE2YR/KPhvjsPlA3TSGeU4rajHqWRxyWdc5Iy2gPZnN8tjdV+pgSnEsfGHDky LF4U4fLUCjUj3WKYZ7kYsvQCJlr1Hrpmvj5dVKBE4c2ERR5NaPrn/yzyj3t/EbP2cwCT MDEj9S59O3g/BW39fkTrRQlhWbBwfd8ay7lEk5tf0ohjECEmplmmEWDQtKuq8Q1dcfLz 4otrWdQ0vQGOsGFllB8KXk+pzN8xvjug8dS6euvKU1/ABwcnhNCqOmkTO9pmpLF3OhOI S0Fp8YTyooHQvvUQBPz7AxXlazsEZdY1w/sBlBl0oxgTkPxyCbzme3QFJu3t0ZxQLztW ErwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netscape.net header.s=a2048 header.b=GTLIiN5f; 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 d3-20020a170903230300b0016c30bffeccsi12353064plh.212.2022.07.11.05.59.58; Mon, 11 Jul 2022 06:00:16 -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=GTLIiN5f; 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 S230043AbiGKM2g (ORCPT + 99 others); Mon, 11 Jul 2022 08:28:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229572AbiGKM2b (ORCPT ); Mon, 11 Jul 2022 08:28:31 -0400 Received: from sonic301-21.consmr.mail.gq1.yahoo.com (sonic301-21.consmr.mail.gq1.yahoo.com [98.137.64.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE6AE29A for ; Mon, 11 Jul 2022 05:28:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netscape.net; s=a2048; t=1657542510; bh=bkyH/2yEtsetdxmue4dlbWNa1NmKY5t/YHv6BZ96HxY=; h=Date:From:Subject:To:Cc:References:In-Reply-To:From:Subject:Reply-To; b=GTLIiN5fXmFB1C1BaPAx0SFI9AP04mdVHbZU/k0HfrHd2y+3PAc+SKx1Gp3mQnrNxUA9AsqFxPhec17O7g+roP7EC2u8pgAXAdAxrnuA8ZPmf/6I3NCTud1nQfPmWk67LgIEihqZfX1w3Wq65fMzPYRXKmSbxrfvM6YcvAynHiV74UihnPWetqicQePfBeB7GEEvGCppeeB/itVk7rPeq1Ml5nzWvkWvSx4iyXNWDIRv9TILZVYWqTtRfZh1QR88vXPHCJTd3OGbfCsFMaDnH9sdAPTAWQnVPxw5jHnz/ZVVi/77Yw+ZNIvqNdonDwbufcaiB/4G6xc/a4PommFEbA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1657542510; bh=rKBwDKvOdcW0IXB0d2qgnDfP+2/IXQxx9Rz8JinpEDY=; h=X-Sonic-MF:Date:From:Subject:To:From:Subject; b=syjCYX+7xEuWmiENfAvcXceGPVibVZgEVJL+6ZHaqcik5TyXhXj658E7JPnjXb6yPj/wvJeAtgrqMaBaVCrKqCDlqBPbQCsxlPtBqX4PZaPevRi/WVg5ao3JsmvKVBF0h/l4mptWD4oezlz6TBt0G4qwOFvaKmG0XS+pcbgNJCGPY9P7Rl/XFziorASUN/RIBEv1auazfG9QX1C+p2zwyxEAf/vzbbIVVUMoxjkoL0tbN476un5MQD0eWgeFiT9V4pdXR2f0WvIlfNbkd4xN/7G7tnPnrJX4KbRwp6TEnejN4jcjQu30ZsMJ9jgbBCO5MFaxv+JPTMMZ+RQgbdLSRg== X-YMail-OSG: ljkONEYVM1nH882XyMvvMTZEG7U2TFqZe4hNcHqpvO7Oh8iFE55axji95cREcTU lQlMiUHgAcIW7xsdWAtaR6ltBhH01Vcjxn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W2BLZpRo5R9j7VjAiyopChAB7Vrw.Orqp4mxgigeq0f jV18X17SRZzqJIyR.qQzJFqgLRAsAyVD.4h8n9EFbMTTjeTdkDq2_51vJL56k1ftWNpckMmFOaam kKmUm0zdFSFhvVEucaisF5VZDzX8vLI_AjWjOQqc0NgQX_5xU6mVHFYMCjG_08HBiMKT4wxgZ1qT p1pq4EGiyvB0aFFRcDgQ1V8XzXLPv1y4Yue.LEQhawncZzxcLlhqZSGiGzftF8IpZf4PUEWPAsqh GJHvZq_xtp3_HKSAnomni8vBusPicdbZ8.xf4xGJjOMydarh1yVTkfo_.wWq.hRhxoQWGAX3WjA6 sbZ8tFXlubTyuKVMQHBQBYj.SjmEZQ8b2FcHplReORAfTApLuSM1ITg8bqs1hsNVDlk59_S_Kbtk yqo3DzTpweTkVYvYfrLMfT7liZLlsqZ_eOVpulMKKkZXC62fGF0mqcZUkldb9IhBxdQ9y7ls3kkK rikm8x9BbUnutghYZvj2kyJDKJD8iv9aiuDlxh03H9TKxO4mNxjh_DLrDu6nfNK8tfpYUGIzL8IA s4JTYaKI7TKw5Q4m2ZHSUFbA_VreILzyT4jht_D93f__OHxHSZvZEhjB.wOL5EsvLngxprhPMgyG VwltPAPc_qawIBdtD48ah5WjF3V7dmIR3L9SvOVHp2rmuuVXPRQNDFBupagPG_3i_6uypm4eUaFB nmUDLKm2F.AM1QLL5kc8US3VUmOobV.ZaZv7jrz7IRv2rl1Zl.SS9EpxoN6dz488eqYjb3vkQTXi 8GgrryN24MpIgHJ.p8HWz1K5vqMEbOC3aPHgg42O_ X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.gq1.yahoo.com with HTTP; Mon, 11 Jul 2022 12:28:30 +0000 Received: by hermes--production-bf1-58957fb66f-2wrgg (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID edfbbd6fa8ecbc3209f72e28e8d17388; Mon, 11 Jul 2022 12:28:25 +0000 (UTC) Message-ID: <63583497-152f-5880-4c8f-d47e2a81f5a6@netscape.net> Date: Mon, 11 Jul 2022 08:28:23 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 From: Chuck Zmudzinski Subject: Re: [PATCH] x86/PAT: have pat_enabled() properly reflect state when running on e.g. Xen, with corrected patch 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> Content-Language: en-US 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,19 @@                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);  }   [N.B. I am re-sending this message because this patch in the earlier message would be malformed because I deleted an inserted line without editing the line in the patch that defines how many new lines are inserted into the patched file. The change from the proposed patch in the previous message is: @@ -315,6 +315,20 @@ -> @@ -315,6 +315,19 @@ Sorry for the confusion.] Like Jan's approach, this patch 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