Skip to contentSkip to conversation

target/mips: fix TLB huge page check to use 64-bit shift

PATCH Superseded [email protected] 2 participants 2 messages Jul 22, 2025 – Jul 23, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/mips: fix TLB huge page check to use 64-bit shift

From: Denis Rastyogin <[email protected]>

Use 1ULL << psn to ensure the shift is done in 64-bit arithmetic, avoiding overflow for large psn values. The 6-bit psn field allows values up to 63, so 64-bit shift is required for correctness.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 target/mips/tcg/system/tlb_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/mips/tcg/system/tlb_helper.c +1 -1
index eccaf3624c..b8b8747064 100644
@@ -652,7 +652,7 @@ static int walk_directory(CPUMIPSState *env, uint64_t *vaddr,
         return 0;
     }
 
-    if ((entry & (1 << psn)) && hugepg) {
+    if ((entry & (1ULL << psn)) && hugepg) {
         *huge_page = true;
         *hgpg_directory_hit = true;
         entry = get_tlb_entry_layout(env, entry, leaf_mop, pf_ptew);
Signature · 1 line
2.42.2
#1 lore raw

Hi Denis,

Quoted 5 lines · On 22/7/25 12:17, [email protected] wrote:

From: Denis Rastyogin <[email protected]>

Use 1ULL << psn to ensure the shift is done in 64-bit arithmetic, avoiding overflow for large psn values. The 6-bit psn field allows values up to 63, so 64-bit shift is required for correctness.

If you are really worried about that, please use the simpler extract64() method instead, it is much clearer to understand when reviewing than (unsigned long long) casts.

Quoted 21 lines

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
  target/mips/tcg/system/tlb_helper.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/mips/tcg/system/tlb_helper.c +1 -1
index eccaf3624c..b8b8747064 100644
@@ -652,7 +652,7 @@ static int walk_directory(CPUMIPSState *env, uint64_t *vaddr,
          return 0;
      }
 
-    if ((entry & (1 << psn)) && hugepg) {
+    if ((entry & (1ULL << psn)) && hugepg) {
          *huge_page = true;
          *hgpg_directory_hit = true;
          entry = get_tlb_entry_layout(env, entry, leaf_mop, pf_ptew);