From: George Guo <dongtai.guo@linux.dev>
To: chenhuacai@kernel.org, yangtiezhu@loongson.cn
Cc: sashiko-reviews@lists.linux.dev, hengqi.chen@gmail.com,
loongarch@lists.linux.dev, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 6/6] LoongArch: BPF: Add support for arena atomics
Date: Wed, 2 Dec 2026 17:41:39 -0800 [thread overview]
Message-ID: <20261203014139.7077-1-dongtai.guo@linux.dev> (raw)
In-Reply-To: <sashiko-outbox-243049@kernel.org>
On 2026/12/1 10:11, sashiko-bot@kernel.org wrote:
> 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:
Yes, this is a real issue. I reproduced it with an atomic one byte off
an aligned arena address, the kernel panics at the first amadd_db.w:
Kernel ale access[#1]:
...
ERA: ffff8000020136f4 bpf_prog_53d40cccca5faaf3_unaligned+0x10c/0x284
ESTAT: 00090000 [ALE] (IS= ECode=9 EsubCode=0)
BADV: ffff80008d600001
...
Kernel panic - not syncing: Fatal exception
The exception table entry added by this patch is fine, the problem is
that the trap code never looks it up for ALE. This is fixed by Tiezhu's
patch "LoongArch: Call fixup_exception() for unaligned accesses", which
calls fixup_exception() on the failure paths of do_ale() and
emulate_load_store_insn():
https://lore.kernel.org/loongarch/20261203012908.27076-1-yangtiezhu@loongson.cn/
With that patch, a new arena_atomics/unaligned subtest (32-bit fetch
add and fetch or, 64-bit xchg and cmpxchg, all one byte off) passed on
Loongson-3C6000, with both CONFIG_ARCH_STRICT_ALIGN=y and
CONFIG_ARCH_STRICT_ALIGN=n:
$ sudo ./test_progs -a arena_atomics/unaligned
#3/10 arena_atomics/unaligned:OK
#3 arena_atomics:OK
Summary: 1/1 PASSED, 0 SKIPPED, 0/0 FAILED
The test is archived in the v1 thread of that patch:
https://lore.kernel.org/loongarch/20261202134056.40836-1-dongtai.guo@linux.dev/
I will send it formally after the LoongArch BPF JIT support is merged.
Thanks,
George
prev parent reply other threads:[~2026-12-03 1:41 UTC|newest]
Thread overview: 9+ 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
2026-12-03 1:41 ` George Guo [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=20261203014139.7077-1-dongtai.guo@linux.dev \
--to=dongtai.guo@linux.dev \
--cc=bpf@vger.kernel.org \
--cc=chenhuacai@kernel.org \
--cc=hengqi.chen@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yangtiezhu@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.