Merge tag 'core-build-2020-10-12' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / arch / arm64 / mm / mmu.c
index e43c805..087a844 100644 (file)
@@ -122,7 +122,7 @@ static bool pgattr_change_is_safe(u64 old, u64 new)
         * The following mapping attributes may be updated in live
         * kernel mappings without the need for break-before-make.
         */
-       static const pteval_t mask = PTE_PXN | PTE_RDONLY | PTE_WRITE | PTE_NG;
+       pteval_t mask = PTE_PXN | PTE_RDONLY | PTE_WRITE | PTE_NG;
 
        /* creating or taking down mappings is always safe */
        if (old == 0 || new == 0)
@@ -136,6 +136,17 @@ static bool pgattr_change_is_safe(u64 old, u64 new)
        if (old & ~new & PTE_NG)
                return false;
 
+       /*
+        * Changing the memory type between Normal and Normal-Tagged is safe
+        * since Tagged is considered a permission attribute from the
+        * mismatched attribute aliases perspective.
+        */
+       if (((old & PTE_ATTRINDX_MASK) == PTE_ATTRINDX(MT_NORMAL) ||
+            (old & PTE_ATTRINDX_MASK) == PTE_ATTRINDX(MT_NORMAL_TAGGED)) &&
+           ((new & PTE_ATTRINDX_MASK) == PTE_ATTRINDX(MT_NORMAL) ||
+            (new & PTE_ATTRINDX_MASK) == PTE_ATTRINDX(MT_NORMAL_TAGGED)))
+               mask |= PTE_ATTRINDX_MASK;
+
        return ((old ^ new) & ~mask) == 0;
 }
 
@@ -491,7 +502,12 @@ static void __init map_mem(pgd_t *pgdp)
                if (memblock_is_nomap(reg))
                        continue;
 
-               __map_memblock(pgdp, start, end, PAGE_KERNEL, flags);
+               /*
+                * The linear map must allow allocation tags reading/writing
+                * if MTE is present. Otherwise, it has the same attributes as
+                * PAGE_KERNEL.
+                */
+               __map_memblock(pgdp, start, end, PAGE_KERNEL_TAGGED, flags);
        }
 
        /*