From: Tiezhu Yang <yangtiezhu@loongson.cn>
To: WANG Rui <wangrui@loongson.cn>
Cc: Huacai Chen <chenhuacai@kernel.org>,
Hengqi Chen <hengqi.chen@gmail.com>,
loongarch@lists.linux.dev, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 4/5] LoongArch: BPF: Support load-acquire and store-release instructions
Date: Mon, 13 Apr 2026 12:02:24 +0800 [thread overview]
Message-ID: <fa0a3521-7373-70d8-e08a-d2059fc62265@loongson.cn> (raw)
In-Reply-To: <CAHirt9jnveJCgCt2TsuyQrJV0tCB+FJStgP6OaCiH8eJWLfpvw@mail.gmail.com>
On 2026/4/12 上午11:46, WANG Rui wrote:
> On Tue, Apr 7, 2026 at 2:23 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>>
>> Use the LoongArch common memory access instructions with the barrier dbar
>> to support the BPF load-acquire and store-release instructions.
...
>> +static int emit_atomic_ld_st(const struct bpf_insn *insn, struct jit_ctx *ctx)
>> +{
>> + const u8 t1 = LOONGARCH_GPR_T1;
>> + const u8 src = regmap[insn->src_reg];
>> + const u8 dst = regmap[insn->dst_reg];
>> + const s16 off = insn->off;
>> + const s32 imm = insn->imm;
>> +
>> + switch (imm) {
>> + /* dst_reg = load_acquire(src_reg + off16) */
>> + case BPF_LOAD_ACQ:
>> + switch (BPF_SIZE(insn->code)) {
>> + case BPF_B:
>> + if (is_signed_imm12(off)) {
>> + emit_insn(ctx, ldb, dst, src, off);
>> + } else {
>> + move_imm(ctx, t1, off, false);
>> + emit_insn(ctx, ldxb, dst, src, t1);
>> + }
>> + emit_zext_8(ctx, dst);
>
> Could we use ld[x].{bu,hu,wu} here to simplify this?
Yes, this is better, the instructions are zero extended, so no need
to use the bstrinsd instruction to clear the higher bits explicitly,
thanks for your suggestion.
I tested the changes, it works well, v3 is coming soon.
Thanks,
Tiezhu
next prev parent reply other threads:[~2026-04-13 4:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-07 6:23 [PATCH v2 0/5] LoongArch: BPF: Support more atomic instructions Tiezhu Yang
2026-04-07 6:23 ` [PATCH v2 1/5] LoongArch: Define format for AM{SWAP/ADD}.{B/H}, DBAR and BSTRINS.D Tiezhu Yang
2026-04-07 6:23 ` [PATCH v2 2/5] LoongArch: BPF: Add the default case in emit_atomic() and rename it Tiezhu Yang
2026-04-07 6:23 ` [PATCH v2 3/5] LoongArch: BPF: Support 8 and 16 bit read-modify-write instructions Tiezhu Yang
2026-04-07 6:23 ` [PATCH v2 4/5] LoongArch: BPF: Support load-acquire and store-release instructions Tiezhu Yang
2026-04-12 3:46 ` WANG Rui
2026-04-13 4:02 ` Tiezhu Yang [this message]
2026-04-07 6:23 ` [PATCH v2 5/5] selftests/bpf: Make CAN_USE_LOAD_ACQ_STORE_REL usable for LoongArch Tiezhu Yang
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=fa0a3521-7373-70d8-e08a-d2059fc62265@loongson.cn \
--to=yangtiezhu@loongson.cn \
--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=wangrui@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).