Skip to content

Commit 296db04

Browse files
thestingeranthraxx
authored andcommitted
mark kernel_set_to_readonly as __ro_after_init
This change was extracted from PaX where it's part of KERNEXEC. Signed-off-by: Daniel Micay <danielmicay@gmail.com>
1 parent b502273 commit 296db04

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

arch/x86/mm/init_32.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ int arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap)
872872
#endif
873873
#endif
874874

875-
int kernel_set_to_readonly __read_mostly;
875+
int kernel_set_to_readonly __ro_after_init;
876876

877877
void set_kernel_text_rw(void)
878878
{
@@ -924,12 +924,11 @@ void mark_rodata_ro(void)
924924
unsigned long start = PFN_ALIGN(_text);
925925
unsigned long size = (unsigned long)__end_rodata - start;
926926

927+
kernel_set_to_readonly = 1;
927928
set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
928929
pr_info("Write protecting kernel text and read-only data: %luk\n",
929930
size >> 10);
930931

931-
kernel_set_to_readonly = 1;
932-
933932
#ifdef CONFIG_CPA_DEBUG
934933
pr_info("Testing CPA: Reverting %lx-%lx\n", start, start + size);
935934
set_pages_rw(virt_to_page(start), size >> PAGE_SHIFT);

arch/x86/mm/init_64.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ void __init mem_init(void)
12061206
mem_init_print_info(NULL);
12071207
}
12081208

1209-
int kernel_set_to_readonly;
1209+
int kernel_set_to_readonly __ro_after_init;
12101210

12111211
void set_kernel_text_rw(void)
12121212
{
@@ -1255,9 +1255,8 @@ void mark_rodata_ro(void)
12551255

12561256
printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n",
12571257
(end - start) >> 10);
1258-
set_memory_ro(start, (end - start) >> PAGE_SHIFT);
1259-
12601258
kernel_set_to_readonly = 1;
1259+
set_memory_ro(start, (end - start) >> PAGE_SHIFT);
12611260

12621261
/*
12631262
* The rodata/data/bss/brk section (but not the kernel text!)

0 commit comments

Comments
 (0)