target/loongarch: fix bad shift in check_ps()

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>
This commit is contained in:
Song Gao 2025-03-21 09:13:58 +08:00 committed by Bibo Mao
parent 1267e1ddeb
commit b8d5503a3e
3 changed files with 7 additions and 7 deletions

View 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;

View 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;
/*

View File

@ -19,12 +19,12 @@
#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,