Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/nohash: Move setup_kuap out of 8xx.c

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

authored by

Christophe Leroy and committed by
Michael Ellerman
25ae981f 937fb700

+32 -22
-21
arch/powerpc/mm/nohash/8xx.c
··· 8 8 */ 9 9 10 10 #include <linux/memblock.h> 11 - #include <linux/mmu_context.h> 12 11 #include <linux/hugetlb.h> 13 - #include <asm/fixmap.h> 14 - #include <asm/code-patching.h> 15 - #include <asm/inst.h> 16 12 17 13 #include <mm/mmu_decl.h> 18 14 ··· 207 211 /* 8xx can only access 32MB at the moment */ 208 212 memblock_set_current_limit(min_t(u64, first_memblock_size, SZ_32M)); 209 213 } 210 - 211 - #ifdef CONFIG_PPC_KUAP 212 - struct static_key_false disable_kuap_key; 213 - EXPORT_SYMBOL(disable_kuap_key); 214 - 215 - void setup_kuap(bool disabled) 216 - { 217 - if (disabled) { 218 - static_branch_enable(&disable_kuap_key); 219 - return; 220 - } 221 - 222 - pr_info("Activating Kernel Userspace Access Protection\n"); 223 - 224 - mtspr(SPRN_MD_AP, MD_APG_KUAP); 225 - } 226 - #endif 227 214 228 215 int pud_clear_huge(pud_t *pud) 229 216 {
+1 -1
arch/powerpc/mm/nohash/Makefile
··· 2 2 3 3 ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC) 4 4 5 - obj-y += mmu_context.o tlb.o tlb_low.o 5 + obj-y += mmu_context.o tlb.o tlb_low.o kup.o 6 6 obj-$(CONFIG_PPC_BOOK3E_64) += tlb_low_64e.o book3e_pgtable.o 7 7 obj-$(CONFIG_40x) += 40x.o 8 8 obj-$(CONFIG_44x) += 44x.o
+31
arch/powerpc/mm/nohash/kup.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * This file contains the routines for initializing kernel userspace protection 4 + */ 5 + 6 + #include <linux/export.h> 7 + #include <linux/init.h> 8 + #include <linux/jump_label.h> 9 + #include <linux/printk.h> 10 + #include <linux/smp.h> 11 + 12 + #include <asm/kup.h> 13 + #include <asm/smp.h> 14 + 15 + #ifdef CONFIG_PPC_KUAP 16 + struct static_key_false disable_kuap_key; 17 + EXPORT_SYMBOL(disable_kuap_key); 18 + 19 + void setup_kuap(bool disabled) 20 + { 21 + if (disabled) { 22 + if (smp_processor_id() == boot_cpuid) 23 + static_branch_enable(&disable_kuap_key); 24 + return; 25 + } 26 + 27 + pr_info("Activating Kernel Userspace Access Protection\n"); 28 + 29 + __prevent_user_access(KUAP_READ_WRITE); 30 + } 31 + #endif