xref: /openbmc/linux/arch/powerpc/mm/nohash/kup.c (revision b7b3c35e)
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 (IS_ENABLED(CONFIG_40x))
23 			disable_kuep = true;
24 		if (smp_processor_id() == boot_cpuid)
25 			static_branch_enable(&disable_kuap_key);
26 		return;
27 	}
28 
29 	pr_info("Activating Kernel Userspace Access Protection\n");
30 
31 	__prevent_user_access(KUAP_READ_WRITE);
32 }
33 #endif
34