Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3366177imw; Mon, 11 Jul 2022 07:21:05 -0700 (PDT) X-Google-Smtp-Source: AGRyM1swTK3IeeRTfUN6xtOyPkgKyEgqRKu8GosjSi3h2U9sa5vHoOcQ4926DVbCfuLNUyOimxR3 X-Received: by 2002:a63:b21:0:b0:3fd:f319:dd6c with SMTP id 33-20020a630b21000000b003fdf319dd6cmr15872469pgl.168.1657549265173; Mon, 11 Jul 2022 07:21:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657549265; cv=none; d=google.com; s=arc-20160816; b=bTrh8ZcOi0fvlr4qigxnedjBm5UZE2z7B+rNqWFh7mrx98szjxqg4swNJjlRAz1F8B c5Ld63IQv55jP1gGGYyXfCa4n4Kb1rRP2uhQjKYhCUZAw+Ly/PqckMvwY+xhbWUNCvh9 /CC0n7sCIsyYgOIsb8Sx1qSf0gytOk0OvnIVJKG+whkiERy528koFcRIIabbDRpcadDJ cfWFtB4GIi6k82i+u21mZ3tOWQXq/caWqFIngGBMPsg0JIJTnI1T5MAKu6v7eM0IoEz5 livmci0CNDKW453sc1xYv2pKi6lYgNmhnDKIfGIcuZ8Ufjqqu5+Am9l54+8cmltP07zV VTrg== 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=R/XMnj1qIU9tgCHkr7IC0xOtwixzIp8+uQb/ugngDu4=; b=h9q4q0fVAgVetqoBFHe3pVUxRH1RW73W+cL8Rkk9vx1eAUf3TYy01bFzvTC/9r9dQE qAVYOl+jBmt1eiGjMqHIXyRmzB6sbUfpb0uX6e5aQ8RhNZqgXz1RDZbkY/5DqlKc6qTo F/FkI8HKeIDdu/fVwNsFpskASombbT77bFqHnCI3vfL8elgjy/owOW1IwnPC2oZVCC6M +fO/tsOHxuBZI3Zu+1k3HXVh4XXoEzrNBMQlZWi+Gp3SbM7evo1ev8jziIv/UBjILxoI AfzaJWEzwmaGUGSe1xssd/t1vS6rFxXe0bVkP3e3yyxEq81axmjhCo2AVMHrCxpFpznG rDEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netscape.net header.s=a2048 header.b=OMwACxHT; 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 m7-20020a63ed47000000b0040cd2567341si10105128pgk.354.2022.07.11.07.20.52; Mon, 11 Jul 2022 07:21:05 -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=OMwACxHT; 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 S229908AbiGKOSX (ORCPT + 99 others); Mon, 11 Jul 2022 10:18:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229904AbiGKOSU (ORCPT ); Mon, 11 Jul 2022 10:18:20 -0400 Received: from sonic306-20.consmr.mail.gq1.yahoo.com (sonic306-20.consmr.mail.gq1.yahoo.com [98.137.68.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD06A62485 for ; Mon, 11 Jul 2022 07:18:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netscape.net; s=a2048; t=1657549096; bh=R/XMnj1qIU9tgCHkr7IC0xOtwixzIp8+uQb/ugngDu4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=OMwACxHT0Brt4IwXkS2dQ8yifnA9WdjEkO44sGRfNkXY+E+Rf04exnhE9EsWQd6Ox/wyLPW3916HQIP1ej5LUNmFoqE9EfmVRjYV2dAOgb81wPWeAkBmzOxArC+2LoZdSKCCyxrazEflZESRH+5jM4UM5sH1IJpPm9Mps3wMaEqtNAV0sK2J9x1+iiloBShMyS6DDOV6zA0jkUi6Xf2/XcvIjyXz1j9iP6o6u9KeWL09cLsSNP4GDvJvjM8t/jBMN5nYWWYqKsxb19uiknusJgffFwntdXdh8BfNkzUGd6G0rOUIdwryfgaohH3TIXF7wX5w23zuZ63k7c5d3blWVQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1657549096; bh=ZdXLxkl/Eo6HEtCnr/qRivqI9jPbOdRlWFPqnEqhM+4=; h=X-Sonic-MF:Date:Subject:To:From:From:Subject; b=Tn2PQwU/alVRwy+mqt8F0wefvrQ3Hmy9m7bOiylRRahz9nNIdPpPsANTYl3V/mFoHpG5lNMoEAPyrRlefbjRWGXCjt/jQYG9OHy/DtowN/dL8QtXKpD3DGhblrSDUcRi9dwSRG+e6G0yKZGPH1XvrSP2XRM1ytXTNhXIBjTd+hos3h8pOWOKkxP/oyYKZkjzImjJk9DlUsAAwnzWjaKGBXmw+kVIW2fLAfWyI8NvPGC6+147YDVSSWgdCqCdAFD2mR++kiFFTSsP6klx1JwQTjg3rUX85NcBkkgZnEtnoYaj2A5AAjIkHs1mkYUY7O1Uyjf5oKilTlnSYUdRT34dQg== X-YMail-OSG: 8V.DSTEVM1mrc4lotEROYeiaCxEjKspywy8V9Kld6BBifq53SFVi7nBgOAc0xnJ jB2Q6XgvUJxY1Ft5S0fc.7qXuepA6sozMwzEn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Udl4cy LvpknkcsYhNa4WtndJ9wKUQ-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.gq1.yahoo.com with HTTP; Mon, 11 Jul 2022 14:18:16 +0000 Received: by hermes--production-ne1-7864dcfd54-8q7fk (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 393f9d76813cf2fb95aa8646fdc67e8e; Mon, 11 Jul 2022 14:18:10 +0000 (UTC) Message-ID: <4e099e2d-e429-252b-ceeb-678066d85e61@netscape.net> Date: Mon, 11 Jul 2022 10:18:08 -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: 7bit 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(). > > 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. Hello, I have spent a fair amount of time this past weekend investigating this regression and what might have caused it and I also have done several tests on my Xen workstation that exhibits the regression to verify my understanding of the problem and also raise other problematic points. I think, in addition to immediately fixing the regression by fixing the now five-year-old commit that is the root cause of the recently exposed regression, as discussed in my earlier message which proposes a simple patch to fix that five-year-old broken commit, https://lore.kernel.org/lkml/63583497-152f-5880-4c8f-d47e2a81f5a6@netscape.net/ there needs to be a decision about how best to deal with this very aptly described "one-off Xen thing" in the future. One problem in x86/mm/pat/memtype.c is the fact that there exist two functions, pat_init(), and init_cache_modes(), that do more or less the same thing, so that when one of those functions needs to be updated, the other also needs to be updated. In the past, when changes to the pat_enable and pat_disable functions and variables were made, all too often, the change was only applied to pat_init() and not to init_cache_modes() and the one-off Xen case was simply not addressed and dealt with properly. So I propose the following: 1) Identify those things that always need to be done in either pat_init() or init_cache_modes() and try to combine those things into a single function so that changes will be applied for both cases. We sort of have that now with __init_cache_modes(), but it is not really good enough to prevent the regressions we sometimes get in Xen PV domains such as the current regression we have with Xen Dom0 and certain particular Intel graphics devices. 2) If it is not possible to do what is proposed in 1), at least re-factor the code to make it very clear that whenever either pat_init() needs to be adjusted or init_cache_modes() needs to be adjusted, care must be taken to ensure that all cases are properly dealt with, including the one-off Xen case of enabling PAT with MTRR disabled, Currently, AIUI, all one really needs to know is that init_cached_modes() handles two special cases: First, when PAT is disabled for any reason, including when the "nopat" boot option is set, and second, the one-off Xen case of MTRR being disabled but PAT being enabled. I am trying to do number 2 with a patch series I am working on. It is up to the experts to decide if it is possible or even desirable to improve the code so that any changes to the caching configuration are more likely to be properly implemented for all supported platforms by successfully combining the two functions pat_init() and init_cache_modes() into a single function. The new function would probably need to be renamed and include bits from mtrr_bp_enabled, etc. for it to function properly. If anyone wants to argue that it is not desirable to try combine pat_init() and init_cache_modes() into a single function, I think the burden of proof rests on that person to demonstrate why it is good and clean coding practice to continue to have them separate and independent from each other in the code when they both essentially do the same thing in the end, which is call __init_cache_modes() and determine the PAT state, and also probably the MTRR state. Best Regards, Chuck