parisc: add support for patching multiple words
add patch_text_multiple() which allows to patch multiple text words in memory. This can be used to copy functions. Signed-off-by: Sven Schnelle <svens@stackframe.org> Signed-off-by: Helge Deller <deller@gmx.de>
This commit is contained in:
Родитель
79c3ba3206
Коммит
4e87ace902
|
@ -4,8 +4,10 @@
|
||||||
|
|
||||||
/* stop machine and patch kernel text */
|
/* stop machine and patch kernel text */
|
||||||
void patch_text(void *addr, unsigned int insn);
|
void patch_text(void *addr, unsigned int insn);
|
||||||
|
void patch_text_multiple(void *addr, u32 *insn, unsigned int len);
|
||||||
|
|
||||||
/* patch kernel text with machine already stopped (e.g. in kgdb) */
|
/* patch kernel text with machine already stopped (e.g. in kgdb) */
|
||||||
void __patch_text(void *addr, unsigned int insn);
|
void __patch_text(void *addr, u32 insn);
|
||||||
|
void __patch_text_multiple(void *addr, u32 *insn, unsigned int len);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,15 +17,18 @@
|
||||||
|
|
||||||
struct patch {
|
struct patch {
|
||||||
void *addr;
|
void *addr;
|
||||||
unsigned int insn;
|
u32 *insn;
|
||||||
|
unsigned int len;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void __kprobes *patch_map(void *addr, int fixmap)
|
static DEFINE_RAW_SPINLOCK(patch_lock);
|
||||||
{
|
|
||||||
|
static void __kprobes *patch_map(void *addr, int fixmap, int *need_unmap)
|
||||||
unsigned long uintaddr = (uintptr_t) addr;
|
unsigned long uintaddr = (uintptr_t) addr;
|
||||||
bool module = !core_kernel_text(uintaddr);
|
bool module = !core_kernel_text(uintaddr);
|
||||||
struct page *page;
|
struct page *page;
|
||||||
|
|
||||||
|
*need_unmap = 0;
|
||||||
if (module && IS_ENABLED(CONFIG_STRICT_MODULE_RWX))
|
if (module && IS_ENABLED(CONFIG_STRICT_MODULE_RWX))
|
||||||
page = vmalloc_to_page(addr);
|
page = vmalloc_to_page(addr);
|
||||||
else if (!module && IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
|
else if (!module && IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
|
||||||
|
@ -33,6 +36,7 @@ static void __kprobes *patch_map(void *addr, int fixmap)
|
||||||
else
|
else
|
||||||
return addr;
|
return addr;
|
||||||
|
|
||||||
|
*need_unmap = 1;
|
||||||
set_fixmap(fixmap, page_to_phys(page));
|
set_fixmap(fixmap, page_to_phys(page));
|
||||||
|
|
||||||
return (void *) (__fix_to_virt(fixmap) + (uintaddr & ~PAGE_MASK));
|
return (void *) (__fix_to_virt(fixmap) + (uintaddr & ~PAGE_MASK));
|
||||||
|
@ -43,26 +47,52 @@ static void __kprobes patch_unmap(int fixmap)
|
||||||
clear_fixmap(fixmap);
|
clear_fixmap(fixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __kprobes __patch_text(void *addr, unsigned int insn)
|
void __kprobes __patch_text_multiple(void *addr, u32 *insn, unsigned int len)
|
||||||
{
|
{
|
||||||
void *waddr = addr;
|
unsigned long start = (unsigned long)addr;
|
||||||
int size;
|
unsigned long end = (unsigned long)addr + len;
|
||||||
|
u32 *p, *fixmap;
|
||||||
|
int mapped;
|
||||||
|
|
||||||
waddr = patch_map(addr, FIX_TEXT_POKE0);
|
/* Make sure we don't have any aliases in cache */
|
||||||
*(u32 *)waddr = insn;
|
flush_kernel_vmap_range(addr, len);
|
||||||
size = sizeof(u32);
|
flush_icache_range(start, end);
|
||||||
flush_kernel_vmap_range(waddr, size);
|
|
||||||
patch_unmap(FIX_TEXT_POKE0);
|
p = fixmap = patch_map(addr, FIX_TEXT_POKE0, &mapped);
|
||||||
flush_icache_range((uintptr_t)(addr),
|
|
||||||
(uintptr_t)(addr) + size);
|
while (len >= 4) {
|
||||||
|
*p++ = *insn++;
|
||||||
|
addr += sizeof(u32);
|
||||||
|
len -= sizeof(u32);
|
||||||
|
if (len && offset_in_page(addr) == 0) {
|
||||||
|
/*
|
||||||
|
* We're crossing a page boundary, so
|
||||||
|
* need to remap
|
||||||
|
*/
|
||||||
|
flush_kernel_vmap_range((void *)fixmap,
|
||||||
|
(p-fixmap) * sizeof(*p));
|
||||||
|
if (mapped)
|
||||||
|
patch_unmap(FIX_TEXT_POKE0);
|
||||||
|
p = fixmap = patch_map(addr, FIX_TEXT_POKE0, &mapped);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
flush_kernel_vmap_range((void *)fixmap, (p-fixmap) * sizeof(*p));
|
||||||
|
if (mapped)
|
||||||
|
patch_unmap(FIX_TEXT_POKE0);
|
||||||
|
flush_icache_range(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __kprobes __patch_text(void *addr, u32 insn)
|
||||||
|
{
|
||||||
|
__patch_text_multiple(addr, &insn, sizeof(insn));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __kprobes patch_text_stop_machine(void *data)
|
static int __kprobes patch_text_stop_machine(void *data)
|
||||||
{
|
{
|
||||||
struct patch *patch = data;
|
struct patch *patch = data;
|
||||||
|
|
||||||
__patch_text(patch->addr, patch->insn);
|
__patch_text_multiple(patch->addr, patch->insn, patch->len);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +100,20 @@ void __kprobes patch_text(void *addr, unsigned int insn)
|
||||||
{
|
{
|
||||||
struct patch patch = {
|
struct patch patch = {
|
||||||
.addr = addr,
|
.addr = addr,
|
||||||
.insn = insn,
|
.insn = &insn,
|
||||||
|
.len = sizeof(insn),
|
||||||
|
};
|
||||||
|
|
||||||
|
stop_machine_cpuslocked(patch_text_stop_machine, &patch, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __kprobes patch_text_multiple(void *addr, u32 *insn, unsigned int len)
|
||||||
|
{
|
||||||
|
|
||||||
|
struct patch patch = {
|
||||||
|
.addr = addr,
|
||||||
|
.insn = insn,
|
||||||
|
.len = len
|
||||||
};
|
};
|
||||||
|
|
||||||
stop_machine_cpuslocked(patch_text_stop_machine, &patch, NULL);
|
stop_machine_cpuslocked(patch_text_stop_machine, &patch, NULL);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче