All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chenghao Duan <duanchenghao@kylinos.cn>
To: Hengqi Chen <hengqi.chen@gmail.com>
Cc: yangtiezhu@loongson.cn, chenhuacai@kernel.org, kernel@xen0n.name,
	zhangtianyang@loongson.cn, masahiroy@kernel.org,
	linux-kernel@vger.kernel.org, loongarch@lists.linux.dev,
	bpf@vger.kernel.org, guodongtai@kylinos.cn,
	youling.tang@linux.dev, jianghaoran@kylinos.cn,
	vincent.mc.li@gmail.com
Subject: Re: [PATCH v1 2/2] LoongArch: Enable BPF exception fixup for specific ADE subcode
Date: Wed, 10 Dec 2025 13:43:29 +0800	[thread overview]
Message-ID: <20251210054329.GA691118@chenghao-pc> (raw)
In-Reply-To: <CAEyhmHTtEE6cnm18_WC+d+o4RnLUw+BUUNL54R6d9W2b868+LA@mail.gmail.com>

On Wed, Dec 10, 2025 at 01:20:12PM +0800, Hengqi Chen wrote:
> On Tue, Dec 9, 2025 at 5:34 PM Chenghao Duan <duanchenghao@kylinos.cn> wrote:
> >
> > This patch allows the LoongArch BPF JIT to handle recoverable memory
> > access errors generated by BPF_PROBE_MEM* instructions.
> >
> > When a BPF program performs memory access operations, the instructions
> > it executes may trigger ADEM exceptions. The kernel’s built-in BPF
> > exception table mechanism (EX_TYPE_BPF) will generate corresponding
> > exception fixup entries in the JIT compilation phase; however, the
> > architecture-specific trap handling function needs to proactively call
> > the common fixup routine to achieve exception recovery.
> >
> > do_ade(): fix EX_TYPE_BPF memory access exceptions for BPF programs,
> > ensure safe execution.
> >
> 
> Which bpf prog triggers this code path ? Why didn't we trigger it before ?

module_attach and subprogs_extable trigger ADE exception via illegal address
access in BPF programs, leading to kernel panic without this patch.

> 
> > Signed-off-by: Chenghao Duan <duanchenghao@kylinos.cn>
> > ---
> >  arch/loongarch/kernel/traps.c | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/loongarch/kernel/traps.c b/arch/loongarch/kernel/traps.c
> > index da5926fead4a..9ca8aacc82b8 100644
> > --- a/arch/loongarch/kernel/traps.c
> > +++ b/arch/loongarch/kernel/traps.c
> > @@ -534,8 +534,13 @@ asmlinkage void noinstr do_fpe(struct pt_regs *regs, unsigned long fcsr)
> >
> >  asmlinkage void noinstr do_ade(struct pt_regs *regs)
> >  {
> > -       irqentry_state_t state = irqentry_enter(regs);
> > +       irqentry_state_t state;
> > +       unsigned int esubcode = FIELD_GET(CSR_ESTAT_ESUBCODE, regs->csr_estat);
> > +
> > +       if ((esubcode == 1) && fixup_exception(regs))
> > +               return;
> >
> > +       state = irqentry_enter(regs);
> >         die_if_kernel("Kernel ade access", regs);
> >         force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)regs->csr_badvaddr);
> >
> > --
> > 2.25.1
> >

  reply	other threads:[~2025-12-10  5:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-09  9:34 [PATCH v1 0/2] Fix the failure issue of the module_attach test case Chenghao Duan
2025-12-09  9:34 ` [PATCH v1 1/2] LoongArch: Modify the jump logic of the trampoline Chenghao Duan
2025-12-10  0:48   ` Tiezhu Yang
2025-12-10  4:15   ` Hengqi Chen
2025-12-10  6:16     ` Chenghao Duan
2025-12-09  9:34 ` [PATCH v1 2/2] LoongArch: Enable BPF exception fixup for specific ADE subcode Chenghao Duan
2025-12-10  1:02   ` Tiezhu Yang
2025-12-10  5:20   ` Hengqi Chen
2025-12-10  5:43     ` Chenghao Duan [this message]
2025-12-10  3:18 ` [PATCH v1 0/2] Fix the failure issue of the module_attach test case Vincent Li
2025-12-10  4:10 ` Hengqi Chen
2025-12-10  6:08   ` Chenghao Duan

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=20251210054329.GA691118@chenghao-pc \
    --to=duanchenghao@kylinos.cn \
    --cc=bpf@vger.kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=guodongtai@kylinos.cn \
    --cc=hengqi.chen@gmail.com \
    --cc=jianghaoran@kylinos.cn \
    --cc=kernel@xen0n.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=masahiroy@kernel.org \
    --cc=vincent.mc.li@gmail.com \
    --cc=yangtiezhu@loongson.cn \
    --cc=youling.tang@linux.dev \
    --cc=zhangtianyang@loongson.cn \
    /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.