[PATCH] check loongarch64 vldi immediates Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2971 Signed-off-by: Lorenz Hetterich <lorenz.hetterich@cispa.de>

Lorenz Hetterich posted 1 patch 5 months, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20250522020837.9080-1-lorenz.hetterich@cispa.de
Maintainers: Song Gao <gaosong@loongson.cn>
target/loongarch/tcg/insn_trans/trans_vec.c.inc | 13 +++++++++++++
1 file changed, 13 insertions(+)
[PATCH] check loongarch64 vldi immediates Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2971 Signed-off-by: Lorenz Hetterich <lorenz.hetterich@cispa.de>
Posted by Lorenz Hetterich 5 months, 3 weeks ago
---
 target/loongarch/tcg/insn_trans/trans_vec.c.inc | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/target/loongarch/tcg/insn_trans/trans_vec.c.inc b/target/loongarch/tcg/insn_trans/trans_vec.c.inc
index dff92772ad..5589a9e865 100644
--- a/target/loongarch/tcg/insn_trans/trans_vec.c.inc
+++ b/target/loongarch/tcg/insn_trans/trans_vec.c.inc
@@ -3460,6 +3460,16 @@ TRANS(xvmskltz_d, LASX, gen_xx, gen_helper_vmskltz_d)
 TRANS(xvmskgez_b, LASX, gen_xx, gen_helper_vmskgez_b)
 TRANS(xvmsknz_b, LASX, gen_xx, gen_helper_vmsknz_b)
 
+static bool vldi_check_value(DisasContext *ctx, uint32_t imm)
+{
+    if (((imm >> 8) & 0xf) > 12) {
+        generate_exception(ctx, EXCCODE_INE);
+        return false;
+    }
+    return true;
+}
+
+
 #define EXPAND_BYTE(bit)  ((uint64_t)(bit ? 0xff : 0))
 
 static uint64_t vldi_get_value(DisasContext *ctx, uint32_t imm)
@@ -3588,6 +3598,9 @@ static bool gen_vldi(DisasContext *ctx, arg_vldi *a, uint32_t oprsz)
     sel = (a->imm >> 12) & 0x1;
 
     if (sel) {
+        if (!vldi_check_value(ctx, a->imm)) {
+            return true;
+        }
         value = vldi_get_value(ctx, a->imm);
         vece = MO_64;
     } else {
-- 
2.43.0
Re: [PATCH] check loongarch64 vldi immediates Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2971 Signed-off-by: Lorenz Hetterich <lorenz.hetterich@cispa.de>
Posted by gaosong 5 months, 3 weeks ago
在 2025/5/22 上午10:08, Lorenz Hetterich 写道:
> ---
>   target/loongarch/tcg/insn_trans/trans_vec.c.inc | 13 +++++++++++++
>   1 file changed, 13 insertions(+)
>
> diff --git a/target/loongarch/tcg/insn_trans/trans_vec.c.inc b/target/loongarch/tcg/insn_trans/trans_vec.c.inc
> index dff92772ad..5589a9e865 100644
> --- a/target/loongarch/tcg/insn_trans/trans_vec.c.inc
> +++ b/target/loongarch/tcg/insn_trans/trans_vec.c.inc
> @@ -3460,6 +3460,16 @@ TRANS(xvmskltz_d, LASX, gen_xx, gen_helper_vmskltz_d)
>   TRANS(xvmskgez_b, LASX, gen_xx, gen_helper_vmskgez_b)
>   TRANS(xvmsknz_b, LASX, gen_xx, gen_helper_vmsknz_b)
>   
> +static bool vldi_check_value(DisasContext *ctx, uint32_t imm)
> +{
> +    if (((imm >> 8) & 0xf) > 12) {
> +        generate_exception(ctx, EXCCODE_INE);
> +        return false;
> +    }
> +    return true;
> +}
> +
> +
>   #define EXPAND_BYTE(bit)  ((uint64_t)(bit ? 0xff : 0))
>   
>   static uint64_t vldi_get_value(DisasContext *ctx, uint32_t imm)
> @@ -3588,6 +3598,9 @@ static bool gen_vldi(DisasContext *ctx, arg_vldi *a, uint32_t oprsz)
>       sel = (a->imm >> 12) & 0x1;
>   
>       if (sel) {
> +        if (!vldi_check_value(ctx, a->imm)) {
> +            return true;
> +        }
Hi , sorry for not reply on gitlab,com,  my accout disabled.
this is incorrect ,  we should't skip  imm > 12.  imm > 12 is a invalid.
you can keep this patch  on your code if you want imm >12 not get  an error.

Thanks.
Song Gao

>           value = vldi_get_value(ctx, a->imm);
>           vece = MO_64;
>       } else {