]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
x86/its: move its_pages array to struct mod_arch_specific
authorMike Rapoport (Microsoft) <rppt@kernel.org>
Tue, 3 Jun 2025 11:14:43 +0000 (14:14 +0300)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 11 Jun 2025 09:20:51 +0000 (11:20 +0200)
The of pages with ITS thunks allocated for modules are tracked by an
array in 'struct module'.

Since this is very architecture specific data structure, move it to
'struct mod_arch_specific'.

No functional changes.

Fixes: 872df34d7c51 ("x86/its: Use dynamic thunks for indirect branches")
Suggested-by: Peter Zijlstra (Intel) <peterz@infradead.org>
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-4-rppt@kernel.org
arch/x86/include/asm/module.h
arch/x86/kernel/alternative.c
include/linux/module.h

index e988bac0a4a1c316fffac9525b2a094cde9b2a51..3c2de4ce3b10de2ff406d15305c2e8d7abddbaa0 100644 (file)
@@ -5,12 +5,20 @@
 #include <asm-generic/module.h>
 #include <asm/orc_types.h>
 
+struct its_array {
+#ifdef CONFIG_MITIGATION_ITS
+       void **pages;
+       int num;
+#endif
+};
+
 struct mod_arch_specific {
 #ifdef CONFIG_UNWINDER_ORC
        unsigned int num_orcs;
        int *orc_unwind_ip;
        struct orc_entry *orc_unwind;
 #endif
+       struct its_array its_pages;
 };
 
 #endif /* _ASM_X86_MODULE_H */
index ecfe7b497cad2611e1f7338837a7bf6bfc50c1eb..b50fe6ce4655e83e6bca8c97a99c62e1fbf9c68b 100644 (file)
@@ -173,8 +173,8 @@ void its_fini_mod(struct module *mod)
        its_page = NULL;
        mutex_unlock(&text_mutex);
 
-       for (int i = 0; i < mod->its_num_pages; i++) {
-               void *page = mod->its_page_array[i];
+       for (int i = 0; i < mod->arch.its_pages.num; i++) {
+               void *page = mod->arch.its_pages.pages[i];
                execmem_restore_rox(page, PAGE_SIZE);
        }
 }
@@ -184,11 +184,11 @@ void its_free_mod(struct module *mod)
        if (!cpu_feature_enabled(X86_FEATURE_INDIRECT_THUNK_ITS))
                return;
 
-       for (int i = 0; i < mod->its_num_pages; i++) {
-               void *page = mod->its_page_array[i];
+       for (int i = 0; i < mod->arch.its_pages.num; i++) {
+               void *page = mod->arch.its_pages.pages[i];
                execmem_free(page);
        }
-       kfree(mod->its_page_array);
+       kfree(mod->arch.its_pages.pages);
 }
 #endif /* CONFIG_MODULES */
 
@@ -201,14 +201,15 @@ static void *its_alloc(void)
 
 #ifdef CONFIG_MODULES
        if (its_mod) {
-               void *tmp = krealloc(its_mod->its_page_array,
-                                    (its_mod->its_num_pages+1) * sizeof(void *),
+               struct its_array *pages = &its_mod->arch.its_pages;
+               void *tmp = krealloc(pages->pages,
+                                    (pages->num+1) * sizeof(void *),
                                     GFP_KERNEL);
                if (!tmp)
                        return NULL;
 
-               its_mod->its_page_array = tmp;
-               its_mod->its_page_array[its_mod->its_num_pages++] = page;
+               pages->pages = tmp;
+               pages->pages[pages->num++] = page;
 
                execmem_make_temp_rw(page, PAGE_SIZE);
        }
index 92e1420fccdffc9de9f49da9061546cc1e0c89d1..5faa1fb1f4b4d5cfe350b346cb1d8204885eea91 100644 (file)
@@ -586,11 +586,6 @@ struct module {
        atomic_t refcnt;
 #endif
 
-#ifdef CONFIG_MITIGATION_ITS
-       int its_num_pages;
-       void **its_page_array;
-#endif
-
 #ifdef CONFIG_CONSTRUCTORS
        /* Constructor functions. */
        ctor_fn_t *ctors;