Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tile: define a macro ktext_writable_addr to get writable kernel text address

It is used by kgdb, ftrace, kprobe and jump label, so we factor
this out into a helper routine.

Reviewed-by: Chris Metcalf <cmetcalf@ezchip.com>
Signed-off-by: Zhigang Lu <zlu@ezchip.com>
Signed-off-by: Chris Metcalf <cmetcalf@ezchip.com>

authored by

Zhigang Lu and committed by
Chris Metcalf
f419e6f6 9f9499ae

+14 -4
+10
arch/tile/include/asm/page.h
··· 319 319 #define virt_to_page(kaddr) pfn_to_page(kaddr_to_pfn((void *)(kaddr))) 320 320 #define page_to_virt(page) pfn_to_kaddr(page_to_pfn(page)) 321 321 322 + /* 323 + * The kernel text is mapped at MEM_SV_START as read-only. To allow 324 + * modifying kernel text, it is also mapped at PAGE_OFFSET as read-write. 325 + * This macro converts a kernel address to its writable kernel text mapping, 326 + * which is used to modify the text code on a running kernel by kgdb, 327 + * ftrace, kprobe, jump label, etc. 328 + */ 329 + #define ktext_writable_addr(kaddr) \ 330 + ((unsigned long)(kaddr) - MEM_SV_START + PAGE_OFFSET) 331 + 322 332 struct mm_struct; 323 333 extern pte_t *virt_to_pte(struct mm_struct *mm, unsigned long addr); 324 334 extern pte_t *virt_to_kpte(unsigned long kaddr);
+1 -1
arch/tile/kernel/ftrace.c
··· 117 117 return -EINVAL; 118 118 119 119 /* Operate on writable kernel text mapping. */ 120 - pc_wr = pc - MEM_SV_START + PAGE_OFFSET; 120 + pc_wr = ktext_writable_addr(pc); 121 121 122 122 if (probe_kernel_write((void *)pc_wr, &new, MCOUNT_INSN_SIZE)) 123 123 return -EPERM;
+1 -1
arch/tile/kernel/kgdb.c
··· 164 164 unsigned long ret = 0; 165 165 166 166 if (core_kernel_text(addr)) 167 - ret = addr - MEM_SV_START + PAGE_OFFSET; 167 + ret = ktext_writable_addr(addr); 168 168 else if (is_module_text_address(addr)) 169 169 ret = addr; 170 170 else
+2 -2
arch/tile/kernel/kprobes.c
··· 116 116 unsigned long addr_wr; 117 117 118 118 /* Operate on writable kernel text mapping. */ 119 - addr_wr = (unsigned long)p->addr - MEM_SV_START + PAGE_OFFSET; 119 + addr_wr = ktext_writable_addr(p->addr); 120 120 121 121 if (probe_kernel_write((void *)addr_wr, &breakpoint_insn, 122 122 sizeof(breakpoint_insn))) ··· 131 131 unsigned long addr_wr; 132 132 133 133 /* Operate on writable kernel text mapping. */ 134 - addr_wr = (unsigned long)kp->addr - MEM_SV_START + PAGE_OFFSET; 134 + addr_wr = ktext_writable_addr(kp->addr); 135 135 136 136 if (probe_kernel_write((void *)addr_wr, &kp->opcode, 137 137 sizeof(kp->opcode)))