Skip to contentSkip to conversation

tcg: gdbstub: Fix missing breakpoint issue

PATCH In review Changbin Du 2 participants 4 messages Jan 24, 2020 – Feb 6, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcg: gdbstub: Fix missing breakpoint issue

When inserting breakpoints, we need to invalidate related TBs to apply helper call. This is done by breakpoint_invalidate(). But many users found the BPs sometimes never hit.

In system mode emulation, the BPs are global in guest but not particular address space. The issue is that the current implementation only trys to invalidate TB of paddr corresponding to the target vaddr in current MMU context. Then some cached TBs continue running without BPs applied.

To fix this issue, we can just invalidate all TBs as what step mode does. (For old version users, issuing a step command can workaround this problem.)

---
 exec.c | 29 +----------------------------
 1 file changed, 1 insertion(+), 28 deletions(-)
exec.c +1 -28
index 67e520d18e..9d9fd48519 100644
@@ -997,36 +997,9 @@ static void breakpoint_invalidate(CPUState *cpu, target_ulong pc)
     tb_invalidate_phys_addr(pc);
 }
 #else
-void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs)
-{
-    ram_addr_t ram_addr;
-    MemoryRegion *mr;
-    hwaddr l = 1;
-
-    if (!tcg_enabled()) {
-        return;
-    }
-
-    RCU_READ_LOCK_GUARD();
-    mr = address_space_translate(as, addr, &addr, &l, false, attrs);
-    if (!(memory_region_is_ram(mr)
-          || memory_region_is_romd(mr))) {
-        return;
-    }
-    ram_addr = memory_region_get_ram_addr(mr) + addr;
-    tb_invalidate_phys_page_range(ram_addr, ram_addr + 1);
-}
-
 static void breakpoint_invalidate(CPUState *cpu, target_ulong pc)
 {
-    MemTxAttrs attrs;
-    hwaddr phys = cpu_get_phys_page_attrs_debug(cpu, pc, &attrs);
-    int asidx = cpu_asidx_from_attrs(cpu, attrs);
-    if (phys != -1) {
-        /* Locks grabbed by tb_invalidate_phys_addr */
-        tb_invalidate_phys_addr(cpu->cpu_ases[asidx].as,
-                                phys | (pc & ~TARGET_PAGE_MASK), attrs);
-    }
+    tb_flush(cpu);
 }
 #endif
 
Signature · 1 line
2.24.0
#1 lore raw

Hello,
Any review?
Thanks!

Quoted 62 lines · Changbin Du

When inserting breakpoints, we need to invalidate related TBs to apply helper call. This is done by breakpoint_invalidate(). But many users found the BPs sometimes never hit.

In system mode emulation, the BPs are global in guest but not particular address space. The issue is that the current implementation only trys to invalidate TB of paddr corresponding to the target vaddr in current MMU context. Then some cached TBs continue running without BPs applied.

To fix this issue, we can just invalidate all TBs as what step mode does. (For old version users, issuing a step command can workaround this problem.)

---
 exec.c | 29 +----------------------------
 1 file changed, 1 insertion(+), 28 deletions(-)
exec.c +1 -28
index 67e520d18e..9d9fd48519 100644
@@ -997,36 +997,9 @@ static void breakpoint_invalidate(CPUState *cpu, target_ulong pc)
     tb_invalidate_phys_addr(pc);
 }
 #else
-void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs)
-{
-    ram_addr_t ram_addr;
-    MemoryRegion *mr;
-    hwaddr l = 1;
-
-    if (!tcg_enabled()) {
-        return;
-    }
-
-    RCU_READ_LOCK_GUARD();
-    mr = address_space_translate(as, addr, &addr, &l, false, attrs);
-    if (!(memory_region_is_ram(mr)
-          || memory_region_is_romd(mr))) {
-        return;
-    }
-    ram_addr = memory_region_get_ram_addr(mr) + addr;
-    tb_invalidate_phys_page_range(ram_addr, ram_addr + 1);
-}
-
 static void breakpoint_invalidate(CPUState *cpu, target_ulong pc)
 {
-    MemTxAttrs attrs;
-    hwaddr phys = cpu_get_phys_page_attrs_debug(cpu, pc, &attrs);
-    int asidx = cpu_asidx_from_attrs(cpu, attrs);
-    if (phys != -1) {
-        /* Locks grabbed by tb_invalidate_phys_addr */
-        tb_invalidate_phys_addr(cpu->cpu_ases[asidx].as,
-                                phys | (pc & ~TARGET_PAGE_MASK), attrs);
-    }
+    tb_flush(cpu);
 }
 #endif
 
Signature · 1 line
2.24.0
Signature · 2 lines
Cheers,
Changbin Du
#2 lore raw
In reply to Changbin Du
Quoted 22 lines · Changbin Du

When inserting breakpoints, we need to invalidate related TBs to apply helper call. This is done by breakpoint_invalidate(). But many users found the BPs sometimes never hit.

In system mode emulation, the BPs are global in guest but not particular address space. The issue is that the current implementation only trys to invalidate TB of paddr corresponding to the target vaddr in current MMU context. Then some cached TBs continue running without BPs applied.

To fix this issue, we can just invalidate all TBs as what step mode does. (For old version users, issuing a step command can workaround this problem.)

---
 exec.c | 29 +----------------------------
 1 file changed, 1 insertion(+), 28 deletions(-)
exec.c +0 -0
index 67e520d18e..9d9fd48519 100644

exec.c static void breakpoint_invalidate(CPUState *cpu, target_ulong pc) · line 1000

Quoted 4 lines
exec.c +0 -1
@@ -997,36 +997,9 @@ static void breakpoint_invalidate(CPUState *cpu, target_ulong pc)
     tb_invalidate_phys_addr(pc);
 }
 #else
-void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs)

You can't remove this function yet.
You should have seen that xtensa-softmmu no longer builds.

I've cc'd you into Max Filippov's thread that addresses the same problem, and I'm going to apply his fix for now.

r~

Quoted 34 lines
exec.c +1 -27
-{
-    ram_addr_t ram_addr;
-    MemoryRegion *mr;
-    hwaddr l = 1;
-
-    if (!tcg_enabled()) {
-        return;
-    }
-
-    RCU_READ_LOCK_GUARD();
-    mr = address_space_translate(as, addr, &addr, &l, false, attrs);
-    if (!(memory_region_is_ram(mr)
-          || memory_region_is_romd(mr))) {
-        return;
-    }
-    ram_addr = memory_region_get_ram_addr(mr) + addr;
-    tb_invalidate_phys_page_range(ram_addr, ram_addr + 1);
-}
-
 static void breakpoint_invalidate(CPUState *cpu, target_ulong pc)
 {
-    MemTxAttrs attrs;
-    hwaddr phys = cpu_get_phys_page_attrs_debug(cpu, pc, &attrs);
-    int asidx = cpu_asidx_from_attrs(cpu, attrs);
-    if (phys != -1) {
-        /* Locks grabbed by tb_invalidate_phys_addr */
-        tb_invalidate_phys_addr(cpu->cpu_ases[asidx].as,
-                                phys | (pc & ~TARGET_PAGE_MASK), attrs);
-    }
+    tb_flush(cpu);
 }
 #endif
 
#3 lore raw
Quoted 31 lines · Richard Henderson
Quoted 22 lines · Changbin Du

When inserting breakpoints, we need to invalidate related TBs to apply helper call. This is done by breakpoint_invalidate(). But many users found the BPs sometimes never hit.

In system mode emulation, the BPs are global in guest but not particular address space. The issue is that the current implementation only trys to invalidate TB of paddr corresponding to the target vaddr in current MMU context. Then some cached TBs continue running without BPs applied.

To fix this issue, we can just invalidate all TBs as what step mode does. (For old version users, issuing a step command can workaround this problem.)

---
 exec.c | 29 +----------------------------
 1 file changed, 1 insertion(+), 28 deletions(-)
exec.c +0 -0
index 67e520d18e..9d9fd48519 100644

exec.c static void breakpoint_invalidate(CPUState *cpu, target_ulong pc) · line 1000

Quoted 4 lines
exec.c +0 -1
@@ -997,36 +997,9 @@ static void breakpoint_invalidate(CPUState *cpu, target_ulong pc)
     tb_invalidate_phys_addr(pc);
 }
 #else
-void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs)

You can't remove this function yet.
You should have seen that xtensa-softmmu no longer builds.

Quoted 6 lines

I've cc'd you into Max Filippov's thread that addresses the same problem, and I'm going to apply his fix for now.

r~

Got it, just go ahead with that one. thanks~

Signature · 2 lines
Cheers,
Changbin Du