Skip to content

Commit b8d5503

Browse files
gaosong-loongsonbibo-mao
authored andcommitted
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: d882c28 ("target/loongarch: check tlb_ps") Suggested-by: Peter Maydell <[email protected]> Signed-off-by: Song Gao <[email protected]> Reviewed-by: Bibo Mao <[email protected]> Signed-off-by: Bibo Mao <[email protected]>
1 parent 1267e1d commit b8d5503

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

target/loongarch/internals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ enum {
4343
TLBRET_PE = 7,
4444
};
4545

46-
bool check_ps(CPULoongArchState *ent, int ps);
46+
bool check_ps(CPULoongArchState *ent, uint8_t ps);
4747

4848
extern const VMStateDescription vmstate_loongarch_cpu;
4949

target/loongarch/tcg/csr_helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ target_ulong helper_csrwr_ticlr(CPULoongArchState *env, target_ulong val)
115115

116116
target_ulong helper_csrwr_pwcl(CPULoongArchState *env, target_ulong val)
117117
{
118-
int shift, ptbase;
118+
uint8_t shift, ptbase;
119119
int64_t old_v = env->CSR_PWCL;
120120

121121
/*

target/loongarch/tcg/tlb_helper.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
#include "exec/log.h"
2020
#include "cpu-csr.h"
2121

22-
bool check_ps(CPULoongArchState *env, int tlb_ps)
22+
bool check_ps(CPULoongArchState *env, uint8_t tlb_ps)
2323
{
24-
if (tlb_ps > 64) {
25-
return false;
26-
}
27-
return BIT_ULL(tlb_ps) & (env->CSR_PRCFG2);
24+
if (tlb_ps >= 64) {
25+
return false;
26+
}
27+
return BIT_ULL(tlb_ps) & (env->CSR_PRCFG2);
2828
}
2929

3030
void get_dir_base_width(CPULoongArchState *env, uint64_t *dir_base,

0 commit comments

Comments
 (0)