191ec6671SChristophe Leroy // SPDX-License-Identifier: GPL-2.0-or-later 291ec6671SChristophe Leroy 391ec6671SChristophe Leroy #include <asm/kup.h> 486f46f34SChristophe Leroy #include <asm/smp.h> 591ec6671SChristophe Leroy 66b4d6300SChristophe Leroy struct static_key_false disable_kuap_key; 76b4d6300SChristophe Leroy EXPORT_SYMBOL(disable_kuap_key); 86b4d6300SChristophe Leroy 916132529SChristophe Leroy void kuap_lock_all_ool(void) 1016132529SChristophe Leroy { 1116132529SChristophe Leroy kuap_lock_all(); 1216132529SChristophe Leroy } 1316132529SChristophe Leroy EXPORT_SYMBOL(kuap_lock_all_ool); 1416132529SChristophe Leroy 1516132529SChristophe Leroy void kuap_unlock_all_ool(void) 1616132529SChristophe Leroy { 1716132529SChristophe Leroy kuap_unlock_all(); 1816132529SChristophe Leroy } 1916132529SChristophe Leroy EXPORT_SYMBOL(kuap_unlock_all_ool); 2016132529SChristophe Leroy 21c89e6326SChristophe Leroy void setup_kuap(bool disabled) 2291ec6671SChristophe Leroy { 23*70428da9SChristophe Leroy if (!disabled) { 2416132529SChristophe Leroy kuap_lock_all_ool(); 25*70428da9SChristophe Leroy init_mm.context.sr0 |= SR_KS; 26*70428da9SChristophe Leroy current->thread.sr0 |= SR_KS; 27*70428da9SChristophe Leroy } 2886f46f34SChristophe Leroy 2986f46f34SChristophe Leroy if (smp_processor_id() != boot_cpuid) 3086f46f34SChristophe Leroy return; 3186f46f34SChristophe Leroy 3291ec6671SChristophe Leroy if (disabled) 336b4d6300SChristophe Leroy static_branch_enable(&disable_kuap_key); 346b4d6300SChristophe Leroy else 356b4d6300SChristophe Leroy pr_info("Activating Kernel Userspace Access Protection\n"); 3691ec6671SChristophe Leroy } 37