Skip to content

Commit 9d37c5c

Browse files
committed
Revert "mm/execmem: Unify early execmem_cache behaviour"
jira LE-4694 Rebuild_History Non-Buildable kernel-6.12.0-55.43.1.el10_0 commit-author Mike Rapoport (Microsoft) <rppt@kernel.org> commit 7cd9a11 The commit d6d1e3e ("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 d6d1e3e. 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 (cherry picked from commit 7cd9a11) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent c7e4314 commit 9d37c5c

File tree

4 files changed

+4
-50
lines changed

4 files changed

+4
-50
lines changed

arch/x86/mm/init_32.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <linux/initrd.h>
3131
#include <linux/cpumask.h>
3232
#include <linux/gfp.h>
33-
#include <linux/execmem.h>
3433

3534
#include <asm/asm.h>
3635
#include <asm/bios_ebda.h>
@@ -791,8 +790,6 @@ void mark_rodata_ro(void)
791790
pr_info("Write protecting kernel text and read-only data: %luk\n",
792791
size >> 10);
793792

794-
execmem_cache_make_ro();
795-
796793
kernel_set_to_readonly = 1;
797794

798795
#ifdef CONFIG_CPA_DEBUG

arch/x86/mm/init_64.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include <linux/gfp.h>
3535
#include <linux/kcore.h>
3636
#include <linux/bootmem_info.h>
37-
#include <linux/execmem.h>
3837

3938
#include <asm/processor.h>
4039
#include <asm/bios_ebda.h>
@@ -1380,8 +1379,6 @@ void mark_rodata_ro(void)
13801379
(end - start) >> 10);
13811380
set_memory_ro(start, (end - start) >> PAGE_SHIFT);
13821381

1383-
execmem_cache_make_ro();
1384-
13851382
kernel_set_to_readonly = 1;
13861383

13871384
/*

include/linux/execmem.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ enum execmem_range_flags {
5353
EXECMEM_ROX_CACHE = (1 << 1),
5454
};
5555

56-
#if defined(CONFIG_ARCH_HAS_EXECMEM_ROX) && defined(CONFIG_EXECMEM)
56+
#ifdef CONFIG_ARCH_HAS_EXECMEM_ROX
5757
/**
5858
* execmem_fill_trapping_insns - set memory to contain instructions that
5959
* will trap
@@ -93,15 +93,9 @@ int execmem_make_temp_rw(void *ptr, size_t size);
9393
* Return: 0 on success or negative error code on failure.
9494
*/
9595
int execmem_restore_rox(void *ptr, size_t size);
96-
97-
/*
98-
* Called from mark_readonly(), where the system transitions to ROX.
99-
*/
100-
void execmem_cache_make_ro(void);
10196
#else
10297
static inline int execmem_make_temp_rw(void *ptr, size_t size) { return 0; }
10398
static inline int execmem_restore_rox(void *ptr, size_t size) { return 0; }
104-
static inline void execmem_cache_make_ro(void) { }
10599
#endif
106100

107101
/**

mm/execmem.c

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -238,34 +238,6 @@ static void *__execmem_cache_alloc(struct execmem_range *range, size_t size)
238238
return ptr;
239239
}
240240

241-
static bool execmem_cache_rox = false;
242-
243-
void execmem_cache_make_ro(void)
244-
{
245-
struct maple_tree *free_areas = &execmem_cache.free_areas;
246-
struct maple_tree *busy_areas = &execmem_cache.busy_areas;
247-
MA_STATE(mas_free, free_areas, 0, ULONG_MAX);
248-
MA_STATE(mas_busy, busy_areas, 0, ULONG_MAX);
249-
struct mutex *mutex = &execmem_cache.mutex;
250-
void *area;
251-
252-
execmem_cache_rox = true;
253-
254-
mutex_lock(mutex);
255-
256-
mas_for_each(&mas_free, area, ULONG_MAX) {
257-
unsigned long pages = mas_range_len(&mas_free) >> PAGE_SHIFT;
258-
set_memory_ro(mas_free.index, pages);
259-
}
260-
261-
mas_for_each(&mas_busy, area, ULONG_MAX) {
262-
unsigned long pages = mas_range_len(&mas_busy) >> PAGE_SHIFT;
263-
set_memory_ro(mas_busy.index, pages);
264-
}
265-
266-
mutex_unlock(mutex);
267-
}
268-
269241
static int execmem_cache_populate(struct execmem_range *range, size_t size)
270242
{
271243
unsigned long vm_flags = VM_ALLOW_HUGE_VMAP;
@@ -286,15 +258,9 @@ static int execmem_cache_populate(struct execmem_range *range, size_t size)
286258
/* fill memory with instructions that will trap */
287259
execmem_fill_trapping_insns(p, alloc_size, /* writable = */ true);
288260

289-
if (execmem_cache_rox) {
290-
err = set_memory_rox((unsigned long)p, vm->nr_pages);
291-
if (err)
292-
goto err_free_mem;
293-
} else {
294-
err = set_memory_x((unsigned long)p, vm->nr_pages);
295-
if (err)
296-
goto err_free_mem;
297-
}
261+
err = set_memory_rox((unsigned long)p, vm->nr_pages);
262+
if (err)
263+
goto err_free_mem;
298264

299265
err = execmem_cache_add(p, alloc_size);
300266
if (err)

0 commit comments

Comments
 (0)