powerpc/lib/code-patching: refactor patch_instruction()
patch_instruction() uses almost the same sequence as __patch_instruction() This patch refactor it so that patch_instruction() uses __patch_instruction() instead of duplicating code. Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> Acked-by: Balbir Singh <bsingharora@gmail.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
This commit is contained in:
parent
4ec591e51a
commit
8cf4c05712
@ -23,19 +23,26 @@
|
|||||||
#include <asm/code-patching.h>
|
#include <asm/code-patching.h>
|
||||||
#include <asm/setup.h>
|
#include <asm/setup.h>
|
||||||
|
|
||||||
static int __patch_instruction(unsigned int *addr, unsigned int instr)
|
static int __patch_instruction(unsigned int *exec_addr, unsigned int instr,
|
||||||
|
unsigned int *patch_addr)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
__put_user_size(instr, addr, 4, err);
|
__put_user_size(instr, patch_addr, 4, err);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
asm ("dcbst 0, %0; sync; icbi 0,%0; sync; isync" :: "r" (addr));
|
asm ("dcbst 0, %0; sync; icbi 0,%1; sync; isync" :: "r" (patch_addr),
|
||||||
|
"r" (exec_addr));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int raw_patch_instruction(unsigned int *addr, unsigned int instr)
|
||||||
|
{
|
||||||
|
return __patch_instruction(addr, instr, addr);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_STRICT_KERNEL_RWX
|
#ifdef CONFIG_STRICT_KERNEL_RWX
|
||||||
static DEFINE_PER_CPU(struct vm_struct *, text_poke_area);
|
static DEFINE_PER_CPU(struct vm_struct *, text_poke_area);
|
||||||
|
|
||||||
@ -138,7 +145,7 @@ static inline int unmap_patch_area(unsigned long addr)
|
|||||||
int patch_instruction(unsigned int *addr, unsigned int instr)
|
int patch_instruction(unsigned int *addr, unsigned int instr)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
unsigned int *dest = NULL;
|
unsigned int *patch_addr = NULL;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
unsigned long text_poke_addr;
|
unsigned long text_poke_addr;
|
||||||
unsigned long kaddr = (unsigned long)addr;
|
unsigned long kaddr = (unsigned long)addr;
|
||||||
@ -149,7 +156,7 @@ int patch_instruction(unsigned int *addr, unsigned int instr)
|
|||||||
* to allow patching. We just do the plain old patching
|
* to allow patching. We just do the plain old patching
|
||||||
*/
|
*/
|
||||||
if (!this_cpu_read(*PTRRELOC(&text_poke_area)))
|
if (!this_cpu_read(*PTRRELOC(&text_poke_area)))
|
||||||
return __patch_instruction(addr, instr);
|
return raw_patch_instruction(addr, instr);
|
||||||
|
|
||||||
local_irq_save(flags);
|
local_irq_save(flags);
|
||||||
|
|
||||||
@ -159,17 +166,10 @@ int patch_instruction(unsigned int *addr, unsigned int instr)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
dest = (unsigned int *)(text_poke_addr) +
|
patch_addr = (unsigned int *)(text_poke_addr) +
|
||||||
((kaddr & ~PAGE_MASK) / sizeof(unsigned int));
|
((kaddr & ~PAGE_MASK) / sizeof(unsigned int));
|
||||||
|
|
||||||
/*
|
__patch_instruction(addr, instr, patch_addr);
|
||||||
* We use __put_user_size so that we can handle faults while
|
|
||||||
* writing to dest and return err to handle faults gracefully
|
|
||||||
*/
|
|
||||||
__put_user_size(instr, dest, 4, err);
|
|
||||||
if (!err)
|
|
||||||
asm ("dcbst 0, %0; sync; icbi 0,%0; icbi 0,%1; sync; isync"
|
|
||||||
::"r" (dest), "r"(addr));
|
|
||||||
|
|
||||||
err = unmap_patch_area(text_poke_addr);
|
err = unmap_patch_area(text_poke_addr);
|
||||||
if (err)
|
if (err)
|
||||||
@ -184,7 +184,7 @@ out:
|
|||||||
|
|
||||||
int patch_instruction(unsigned int *addr, unsigned int instr)
|
int patch_instruction(unsigned int *addr, unsigned int instr)
|
||||||
{
|
{
|
||||||
return __patch_instruction(addr, instr);
|
return raw_patch_instruction(addr, instr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_STRICT_KERNEL_RWX */
|
#endif /* CONFIG_STRICT_KERNEL_RWX */
|
||||||
|
Loading…
Reference in New Issue
Block a user