Skip to contentSkip to conversation

cputlb: cast size_t to target_ulong before using for address masks

PATCH In review Alex Bennée 4 participants 6 messages Jun 6, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cputlb: cast size_t to target_ulong before using for address masks

While size_t is defined to happily access the biggest host object this isn't the case when generating masks for 64 bit guests on 32 bit hosts. Otherwise we end up truncating the address when we fall back to our unaligned helper.

Cc Andrew Randrianasulu <[email protected]>
---
 accel/tcg/cputlb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
accel/tcg/cputlb.c +1 -1
index b796ab1cbe..8f814a1a2c 100644
@@ -1306,7 +1306,7 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi,
         uint64_t r1, r2;
         unsigned shift;
     do_unaligned_access:
-        addr1 = addr & ~(size - 1);
+        addr1 = addr & ~((target_ulong)size - 1);
         addr2 = addr1 + size;
         r1 = full_load(env, addr1, oi, retaddr);
         r2 = full_load(env, addr2, oi, retaddr);
Signature · 1 line
2.20.1
#1 lore raw

В сообщении от Thursday 06 June 2019 18:43:10 Alex Bennée написал(а):

Quoted 1 line

addr1 = addr & ~((target_ulong)size - 1);

yes, this fixes my hang! Thanks!

author Tested-by Andrew Randrianasulu
#2 lore raw
Quoted 4 lines · Andrew Randrianasulu

В сообщении от Thursday 06 June 2019 18:43:10 Alex Bennée написал(а):

Quoted 1 line

addr1 = addr & ~((target_ulong)size - 1);

yes, this fixes my hang! Thanks!

Can I take that as a:

?

--
Alex Bennée

#3 lore raw

В сообщении от Thursday 06 June 2019 20:04:07 Alex Bennée написал(а):

Quoted 6 lines
Quoted 3 lines · Andrew Randrianasulu

В сообщении от Thursday 06 June 2019 18:43:10 Alex Bennée написал(а):

Quoted 1 line

addr1 = addr & ~((target_ulong)size - 1);

Quoted 7 lines
Quoted 1 line

yes, this fixes my hang! Thanks!

Can I take that as a:

?

Yes, while I only tested 64-bit x86-64 kernel on 32-bit x86 host, not other machines.

Quoted 4 lines

--
Alex Bennée

Reviewed-by on v1 1/1
#4 lore raw
In reply to Alex Bennée
Quoted 10 lines · Alex Bennée

While size_t is defined to happily access the biggest host object this isn't the case when generating masks for 64 bit guests on 32 bit hosts. Otherwise we end up truncating the address when we fall back to our unaligned helper.

Cc Andrew Randrianasulu <[email protected]>
---
 accel/tcg/cputlb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

r~

Reviewed-by on v1 1/1
#5 lore raw
In reply to Alex Bennée
Quoted 6 lines · Alex Bennée

While size_t is defined to happily access the biggest host object this isn't the case when generating masks for 64 bit guests on 32 bit hosts. Otherwise we end up truncating the address when we fall back to our unaligned helper.

Cc Andrew Randrianasulu <[email protected]>
Quoted 10 lines
---
 accel/tcg/cputlb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
accel/tcg/cputlb.c +0 -0
index b796ab1cbe..8f814a1a2c 100644

accel/tcg/cputlb.c load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, · line 1309

Quoted 5 lines
accel/tcg/cputlb.c +1 -1
@@ -1306,7 +1306,7 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi,
         uint64_t r1, r2;
         unsigned shift;
     do_unaligned_access:
-        addr1 = addr & ~(size - 1);
+        addr1 = addr & ~((target_ulong)size - 1);

Tricky...

Quoted 4 lines
accel/tcg/cputlb.c +0 -0
         addr2 = addr1 + size;
         r1 = full_load(env, addr1, oi, retaddr);
         r2 = full_load(env, addr2, oi, retaddr);