]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Revert "mm/execmem: Unify early execmem_cache behaviour"
authorMike Rapoport (Microsoft) <rppt@kernel.org>
Tue, 3 Jun 2025 11:14:45 +0000 (14:14 +0300)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 11 Jun 2025 09:20:52 +0000 (11:20 +0200)
The commit d6d1e3e6580c ("mm/execmem: Unify early execmem_cache
behaviour") changed early behaviour of execemem ROX cache to allow its
usage in early x86 code that allocates text pages when
CONFIG_MITGATION_ITS is enabled.

The permission management of the pages allocated from execmem for ITS
mitigation is now completely contained in arch/x86/kernel/alternatives.c
and therefore there is no need to special case early allocations in
execmem.

This reverts commit d6d1e3e6580ca35071ad474381f053cbf1fb6414.

Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/20250603111446.2609381-6-rppt@kernel.org
arch/x86/mm/init_32.c
arch/x86/mm/init_64.c
include/linux/execmem.h
mm/execmem.c

index 607d6a2e66e2e9055f0c8597fd378da0018b0e7d..8a34fff6ab2b19f083f4fdf706de3ca0867416ba 100644 (file)
@@ -30,7 +30,6 @@
 #include <linux/initrd.h>
 #include <linux/cpumask.h>
 #include <linux/gfp.h>
-#include <linux/execmem.h>
 
 #include <asm/asm.h>
 #include <asm/bios_ebda.h>
@@ -749,8 +748,6 @@ void mark_rodata_ro(void)
        pr_info("Write protecting kernel text and read-only data: %luk\n",
                size >> 10);
 
-       execmem_cache_make_ro();
-
        kernel_set_to_readonly = 1;
 
 #ifdef CONFIG_CPA_DEBUG
index ee66fae9ebcc34a5c75a7bbad7c8fed04d0bf153..fdb6cab524f08d8ef45f52bfd187d57615e0adf6 100644 (file)
@@ -34,7 +34,6 @@
 #include <linux/gfp.h>
 #include <linux/kcore.h>
 #include <linux/bootmem_info.h>
-#include <linux/execmem.h>
 
 #include <asm/processor.h>
 #include <asm/bios_ebda.h>
@@ -1392,8 +1391,6 @@ void mark_rodata_ro(void)
               (end - start) >> 10);
        set_memory_ro(start, (end - start) >> PAGE_SHIFT);
 
-       execmem_cache_make_ro();
-
        kernel_set_to_readonly = 1;
 
        /*
index ca42d5e46ccc6b7dd912d5a6da004b8b24420bd3..3be35680a54fd1666e2db60a667b72efbe331e12 100644 (file)
@@ -54,7 +54,7 @@ enum execmem_range_flags {
        EXECMEM_ROX_CACHE       = (1 << 1),
 };
 
-#if defined(CONFIG_ARCH_HAS_EXECMEM_ROX) && defined(CONFIG_EXECMEM)
+#ifdef CONFIG_ARCH_HAS_EXECMEM_ROX
 /**
  * execmem_fill_trapping_insns - set memory to contain instructions that
  *                              will trap
@@ -94,15 +94,9 @@ int execmem_make_temp_rw(void *ptr, size_t size);
  * Return: 0 on success or negative error code on failure.
  */
 int execmem_restore_rox(void *ptr, size_t size);
-
-/*
- * Called from mark_readonly(), where the system transitions to ROX.
- */
-void execmem_cache_make_ro(void);
 #else
 static inline int execmem_make_temp_rw(void *ptr, size_t size) { return 0; }
 static inline int execmem_restore_rox(void *ptr, size_t size) { return 0; }
-static inline void execmem_cache_make_ro(void) { }
 #endif
 
 /**
index 9720ac2dfa41c7c37e8853b7e6bec9dd1aa4e318..2b683e7d864d83e32e93ba6c3ca873f85da0b43f 100644 (file)
@@ -254,34 +254,6 @@ out_unlock:
        return ptr;
 }
 
-static bool execmem_cache_rox = false;
-
-void execmem_cache_make_ro(void)
-{
-       struct maple_tree *free_areas = &execmem_cache.free_areas;
-       struct maple_tree *busy_areas = &execmem_cache.busy_areas;
-       MA_STATE(mas_free, free_areas, 0, ULONG_MAX);
-       MA_STATE(mas_busy, busy_areas, 0, ULONG_MAX);
-       struct mutex *mutex = &execmem_cache.mutex;
-       void *area;
-
-       execmem_cache_rox = true;
-
-       mutex_lock(mutex);
-
-       mas_for_each(&mas_free, area, ULONG_MAX) {
-               unsigned long pages = mas_range_len(&mas_free) >> PAGE_SHIFT;
-               set_memory_ro(mas_free.index, pages);
-       }
-
-       mas_for_each(&mas_busy, area, ULONG_MAX) {
-               unsigned long pages = mas_range_len(&mas_busy) >> PAGE_SHIFT;
-               set_memory_ro(mas_busy.index, pages);
-       }
-
-       mutex_unlock(mutex);
-}
-
 static int execmem_cache_populate(struct execmem_range *range, size_t size)
 {
        unsigned long vm_flags = VM_ALLOW_HUGE_VMAP;
@@ -302,15 +274,9 @@ static int execmem_cache_populate(struct execmem_range *range, size_t size)
        /* fill memory with instructions that will trap */
        execmem_fill_trapping_insns(p, alloc_size, /* writable = */ true);
 
-       if (execmem_cache_rox) {
-               err = set_memory_rox((unsigned long)p, vm->nr_pages);
-               if (err)
-                       goto err_free_mem;
-       } else {
-               err = set_memory_x((unsigned long)p, vm->nr_pages);
-               if (err)
-                       goto err_free_mem;
-       }
+       err = set_memory_rox((unsigned long)p, vm->nr_pages);
+       if (err)
+               goto err_free_mem;
 
        err = execmem_cache_add(p, alloc_size);
        if (err)