On Tue, Aug 05, 2025 at 11:38:07AM +0200, Geert Uytterhoeven wrote:
> Hi Stafford,
> 
> On Tue, 5 Aug 2025 at 11:15, Stafford Horne <[email protected]> wrote:
> > On Tue, Aug 05, 2025 at 08:40:57AM +0000, ChenMiao wrote:
> > > From: chenmiao <[email protected]>
> > >
> > > We need a text patching mechanism to ensure that in the subsequent
> > > implementation of jump_label, the code can be modified to the correct
> > > location. Therefore, FIX_TEXT_POKE0 has been added as a mapping area.
> > >
> > > And, I create a new file named insn-def.h to define the or1k insn macro
> > > size and more define in the future.
> > >
> > > Among these changes, we implement patch_map and support the
> > > patch_insn_write API for single instruction writing.
> > >
> > > Signed-off-by: chenmiao <[email protected]>
> 
> > > --- /dev/null
> > > +++ b/arch/openrisc/include/asm/insn-def.h
> 
> > > +/* or1k instructions are always 32 bits. */
> > > +#define      OPENRISC_INSN_SIZE              4
> 
> > > --- /dev/null
> > > +++ b/arch/openrisc/kernel/patching.c
> 
> > > +static int __patch_insn_write(void *addr, const void *insn)
> > > +{
> > > +     void *waddr = addr;
> > > +     unsigned long flags = 0;
> > > +     int ret;
> > > +
> > > +     raw_spin_lock_irqsave(&patch_lock, flags);
> > > +
> > > +     waddr = patch_map(addr, FIX_TEXT_POKE0);
> > > +
> > > +     ret = copy_to_kernel_nofault(waddr, insn, OPENRISC_INSN_SIZE);
> >
> > If you change *insn to unsigned long insn, you can do:
> >
> >         ret = copy_to_kernel_nofault(waddr, &insn, iszeof(insn));
> 
> sizeof(*insn)?

Yes, typo, thanks.

> >
> > > +     local_icache_range_inv((unsigned long)waddr,
> > > +                            (unsigned long)waddr + OPENRISC_INSN_SIZE);
> > > +
> > > +     patch_unmap(FIX_TEXT_POKE0);
> > > +
> > > +     raw_spin_unlock_irqrestore(&patch_lock, flags);
> > > +
> > > +     return ret;
> > > +}
> > > +
> > > +int patch_insn_write(void *addr, const void *insn)
> >
> > Does insn need to be void *?  It think it could be just unsigned long. See
> > comment above.
> 
> u32?
> 
> unsigned long would be 64-bit on 64-bit platforms.

Thanks, yes for us it's more correct to use u32.  I always thing unsigned long 
is
OK in openrisc as we have no 64-bit implementations.  But might as well have it
correct in case we ever add the 64-bit implementation.

-Stafford

Reply via email to