diff mbox series

MIPS/tlbex: Fix LDDIR usage in setup_pw() for Loongson-3

Message ID 1585107894-8803-1-git-send-email-chenhc@lemote.com (mailing list archive)
State Mainlined
Commit d191aaffe3687d1e73e644c185f5f0550ec242b5
Headers show
Series MIPS/tlbex: Fix LDDIR usage in setup_pw() for Loongson-3 | expand

Commit Message

Huacai Chen March 25, 2020, 3:44 a.m. UTC
LDDIR/LDPTE is Loongson-3's acceleration for Page Table Walking. If BD
(Base Directory, the 4th page directory) is not enabled, then GDOffset
is biased by BadVAddr[63:62]. So, if GDOffset (aka. BadVAddr[47:36] for
Loongson-3) is big enough, "0b11(BadVAddr[63:62])|BadVAddr[47:36]|...."
can far beyond pg_swapper_dir. This means the pg_swapper_dir may NOT be
accessed by LDDIR correctly, so fix it by set PWDirExt in CP0_PWCtl.

Cc: <stable@vger.kernel.org>
Signed-off-by: Pei Huang <huangpei@loongson.cn>
Signed-off-by: Huacai Chen <chenhc@lemote.com>
---
 arch/mips/mm/tlbex.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Thomas Bogendoerfer March 25, 2020, 5:30 p.m. UTC | #1
On Wed, Mar 25, 2020 at 11:44:54AM +0800, Huacai Chen wrote:
> LDDIR/LDPTE is Loongson-3's acceleration for Page Table Walking. If BD
> (Base Directory, the 4th page directory) is not enabled, then GDOffset
> is biased by BadVAddr[63:62]. So, if GDOffset (aka. BadVAddr[47:36] for
> Loongson-3) is big enough, "0b11(BadVAddr[63:62])|BadVAddr[47:36]|...."
> can far beyond pg_swapper_dir. This means the pg_swapper_dir may NOT be
> accessed by LDDIR correctly, so fix it by set PWDirExt in CP0_PWCtl.
> 
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Pei Huang <huangpei@loongson.cn>
> Signed-off-by: Huacai Chen <chenhc@lemote.com>
> ---
>  arch/mips/mm/tlbex.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

applied to mips-next.

Thomas.
Sasha Levin March 27, 2020, 3:03 p.m. UTC | #2
Hi

[This is an automated email]

This commit has been processed because it contains a -stable tag.
The stable tag indicates that it's relevant for the following trees: all

The bot has tested the following trees: v5.5.11, v5.4.27, v4.19.112, v4.14.174, v4.9.217, v4.4.217.

v5.5.11: Build OK!
v5.4.27: Build OK!
v4.19.112: Build OK!
v4.14.174: Failed to apply! Possible dependencies:
    b023a9396062 ("MIPS: Avoid using array as parameter to write_c0_kpgd()")

v4.9.217: Failed to apply! Possible dependencies:
    b023a9396062 ("MIPS: Avoid using array as parameter to write_c0_kpgd()")

v4.4.217: Failed to apply! Possible dependencies:
    0c94fa33b4de ("MIPS: cpu: Convert MIPS_CPU_* defs to (1ull << x)")
    380cd582c088 ("MIPS: Loongson-3: Fast TLB refill handler")
    5fa393c85719 ("MIPS: Break down cacheops.h definitions")
    9519ef37a4a4 ("MIPS: Define the legacy-NaN and 2008-NaN features")
    b023a9396062 ("MIPS: Avoid using array as parameter to write_c0_kpgd()")
    b2edcfc81401 ("MIPS: Loongson: Add Loongson-3A R2 basic support")
    c0291f7c7359 ("MIPS: cpu: Alter MIPS_CPU_* definitions to fill gap")
    f270d881fa55 ("MIPS: Detect MIPSr6 Virtual Processor support")


NOTE: The patch will not be queued to stable trees until it is upstream.

How should we proceed with this patch?
Huacai Chen March 28, 2020, 2:22 a.m. UTC | #3
Hi, Sasha,

For 4.9 and 4.14 please backport b023a9396062 ("MIPS: Avoid using
array as parameter to write_c0_kpgd()"). And for 4.4 please just
ignore this patch.

Regards,
Huacai

On Fri, Mar 27, 2020 at 11:03 PM Sasha Levin <sashal@kernel.org> wrote:
>
> Hi
>
> [This is an automated email]
>
> This commit has been processed because it contains a -stable tag.
> The stable tag indicates that it's relevant for the following trees: all
>
> The bot has tested the following trees: v5.5.11, v5.4.27, v4.19.112, v4.14.174, v4.9.217, v4.4.217.
>
> v5.5.11: Build OK!
> v5.4.27: Build OK!
> v4.19.112: Build OK!
> v4.14.174: Failed to apply! Possible dependencies:
>     b023a9396062 ("MIPS: Avoid using array as parameter to write_c0_kpgd()")
>
> v4.9.217: Failed to apply! Possible dependencies:
>     b023a9396062 ("MIPS: Avoid using array as parameter to write_c0_kpgd()")
>
> v4.4.217: Failed to apply! Possible dependencies:
>     0c94fa33b4de ("MIPS: cpu: Convert MIPS_CPU_* defs to (1ull << x)")
>     380cd582c088 ("MIPS: Loongson-3: Fast TLB refill handler")
>     5fa393c85719 ("MIPS: Break down cacheops.h definitions")
>     9519ef37a4a4 ("MIPS: Define the legacy-NaN and 2008-NaN features")
>     b023a9396062 ("MIPS: Avoid using array as parameter to write_c0_kpgd()")
>     b2edcfc81401 ("MIPS: Loongson: Add Loongson-3A R2 basic support")
>     c0291f7c7359 ("MIPS: cpu: Alter MIPS_CPU_* definitions to fill gap")
>     f270d881fa55 ("MIPS: Detect MIPSr6 Virtual Processor support")
>
>
> NOTE: The patch will not be queued to stable trees until it is upstream.
>
> How should we proceed with this patch?
>
> --
> Thanks
> Sasha
diff mbox series

Patch

diff --git a/arch/mips/mm/tlbex.c b/arch/mips/mm/tlbex.c
index 344e6e9..da407cd 100644
--- a/arch/mips/mm/tlbex.c
+++ b/arch/mips/mm/tlbex.c
@@ -1480,6 +1480,7 @@  static void build_r4000_tlb_refill_handler(void)
 
 static void setup_pw(void)
 {
+	unsigned int pwctl;
 	unsigned long pgd_i, pgd_w;
 #ifndef __PAGETABLE_PMD_FOLDED
 	unsigned long pmd_i, pmd_w;
@@ -1506,6 +1507,7 @@  static void setup_pw(void)
 
 	pte_i = ilog2(_PAGE_GLOBAL);
 	pte_w = 0;
+	pwctl = 1 << 30; /* Set PWDirExt */
 
 #ifndef __PAGETABLE_PMD_FOLDED
 	write_c0_pwfield(pgd_i << 24 | pmd_i << 12 | pt_i << 6 | pte_i);
@@ -1516,8 +1518,9 @@  static void setup_pw(void)
 #endif
 
 #ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT
-	write_c0_pwctl(1 << 6 | psn);
+	pwctl |= (1 << 6 | psn);
 #endif
+	write_c0_pwctl(pwctl);
 	write_c0_kpgd((long)swapper_pg_dir);
 	kscratch_used_mask |= (1 << 7); /* KScratch6 is used for KPGD */
 }