Skip to contentSkip to conversation

Revert "LoongArch: BPF: Sign extend kfunc call arguments"

PATCH In review Wentao Guan 2 participants 5 messages Jan 14 – Feb 3

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Revert "LoongArch: BPF: Sign extend kfunc call arguments"

It cause loongarch build failed. it need merge more depends, such as "LoongArch: Add more instruction opcodes and emit_* helpers" This reverts commit fd43edf357a3a1f5ed1c4bf450b60001c9091c39.

config: https://gist.github.com/opsiff/b6c9c32ade5f6d4abb5454a476f4c4e1

---
 arch/loongarch/net/bpf_jit.c | 16 ----------------
 arch/loongarch/net/bpf_jit.h | 26 --------------------------
 2 files changed, 42 deletions(-)
arch/loongarch/net/bpf_jit.c +0 -16
index 54661cffd654f..c6400d7b95ee8 100644
@@ -834,22 +834,6 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
 		if (ret < 0)
 			return ret;
 
-		if (insn->src_reg == BPF_PSEUDO_KFUNC_CALL) {
-			const struct btf_func_model *m;
-			int i;
-
-			m = bpf_jit_find_kfunc_model(ctx->prog, insn);
-			if (!m)
-				return -EINVAL;
-
-			for (i = 0; i < m->nr_args; i++) {
-				u8 reg = regmap[BPF_REG_1 + i];
-				bool sign = m->arg_flags[i] & BTF_FMODEL_SIGNED_ARG;
-
-				emit_abi_ext(ctx, reg, m->arg_size[i], sign);
-			}
-		}
-
 		move_addr(ctx, t1, func_addr);
 		emit_insn(ctx, jirl, LOONGARCH_GPR_RA, t1, 0);
 
arch/loongarch/net/bpf_jit.h +0 -26
index 9352ea5545308..f9c569f539491 100644
@@ -87,32 +87,6 @@ static inline void emit_sext_32(struct jit_ctx *ctx, enum loongarch_gpr reg, boo
 	emit_insn(ctx, addiw, reg, reg, 0);
 }
 
-/* Emit proper extension according to ABI requirements.
- * Note that it requires a value of size `size` already resides in register `reg`.
- */
-static inline void emit_abi_ext(struct jit_ctx *ctx, int reg, u8 size, bool sign)
-{
-	/* ABI requires unsigned char/short to be zero-extended */
-	if (!sign && (size == 1 || size == 2))
-		return;
-
-	switch (size) {
-	case 1:
-		emit_insn(ctx, extwb, reg, reg);
-		break;
-	case 2:
-		emit_insn(ctx, extwh, reg, reg);
-		break;
-	case 4:
-		emit_insn(ctx, addiw, reg, reg, 0);
-		break;
-	case 8:
-		break;
-	default:
-		pr_warn("bpf_jit: invalid size %d for extension\n", size);
-	}
-}
-
 static inline void move_addr(struct jit_ctx *ctx, enum loongarch_gpr rd, u64 addr)
 {
 	u64 imm_11_0, imm_31_12, imm_51_32, imm_63_52;
#1 lore raw

Hello All,

I think the best way is backport add28024405ed600afaa02749989d4fd119f9057, ("LoongArch: Add more instruction opcodes and emit_* helpers") I test when cherry-pick it, it build ok.

BRs
Wentao Guan

From fd6e09e78813b62fe1f4c49dc20255b4e4144e2d Mon Sep 17 00:00:00 2001
From: Hengqi Chen <[email protected]>
Date: Wed, 8 Nov 2023 14:12:15 +0800
Subject: [PATCH] LoongArch: Add more instruction opcodes and emit_* helpers

This patch adds more instruction opcodes and their corresponding emit_* helpers which will be used in later patches.

(cherry picked from commit add28024405ed600afaa02749989d4fd119f9057)
---
 arch/loongarch/include/asm/inst.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
arch/loongarch/include/asm/inst.h +13 -0
index 4fa53ad82efb3..964258e2972e9 100644
@@ -65,6 +65,8 @@ enum reg2_op {
        revbd_op        = 0x0f,
        revh2w_op       = 0x10,
        revhd_op        = 0x11,
+       extwh_op        = 0x16,
+       extwb_op        = 0x17,
 };
 
 enum reg2i5_op {
@@ -556,6 +558,8 @@ static inline void emit_##NAME(union loongarch_instruction *insn,   \
 DEF_EMIT_REG2_FORMAT(revb2h, revb2h_op)
 DEF_EMIT_REG2_FORMAT(revb2w, revb2w_op)
 DEF_EMIT_REG2_FORMAT(revbd, revbd_op)
+DEF_EMIT_REG2_FORMAT(extwh, extwh_op)
+DEF_EMIT_REG2_FORMAT(extwb, extwb_op)
 
 #define DEF_EMIT_REG2I5_FORMAT(NAME, OP)                               \
 static inline void emit_##NAME(union loongarch_instruction *insn,      \
@@ -607,6 +611,9 @@ DEF_EMIT_REG2I12_FORMAT(lu52id, lu52id_op)
 DEF_EMIT_REG2I12_FORMAT(andi, andi_op)
 DEF_EMIT_REG2I12_FORMAT(ori, ori_op)
 DEF_EMIT_REG2I12_FORMAT(xori, xori_op)
+DEF_EMIT_REG2I12_FORMAT(ldb, ldb_op)
+DEF_EMIT_REG2I12_FORMAT(ldh, ldh_op)
+DEF_EMIT_REG2I12_FORMAT(ldw, ldw_op)
 DEF_EMIT_REG2I12_FORMAT(ldbu, ldbu_op)
 DEF_EMIT_REG2I12_FORMAT(ldhu, ldhu_op)
 DEF_EMIT_REG2I12_FORMAT(ldwu, ldwu_op)
@@ -695,9 +702,12 @@ static inline void emit_##NAME(union loongarch_instruction *insn,  \
        insn->reg3_format.rk = rk;                                      \
 }
 
+DEF_EMIT_REG3_FORMAT(addw, addw_op)
 DEF_EMIT_REG3_FORMAT(addd, addd_op)
 DEF_EMIT_REG3_FORMAT(subd, subd_op)
 DEF_EMIT_REG3_FORMAT(muld, muld_op)
+DEF_EMIT_REG3_FORMAT(divd, divd_op)
+DEF_EMIT_REG3_FORMAT(modd, modd_op)
 DEF_EMIT_REG3_FORMAT(divdu, divdu_op)
 DEF_EMIT_REG3_FORMAT(moddu, moddu_op)
 DEF_EMIT_REG3_FORMAT(and, and_op)
@@ -709,6 +719,9 @@ DEF_EMIT_REG3_FORMAT(srlw, srlw_op)
 DEF_EMIT_REG3_FORMAT(srld, srld_op)
 DEF_EMIT_REG3_FORMAT(sraw, sraw_op)
 DEF_EMIT_REG3_FORMAT(srad, srad_op)
+DEF_EMIT_REG3_FORMAT(ldxb, ldxb_op)
+DEF_EMIT_REG3_FORMAT(ldxh, ldxh_op)
+DEF_EMIT_REG3_FORMAT(ldxw, ldxw_op)
 DEF_EMIT_REG3_FORMAT(ldxbu, ldxbu_op)
 DEF_EMIT_REG3_FORMAT(ldxhu, ldxhu_op)
 DEF_EMIT_REG3_FORMAT(ldxwu, ldxwu_op)
Signature · 1 line
2.20.1
maintainer
#2 lore raw
Quoted 5 lines · Wentao Guan

Hello All,

I think the best way is backport add28024405ed600afaa02749989d4fd119f9057, ("LoongArch: Add more instruction opcodes and emit_* helpers") I test when cherry-pick it, it build ok.

Great, I'll do that instead, thanks!

greg k-h

#3 lore raw

PATCH 1/1 ALSA: usb-audio: Fix missing unlock at error path of maxpacksize check

In reply to Wentao Guan

I found that patch which in v6.12.60 should be applied in v6.6-stable tree.

From: Takashi Iwai <[email protected]>

The recent backport of the upstream commit 05a1fc5efdd8 ("ALSA:
usb-audio: Fix potential overflow of PCM transfer buffer") on the older stable kernels like 6.12.y was broken since it doesn't consider the mutex unlock, where the upstream code manages with guard(). In the older code, we still need an explicit unlock.

This is a fix that corrects the error path, applied only on old stable trees.

Fixes 98e9d5e33bda ("ALSA: usb-audio: Fix potential overflow of PCM transfer buffer")
(cherry picked from commit fdf0dc82eb60091772ecea73cbc5a8fb7562fc45)
---
 sound/usb/endpoint.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/usb/endpoint.c +2 -1
index 7238f65cbcfff..aa201e4744bf6 100644
@@ -1389,7 +1389,8 @@ int snd_usb_endpoint_set_params(struct snd_usb_audio *chip,
        if (ep->packsize[1] > ep->maxpacksize) {
                usb_audio_dbg(chip, "Too small maxpacksize %u for rate %u / pps %u\n",
                              ep->maxpacksize, ep->cur_rate, ep->pps);
-               return -EINVAL;
+               err = -EINVAL;
+               goto unlock;
        }
 
        /* calculate the frequency in 16.16 format */
Signature · 1 line
2.51.0
maintainer
#4 lore raw

Re: [PATCH 6.6] ALSA: usb-audio: Fix missing unlock at error path of maxpacksize check

Quoted 21 lines · Wentao Guan

I found that patch which in v6.12.60 should be applied in v6.6-stable tree.

From: Takashi Iwai <[email protected]>

The recent backport of the upstream commit 05a1fc5efdd8 ("ALSA:
usb-audio: Fix potential overflow of PCM transfer buffer") on the older stable kernels like 6.12.y was broken since it doesn't consider the mutex unlock, where the upstream code manages with guard(). In the older code, we still need an explicit unlock.

This is a fix that corrects the error path, applied only on old stable trees.

Fixes 98e9d5e33bda ("ALSA: usb-audio: Fix potential overflow of PCM transfer buffer")
(cherry picked from commit fdf0dc82eb60091772ecea73cbc5a8fb7562fc45)
Quoted 3 lines
---
 sound/usb/endpoint.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

This does not apply to the 6.6.y kernel tree :(

Please fix up and resend.

thanks,

greg k-h