All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sam James <sam@gentoo.org>
To: Sean Young <sean@mess.org>
Cc: James Le Cuirot <chewi@gentoo.org>,  linux-media@vger.kernel.org
Subject: Re: [PATCH] meson: Allow BPF code to be built with GCC
Date: Wed, 06 Aug 2025 22:09:47 +0100	[thread overview]
Message-ID: <87bjos17j8.fsf@gentoo.org> (raw)
In-Reply-To: <aJPAsYVyCqxmwxDg@gofer.mess.org>

Sean Young <sean@mess.org> writes:

> On Tue, Aug 05, 2025 at 11:32:54PM +0100, Sam James wrote:
>> Sam James <sam@gentoo.org> writes:
>> 
>> > Sean Young <sean@mess.org> writes:
>> >
>> >> On Mon, Aug 04, 2025 at 10:13:18AM +0100, Sean Young wrote:
>> >>> On Sun, Aug 03, 2025 at 09:17:59AM +0100, James Le Cuirot wrote:
>> >>> > Disclaimer: I haven't actually tested the result of the GCC build.
>> >>> 
>> >>> Let me test this.
>> >>
>> >> It doesn't work:
>> >>
>> >> # ir-keytable -p ./imon_rsc.o 
>> >> Protocols changed to 
>> >> symbol  has unknown section 6
>> >> bpf_load_program() err=Permission denied
>> >> 0: R1=ctx() R10=fp0
>> >> 0: (bf) r6 = r1                       ; R1=ctx() R6_w=ctx()
>> >> 1: (62) *(u32 *)(r10 -4) = 0          ; R10=fp0 fp-8=0000????
>> >> 2: (bf) r2 = r10                      ; R2_w=fp0 R10=fp0
>> >> 3: (18) r1 = 0xffff89ed1318f800       ; R1_w=map_ptr(ks=4,vs=16)
>> >> 5: (07) r2 += -4                      ; R2_w=fp-4
>> >> 6: (85) call bpf_map_lookup_elem#1    ; R0_w=map_value(ks=4,vs=16)
>> >> 7: (bf) r4 = r0                       ; R0_w=map_value(ks=4,vs=16) R4_w=map_value(ks=4,vs=16)
>> >> 8: (15) if r0 == 0x0 goto pc+7        ; R0_w=map_value(ks=4,vs=16)
>> >> 9: (61) r0 = *(u32 *)(r6 +0)          ; R0_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R6_w=ctx()
>> >> 10: (bf) r1 = r0 ;
>> >> R0_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0;
>> >> 0xffffffff))
>> >> R1_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0;
>> >> 0xffffffff))
>> >> 11: (bf) r2 = r0 ;
>> >> R0_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0;
>> >> 0xffffffff))
>> >> R2_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0;
>> >> 0xffffffff))
>> >> 12: (54) w1 &= -16777216              ; R1_w=scalar(smin=0,smax=umax=umax32=0xff000000,smax32=0x7f000000,var_off=(0x0; 0xff000000))
>> >> 13: (54) w2 &= -33554432              ; R2=scalar(smin=0,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000))
>> >> 14: (16) if w2 == 0x0 goto pc+3       ; R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000))
>> >> 15: (16) if w1 == 0x3000000 goto pc+31 47:
>> >> R0=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>> >> R1=0x3000000
>> >> R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0;
>> >> 0xfe000000)) R4=map_value(ks=4,vs=16) R6=ctx() R10=fp0 fp-8=0000????
>> >> 47: (61) r5 = *(u32 *)(r4 +8)         ; R4=map_value(ks=4,vs=16) R5_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>> >> 48: (16) if w5 == 0x1 goto pc+7 56:
>> >> R0=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>> >> R1=0x3000000
>> >> R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0;
>> >> 0xfe000000)) R4=map_value(ks=4,vs=16) R5_w=1 R6=ctx() R10=fp0
>> >> fp-8=0000????
>> >> 56: (57) r0 &= 16777215               ; R0_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=0xffffff,var_off=(0x0; 0xffffff))
>> >> 57: (b6) if w0 <= 0x960 goto pc+22    ; R0_w=scalar(smin=umin=smin32=umin32=2401,smax=umax=smax32=umax32=0xffffff,var_off=(0x0; 0xffffff))
>> >> 58: (61) r1 = *(u32 *)(r4 +12)        ; R1_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R4=map_value(ks=4,vs=16)
>> >> 59: (04) w1 += -4                     ; R1=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>> >> 60: (26) if w1 > 0x1 goto pc-11       ; R1=scalar(smin=smin32=0,smax=umax=smax32=umax32=1,var_off=(0x0; 0x1))
>> >> 61: (79) r3 = *(u64 *)(r4 +0)         ; R3_w=scalar() R4=map_value(ks=4,vs=16)
>> >> 62: (57) r3 &= 15                     ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=15,var_off=(0x0; 0xf))
>> >> 63: (07) r3 += -1                     ; R3_w=scalar(smin=smin32=-1,smax=smax32=14)
>> >> 64: (25) if r3 > 0xe goto pc+46       ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=14,var_off=(0x0; 0xf))
>> >> 65: (67) r3 <<= 2                     ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0; 0x3c))
>> >> 66: (18) r2 = 0x3c                    ; R2_w=60
>> >> 68: (18) r9 = 0x0                     ; R9_w=0
>> >> 70: (0f) r2 += r3 ;
>> >> R2_w=scalar(smin=umin=smin32=umin32=60,smax=umax=smax32=umax32=116,var_off=(0x0;
>> >> 0x7c))
>> >> R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
>> >> 0x3c))
>> >> 71: (0f) r9 += r3 ;
>> >> R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
>> >> 0x3c))
>> >> R9_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
>> >> 0x3c))
>> >> 72: (81) r2 = *(s32 *)(r2 +0)
>> >> R2 invalid mem access 'scalar'
>> >> processed 40 insns (limit 1000000) max_states_per_insn 0 total_states 3 peak_states 3 mark_read 1
>> >
>> > I'll have a look. Thanks.
>> 
>> OK, I can't reproduce it yet because I don't have the hardware (using
>> loopback doesn't seem to be sufficient, even with Clang).
>> 
>> Could you get the full bpf-* gcc invocation with `ninja --verbose`, and
>> then append -save-temps to it, and attach the .i it makes?
>
> Works fine with rc-loopback.
>

Huh, okay. I couldn't get the verify failure to spit out.

> The problem is that gcc compiles this down to a lookup table which is then
> stored in the .rodata section.
>
> https://git.linuxtv.org/v4l-utils.git/tree/utils/keytable/bpf_protocols/imon_rsc.c#n97
>
> Then ir-keytable fails to load and relocate the rodata section. Note the 
> error:
>
> symbol  has unknown section 6
>
> section 6 is the rodata section.
>
> ir-keytable simply has no handling for .rodata right now. I am not sure how
> bpf handles .rodata (if at all), needs more investigation.

I'd spotted that and naively assumed it was unrelated given I couldn't
get the verify failure even with Clang. Mea culpa!

>  
>
> Sean

sam

  reply	other threads:[~2025-08-06 21:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-03  8:17 [PATCH] meson: Allow BPF code to be built with GCC James Le Cuirot
2025-08-04  9:13 ` Sean Young
2025-08-04 20:22   ` Sam James
2025-08-04 20:34     ` James Le Cuirot
2025-08-05 11:32   ` Sean Young
2025-08-05 15:03     ` Sam James
2025-08-05 22:32       ` Sam James
2025-08-06 20:53         ` Sean Young
2025-08-06 21:09           ` Sam James [this message]
2025-08-08  1:19             ` Sam James
2025-08-08 12:42               ` Sean Young
2025-08-10 14:20 ` [PATCH v2] " James Le Cuirot
2025-08-12 13:48   ` Sean Young

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bjos17j8.fsf@gentoo.org \
    --to=sam@gentoo.org \
    --cc=chewi@gentoo.org \
    --cc=linux-media@vger.kernel.org \
    --cc=sean@mess.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.