在 2025/3/20 下午4:49, bibo mao 写道:
On 2025/3/19 上午9:41, Song Gao wrote:
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.mayd...@linaro.org>
Signed-off-by: Song Gao <gaos...@loongson.cn>
---
target/loongarch/tcg/tlb_helper.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/target/loongarch/tcg/tlb_helper.c
b/target/loongarch/tcg/tlb_helper.c
index 646dbf59de..e960adad4d 100644
--- a/target/loongarch/tcg/tlb_helper.c
+++ b/target/loongarch/tcg/tlb_helper.c
@@ -21,10 +21,10 @@
bool check_ps(CPULoongArchState *env, int tlb_ps)
{
- if (tlb_ps > 64) {
- return false;
- }
- return BIT_ULL(tlb_ps) & (env->CSR_PRCFG2);
+ if (tlb_ps >= 64) {
+ return false;
+ }
Do we need check (tlb_ps < 0) || (tlb_ps >= 64)? or define parameter
tlb_ps as uint type.
hi, Peter and RIchard, what's your opinion?
I 'll define parameter tlb_ps as uint type on v2.
Thanks.
Song Gao
Regards
Bibo Mao
+ return BIT_ULL(tlb_ps) & (env->CSR_PRCFG2);
}
void get_dir_base_width(CPULoongArchState *env, uint64_t *dir_base,