[PATCH 5/7] RISC-V: fix auipc-jalr addresses in patched alternatives
Lad, Prabhakar
prabhakar.csengg at gmail.com
Mon Nov 21 16:16:10 PST 2022
Hi Heiko,
On Mon, Nov 21, 2022 at 10:38 PM Heiko Stübner <heiko at sntech.de> wrote:
>
> Am Montag, 21. November 2022, 23:17:11 CET schrieb Heiko Stübner:
> > Am Montag, 21. November 2022, 22:31:36 CET schrieb Lad, Prabhakar:
> > > Some more information,
> > >
> > > - If I drop the riscv_alternative_fix_auipc_jalr() call after
> > > patch_text_nosync() and then print the alt->old_ptr instructions
> > > before patching I can see the instructions as 0x13 (nop) which is
> > > correct.
> > >
> > > - if I call riscv_alternative_fix_auipc_jalr() call after
> > > patch_text_nosync() and then print the alt->old_ptr instructions
> > > before patching I dont see 0x13 (nop) consistently for old
> > > instructions.
> >
> > which is to be expected I guess.
> >
> > alt->old_ptr points to the memory location where the live kernel code
> > lives.
> >
> > I.e. the code at this location is the thing the kernel actually runs.
> > The code at this location then gets overwritten by the alternative
> > assembly.
> >
> >
> > > - If I replace the nop's in the old instructions with my assembly code
> > > of rz/five cmo and then just use patch_text_nosync() I can see the
> > > correct actual instruction being printed apart from jalr (is some sort
> > > of offset added to it as I see last 4 bits match?) and then is
> > > replaced correctly by the same alt instructions apart from the jalr
> > > (log [0]).
> > >
> > > - If I replace the nop's in the old instructions with my assembly code
> > > of rz/five cmo and then use patch_text_nosync() and
> > > riscv_alternative_fix_auipc_jalr() I can see the actual old
> > > instructions differs a bit and again the jalr instruction differs too
> > > in the patched code (log [1]).
> > >
> > > [0] https://paste.debian.net/1261412/
> > > [1] https://paste.debian.net/1261413/
> > >
> > > Attached is the objump of dma-noncoherent.o for reference.
> >
> > I did read that objdumps are not really conclusive when looking
> > at auipc + jalr instructions, hence the printing of the actual instructions.
> >
> > As either manually or with a helper like
> >
> > https://luplab.gitlab.io/rvcodecjs/#q=0xf4c080e7
> >
> > you can then decode the actual instruction and compare.
> >
> > In your log the two jalr instructions decode to different offsets,
> > jalr x1, x1, -180
> > vs
> > jalr x1, x1, -834
> >
> > Can you check what the patch_offset value is in your case?
> >
> > Interestingly the
> > auipc x1, 0
> > is 0 for both cases.
> >
> > I'll try to build a real test-setup mimicing what you're doing
> > tomorrow (european tomorrow).
>
> also, is it possible for you to put your code on some github
> or so? Sometimes looking at the actual code makes things
> a lot easier :-)
>
I have pushed my changes here
https://github.com/prabhakarlad/linux/tree/rzfive-cmo
Cheers,
Prabhakar
More information about the linux-riscv
mailing list