powerpc/nohash: Move setup_kuap out of 8xx.c
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Tue, 19 Oct 2021 07:29:24 +0000 (09:29 +0200)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 9 Dec 2021 11:41:19 +0000 (22:41 +1100)
In order to reuse it on booke/4xx, move KUAP
setup routine out of 8xx.c

Make them usable on SMP by removing the __init tag
as it is called for each CPU.

And use __prevent_user_access() instead of hard
coding initial lock.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/ae35eec3426509efc2b8ae69586c822e2fe2642a.1634627931.git.christophe.leroy@csgroup.eu
arch/powerpc/mm/nohash/8xx.c
arch/powerpc/mm/nohash/Makefile
arch/powerpc/mm/nohash/kup.c [new file with mode: 0644]

index 36010d1c0bc4cd6269c0518398594032c95d8054..27f9186ae37404ae1865f979a04263734935170c 100644 (file)
@@ -8,11 +8,7 @@
  */
 
 #include <linux/memblock.h>
-#include <linux/mmu_context.h>
 #include <linux/hugetlb.h>
-#include <asm/fixmap.h>
-#include <asm/code-patching.h>
-#include <asm/inst.h>
 
 #include <mm/mmu_decl.h>
 
@@ -212,23 +208,6 @@ void __init setup_initial_memory_limit(phys_addr_t first_memblock_base,
        memblock_set_current_limit(min_t(u64, first_memblock_size, SZ_32M));
 }
 
-#ifdef CONFIG_PPC_KUAP
-struct static_key_false disable_kuap_key;
-EXPORT_SYMBOL(disable_kuap_key);
-
-void setup_kuap(bool disabled)
-{
-       if (disabled) {
-               static_branch_enable(&disable_kuap_key);
-               return;
-       }
-
-       pr_info("Activating Kernel Userspace Access Protection\n");
-
-       mtspr(SPRN_MD_AP, MD_APG_KUAP);
-}
-#endif
-
 int pud_clear_huge(pud_t *pud)
 {
         return 0;
index b1f630d423d819c938f78931a4c21ff6641be054..b467a25ee155d16e61295a4da2a58816f9a42ec6 100644 (file)
@@ -2,7 +2,7 @@
 
 ccflags-$(CONFIG_PPC64)        := $(NO_MINIMAL_TOC)
 
-obj-y                          += mmu_context.o tlb.o tlb_low.o
+obj-y                          += mmu_context.o tlb.o tlb_low.o kup.o
 obj-$(CONFIG_PPC_BOOK3E_64)    += tlb_low_64e.o book3e_pgtable.o
 obj-$(CONFIG_40x)              += 40x.o
 obj-$(CONFIG_44x)              += 44x.o
diff --git a/arch/powerpc/mm/nohash/kup.c b/arch/powerpc/mm/nohash/kup.c
new file mode 100644 (file)
index 0000000..eaea522
--- /dev/null
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * This file contains the routines for initializing kernel userspace protection
+ */
+
+#include <linux/export.h>
+#include <linux/init.h>
+#include <linux/jump_label.h>
+#include <linux/printk.h>
+#include <linux/smp.h>
+
+#include <asm/kup.h>
+#include <asm/smp.h>
+
+#ifdef CONFIG_PPC_KUAP
+struct static_key_false disable_kuap_key;
+EXPORT_SYMBOL(disable_kuap_key);
+
+void setup_kuap(bool disabled)
+{
+       if (disabled) {
+               if (smp_processor_id() == boot_cpuid)
+                       static_branch_enable(&disable_kuap_key);
+               return;
+       }
+
+       pr_info("Activating Kernel Userspace Access Protection\n");
+
+       __prevent_user_access(KUAP_READ_WRITE);
+}
+#endif