BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "George Guo" <dongtai.guo@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v4 6/6] LoongArch: BPF: Add support for arena atomics
Date: Tue, 01 Dec 2026 10:11:48 +0000	[thread overview]
Message-ID: <sashiko-outbox-243049@kernel.org> (raw)
In-Reply-To: <20261201095106.468000-7-dongtai.guo@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] loongarch: bpf: unhandled ALE fault on unaligned
  BPF_PROBE_ATOMIC in do_ale()
--

commit 816bae6b80f89e3bbb5bce679c6317c6a3a89d2d
Author: George Guo <guodongtai@kylinos.cn>

LoongArch: BPF: Add support for arena atomics

This commit adds LoongArch BPF JIT support for atomic instructions on arena
pointers (BPF_PROBE_ATOMIC), including exception table registration and
amcas.{w/d} emission for arena cmpxchg.

> diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
> index b78d38559598d..abf96ed6cd649 100644
> --- a/arch/loongarch/net/bpf_jit.c
> +++ b/arch/loongarch/net/bpf_jit.c
[ ... ]
> @@ -613,8 +645,23 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)
>  		return -EINVAL;
>  	}
>  
> +	/*
> +	 * On arena, the memory access is the last instruction emitted so far.
> +	 * If it faults, clear the register it loads into, as the verifier
> +	 * expects, and resume at the next instruction: zero-extending the
> +	 * cleared register keeps it zero.
> +	 */
> +	if (arena) {
> +		int load_reg = bpf_atomic_load_reg(insn);
> +
> +		ret = add_exception_handler(insn, ctx, load_reg < 0 ?
> +					    REG_DONT_CLEAR_MARKER : regmap[load_reg]);
> +		if (ret)
> +			return ret;
> +	}

[Severity: High]
Can an unaligned BPF_PROBE_ATOMIC read-modify-write access trigger a kernel
Oops in do_ale() instead of recovering through ex_handler_bpf()?

check_ptr_alignment() returns 0 unconditionally for PTR_TO_ARENA, so the
verifier allows unaligned arena addresses to reach the atomic instructions
emitted by emit_atomic_rmw().  On LoongArch, AM* atomic instructions require
natural alignment and raise EXCCODE_ALE when unaligned.

However, neither do_ale() nor emulate_load_store_insn() consults
fixup_exception(regs) on kernel alignment faults:

arch/loongarch/kernel/traps.c:do_ale() {
	...
#ifndef CONFIG_ARCH_STRICT_ALIGN
	die_if_kernel("Kernel ale access", regs);
	...
}

arch/loongarch/kernel/unaligned.c:emulate_load_store_insn() {
	...
	if (!size)
		goto sigbus;
	...
sigbus:
	die_if_kernel("Unhandled kernel unaligned access", regs);
	...
}

Since AM* opcodes are not emulated in emulate_load_store_insn() (size == 0),
an unaligned arena atomic RMW faults into die_if_kernel() rather than
invoking the BPF exception table fixup.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201095106.468000-1-dongtai.guo@linux.dev?part=6

      reply	other threads:[~2026-12-01 10:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  9:51 [PATCH v4 0/6] LoongArch: BPF: Add private stack, exceptions, large stack and arena support George Guo
2026-12-01  9:51 ` [PATCH v4 1/6] LoongArch: BPF: Add support for private stack George Guo
2026-12-01  9:51 ` [PATCH v4 2/6] LoongArch: BPF: Allow programs 2 KiB of stack George Guo
2026-12-01  9:51 ` [PATCH v4 3/6] LoongArch: BPF: Add support for exceptions George Guo
2026-12-01  9:51 ` [PATCH v4 4/6] LoongArch: BPF: Add support for signed arena loads George Guo
2026-12-01  9:51 ` [PATCH v4 5/6] LoongArch: BPF: Consolidate zero-extension in emit_atomic_rmw() George Guo
2026-12-01  9:51 ` [PATCH v4 6/6] LoongArch: BPF: Add support for arena atomics George Guo
2026-12-01 10:11   ` sashiko-bot [this message]

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=sashiko-outbox-243049@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=dongtai.guo@linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox