exec: flush the whole TLB if a watchpoint crosses a page boundary
RFC PATCH 1/1 exec: flush the whole TLB if a watchpoint crosses a page boundary
There is no particular reason why you can't have a watchpoint in TCG that covers a large chunk of the address space. We could be clever about it but these cases are pretty rare and we can assume the user will expect a little performance degradation.
NB: In my testing gdb will silently squash a watchpoint like:
watch (char[0x7fffffffff]) *0x0
to a 4 byte watchpoint. Practically it will limit the maximum size based on max-value-size. However given enough of a tweak the sky is the limit.
--- exec.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
exec.c +5 -1
@@ -1056,7 +1056,11 @@ int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,QTAILQ_INSERT_TAIL (&cpu->watchpoints, wp, entry); } -tlb_flush_page (cpu, addr); +if (((addr + len) &TARGET_PAGE_MASK ) != (addr &TARGET_PAGE_MASK )) { +tlb_flush (cpu); + }else { +tlb_flush_page (cpu, addr); + }if (watchpoint) *watchpoint = wp;
Signature · 1 line
2.20.1
Quoted 24 lines · Alex Bennée
There is no particular reason why you can't have a watchpoint in TCG that covers a large chunk of the address space. We could be clever about it but these cases are pretty rare and we can assume the user will expect a little performance degradation.
NB: In my testing gdb will silently squash a watchpoint like:
watch (char[0x7fffffffff]) *0x0
to a 4 byte watchpoint. Practically it will limit the maximum size based on max-value-size. However given enough of a tweak the sky is the limit.
Reported-by Alexander Bulekov <[email protected]>Signed-off-by Alex Bennée <[email protected]>--- exec.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)exec.c +0
-0
exec.c int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len, · line 1059
Quoted 5 lines
exec.c +1
-1@@ -1056,7 +1056,11 @@ int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,QTAILQ_INSERT_TAIL (&cpu->watchpoints, wp, entry); } -tlb_flush_page (cpu, addr); +if (((addr + len) &TARGET_PAGE_MASK ) != (addr &TARGET_PAGE_MASK )) {
This computation will be false when adding a watchpoint for the last len bytes in the page, and no actual page crossing is required. For this reason I prefer
in_page = -(addr | TARGET_PAGE_MASK);
if (len <= in_page)r~
Quoted 8 lines
exec.c +4
-0+tlb_flush (cpu); + }else { +tlb_flush_page (cpu, addr); + }if (watchpoint) *watchpoint = wp;