diff mbox series

[v8,3/6] powerpc/code-patching: Verify instruction patch succeeded

Message ID 20221021052238.580986-4-bgray@linux.ibm.com (mailing list archive)
State Superseded
Headers show
Series Use per-CPU temporary mappings for patching | expand

Commit Message

Benjamin Gray Oct. 21, 2022, 5:22 a.m. UTC
Verifies that if the instruction patching did not return an error then
the value stored at the given address to patch is now equal to the
instruction we patched it to.

Signed-off-by: Benjamin Gray <bgray@linux.ibm.com>
---
 arch/powerpc/lib/code-patching.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Russell Currey Oct. 24, 2022, 3:20 a.m. UTC | #1
On Fri, 2022-10-21 at 16:22 +1100, Benjamin Gray wrote:
> Verifies that if the instruction patching did not return an error
> then
> the value stored at the given address to patch is now equal to the
> instruction we patched it to.
> 
> Signed-off-by: Benjamin Gray <bgray@linux.ibm.com>
> ---
>  arch/powerpc/lib/code-patching.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/powerpc/lib/code-patching.c
> b/arch/powerpc/lib/code-patching.c
> index 34fc7ac34d91..9b9eba574d7e 100644
> --- a/arch/powerpc/lib/code-patching.c
> +++ b/arch/powerpc/lib/code-patching.c
> @@ -186,6 +186,8 @@ static int do_patch_instruction(u32 *addr,
> ppc_inst_t instr)
>         err = __do_patch_instruction(addr, instr);
>         local_irq_restore(flags);
>  
> +       WARN_ON(!err && !ppc_inst_equal(instr, ppc_inst_read(addr)));
> +

As a side note, I had a look at test-code-patching.c and it doesn't
look like we don't have a test for ppc_inst_equal() with prefixed
instructions.  We should fix that.

>         return err;
>  }
>  #else /* !CONFIG_STRICT_KERNEL_RWX */
Benjamin Gray Oct. 25, 2022, 3:30 a.m. UTC | #2
On Mon, 2022-10-24 at 14:20 +1100, Russell Currey wrote:
> On Fri, 2022-10-21 at 16:22 +1100, Benjamin Gray wrote:
> > diff --git a/arch/powerpc/lib/code-patching.c
> > b/arch/powerpc/lib/code-patching.c
> > index 34fc7ac34d91..9b9eba574d7e 100644
> > --- a/arch/powerpc/lib/code-patching.c
> > +++ b/arch/powerpc/lib/code-patching.c
> > @@ -186,6 +186,8 @@ static int do_patch_instruction(u32 *addr,
> > ppc_inst_t instr)
> >         err = __do_patch_instruction(addr, instr);
> >         local_irq_restore(flags);
> >  
> > +       WARN_ON(!err && !ppc_inst_equal(instr,
> > ppc_inst_read(addr)));
> > +
> 
> As a side note, I had a look at test-code-patching.c and it doesn't
> look like we don't have a test for ppc_inst_equal() with prefixed
> instructions.  We should fix that.

Yeah, for a different series though I assume. And I think it would be
better suited in a suite dedicated to testing asm/inst.h functions.
diff mbox series

Patch

diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
index 34fc7ac34d91..9b9eba574d7e 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -186,6 +186,8 @@  static int do_patch_instruction(u32 *addr, ppc_inst_t instr)
 	err = __do_patch_instruction(addr, instr);
 	local_irq_restore(flags);
 
+	WARN_ON(!err && !ppc_inst_equal(instr, ppc_inst_read(addr)));
+
 	return err;
 }
 #else /* !CONFIG_STRICT_KERNEL_RWX */