Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3293749lfo; Mon, 23 May 2022 00:55:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4SvXVwpCNAImorKMmi4+FP7LM2YXjpggM3I8+LTHk890aUNr+gg1qiqzs+Rjos2MYFmIR X-Received: by 2002:a05:6a00:b44:b0:518:aac0:aac2 with SMTP id p4-20020a056a000b4400b00518aac0aac2mr2383680pfo.19.1653292527645; Mon, 23 May 2022 00:55:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653292527; cv=none; d=google.com; s=arc-20160816; b=fccYlVY19vOeBq4jMJoLANs90INjmmH/On3RWkOrFWoPgm2FZGAu1lcSkduClJLGPL uqx8S/T3uvfvAR1whhSONTVxAW1hQbPlRGQXAbZF2jfH6qRuhVlCZQ3/l5ULuPB4lmK9 wUvVIxjd8gkntO+bv0XzdzlLMkApFSxDitP2USc4yi+ca97u9eC2QYubC2x/MlFGa+fw mnbTRoVXA/OwzSGtkjqKRbmv4596RrCO3/hc66TYqLeoQ8aD/OIGvUjsSSl/FHe7vEIa su1fVNF1SbW6ZdvPgdMQT4RxaEizehKZPHfjVur7LNtzJTgXl5nW1x1wOZ+0zYbTqvfi dA+w== 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=7b30/DpTLb5SVpAp4UHZjIHf2v+mEoFOGRCWalC6alk=; b=FIlnO+7BFmJtCQTElAyiMgqSIdzF5F18HhrjXYkB/MFNEUSO+rG/Ii0Sldt8UwYO87 WJr8I6YXsV2KIAeI0taGF6NbtxJAiapdMV3YphV/q3RuH4cXbOIJtr4xhR9gLdQKUUZP f+SWvP6mICQcWakglAIDmZMFqNI2bcP+edo2c7khSj/Lv5u8lr4pnJ22d3p3QabC9t0v c8BezGdmfHWXbYQyjapE1v/1SE0I2O+kMZMFrZ0SM1LD53LBAfVCObpFmeV+PUt22tkL hyAr2DHcDEB65cq7Xp+4MU6UKQa3NKb4yn9jq8jD9MJHqXx6048+xlb8WbMG2+pqHi3X neMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netscape.net header.s=a2048 header.b=USnf2QYQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u2-20020a6540c2000000b003ab1a31adaasi9404222pgp.237.2022.05.23.00.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 00:55:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@netscape.net header.s=a2048 header.b=USnf2QYQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=netscape.net Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CD77813F6F; Sun, 22 May 2022 23:55:40 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344679AbiETCQM (ORCPT + 99 others); Thu, 19 May 2022 22:16:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240786AbiETCQJ (ORCPT ); Thu, 19 May 2022 22:16:09 -0400 Received: from sonic309-22.consmr.mail.gq1.yahoo.com (sonic309-22.consmr.mail.gq1.yahoo.com [98.137.65.148]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1007B22502 for ; Thu, 19 May 2022 19:16:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netscape.net; s=a2048; t=1653012961; bh=7b30/DpTLb5SVpAp4UHZjIHf2v+mEoFOGRCWalC6alk=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=USnf2QYQaj6nl7LxofQViMdBJ/eDjmsJlBtwH3wY3YWSXuIbV72F/oLNBlH2zSrKM/+WYQPZgD/BCCXKIyaEY1TcolQROmvaDF/sOFm2Q4RxqekIFvP5NSABaxk4BXOqHlry+PF1caE3Mat0azFw2v0UvpirjGd4UFv4my14ekQDkOLDo8h7T22f0xN4Z8vKuXLsF6OO+vublN1oZKzOW7ILp3+bh4IuQaUvEgq5Ml2fdvg6Tw1Crs0M1RkwaMvfKc8OpRlCZKB1M6xvJxnj3nMn00EeSoWyTD20QzT4jbzt1rPBZdR5LQ2N9sQJ6VN1kVP4BJKJx+qWNb33RzHSoA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1653012961; bh=lgtsVyE93WpkxCRZRawyN3iVw0rx+Gw65El69Q/tblA=; h=X-Sonic-MF:Date:Subject:To:From:From:Subject; b=ZfRx5ZVV9BxgiCZHXZgrp/nKsLmi/bcLkMx7gwgoxYRIKTaV7x/POQdGunMnhTkyXVhN7DSYNVTYAwudLiuLamOyBtecwE6IHPKLB1NAqEh+4CEaQQ+EmPt2i3aOZ3UOHrb9nIUvZPJyZjcCKOoiLMNy19csJltJmYXTWY84VLIL3AceIXuEXHfl2bRPZGrAmmx2GaaIGbQhWVZqV692qCkU1ZCJb8Fxjt7BOQtXlwW/i8vcgoqH5S19Jx4/eq5zlhnZ3qoc44Y9Lf0q1NZEopQGaadV4q7G3XhUQ2vEbHUFcLLjs98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3mZLFZCkmLJ6ftHtKSX4y6H0Ksu daL1QttImJ2XKvC4Se4LjOL5GTnpsCvzIQ3NAjXaOfE0dZIUTIQtNzddksp.2whsQzIiGMblgvja UNEjIAICtPtD6FBzQrCLHpkHcMNazh9zI4d9MkmAU6guyAdu48msc7xAihTX7vsBVc1FlE0IG X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Fri, 20 May 2022 02:16:01 +0000 Received: by hermes--canary-production-ne1-5495f4d555-xgn59 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 49a5d3ad8fd09327a59bccdd561ab452; Fri, 20 May 2022 02:16:00 +0000 (UTC) Message-ID: <788dc391-6a20-5c03-9613-9f22fcc125f1@netscape.net> Date: Thu, 19 May 2022 22:15:57 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH 2/2] x86/pat: add functions to query specific cache mode availability Content-Language: en-US To: Juergen Gross , 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, 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 , pkg-xen-devel@alioth-lists.debian.net References: <20220503132207.17234-1-jgross@suse.com> <20220503132207.17234-3-jgross@suse.com> From: Chuck Zmudzinski In-Reply-To: <20220503132207.17234-3-jgross@suse.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Mailer: WebService/1.1.20258 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.aol X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 5/3/22 9:22 AM, Juergen Gross wrote: > 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. Hello, I am also getting a false positive in a Xen Dom0 from pat_enabled() where bdd8b6c98239 patched the file drivers/gpu/drm/i915/gem/i915_gem_pages.c I think this patch also needs to touch that file to fix the issue I am seeing. Ever since bdd8b6c98239 was committed, I get the following in the logs when running as a Dom0 on my Haswell processor, including with the untainted official Debian build of 5.17.6: May 15 06:31:59 debian kernel: [    3.721146] i915 0000:00:02.0: [drm:add_taint_for_CI [i915]] CI tainted:0x9 by intel_gt_init+0xb6/0x2e0 [i915] This causes the system to hang with the backlight on. The only recovery is by hitting the reset button and rebooting Linux Dom0 on Xen with Linux version 5.16 or earlier, or by rebooting Linux version 5.17 without Xen. I was able to fix it with a kernel that fixes the false negative I was getting in drivers/gpu/drm/i915/gem/i915_gem_pages.c Can the patch also touch that file, replacing pat_enabled() with x86_has_pat_wc() in the place where bdd8b6c98239 patched that file? Thanks, Chuck Zmudzinski > > 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, resource_size_t end); > extern bool pat_pfn_immune_to_uc_mtrr(unsigned long pfn); > > 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); > > #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); > > > #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 > > #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] = { > [__pte2cm_idx(_PAGE_PWT | _PAGE_PCD | _PAGE_PAT)] = _PAGE_CACHE_MODE_UC, > }; > > -/* 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]] == mode; > +} > + > +/* Check that PAT supports write-protect */ > bool x86_has_pat_wp(void) > { > - return __pte2cachemode_tbl[__cachemode2pte_tbl[_PAGE_CACHE_MODE_WP]] == > - _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); > > enum page_cache_mode pgprot2cachemode(pgprot_t pgprot) > { > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_mman.c b/drivers/gpu/drm/i915/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; > > - if (args->flags & I915_MMAP_WC && !pat_enabled()) > + if (args->flags & I915_MMAP_WC && !x86_has_pat_wc()) > return -ENODEV; > > obj = i915_gem_object_lookup(file, args->handle); > @@ -757,7 +757,7 @@ i915_gem_dumb_mmap_offset(struct drm_file *file, > > if (HAS_LMEM(to_i915(dev))) > mmap_type = I915_MMAP_TYPE_FIXED; > - else if (pat_enabled()) > + else if (x86_has_pat_wc()) > mmap_type = 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; > > case I915_MMAP_OFFSET_WC: > - if (!pat_enabled()) > + if (!x86_has_pat_wc()) > return -ENODEV; > type = I915_MMAP_TYPE_WC; > break; > @@ -823,7 +823,7 @@ i915_gem_mmap_offset_ioctl(struct drm_device *dev, void *data, > break; > > case I915_MMAP_OFFSET_UC: > - if (!pat_enabled()) > + if (!x86_has_pat_uc_minus()) > return -ENODEV; > type = I915_MMAP_TYPE_UC; > break;