From nobody Thu May 9 20:44:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1651584157; cv=none; d=zohomail.com; s=zohoarc; b=FTfLPmO52I7iy5tZiQqepQoX9RntTbGy/TngDNF8xUztm9Q/unsMaZKaFnmo0J9RzllEcUC4mxhyWA2x22YMg7LUzuCHPVLYAKEgTSp7oP0qC4/N1Ts+P9wVR3asgN05B5CUne+nzU6/49nyipdidffoj9fE+dQOJE7asts119U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651584157; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CsELYWB9g735n4psOgGA9RLVHOTzorxnOT84eRzNkC4=; b=O4NCq9FuGuc40aR3fz7sFGikR1tG2OYcxEwrjLtL/PtmFIHn+MwEZ+1GZF09dAyjX15r6RHx+sTTk5EifldQpmgEAe+HkGHtW+PgBm4dykHip3cFzeX7mppg+ndUxtojg3vdTivtma4KsLBbjSGyL8OvG8mQ+VIcyMQL4k9Heo8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1651584156999782.1170145514302; Tue, 3 May 2022 06:22:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.319640.539932 (Exim 4.92) (envelope-from ) id 1nlsTk-0006lO-Ix; Tue, 03 May 2022 13:22:12 +0000 Received: by outflank-mailman (output) from mailman id 319640.539932; Tue, 03 May 2022 13:22:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nlsTk-0006lH-DT; Tue, 03 May 2022 13:22:12 +0000 Received: by outflank-mailman (input) for mailman id 319640; Tue, 03 May 2022 13:22:11 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nlsTj-0006lA-IE for xen-devel@lists.xenproject.org; Tue, 03 May 2022 13:22:11 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 09a1e0a8-cae4-11ec-a406-831a346695d4; Tue, 03 May 2022 15:22:10 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 60A7521871; Tue, 3 May 2022 13:22:10 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0838913AE0; Tue, 3 May 2022 13:22:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4IeDAIIscWIASAAAMHmgww (envelope-from ); Tue, 03 May 2022 13:22:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 09a1e0a8-cae4-11ec-a406-831a346695d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1651584130; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CsELYWB9g735n4psOgGA9RLVHOTzorxnOT84eRzNkC4=; b=bTPrVtI98WQI22j4IYJLmfiH/e8o2FSFZ7FrB5SFsp33Oi13Cy18uQCxYfHrJpShK6M1t4 K9qPTJ0SxyLjKyMS0KuYdCJGf2bVdcqC2KyIgsR1uPLFEPrejQ1cJVWYyEMo+F3ATAxyEM DnCZsYFDCVgN2tCW6uOkWMgAo9KNMnI= From: Juergen Gross To: xen-devel@lists.xenproject.org, x86@kernel.org, linux-kernel@vger.kernel.org Cc: jbeulich@suse.com, Juergen Gross , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Subject: [PATCH 1/2] x86/pat: fix x86_has_pat_wp() Date: Tue, 3 May 2022 15:22:06 +0200 Message-Id: <20220503132207.17234-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220503132207.17234-1-jgross@suse.com> References: <20220503132207.17234-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1651584159304100001 Content-Type: text/plain; charset="utf-8" x86_has_pat_wp() is using a wrong test, as it relies on the normal PAT configuration used by the kernel. In case the PAT MSR has been setup by another entity (e.g. BIOS or Xen hypervisor) it might return false even if the PAT configuration is allowing WP mappings. Fixes: 1f6f655e01ad ("x86/mm: Add a x86_has_pat_wp() helper") Signed-off-by: Juergen Gross --- arch/x86/mm/init.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index d8cfce221275..71e182ebced3 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -80,7 +80,8 @@ static uint8_t __pte2cachemode_tbl[8] =3D { /* Check that the write-protect PAT entry is set for write-protect */ bool x86_has_pat_wp(void) { - return __pte2cachemode_tbl[_PAGE_CACHE_MODE_WP] =3D=3D _PAGE_CACHE_MODE_W= P; + return __pte2cachemode_tbl[__cachemode2pte_tbl[_PAGE_CACHE_MODE_WP]] =3D= =3D + _PAGE_CACHE_MODE_WP; } =20 enum page_cache_mode pgprot2cachemode(pgprot_t pgprot) --=20 2.35.3 From nobody Thu May 9 20:44:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1651584153; cv=none; d=zohomail.com; s=zohoarc; b=jY+2wjrLeVBSsrl7PpR/NUJFl0fSeKIqaUZNg1VUebjed+cDkwn3cPVUu7zEU0q51dnjnFCO4j+IxmVgQpcNFE3ngru+/T7vUYHFzx0YmwEhb1j81bvHC/SeBJPOiq33EsU0Xm/f9BM2RMNSO7HjsTpk0mWi/kGfj/8PVEIj5OM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651584153; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vpkV8V5Y+6Vb55bRfQcavzTocu4t1BaNWLiM7KsOY1Y=; b=Dbc1AjQulf4BPImDVm9SDai1hVlRt9hP7zq2N/ViwKZh4usvhw86lVIFdt0fF14h+7GLFnHItbJhwE/cpVv+SLg9lbUxmaOvZyRQGrmVJzg9RWcwIf8tgFI4689qeavxDEcpm9TPZPUDbz2Odqar+7L4raIixcgr0RULlbnDVm8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1651584153688859.0050749158363; Tue, 3 May 2022 06:22:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.319641.539943 (Exim 4.92) (envelope-from ) id 1nlsTl-00070z-OL; Tue, 03 May 2022 13:22:13 +0000 Received: by outflank-mailman (output) from mailman id 319641.539943; Tue, 03 May 2022 13:22:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nlsTl-00070s-LH; Tue, 03 May 2022 13:22:13 +0000 Received: by outflank-mailman (input) for mailman id 319641; Tue, 03 May 2022 13:22:12 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nlsTk-0006lA-BJ for xen-devel@lists.xenproject.org; Tue, 03 May 2022 13:22:12 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0a0e3f69-cae4-11ec-a406-831a346695d4; Tue, 03 May 2022 15:22:11 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id F0C3B1F749; Tue, 3 May 2022 13:22:10 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6806513ABE; Tue, 3 May 2022 13:22:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iNYLGIIscWIASAAAMHmgww (envelope-from ); Tue, 03 May 2022 13:22:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0a0e3f69-cae4-11ec-a406-831a346695d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1651584131; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vpkV8V5Y+6Vb55bRfQcavzTocu4t1BaNWLiM7KsOY1Y=; b=ubKL3UxTpmVXRWOdBpBxP1Blc7iCSFjpprMuVtEqjUkNxvt5KgAL1kIcTNjkGyUG/j5v7g eP8pHFW6Rm0suxVOYcYDsv/lL+qGJmUY9KnmCMOK0w391MnS/4uG7jTU1+tHyDmy49tmTD f4U0Tn/Uxnm7o0c9V2tpCWb8OLMoFfk= From: Juergen Gross To: xen-devel@lists.xenproject.org, x86@kernel.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: jbeulich@suse.com, Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter Subject: [PATCH 2/2] x86/pat: add functions to query specific cache mode availability Date: Tue, 3 May 2022 15:22:07 +0200 Message-Id: <20220503132207.17234-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220503132207.17234-1-jgross@suse.com> References: <20220503132207.17234-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1651584154380100001 Content-Type: text/plain; charset="utf-8" Some drivers are using pat_enabled() in order to test availability of special caching modes (WC and UC-). This will lead to false negatives in case the system was booted e.g. with the "nopat" variant and the BIOS did setup the PAT MSR supporting the queried mode, or if the system is running as a Xen PV guest. Add test functions for those caching modes instead and use them at the appropriate places. For symmetry reasons export the already existing x86_has_pat_wp() for modules, too. Fixes: bdd8b6c98239 ("drm/i915: replace X86_FEATURE_PAT with pat_enabled()") Fixes: ae749c7ab475 ("PCI: Add arch_can_pci_mmap_wc() macro") Signed-off-by: Juergen Gross --- arch/x86/include/asm/memtype.h | 2 ++ arch/x86/include/asm/pci.h | 2 +- arch/x86/mm/init.c | 25 +++++++++++++++++++++--- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 8 ++++---- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/memtype.h b/arch/x86/include/asm/memtype.h index 9ca760e430b9..d00e0be854d4 100644 --- a/arch/x86/include/asm/memtype.h +++ b/arch/x86/include/asm/memtype.h @@ -25,6 +25,8 @@ extern void memtype_free_io(resource_size_t start, resour= ce_size_t end); extern bool pat_pfn_immune_to_uc_mtrr(unsigned long pfn); =20 bool x86_has_pat_wp(void); +bool x86_has_pat_wc(void); +bool x86_has_pat_uc_minus(void); enum page_cache_mode pgprot2cachemode(pgprot_t pgprot); =20 #endif /* _ASM_X86_MEMTYPE_H */ diff --git a/arch/x86/include/asm/pci.h b/arch/x86/include/asm/pci.h index f3fd5928bcbb..a5742268dec1 100644 --- a/arch/x86/include/asm/pci.h +++ b/arch/x86/include/asm/pci.h @@ -94,7 +94,7 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin,= int irq); =20 =20 #define HAVE_PCI_MMAP -#define arch_can_pci_mmap_wc() pat_enabled() +#define arch_can_pci_mmap_wc() x86_has_pat_wc() #define ARCH_GENERIC_PCI_MMAP_RESOURCE =20 #ifdef CONFIG_PCI diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index 71e182ebced3..b6431f714dc2 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -77,12 +77,31 @@ static uint8_t __pte2cachemode_tbl[8] =3D { [__pte2cm_idx(_PAGE_PWT | _PAGE_PCD | _PAGE_PAT)] =3D _PAGE_CACHE_MODE_UC, }; =20 -/* Check that the write-protect PAT entry is set for write-protect */ +static bool x86_has_pat_mode(unsigned int mode) +{ + return __pte2cachemode_tbl[__cachemode2pte_tbl[mode]] =3D=3D mode; +} + +/* Check that PAT supports write-protect */ bool x86_has_pat_wp(void) { - return __pte2cachemode_tbl[__cachemode2pte_tbl[_PAGE_CACHE_MODE_WP]] =3D= =3D - _PAGE_CACHE_MODE_WP; + return x86_has_pat_mode(_PAGE_CACHE_MODE_WP); +} +EXPORT_SYMBOL_GPL(x86_has_pat_wp); + +/* Check that PAT supports WC */ +bool x86_has_pat_wc(void) +{ + return x86_has_pat_mode(_PAGE_CACHE_MODE_WC); +} +EXPORT_SYMBOL_GPL(x86_has_pat_wc); + +/* Check that PAT supports UC- */ +bool x86_has_pat_uc_minus(void) +{ + return x86_has_pat_mode(_PAGE_CACHE_MODE_UC_MINUS); } +EXPORT_SYMBOL_GPL(x86_has_pat_uc_minus); =20 enum page_cache_mode pgprot2cachemode(pgprot_t pgprot) { diff --git a/drivers/gpu/drm/i915/gem/i915_gem_mman.c b/drivers/gpu/drm/i91= 5/gem/i915_gem_mman.c index 0c5c43852e24..f43ecf3f63eb 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_mman.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_mman.c @@ -76,7 +76,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, if (args->flags & ~(I915_MMAP_WC)) return -EINVAL; =20 - if (args->flags & I915_MMAP_WC && !pat_enabled()) + if (args->flags & I915_MMAP_WC && !x86_has_pat_wc()) return -ENODEV; =20 obj =3D i915_gem_object_lookup(file, args->handle); @@ -757,7 +757,7 @@ i915_gem_dumb_mmap_offset(struct drm_file *file, =20 if (HAS_LMEM(to_i915(dev))) mmap_type =3D I915_MMAP_TYPE_FIXED; - else if (pat_enabled()) + else if (x86_has_pat_wc()) mmap_type =3D I915_MMAP_TYPE_WC; else if (!i915_ggtt_has_aperture(to_gt(i915)->ggtt)) return -ENODEV; @@ -813,7 +813,7 @@ i915_gem_mmap_offset_ioctl(struct drm_device *dev, void= *data, break; =20 case I915_MMAP_OFFSET_WC: - if (!pat_enabled()) + if (!x86_has_pat_wc()) return -ENODEV; type =3D I915_MMAP_TYPE_WC; break; @@ -823,7 +823,7 @@ i915_gem_mmap_offset_ioctl(struct drm_device *dev, void= *data, break; =20 case I915_MMAP_OFFSET_UC: - if (!pat_enabled()) + if (!x86_has_pat_uc_minus()) return -ENODEV; type =3D I915_MMAP_TYPE_UC; break; --=20 2.35.3