MIPS: Fix 64-bit HTW configuration
authorJames Hogan <james.hogan@imgtec.com>
Fri, 27 May 2016 21:25:23 +0000 (22:25 +0100)
committerRalf Baechle <ralf@linux-mips.org>
Sat, 28 May 2016 10:35:11 +0000 (12:35 +0200)
The Hardware page Table Walker (HTW) is being misconfigured on 64-bit
kernels. The PWSize.PS (pointer size) bit determines whether pointers
within directories are loaded as 32-bit or 64-bit addresses, but was
never being set to 1 for 64-bit kernels where the unsigned long in pgd_t
is 64-bits wide.

This actually reduces rather than improves performance when the HTW is
enabled on P6600 since the HTW is initiated lots, but walks are all
aborted due I think to bad intermediate pointers.

Since we were already taking the width of the PTEs into account by
setting PWSize.PTEW, which is the left shift applied to the page table
index *in addition to* the native pointer size, we also need to reduce
PTEW by 1 when PS=1. This is done by calculating PTEW based on the
relative size of pte_t compared to pgd_t.

Finally in order for the HTW to be used when PS=1, the appropriate
XK/XS/XU bits corresponding to the different 64-bit segments need to be
set in PWCtl. We enable only XU for now to enable walking for XUSeg.

Supporting walking for XKSeg would be a bit more involved so is left for
a future patch. It would either require the use of a per-CPU top level
base directory if supported by the HTW (a bit like pgd_current but with
a second entry pointing at swapper_pg_dir), or the HTW would prepend bit
63 of the address to the global directory index which doesn't really
match how we split user and kernel page directories.

Fixes: cab25bc7537b ("MIPS: Extend hardware table walking support to MIPS64")
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/13364/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
arch/mips/mm/tlbex.c

index c363890368cd4ba9e64fcc176f3c4d6cf8e0515d..4004b659ce50ef439c6782fb70b42c44c1ecd7eb 100644 (file)
@@ -2431,15 +2431,25 @@ static void config_htw_params(void)
        if (CONFIG_PGTABLE_LEVELS >= 3)
                pwsize |= ilog2(PTRS_PER_PMD) << MIPS_PWSIZE_MDW_SHIFT;
 
-       pwsize |= ilog2(sizeof(pte_t)/4) << MIPS_PWSIZE_PTEW_SHIFT;
+       /* Set pointer size to size of directory pointers */
+       if (config_enabled(CONFIG_64BIT))
+               pwsize |= MIPS_PWSIZE_PS_MASK;
+       /* PTEs may be multiple pointers long (e.g. with XPA) */
+       pwsize |= ((PTE_T_LOG2 - PGD_T_LOG2) << MIPS_PWSIZE_PTEW_SHIFT)
+                       & MIPS_PWSIZE_PTEW_MASK;
 
        write_c0_pwsize(pwsize);
 
        /* Make sure everything is set before we enable the HTW */
        back_to_back_c0_hazard();
 
-       /* Enable HTW and disable the rest of the pwctl fields */
+       /*
+        * Enable HTW (and only for XUSeg on 64-bit), and disable the rest of
+        * the pwctl fields.
+        */
        config = 1 << MIPS_PWCTL_PWEN_SHIFT;
+       if (config_enabled(CONFIG_64BIT))
+               config |= MIPS_PWCTL_XU_MASK;
        write_c0_pwctl(config);
        pr_info("Hardware Page Table Walker enabled\n");