mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: George Guo <dongtai.guo@linux.dev>
To: chenhuacai@kernel.org, yangtiezhu@loongson.cn
Cc: hengqi.chen@gmail.com, guodongtai@kylinos.cn,
	bpf@vger.kernel.org, loongarch@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: [PATCH v4 5/6] LoongArch: BPF: Consolidate zero-extension in emit_atomic_rmw()
Date: Tue,  1 Dec 2026 01:51:05 -0800	[thread overview]
Message-ID: <20261201095106.468000-6-dongtai.guo@linux.dev> (raw)
In-Reply-To: <20261201095106.468000-1-dongtai.guo@linux.dev>

From: George Guo <guodongtai@kylinos.cn>

Currently, emit_atomic_rmw() emits 'bstrpickd' right after the 32-bit
fetch and xchg instructions in five places, to zero-extend the old value
loaded into src.

In order to support atomics on arena, a later patch adds an exception
table entry for the memory access instruction. add_exception_handler()
takes the last emitted instruction as the one that can fault, so the
zero-extension must come after the entry is added.

So set a zext flag in these five places instead, and emit 'bstrpickd'
once after the switch statement. The emitted instructions are the same.

This is preparation for later patch, no functional changes.

Signed-off-by: George Guo <guodongtai@kylinos.cn>
---
 arch/loongarch/net/bpf_jit.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
index 423c9807a84a..b78d38559598 100644
--- a/arch/loongarch/net/bpf_jit.c
+++ b/arch/loongarch/net/bpf_jit.c
@@ -461,6 +461,7 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)
 	const s16 off = insn->off;
 	const s32 imm = insn->imm;
 	const bool isdw = BPF_SIZE(insn->code) == BPF_DW;
+	bool zext = false;
 
 	move_imm(ctx, t1, off);
 	emit_insn(ctx, addd, t1, dst, t1);
@@ -534,15 +535,14 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)
 			emit_insn(ctx, amadddbd, src, t1, t3);
 			break;
 		}
-		if (!isdw)
-			emit_insn(ctx, bstrpickd, src, src, 31, 0);
+		zext = !isdw;
 		break;
 	case BPF_AND | BPF_FETCH:
 		if (isdw) {
 			emit_insn(ctx, amanddbd, src, t1, t3);
 		} else {
 			emit_insn(ctx, amanddbw, src, t1, t3);
-			emit_insn(ctx, bstrpickd, src, src, 31, 0);
+			zext = true;
 		}
 		break;
 	case BPF_OR | BPF_FETCH:
@@ -550,7 +550,7 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)
 			emit_insn(ctx, amordbd, src, t1, t3);
 		} else {
 			emit_insn(ctx, amordbw, src, t1, t3);
-			emit_insn(ctx, bstrpickd, src, src, 31, 0);
+			zext = true;
 		}
 		break;
 	case BPF_XOR | BPF_FETCH:
@@ -558,7 +558,7 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)
 			emit_insn(ctx, amxordbd, src, t1, t3);
 		} else {
 			emit_insn(ctx, amxordbw, src, t1, t3);
-			emit_insn(ctx, bstrpickd, src, src, 31, 0);
+			zext = true;
 		}
 		break;
 	/* src = atomic_xchg(dst + off, src); */
@@ -585,8 +585,7 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)
 			emit_insn(ctx, amswapdbd, src, t1, t3);
 			break;
 		}
-		if (!isdw)
-			emit_insn(ctx, bstrpickd, src, src, 31, 0);
+		zext = !isdw;
 		break;
 	/* r0 = atomic_cmpxchg(dst + off, r0, src); */
 	case BPF_CMPXCHG:
@@ -614,6 +613,9 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)
 		return -EINVAL;
 	}
 
+	if (zext)
+		emit_insn(ctx, bstrpickd, src, src, 31, 0);
+
 	return 0;
 }
 
-- 
2.53.0


  parent reply	other threads:[~2026-12-01  9:51 UTC|newest]

Thread overview: 7+ 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 ` George Guo [this message]
2026-12-01  9:51 ` [PATCH v4 6/6] LoongArch: BPF: Add support for arena atomics George Guo

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=20261201095106.468000-6-dongtai.guo@linux.dev \
    --to=dongtai.guo@linux.dev \
    --cc=bpf@vger.kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=guodongtai@kylinos.cn \
    --cc=hengqi.chen@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongarch@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®