Skip to contentSkip to conversation

Fix SEGFAULT on getting physical address of MMIO region.

PATCH Superseded Mikhail Tyutin 2 participants 4 messages Aug 2, 2023 – Aug 9, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix SEGFAULT on getting physical address of MMIO region.

The fix is to clear TLB_INVALID_MASK bit in tlb_addr, as it happens in other places e.g. load_helper().

---
 accel/tcg/cputlb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
accel/tcg/cputlb.c +1 -1
index ba44501a7c..900dfc1079 100644
@@ -1735,7 +1735,7 @@ bool tlb_plugin_lookup(CPUState *cpu, vaddr addr, int mmu_idx,
     uintptr_t index = tlb_index(env, mmu_idx, addr);
     uint64_t tlb_addr = is_store ? tlb_addr_write(tlbe) : tlbe->addr_read;
 
-    if (likely(tlb_hit(tlb_addr, addr))) {
+    if (likely(tlb_hit(tlb_addr & ~TLB_INVALID_MASK, addr))) {
         /* We must have an iotlb entry for MMIO */
         if (tlb_addr & TLB_MMIO) {
             CPUTLBEntryFull *full;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 7 lines · Mikhail Tyutin

The fix is to clear TLB_INVALID_MASK bit in tlb_addr, as it happens in other places e.g. load_helper().

---
  accel/tcg/cputlb.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

The other places in load_helper happen only directly after tlb_fill has succeeded. Here you have no such guarantee.

I think perhaps the save_iotlb_data() call should be applied to loads as well, and then tlb_plugin_lookup simplified.

r~

#2 lore raw
Quoted 10 lines · Mikhail Tyutin
Quoted 8 lines

The fix is to clear TLB_INVALID_MASK bit in tlb_addr, as it happens in other places e.g. load_helper().

---
  accel/tcg/cputlb.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 6 lines

The other places in load_helper happen only directly after tlb_fill has succeeded. Here you have no such guarantee.

I think perhaps the save_iotlb_data() call should be applied to loads as well, and then tlb_plugin_lookup simplified.

Hello Richard,

We performed testing on more scenarios and noticed that patch when save_iotlb_data() call is added to io_readx
(https://patchew.org/QEMU/[email protected]/). It doesn't work for addresses in OCRAM region. Those accessed bypass io_writex/io_readx function and therefore don’t invoke save_iotlb_data(). So we observe the wrong value of cpu->saved_iotlb for it.

Would not be better to get back to initial v1 approach when we clean TLB_INVALID_MASK flag in tlb_plugin_lookup()? It works well for those regions.
(https://patchew.org/QEMU/[email protected])

#3 lore raw
Quoted 2 lines · Mikhail Tyutin

Would not be better to get back to initial v1 approach when we clean TLB_INVALID_MASK flag in tlb_plugin_lookup()? It works well for those regions.

You're just as likely to get invalid data.

r~