On 18/05/26 12:55 pm, Hari Bathini wrote:


On 18/05/26 3:10 am, [email protected] wrote:
From: Abhishek Dubey <[email protected]>

Move the long branch address space to the bottom of the long
branch stub. This allows uninterrupted disassembly until the
last 8 bytes. Exclude these last bytes from the overall
program length to prevent failure in assembly generation.
Also, align dummy_tramp_addr field with 8-byte boundary.

Following is disassembler output for test program with moved down
dummy_tramp_addr field:
.....
.....
pc:68    left:44     a6 03 08 7c  :  mtlr 0
pc:72    left:40     bc ff ff 4b  :  b .-68
pc:76    left:36     a6 02 68 7d  :  mflr 11
pc:80    left:32     05 00 9f 42  :  bcl 20, 31, .+4
pc:84    left:28     a6 02 88 7d  :  mflr 12
pc:88    left:24     14 00 8c e9  :  ld 12, 20(12)
pc:92    left:20     a6 03 89 7d  :  mtctr 12
pc:96    left:16     a6 03 68 7d  :  mtlr 11
pc:100   left:12     20 04 80 4e  :  bctr
pc:104   left:8      c0 34 1d 00  :

Failure log:
Can't disasm instruction at offset 104: c0 34 1d 00 00 00 00 c0
Disassembly logic can truncate at 104, ignoring last 8 bytes.

Update the dummy_tramp_addr field offset calculation from the end
of the program to reflect its new location, for bpf_arch_text_poke()
to update the actual trampoline's address in this field.

All BPF trampoline selftests continue to pass with this patch applied.

Signed-off-by: Abhishek Dubey <[email protected]>
---
  arch/powerpc/net/bpf_jit_comp.c | 34 +++++++++++++++++++--------------
  1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/ bpf_jit_comp.c
index ef7614177cb1..b73bc9295c31 100644
--- a/arch/powerpc/net/bpf_jit_comp.c
+++ b/arch/powerpc/net/bpf_jit_comp.c
@@ -57,19 +57,21 @@ void bpf_jit_build_fentry_stubs(u32 *image, u32 *fimage, struct codegen_context
       * In the final pass, align the mis-aligned dummy_tramp_addr field
       * in the fimage. The alignment NOP must appear before OOL stub,
       * to make ool_stub_idx & long_branch_stub_idx constant from end.
+     *
+     * The dummy_tramp_addr field is placed at bottom of Long branch stub.
       */
  #ifdef CONFIG_PPC64
      if (fimage && image) {
          /*
           * pc points to first instruction of OOL stub,
-         * dummy_tramp_addr is past 4/3 instructions depending on
+         * dummy_tramp_addr is past 11/10 instructions depending on
           * CONFIG_PPC_FTRACE_OUT_OF_LINE is enabled/not respectively.
           *
           * The decision to emit alignment NOP must depend on the alignment
           * of dummy_tramp_addr field.
           */
          unsigned long pc = (unsigned long)fimage + CTX_NIA(ctx);

-        pc += IS_ENABLED(CONFIG_PPC_FTRACE_OUT_OF_LINE) ? 4 : 3;
+        pc += IS_ENABLED(CONFIG_PPC_FTRACE_OUT_OF_LINE) ? 11 : 10;

To get the address, should multiply the instruction count with 4..

     pc += (IS_ENABLED(CONFIG_PPC_FTRACE_OUT_OF_LINE) ? 11 : 10) * 4;

Also, pc may not be appropriate name here. We are essentially
calculating the pointer address of dummy_tramp_addr. `addrp` maybe?

Something like this:

+               u32 *addrp = fimage + ctx->idx;
+
+               addrp += IS_ENABLED(CONFIG_PPC_FTRACE_OUT_OF_LINE) ? 4 : 3;
+               if (!IS_ALIGNED((unsigned long)addrp, 8))
+                       EMIT(PPC_RAW_NOP());

- Hari

Reply via email to