Skip to content

Commit 2a25dc7

Browse files
committed
x86/mm/init32: Mark text and rodata RO in one go
The sequence of marking text and rodata read-only in 32bit init is: set_ro(text); kernel_set_to_readonly = 1; set_ro(rodata); When kernel_set_to_readonly is 1 it enables the protection mechanism in CPA for the read only regions. With the upcoming checks for existing mappings this consequently triggers the warning about an existing mapping being incorrect vs. static protections because rodata has not been converted yet. There is no technical reason to split the two, so just combine the RO protection to convert text and rodata in one go. Convert the printks to pr_info while at it. Reported-by: kernel test robot <rong.a.chen@intel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Dave Hansen <dave.hansen@intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Bin Yang <bin.yang@intel.com> Cc: Mark Gross <mark.gross@intel.com> Link: https://lkml.kernel.org/r/20180917143545.731701535@linutronix.de
1 parent 6bf4ca7 commit 2a25dc7

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

arch/x86/mm/init_32.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -923,34 +923,19 @@ static void mark_nxdata_nx(void)
923923
void mark_rodata_ro(void)
924924
{
925925
unsigned long start = PFN_ALIGN(_text);
926-
unsigned long size = PFN_ALIGN(_etext) - start;
926+
unsigned long size = (unsigned long)__end_rodata - start;
927927

928928
set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
929-
printk(KERN_INFO "Write protecting the kernel text: %luk\n",
929+
pr_info("Write protecting kernel text and read-only data: %luk\n",
930930
size >> 10);
931931

932932
kernel_set_to_readonly = 1;
933933

934934
#ifdef CONFIG_CPA_DEBUG
935-
printk(KERN_INFO "Testing CPA: Reverting %lx-%lx\n",
936-
start, start+size);
937-
set_pages_rw(virt_to_page(start), size>>PAGE_SHIFT);
938-
939-
printk(KERN_INFO "Testing CPA: write protecting again\n");
940-
set_pages_ro(virt_to_page(start), size>>PAGE_SHIFT);
941-
#endif
942-
943-
start += size;
944-
size = (unsigned long)__end_rodata - start;
945-
set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
946-
printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n",
947-
size >> 10);
948-
949-
#ifdef CONFIG_CPA_DEBUG
950-
printk(KERN_INFO "Testing CPA: undo %lx-%lx\n", start, start + size);
935+
pr_info("Testing CPA: Reverting %lx-%lx\n", start, start + size);
951936
set_pages_rw(virt_to_page(start), size >> PAGE_SHIFT);
952937

953-
printk(KERN_INFO "Testing CPA: write protecting again\n");
938+
pr_info("Testing CPA: write protecting again\n");
954939
set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
955940
#endif
956941
mark_nxdata_nx();

0 commit comments

Comments
 (0)