Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.104 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796118703; b=CKASVS2tFKjKPooiETHyMtGZBVBhLFgodD8pWZSZc9DFYliUk3B3zOTZdrB5LaBO+oIg 0Qr3HXlywH3RJh1av5ElAPEPiqKwC2iKbsZirVDVyOO0NLEPP6DiUPJiF2f0leQe4ZlNB 31O8pgqTMD8yNzpjgAdAgee58HCn5v6dMspnpJWouh06bl50+Cvcou3fBe1K8Dj15pgJZ H4Hd/WhMyxqzhUcAmTdj8HtWLMTCTHpAvcQwv7mrNKIulSxyyqb6xyys0knd1N50PYN1d w6mDjl/YCZ5p26rRMA9vE5+3Uaw+9vAJpG/nNAg8gLoR5vxD+u8vYbpFUf1hj6hzaDw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796118703; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=dqD6dEh5/YUgvA5AWbJT2iNmiJIJ0POJB0CBkvnQMT0=; b=DcaRwMfMzKIeYe8Uhgbfzm3KjRKwiltoTJ7dK7v36rQU6XSoE/jG+ad6w3bd9ycl4mX0 h7YOiKxAyYSY697gpf9Co2KBhnAgmjSJpq93ode2Z/27EK1/7yfgfgNUZqlodNOoFqw7x Ak0Mi2prO5JCHc2kG4rGJ3B/klGavw0zjRSuHG4XxJVQvR0y6t5Q+NH9WOPgLlwXt9aON r6GmI+ZYhFh/0Mk0iuGlCEQ2ZhYPxKzpGtMHf/6o1THkXl7RMQ5yeR5W1aouoNad4Os5Q KxtTMLJH44qFrzoe3FPgaenBUaQ/QiNr/29RQt9NbmOYsMvTQq5ZNWyUwguTRPPaKdg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=HqBi40kd; arc=none smtp.remote-ip=91.218.175.104 Received: from mta0.migadu.com (out-104.mta0.migadu.com [91.218.175.104]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C66D1606A334 for ; Tue, 1 Dec 2026 09:51:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C66D1606A334 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=HqBi40kd X-Envelope-To: bpf@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=qQ0jico/PtejuPmwPGKlZZzu45maoEh3vwMgN6SMLaE=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796118700; v=1; x=1796723500; b=HqBi40kdc8Qfvq/yGA9YNSDbx0xhLgMosGo8nwFNahxQaLM21RBZqTpFDn/16WLk36tC6l5F DkRbemGfH9sm9e2NzAJFGuktG1CIicYmW+Y7zsDDKJPOvgQ440dLgvNCRagLtung8QhG8/8ZZR8 S9DIFYrhnX92V0Mz3Ed27AO8= X-Envelope-To: bpf@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 3f4a30efdfc1730d; Tue, 01 Dec 2026 09:51:40 +0000 X-Mizu-Trace-ID: 3f4a30efdfc1730d X-Migadu-Flow: FLOW_OUT From: George Guo 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 Message-ID: <20261201095106.468000-6-dongtai.guo@linux.dev> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201095106.468000-1-dongtai.guo@linux.dev> References: <20261201095106.468000-1-dongtai.guo@linux.dev> X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: George Guo 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 --- 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