On Tue, 2 Sept 2025 at 04:25, Alexei Starovoitov <alexei.starovoitov@xxxxxxxxx> wrote: > > On Mon, Sep 1, 2025 at 12:37 PM Puranjay Mohan <puranjay@xxxxxxxxxx> wrote: > > > > BPF streams are only valid for the main programs, to make it easier to > > access streams from subprogs, introduce main_prog_aux in struct > > bpf_prog_aux. > > > > prog->aux->main_prog_aux = prog->aux, for main programs and > > prog->aux->main_prog_aux = main_prog->aux, for subprograms. > > > > This makes it easy to access streams like: > > stream = bpf_stream_get(stream_id, prog->main_prog_aux); > > > > Signed-off-by: Puranjay Mohan <puranjay@xxxxxxxxxx> > > --- > > include/linux/bpf.h | 1 + > > kernel/bpf/core.c | 3 +-- > > kernel/bpf/stream.c | 6 +++--- > > kernel/bpf/verifier.c | 1 + > > 4 files changed, 6 insertions(+), 5 deletions(-) > > > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > > index 8f6e87f0f3a89..d133171c4d2a9 100644 > > --- a/include/linux/bpf.h > > +++ b/include/linux/bpf.h > > @@ -1633,6 +1633,7 @@ struct bpf_prog_aux { > > /* function name for valid attach_btf_id */ > > const char *attach_func_name; > > struct bpf_prog **func; > > + struct bpf_prog_aux *main_prog_aux; > > void *jit_data; /* JIT specific data. arch dependent */ > > struct bpf_jit_poke_descriptor *poke_tab; > > struct bpf_kfunc_desc_tab *kfunc_tab; > > diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c > > index ef01cc644a965..dbbf8e4b6e4c2 100644 > > --- a/kernel/bpf/core.c > > +++ b/kernel/bpf/core.c > > @@ -120,6 +120,7 @@ struct bpf_prog *bpf_prog_alloc_no_stats(unsigned int size, gfp_t gfp_extra_flag > > > > fp->pages = size / PAGE_SIZE; > > fp->aux = aux; > > + fp->aux->main_prog_aux = aux; > > Though I agree that it's not strictly necessary, this approach > is so much easier to reason about. > > Kumar, wdyt? Yeah, nbd, this looks fine as well.