Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3086858rwe; Mon, 29 Aug 2022 05:43:55 -0700 (PDT) X-Google-Smtp-Source: AA6agR46zEgdKdYALUG2vEPX8ptDcwJYAbHcF3QpMjD08RZlqjV4u5wvVaOAg/bZBZnpshp0joSz X-Received: by 2002:a17:903:2349:b0:174:cef1:69ad with SMTP id c9-20020a170903234900b00174cef169admr4110294plh.138.1661777034969; Mon, 29 Aug 2022 05:43:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661777034; cv=none; d=google.com; s=arc-20160816; b=giBNTbnPpOHsS6TKrYwTMZIY8AEuU4tzYzLpdVYrA4N49LtwaI5yJXEgHoMvedny8F THaET4NMfPHhujemQc4agBnRsYHRVrIz8yWk+ALKd6Q1P0swvze+usq+Aepxv0QdOP71 xv4nr0lCBfZYNt0LXPjsqzHlIBKu8aIrolRyjb3craw3nYi4vtwJKlBS9xZyKxyW/vQe LHW1XPi8einDEuycDAMag8qv+VJ1WouFfimLeb60TWpZ99flJWbBVuRniHf5Fkoox9Ii xy3L9ZtsxdWMYF7jF5E8ZByV7a8goV8Lv4buZz45464nphcGWXkBHCo4Asgfg0UiYhSQ cbKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jJjkmKuqQsWAkyGPuAntGuKiOV/owcJo4uFK92DfEzo=; b=ihZZT8S1Ogj4IGgNhkGmcCKCuv5OUsa8F3vyO6jqFy3h4WufbVWem5zYlrhD5KLwWH lj1SnJQYSuZt4nIbY3+GlGTSPxDyAcxE3sBlyiWLAOEhwgJ0j+R9MO1dQxcxb0AAwaKt MSVSkIjgKaJrhBlEXuErZqW04ErnrZ1/WaGMx6C26amWeacaYwGGkQZ6SKdclJJr2V3a 9QVGr68nRRDvmcsFhwBoKRuwZoTvQ4LfTcg7Z7vwyC5DT8pvFG0VlOLR6oD21MTuIcvX 8HFJ0FgXVAegC3+Y2otnm8ECfARXBHEGI+/GBgnP+vdsKThFqHBucRT9VyTsW9HYgthC THaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ujXWigU0; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f13-20020a056a00228d00b005360fd17809si472641pfe.63.2022.08.29.05.43.43; Mon, 29 Aug 2022 05:43:54 -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=@linuxfoundation.org header.s=korg header.b=ujXWigU0; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229980AbiH2M2T (ORCPT + 99 others); Mon, 29 Aug 2022 08:28:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229871AbiH2M1w (ORCPT ); Mon, 29 Aug 2022 08:27:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83C02AE205; Mon, 29 Aug 2022 05:11:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B2F8A6123D; Mon, 29 Aug 2022 11:17:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2E6FC433D7; Mon, 29 Aug 2022 11:17:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771827; bh=gcZSMS/DK5coU0N9vP5BKXdPmMcCP9sZHKX5Iz1YpP4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ujXWigU00y44mI2pEXTx2I0J+gH1regmgD+lP/imqFtAWjnCQER7n3n/uUUsj4zF0 9XymOfqBCL3DZyNmiBa2szuUXpWjr42vHqkdof2R8kqh8lA3CBS8je5FEYVAYJ6lO2 HKSDCKNnpfgd/XvzANJIvcav+oDkkGhscVXyGlwE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Beulich , Borislav Petkov , Ingo Molnar , Juergen Gross , Lucas De Marchi Subject: [PATCH 5.19 109/158] x86/PAT: Have pat_enabled() properly reflect state when running on Xen Date: Mon, 29 Aug 2022 12:59:19 +0200 Message-Id: <20220829105813.685677959@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105808.828227973@linuxfoundation.org> References: <20220829105808.828227973@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Jan Beulich commit 72cbc8f04fe2fa93443c0fcccb7ad91dfea3d9ce upstream. After commit ID in the Fixes: tag, pat_enabled() returns false (because of PAT initialization being suppressed in the absence of MTRRs being announced to be available). This has become a problem: the i915 driver now fails to initialize when running PV on Xen (i915_gem_object_pin_map() is where I located the induced failure), and its error handling is flaky enough to (at least sometimes) result in a hung system. Yet even beyond that problem 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 would have been quite a bit less optimal than possible. Arrange for the function to return true in such environments, without undermining the rest of PAT MSR management logic considering PAT to be disabled: specifically, no writes to the PAT MSR should occur. 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). [ bp: This is the "small fix" variant for stable. It'll get replaced with a proper PAT and MTRR detection split upstream but that is too involved for a stable backport. - additional touchups to commit msg. Use cpu_feature_enabled(). ] Fixes: bdd8b6c98239 ("drm/i915: replace X86_FEATURE_PAT with pat_enabled()") Signed-off-by: Jan Beulich Signed-off-by: Borislav Petkov Acked-by: Ingo Molnar Cc: Cc: Juergen Gross Cc: Lucas De Marchi Link: https://lore.kernel.org/r/9385fa60-fa5d-f559-a137-6608408f88b0@suse.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/mm/pat/memtype.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- 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; @@ -313,6 +315,12 @@ 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_force_disabled && cpu_feature_enabled(X86_FEATURE_HYPERVISOR)) { + /* + * Clearly PAT is enabled underneath. Allow pat_enabled() to + * reflect this. + */ + pat_bp_enabled = true; } __init_cache_modes(pat);