]> git.dujemihanovic.xyz Git - linux.git/commitdiff
powerpc/kuap: Use MMU_FTR_KUAP on all and refactor disabling kuap
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Tue, 11 Jul 2023 15:59:18 +0000 (17:59 +0200)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 2 Aug 2023 12:22:18 +0000 (22:22 +1000)
All but book3s/64 use a static branch key for disabling kuap.
book3s/64 uses an mmu feature.

Refactor all targets to use MMU_FTR_KUAP like book3s/64.

For PPC32 that implies updating mmu features fixups once KUAP
has been initialised.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/6b3d7c977bad73378ea368bc6818e9c94ea95ab0.1689091022.git.christophe.leroy@csgroup.eu
arch/powerpc/include/asm/book3s/32/kup.h
arch/powerpc/include/asm/book3s/64/kup.h
arch/powerpc/include/asm/kup.h
arch/powerpc/include/asm/nohash/32/kup-8xx.h
arch/powerpc/include/asm/nohash/kup-booke.h
arch/powerpc/kernel/cputable.c
arch/powerpc/mm/book3s32/kuap.c
arch/powerpc/mm/init_32.c
arch/powerpc/mm/nohash/kup.c

index 0da0dea76c473190e5194c7a6b87a798f668648a..4ca6122ef0e1350c804866528c49aaffad51e94f 100644 (file)
@@ -9,10 +9,6 @@
 
 #ifndef __ASSEMBLY__
 
-#include <linux/jump_label.h>
-
-extern struct static_key_false disable_kuap_key;
-
 #ifdef CONFIG_PPC_KUAP
 
 #include <linux/sched.h>
@@ -20,11 +16,6 @@ extern struct static_key_false disable_kuap_key;
 #define KUAP_NONE      (~0UL)
 #define KUAP_ALL       (~1UL)
 
-static __always_inline bool kuap_is_disabled(void)
-{
-       return static_branch_unlikely(&disable_kuap_key);
-}
-
 static inline void kuap_lock_one(unsigned long addr)
 {
        mtsr(mfsr(addr) | SR_KS, addr);
index 72fc4263ed2673a3c945260f890f7ae26d72f7b4..a014f4d9a2aa5d4dd0954757d781e02d31be5083 100644 (file)
@@ -230,11 +230,6 @@ static inline u64 current_thread_iamr(void)
 
 #ifdef CONFIG_PPC_KUAP
 
-static __always_inline bool kuap_is_disabled(void)
-{
-       return !mmu_has_feature(MMU_FTR_KUAP);
-}
-
 static inline void kuap_user_restore(struct pt_regs *regs)
 {
        bool restore_amr = false, restore_iamr = false;
index 24cde16c4fbede6e623d7c40e83eadb276dd1847..bab161b609c168a6033af3b17df0e576968d86d7 100644 (file)
@@ -6,6 +6,12 @@
 #define KUAP_WRITE     2
 #define KUAP_READ_WRITE        (KUAP_READ | KUAP_WRITE)
 
+#ifndef __ASSEMBLY__
+#include <linux/types.h>
+
+static __always_inline bool kuap_is_disabled(void);
+#endif
+
 #ifdef CONFIG_PPC_BOOK3S_64
 #include <asm/book3s/64/kup.h>
 #endif
@@ -41,6 +47,11 @@ void setup_kuep(bool disabled);
 
 #ifdef CONFIG_PPC_KUAP
 void setup_kuap(bool disabled);
+
+static __always_inline bool kuap_is_disabled(void)
+{
+       return !mmu_has_feature(MMU_FTR_KUAP);
+}
 #else
 static inline void setup_kuap(bool disabled) { }
 
index a372cd822887b41eba9f10f69e2255b6d6421a35..d0601859c45a0d27c11262b5585a9852f0744294 100644 (file)
@@ -9,17 +9,8 @@
 
 #ifndef __ASSEMBLY__
 
-#include <linux/jump_label.h>
-
 #include <asm/reg.h>
 
-extern struct static_key_false disable_kuap_key;
-
-static __always_inline bool kuap_is_disabled(void)
-{
-       return static_branch_unlikely(&disable_kuap_key);
-}
-
 static inline void __kuap_save_and_lock(struct pt_regs *regs)
 {
        regs->kuap = mfspr(SPRN_MD_AP);
index 71182cbe20c3e9d2fc5aa833af8adce31c739a73..8e4734c8fef198f02960fa11f058c8b27466e5aa 100644 (file)
 
 #else
 
-#include <linux/jump_label.h>
 #include <linux/sched.h>
 
 #include <asm/reg.h>
 
-extern struct static_key_false disable_kuap_key;
-
-static __always_inline bool kuap_is_disabled(void)
-{
-       return static_branch_unlikely(&disable_kuap_key);
-}
-
 static inline void __kuap_lock(void)
 {
        mtspr(SPRN_PID, 0);
index 8a32bffefa5b716f90c989606acd5b225c07ad52..e97a0fd0ae905d7e5005fc75b78423256b6aa432 100644 (file)
@@ -75,6 +75,10 @@ static struct cpu_spec * __init setup_cpu_spec(unsigned long offset,
                t->cpu_features |= old.cpu_features & CPU_FTR_PMAO_BUG;
        }
 
+       /* Set kuap ON at startup, will be disabled later if cmdline has 'nosmap' */
+       if (IS_ENABLED(CONFIG_PPC_KUAP) && IS_ENABLED(CONFIG_PPC32))
+               t->mmu_features |= MMU_FTR_KUAP;
+
        *PTRRELOC(&cur_cpu_spec) = &the_cpu_spec;
 
        /*
index 28676cabb005deccbf3bb3ee341048bbdc8b4000..24c1c686e6b983f1278e28aa46fc909aaff4548e 100644 (file)
@@ -3,9 +3,6 @@
 #include <asm/kup.h>
 #include <asm/smp.h>
 
-struct static_key_false disable_kuap_key;
-EXPORT_SYMBOL(disable_kuap_key);
-
 void kuap_lock_all_ool(void)
 {
        kuap_lock_all();
@@ -30,7 +27,7 @@ void setup_kuap(bool disabled)
                return;
 
        if (disabled)
-               static_branch_enable(&disable_kuap_key);
+               cur_cpu_spec->mmu_features &= ~MMU_FTR_KUAP;
        else
                pr_info("Activating Kernel Userspace Access Protection\n");
 }
index d4cc3749e6214864f1a51b3e68186a53a0e4048f..d8adc452f4310834842448044d9923046f1f27a2 100644 (file)
@@ -126,6 +126,8 @@ void __init MMU_init(void)
 
        setup_kup();
 
+       update_mmu_feature_fixups(MMU_FTR_KUAP);
+
        /* Shortly after that, the entire linear mapping will be available */
        memblock_set_current_limit(lowmem_end_addr);
 }
index 552becf90e97a0a85f87814960d4b37dc3888d71..94ff82b9ae6000081e73fd5c342ced91ea75636c 100644 (file)
@@ -5,7 +5,6 @@
 
 #include <linux/export.h>
 #include <linux/init.h>
-#include <linux/jump_label.h>
 #include <linux/printk.h>
 #include <linux/smp.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 (IS_ENABLED(CONFIG_40x))
                        disable_kuep = true;
                if (smp_processor_id() == boot_cpuid)
-                       static_branch_enable(&disable_kuap_key);
+                       cur_cpu_spec->mmu_features &= ~MMU_FTR_KUAP;
                return;
        }