[PATCH v2 2/2] x86/cfi,bpf: Fix BPF JIT call
Alexei Starovoitov
alexei.starovoitov at gmail.com
Fri Dec 8 12:45:51 PST 2023
On Fri, Dec 8, 2023 at 12:18 PM Peter Zijlstra <peterz at infradead.org> wrote:
>
> On Fri, Dec 08, 2023 at 11:32:07AM -0800, Alexei Starovoitov wrote:
> > On Fri, Dec 8, 2023 at 5:41 AM Peter Zijlstra <peterz at infradead.org> wrote:
> > >
> > > On Fri, Dec 08, 2023 at 11:29:40AM +0100, Peter Zijlstra wrote:
> > > > The only problem I now have is the one XXX, I'm not entirely sure what
> > > > signature to use there.
> > >
> > > > @@ -119,6 +119,7 @@ int bpf_struct_ops_test_run(struct bpf_p
> > > > op_idx = prog->expected_attach_type;
> > > > err = bpf_struct_ops_prepare_trampoline(tlinks, link,
> > > > &st_ops->func_models[op_idx],
> > > > + /* XXX */ NULL,
> > > > image, image + PAGE_SIZE);
> > > > if (err < 0)
> > > > goto out;
> > >
> > > Duh, that should ofcourse be something of dummy_ops_test_ret_fn type.
> > > Let me go fix that.
> >
> > Right. That should work.
> > A bit wasteful to generate real code just to read hash from it
> > via cfi_get_func_hash(), but it's a neat idea.
>
> Right, bit wasteful. But the advantage is that I get a structure with
> pointers that exactly mirrors the structure we're writing.
>
> > I guess it's hard to get kcfi from __ADDRESSABLE in plain C
> > and sprinkling asm("cfi_xxx: .long __kcfi_typeid..."); is worse?
> > Even if it's a macro ?
>
> I can try this, but I'm not sure it'll be pretty. Even if I wrap it in a
> decent macro, I still get to define a ton of variables and then wrap the
> lot into a structure -- one that expects function pointers.
>
> I'll see how horrible it will become.
I mean we don't need to store a pointer to a func in stubs.
Can it be, roughly:
extern void bpf_tcp_ca_cong_avoid(struct sock *sk, u32 ack, u32 acked);
KCFI_MACRO(hash_of_cong_avoid, bpf_tcp_ca_cong_avoid);
u32 __array_of_kcfi_hash[] = {hash_of_cong_avoid, hash_of_set_state,...};
.bpf_ops_stubs = __array_of_kcfi_hash,
More information about the linux-riscv
mailing list