Re: [PATCH v4 5/8] LoongArch: BPF: Don't assume trampoline size is page aligned

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 4, 2025 at 9:56 AM Hengqi Chen <hengqi.chen@xxxxxxxxx> wrote:
>
> On Wed, Sep 3, 2025 at 10:56 PM Huacai Chen <chenhuacai@xxxxxxxxxx> wrote:
> >
> > Hi, Hengqi,
> >
> > On Wed, Sep 3, 2025 at 8:06 PM Hengqi Chen <hengqi.chen@xxxxxxxxx> wrote:
> > >
> > > Currently, arch_alloc_bpf_trampoline() use bpf_prog_pack_alloc()
> > > which will pack multiple trampolines into a huge page. So no need
> > > to assume the trampoline size is page aligned.
> > We do the alignment because larch_insn_text_copy() changes page attrs.
> > If there is other data and BPF trampoline is in the same page,
> > changing page attrs may cause errors.
> >
>
> Doesn't stop_machine() prevent this side effect?
I don't think so.

Consider such a case: BPF trampoline and another vmalloc area share
the same page, larch_insn_text_copy() makes the whole page be "rox",
even if stop_machine() completes. But "rox" is only needed by BPF
trampoline, and the other vmalloc area isn't.

Huacai

>
> > Huacai
> >
> > >
> > > Signed-off-by: Hengqi Chen <hengqi.chen@xxxxxxxxx>
> > > ---
> > >  arch/loongarch/net/bpf_jit.c | 3 +--
> > >  1 file changed, 1 insertion(+), 2 deletions(-)
> > >
> > > diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
> > > index 35b13d91a979..43628b5e1553 100644
> > > --- a/arch/loongarch/net/bpf_jit.c
> > > +++ b/arch/loongarch/net/bpf_jit.c
> > > @@ -1747,8 +1747,7 @@ int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
> > >
> > >         ret = __arch_prepare_bpf_trampoline(&ctx, &im, m, tlinks, func_addr, flags);
> > >
> > > -       /* Page align */
> > > -       return ret < 0 ? ret : round_up(ret * LOONGARCH_INSN_SIZE, PAGE_SIZE);
> > > +       return ret < 0 ? ret : ret * LOONGARCH_INSN_SIZE;
> > >  }
> > >
> > >  struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
> > > --
> > > 2.43.5
> > >
>





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux