From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42CFD10A19 for ; Sun, 29 Oct 2023 22:56:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="o3WXAjUd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10712C433C7; Sun, 29 Oct 2023 22:56:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698620209; bh=ChxiZgj1s8N53L3B1UfbFt7sFdErPWaTFgDKiWCLX6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o3WXAjUdVZmoJNWTCQBxxg8qybKdXraPXEqRtA8wlZ5JJjrLxbDUZ18A+diSq3DSr CUnsj7Ke75ePtOG5vZZDfR0aZf+LGNYmSoyIVOabb1e90Tr0FYJ933HWNIwaU9gqjT IIkXhmE+OFevPPA39mYWJznu+o4f4r+k7jHQxZkDZ+j/7OgntDXlB7xmSxjiOBcx1D 27ave2Nv4+EWa+WB4T/e5YcElWZKA5MdP3loy5UkjYykdfqrgqQbS6Gl8wApbS0456 s8QtVfv9zwdORR5oswRJbO9FArSKpPNjr4gLY1l4dV4Rt/h3Yewd7f3WEQMJuOeAYr V7DMoSm5mcRPA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Icenowy Zheng , Huacai Chen , Sasha Levin , chenhuacai@kernel.org, kernel@xen0n.name, akpm@linux-foundation.org, bhe@redhat.com, rppt@kernel.org, willy@infradead.org, zhanghongchen@loongson.cn, david@redhat.com, zhoubinbin@loongson.cn, donmor3000@hotmail.com, yangtiezhu@loongson.cn, tangyouling@loongson.cn, tglx@linutronix.de, loongarch@lists.linux.dev Subject: [PATCH AUTOSEL 6.5 43/52] LoongArch: Disable WUC for pgprot_writecombine() like ioremap_wc() Date: Sun, 29 Oct 2023 18:53:30 -0400 Message-ID: <20231029225441.789781-43-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231029225441.789781-1-sashal@kernel.org> References: <20231029225441.789781-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: loongarch@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.5.9 Content-Transfer-Encoding: 8bit From: Icenowy Zheng [ Upstream commit 278be83601dd1725d4732241f066d528e160a39d ] Currently the code disables WUC only disables it for ioremap_wc(), which is only used when mapping writecombine pages like ioremap() (mapped to the kernel space). But for VRAM mapped in TTM/GEM, it is mapped with a crafted pgprot by the pgprot_writecombine() function, in which case WUC isn't disabled now. Disable WUC for pgprot_writecombine() (fallback to SUC) if needed, like ioremap_wc(). This improves the AMDGPU driver's stability (solves some misrendering) on Loongson-3A5000/3A6000 machines. Signed-off-by: Icenowy Zheng Signed-off-by: Huacai Chen Signed-off-by: Sasha Levin --- arch/loongarch/include/asm/io.h | 5 ++--- arch/loongarch/include/asm/pgtable-bits.h | 4 +++- arch/loongarch/kernel/setup.c | 10 +++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/arch/loongarch/include/asm/io.h b/arch/loongarch/include/asm/io.h index 1c94102200407..0355b64e90ed0 100644 --- a/arch/loongarch/include/asm/io.h +++ b/arch/loongarch/include/asm/io.h @@ -54,10 +54,9 @@ static inline void __iomem *ioremap_prot(phys_addr_t offset, unsigned long size, * @offset: bus address of the memory * @size: size of the resource to map */ -extern pgprot_t pgprot_wc; - #define ioremap_wc(offset, size) \ - ioremap_prot((offset), (size), pgprot_val(pgprot_wc)) + ioremap_prot((offset), (size), \ + pgprot_val(wc_enabled ? PAGE_KERNEL_WUC : PAGE_KERNEL_SUC)) #define ioremap_cache(offset, size) \ ioremap_prot((offset), (size), pgprot_val(PAGE_KERNEL)) diff --git a/arch/loongarch/include/asm/pgtable-bits.h b/arch/loongarch/include/asm/pgtable-bits.h index de46a6b1e9f11..7b9ac012cd090 100644 --- a/arch/loongarch/include/asm/pgtable-bits.h +++ b/arch/loongarch/include/asm/pgtable-bits.h @@ -105,13 +105,15 @@ static inline pgprot_t pgprot_noncached(pgprot_t _prot) return __pgprot(prot); } +extern bool wc_enabled; + #define pgprot_writecombine pgprot_writecombine static inline pgprot_t pgprot_writecombine(pgprot_t _prot) { unsigned long prot = pgprot_val(_prot); - prot = (prot & ~_CACHE_MASK) | _CACHE_WUC; + prot = (prot & ~_CACHE_MASK) | (wc_enabled ? _CACHE_WUC : _CACHE_SUC); return __pgprot(prot); } diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c index 9d830ab4e3025..1351614042d4e 100644 --- a/arch/loongarch/kernel/setup.c +++ b/arch/loongarch/kernel/setup.c @@ -161,19 +161,19 @@ static void __init smbios_parse(void) } #ifdef CONFIG_ARCH_WRITECOMBINE -pgprot_t pgprot_wc = PAGE_KERNEL_WUC; +bool wc_enabled = true; #else -pgprot_t pgprot_wc = PAGE_KERNEL_SUC; +bool wc_enabled = false; #endif -EXPORT_SYMBOL(pgprot_wc); +EXPORT_SYMBOL(wc_enabled); static int __init setup_writecombine(char *p) { if (!strcmp(p, "on")) - pgprot_wc = PAGE_KERNEL_WUC; + wc_enabled = true; else if (!strcmp(p, "off")) - pgprot_wc = PAGE_KERNEL_SUC; + wc_enabled = false; else pr_warn("Unknown writecombine setting \"%s\".\n", p); -- 2.42.0