]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
target/loongarch: fix bad shift in check_ps()
authorSong Gao <gaosong@loongson.cn>
Fri, 21 Mar 2025 01:13:58 +0000 (09:13 +0800)
committerBibo Mao <maobibo@loongson.cn>
Fri, 21 Mar 2025 03:31:56 +0000 (11:31 +0800)
In expression 1ULL << tlb_ps, left shifting by more than 63 bits has
undefined behavior. The shift amount, tlb_ps, is as much as 64. check
"tlb_ps >=64" to fix.

Resolves: Coverity CID 1593475

Fixes: d882c284a3 ("target/loongarch: check tlb_ps")
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Song Gao <gaosong@loongson.cn>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
target/loongarch/internals.h
target/loongarch/tcg/csr_helper.c
target/loongarch/tcg/tlb_helper.c

index 1cd959a76677390094aeac5f512f494c709d711a..9fdc3059d86dcffa8352ab83684dab59c4c3de5b 100644 (file)
@@ -43,7 +43,7 @@ enum {
     TLBRET_PE = 7,
 };
 
-bool check_ps(CPULoongArchState *ent, int ps);
+bool check_ps(CPULoongArchState *ent, uint8_t ps);
 
 extern const VMStateDescription vmstate_loongarch_cpu;
 
index 379c71e741343397af5c292f10efa90d4340abc5..6a7a65c860b2d3056d4ecd5e4d0ef85864407236 100644 (file)
@@ -115,7 +115,7 @@ target_ulong helper_csrwr_ticlr(CPULoongArchState *env, target_ulong val)
 
 target_ulong helper_csrwr_pwcl(CPULoongArchState *env, target_ulong val)
 {
-    int shift, ptbase;
+    uint8_t shift, ptbase;
     int64_t old_v = env->CSR_PWCL;
 
     /*
index 646dbf59de5cc06e2150fbd622b60219ad20d5a3..bd8081e886dd7fff034db79658935206d175bbe5 100644 (file)
 #include "exec/log.h"
 #include "cpu-csr.h"
 
-bool check_ps(CPULoongArchState *env, int tlb_ps)
+bool check_ps(CPULoongArchState *env, uint8_t tlb_ps)
 {
-     if (tlb_ps > 64) {
-         return false;
-     }
-     return BIT_ULL(tlb_ps) & (env->CSR_PRCFG2);
+    if (tlb_ps >= 64) {
+        return false;
+    }
+    return BIT_ULL(tlb_ps) & (env->CSR_PRCFG2);
 }
 
 void get_dir_base_width(CPULoongArchState *env, uint64_t *dir_base,