Skip to contentSkip to conversation

exec: add cpu_synchronize_state to cpu_memory_rw_debug

Qemu-devel Christian Borntraeger 3 participants 4 messages Mar 7, 2017 – Mar 9, 2017

lore
Share & tools
lore
#0 lore raw

I sometimes got "Cannot access memory" when using the x command on the monitor. Turns out that the cpu env did contain stale data (e.g. wrong control register content for page table origin). We must synchronize the state of the CPU before walking the page tables. A similar issues happens for a remote gdb, so lets do the cpu_synchronize_state in cpu_memory_rw_debug.

---
 exec.c | 2 ++
 1 file changed, 2 insertions(+)
exec.c +2 -0
index aabb035..e754a03 100644
@@ -43,6 +43,7 @@
 #include "exec/ioport.h"
 #include "sysemu/dma.h"
 #include "sysemu/numa.h"
+#include "sysemu/hw_accel.h"
 #include "exec/address-spaces.h"
 #include "sysemu/xen-mapcache.h"
 #include "trace-root.h"
@@ -3309,6 +3310,7 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
     hwaddr phys_addr;
     target_ulong page;
 
+    cpu_synchronize_state(cpu);
     while (len > 0) {
         int asidx;
         MemTxAttrs attrs;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 25 lines · Christian Borntraeger

I sometimes got "Cannot access memory" when using the x command on the monitor. Turns out that the cpu env did contain stale data (e.g. wrong control register content for page table origin). We must synchronize the state of the CPU before walking the page tables. A similar issues happens for a remote gdb, so lets do the cpu_synchronize_state in cpu_memory_rw_debug.

---
 exec.c | 2 ++
 1 file changed, 2 insertions(+)
exec.c +1 -0
index aabb035..e754a03 100644
@@ -43,6 +43,7 @@
 #include "exec/ioport.h"
 #include "sysemu/dma.h"
 #include "sysemu/numa.h"
+#include "sysemu/hw_accel.h"
 #include "exec/address-spaces.h"
 #include "sysemu/xen-mapcache.h"
 #include "trace-root.h"

exec.c int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, · line 3316

Quoted 7 lines
exec.c +1 -0
@@ -3309,6 +3310,7 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
     hwaddr phys_addr;
     target_ulong page;
 
+    cpu_synchronize_state(cpu);
     while (len > 0) {
         int asidx;
         MemTxAttrs attrs;

This seems like the wrong place to put it. Would we end up doing a potentially expensive sync operations for every byte/word we dump out?

Certainly when I was messing around with ARM KVM debug I did the synchronise state as we entered the debug handling (e.g. gdb_handle_packet/memory_dump)?

--
Alex Bennée

#2 lore raw
Quoted 31 lines · Alex Bennée
Quoted 28 lines · Christian Borntraeger

I sometimes got "Cannot access memory" when using the x command on the monitor. Turns out that the cpu env did contain stale data (e.g. wrong control register content for page table origin). We must synchronize the state of the CPU before walking the page tables. A similar issues happens for a remote gdb, so lets do the cpu_synchronize_state in cpu_memory_rw_debug.

---
 exec.c | 2 ++
 1 file changed, 2 insertions(+)
exec.c +1 -0
index aabb035..e754a03 100644
@@ -43,6 +43,7 @@
 #include "exec/ioport.h"
 #include "sysemu/dma.h"
 #include "sysemu/numa.h"
+#include "sysemu/hw_accel.h"
 #include "exec/address-spaces.h"
 #include "sysemu/xen-mapcache.h"
 #include "trace-root.h"
@@ -3309,6 +3310,7 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
     hwaddr phys_addr;
     target_ulong page;
 
Quoted 7 lines

exec.c int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, · line 3316

Quoted 4 lines
exec.c +1 -0
+    cpu_synchronize_state(cpu);
     while (len > 0) {
         int asidx;
         MemTxAttrs attrs;

This seems like the wrong place to put it. Would we end up doing a potentially expensive sync operations for every byte/word we dump out?

kvm_synchronize_state is clever enough to only sync once. This function mostly seems to be for debugging stuff (gdb, monitor). Instead of adding the sync in several places putting it here is a big hammer but it probably fixes all places. I fear that we will forget this in other places. No idea whats right.

Quoted 7 lines

Certainly when I was messing around with ARM KVM debug I did the synchronise state as we entered the debug handling (e.g. gdb_handle_packet/memory_dump)?

--
Alex Bennée

#3 lore raw
In reply to Christian Borntraeger
Quoted 6 lines · Christian Borntraeger

I sometimes got "Cannot access memory" when using the x command on the monitor. Turns out that the cpu env did contain stale data (e.g. wrong control register content for page table origin). We must synchronize the state of the CPU before walking the page tables. A similar issues happens for a remote gdb, so lets do the cpu_synchronize_state in cpu_memory_rw_debug.

Makes sense (the bit missing from the commit message, at least the one that I had to look up, is that cpu_memory_rw_debug takes virtual addresses).

Paolo

Quoted 26 lines
---
 exec.c | 2 ++
 1 file changed, 2 insertions(+)
exec.c +2 -0
index aabb035..e754a03 100644
@@ -43,6 +43,7 @@
 #include "exec/ioport.h"
 #include "sysemu/dma.h"
 #include "sysemu/numa.h"
+#include "sysemu/hw_accel.h"
 #include "exec/address-spaces.h"
 #include "sysemu/xen-mapcache.h"
 #include "trace-root.h"
@@ -3309,6 +3310,7 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
     hwaddr phys_addr;
     target_ulong page;
 
+    cpu_synchronize_state(cpu);
     while (len > 0) {
         int asidx;
         MemTxAttrs attrs;