qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] target/mips: fix TLB huge page check to use 64-bit shift
@ 2025-07-22 10:17 gerben
  2025-07-23 12:12 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 2+ messages in thread
From: gerben @ 2025-07-22 10:17 UTC (permalink / raw)
  To: qemu-devel, philmd; +Cc: sdl.qemu

From: Denis Rastyogin <gerben@altlinux.org>

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.

Signed-off-by: Denis Rastyogin <gerben@altlinux.org>
---
 target/mips/tcg/system/tlb_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/mips/tcg/system/tlb_helper.c b/target/mips/tcg/system/tlb_helper.c
index eccaf3624c..b8b8747064 100644
--- a/target/mips/tcg/system/tlb_helper.c
+++ b/target/mips/tcg/system/tlb_helper.c
@@ -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);
-- 
2.42.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] target/mips: fix TLB huge page check to use 64-bit shift
  2025-07-22 10:17 [PATCH] target/mips: fix TLB huge page check to use 64-bit shift gerben
@ 2025-07-23 12:12 ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-07-23 12:12 UTC (permalink / raw)
  To: gerben, qemu-devel; +Cc: sdl.qemu

Hi Denis,

On 22/7/25 12:17, gerben@altlinux.org wrote:
> From: Denis Rastyogin <gerben@altlinux.org>
> 
> 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.

> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Signed-off-by: Denis Rastyogin <gerben@altlinux.org>
> ---
>   target/mips/tcg/system/tlb_helper.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/target/mips/tcg/system/tlb_helper.c b/target/mips/tcg/system/tlb_helper.c
> index eccaf3624c..b8b8747064 100644
> --- a/target/mips/tcg/system/tlb_helper.c
> +++ b/target/mips/tcg/system/tlb_helper.c
> @@ -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);



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-07-23 12:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-22 10:17 [PATCH] target/mips: fix TLB huge page check to use 64-bit shift gerben
2025-07-23 12:12 ` Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).