Skip to content

Commit

Permalink
x86_64, cpa: Use only text section in set_kernel_text_rw/ro
Browse files Browse the repository at this point in the history
set_kernel_text_rw()/set_kernel_text_ro() are marking pages
starting from _text to __start_rodata as RW or RO.

With CONFIG_DEBUG_RODATA, there might be free pages (associated
with padding the sections to 2MB large page boundary) between
text and rodata sections that are given back to page allocator.
So we should use only use the start (__text) and end
(__stop___ex_table) of the text section in
set_kernel_text_rw()/set_kernel_text_ro().

Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Tested-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <20091029024821.164525222@sbs-t61.sc.intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Suresh Siddha authored and Ingo Molnar committed Nov 2, 2009
1 parent 55ca3cc commit e7d23dd
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions arch/x86/mm/init_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,28 +700,36 @@ int kernel_set_to_readonly;
void set_kernel_text_rw(void)
{
unsigned long start = PFN_ALIGN(_text);
unsigned long end = PFN_ALIGN(__start_rodata);
unsigned long end = PFN_ALIGN(__stop___ex_table);

if (!kernel_set_to_readonly)
return;

pr_debug("Set kernel text: %lx - %lx for read write\n",
start, end);

/*
* Make the kernel identity mapping for text RW. Kernel text
* mapping will always be RO. Refer to the comment in
* static_protections() in pageattr.c
*/
set_memory_rw(start, (end - start) >> PAGE_SHIFT);
}

void set_kernel_text_ro(void)
{
unsigned long start = PFN_ALIGN(_text);
unsigned long end = PFN_ALIGN(__start_rodata);
unsigned long end = PFN_ALIGN(__stop___ex_table);

if (!kernel_set_to_readonly)
return;

pr_debug("Set kernel text: %lx - %lx for read only\n",
start, end);

/*
* Set the kernel identity mapping for text RO.
*/
set_memory_ro(start, (end - start) >> PAGE_SHIFT);
}

Expand Down

0 comments on commit e7d23dd

Please sign in to comment.