Skip to content

Commit 0b0cae7

Browse files
rpptPeter Zijlstra
authored andcommitted
x86/its: move its_pages array to struct mod_arch_specific
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: 872df34 ("x86/its: Use dynamic thunks for indirect branches") Suggested-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Mike Rapoport (Microsoft) <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 47410d8 commit 0b0cae7

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

arch/x86/include/asm/module.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@
55
#include <asm-generic/module.h>
66
#include <asm/orc_types.h>
77

8+
struct its_array {
9+
#ifdef CONFIG_MITIGATION_ITS
10+
void **pages;
11+
int num;
12+
#endif
13+
};
14+
815
struct mod_arch_specific {
916
#ifdef CONFIG_UNWINDER_ORC
1017
unsigned int num_orcs;
1118
int *orc_unwind_ip;
1219
struct orc_entry *orc_unwind;
1320
#endif
21+
struct its_array its_pages;
1422
};
1523

1624
#endif /* _ASM_X86_MODULE_H */

arch/x86/kernel/alternative.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ void its_fini_mod(struct module *mod)
173173
its_page = NULL;
174174
mutex_unlock(&text_mutex);
175175

176-
for (int i = 0; i < mod->its_num_pages; i++) {
177-
void *page = mod->its_page_array[i];
176+
for (int i = 0; i < mod->arch.its_pages.num; i++) {
177+
void *page = mod->arch.its_pages.pages[i];
178178
execmem_restore_rox(page, PAGE_SIZE);
179179
}
180180
}
@@ -184,11 +184,11 @@ void its_free_mod(struct module *mod)
184184
if (!cpu_feature_enabled(X86_FEATURE_INDIRECT_THUNK_ITS))
185185
return;
186186

187-
for (int i = 0; i < mod->its_num_pages; i++) {
188-
void *page = mod->its_page_array[i];
187+
for (int i = 0; i < mod->arch.its_pages.num; i++) {
188+
void *page = mod->arch.its_pages.pages[i];
189189
execmem_free(page);
190190
}
191-
kfree(mod->its_page_array);
191+
kfree(mod->arch.its_pages.pages);
192192
}
193193
#endif /* CONFIG_MODULES */
194194

@@ -201,14 +201,15 @@ static void *its_alloc(void)
201201

202202
#ifdef CONFIG_MODULES
203203
if (its_mod) {
204-
void *tmp = krealloc(its_mod->its_page_array,
205-
(its_mod->its_num_pages+1) * sizeof(void *),
204+
struct its_array *pages = &its_mod->arch.its_pages;
205+
void *tmp = krealloc(pages->pages,
206+
(pages->num+1) * sizeof(void *),
206207
GFP_KERNEL);
207208
if (!tmp)
208209
return NULL;
209210

210-
its_mod->its_page_array = tmp;
211-
its_mod->its_page_array[its_mod->its_num_pages++] = page;
211+
pages->pages = tmp;
212+
pages->pages[pages->num++] = page;
212213

213214
execmem_make_temp_rw(page, PAGE_SIZE);
214215
}

include/linux/module.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,6 @@ struct module {
586586
atomic_t refcnt;
587587
#endif
588588

589-
#ifdef CONFIG_MITIGATION_ITS
590-
int its_num_pages;
591-
void **its_page_array;
592-
#endif
593-
594589
#ifdef CONFIG_CONSTRUCTORS
595590
/* Constructor functions. */
596591
ctor_fn_t *ctors;

0 commit comments

Comments
 (0)