Skip to contentSkip to conversation

fixes for kvm/arm64 guest debug

PATCH Superseded Alex Bennée 2 participants 10 messages Sep 26, 2018 – Nov 1, 2018

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover fixes for kvm/arm64 guest debug

Hi,

While at Connect I had a go at reproducing a problem that Ard had reported to me about guest debug not working. I managed to replicate it and uncovered a few other nits in the process. While upgrading to a tip-of-tree gdb to get around:

https://sourceware.org/bugzilla/show_bug.cgi?id=23127

works we certainly can be better at handling the DBGBVR bits in QEMU. That fixed the additional BQL assertion and target_el assertion failures are harder to trigger (you need to debug your debug while debugging debug). However I've included the obvious fixes for that as well.

Alex Bennée (4):
target/arm64: properly handle DBGVR RESS bits target/arm64: hold BQL when calling do_interrupt() target/arm64: kvm debug set target_el when passing exception to guest tests/guest-debug: fix scoping of failcount

 target/arm/kvm64.c                | 15 ++++++++++++++-
 tests/guest-debug/test-gdbstub.py |  1 +
 2 files changed, 15 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/4 target/arm64: properly handle DBGVR RESS bits

This only fails with some (broken) versions of gdb but we should treat the top bits of DBGBVR as RESS. As the hardware may have IMPDEF approaches to writes to this register we apply the sign extension when checking breakpoints.

---
 target/arm/kvm64.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
target/arm/kvm64.c +11 -1
index e0b8246283..80ad07ed0c 100644
@@ -356,13 +356,23 @@ bool kvm_arm_hw_debug_active(CPUState *cs)
     return ((cur_hw_wps > 0) || (cur_hw_bps > 0));
 }
 
+/*
+ * We shouldn't rely on gdb correctly setting the top bits of DBGBVR
+ * and the HW lists the top bits a RESS - sign-extending the top bit
+ * of the VA address. As it is IMPDEF if the write is either a sign
+ * extension or kept as is we might fix it up before we compare with
+ * the correctly reported and sign extended address.
+ */
+
 static bool find_hw_breakpoint(CPUState *cpu, target_ulong pc)
 {
     int i;
 
     for (i = 0; i < cur_hw_bps; i++) {
         HWBreakpoint *bp = get_hw_bp(i);
-        if (bp->bvr == pc) {
+        target_ulong bvr = bp->bvr;
+        bvr |= extract64(bvr, 52, 1) ? MAKE_64BIT_MASK(53, 11) : 0;
+        if (bvr == pc) {
             return true;
         }
     }
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v1 1/4] target/arm64: properly handle DBGVR RESS bits

Quoted 29 lines · Alex Bennée

This only fails with some (broken) versions of gdb but we should treat the top bits of DBGBVR as RESS. As the hardware may have IMPDEF approaches to writes to this register we apply the sign extension when checking breakpoints.

---
 target/arm/kvm64.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
target/arm/kvm64.c +8 -0
index e0b8246283..80ad07ed0c 100644
@@ -356,13 +356,23 @@ bool kvm_arm_hw_debug_active(CPUState *cs)
     return ((cur_hw_wps > 0) || (cur_hw_bps > 0));
 }
 
+/*
+ * We shouldn't rely on gdb correctly setting the top bits of DBGBVR
+ * and the HW lists the top bits a RESS - sign-extending the top bit
+ * of the VA address. As it is IMPDEF if the write is either a sign
+ * extension or kept as is we might fix it up before we compare with
+ * the correctly reported and sign extended address.
+ */
+
 static bool find_hw_breakpoint(CPUState *cpu, target_ulong pc)
 {
     int i;

target/arm/kvm64.c bool kvm_arm_hw_debug_active(CPUState *cs) · line 378

Quoted 10 lines
target/arm/kvm64.c +3 -1
 
     for (i = 0; i < cur_hw_bps; i++) {
         HWBreakpoint *bp = get_hw_bp(i);
-        if (bp->bvr == pc) {
+        target_ulong bvr = bp->bvr;
+        bvr |= extract64(bvr, 52, 1) ? MAKE_64BIT_MASK(53, 11) : 0;
+        if (bvr == pc) {
             return true;
         }
     }

Shouldn't we be sanitizing the addresses we get from gdb before we put them into the hardware watchpoint registers, rather than doing the sign extension when we read the registers?

thanks
-- PMM

#3 lore raw

Re: [PATCH v1 1/4] target/arm64: properly handle DBGVR RESS bits

Quoted 31 lines · Peter Maydell
Quoted 30 lines · Alex Bennée

This only fails with some (broken) versions of gdb but we should treat the top bits of DBGBVR as RESS. As the hardware may have IMPDEF approaches to writes to this register we apply the sign extension when checking breakpoints.

---
 target/arm/kvm64.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
target/arm/kvm64.c +8 -0
index e0b8246283..80ad07ed0c 100644
@@ -356,13 +356,23 @@ bool kvm_arm_hw_debug_active(CPUState *cs)
     return ((cur_hw_wps > 0) || (cur_hw_bps > 0));
 }
 
+/*
+ * We shouldn't rely on gdb correctly setting the top bits of DBGBVR
+ * and the HW lists the top bits a RESS - sign-extending the top bit
+ * of the VA address. As it is IMPDEF if the write is either a sign
+ * extension or kept as is we might fix it up before we compare with
+ * the correctly reported and sign extended address.
+ */
+
 static bool find_hw_breakpoint(CPUState *cpu, target_ulong pc)
 {
     int i;
 
Quoted 13 lines

target/arm/kvm64.c bool kvm_arm_hw_debug_active(CPUState *cs) · line 378

Quoted 9 lines
target/arm/kvm64.c +3 -1
     for (i = 0; i < cur_hw_bps; i++) {
         HWBreakpoint *bp = get_hw_bp(i);
-        if (bp->bvr == pc) {
+        target_ulong bvr = bp->bvr;
+        bvr |= extract64(bvr, 52, 1) ? MAKE_64BIT_MASK(53, 11) : 0;
+        if (bvr == pc) {
             return true;
         }
     }

Shouldn't we be sanitizing the addresses we get from gdb before we put them into the hardware watchpoint registers, rather than doing the sign extension when we read the registers?

I guess that works too. I'll switch it around.

--
Alex Bennée

#4 lore raw

PATCH 2/4 target/arm64: hold BQL when calling do_interrupt()

In reply to Alex Bennée

Fix the assertion failure when running interrupts.

---
 target/arm/kvm64.c | 2 ++
 1 file changed, 2 insertions(+)
target/arm/kvm64.c +2 -0
index 80ad07ed0c..346e1f1a73 100644
@@ -984,7 +984,9 @@ bool kvm_arm_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *debug_exit)
     cs->exception_index = EXCP_BKPT;
     env->exception.syndrome = debug_exit->hsr;
     env->exception.vaddress = debug_exit->far;
+    qemu_mutex_lock_iothread();
     cc->do_interrupt(cs);
+    qemu_mutex_unlock_iothread();
 
     return false;
 }
Signature · 1 line
2.17.1
Reviewed-by on v1 2/4
#5 lore raw

Re: [PATCH v1 2/4] target/arm64: hold BQL when calling do_interrupt()

Quoted 22 lines · Alex Bennée

Fix the assertion failure when running interrupts.

---
 target/arm/kvm64.c | 2 ++
 1 file changed, 2 insertions(+)
target/arm/kvm64.c +2 -1
index 80ad07ed0c..346e1f1a73 100644
@@ -984,7 +984,9 @@ bool kvm_arm_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *debug_exit)
     cs->exception_index = EXCP_BKPT;
     env->exception.syndrome = debug_exit->hsr;
     env->exception.vaddress = debug_exit->far;
+    qemu_mutex_lock_iothread();
     cc->do_interrupt(cs);
+    qemu_mutex_unlock_iothread();
 
     return false;
 }
--
Quoted 1 line

2.17.1

thanks
-- PMM

#6 lore raw

PATCH 3/4 target/arm64: kvm debug set target_el when passing exception to guest

In reply to Alex Bennée

When we are debugging the guest all exception come our way but might be for the guests own debug exceptions. We use the ->do_interrupt() infrastructure to do this however we are missing a full setup of the exception structure causing an assert later down the line.

---
 target/arm/kvm64.c | 1 +
 1 file changed, 1 insertion(+)
target/arm/kvm64.c +1 -0
index 346e1f1a73..9ceff1884c 100644
@@ -984,6 +984,7 @@ bool kvm_arm_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *debug_exit)
     cs->exception_index = EXCP_BKPT;
     env->exception.syndrome = debug_exit->hsr;
     env->exception.vaddress = debug_exit->far;
+    env->exception.target_el = 1;
     qemu_mutex_lock_iothread();
     cc->do_interrupt(cs);
     qemu_mutex_unlock_iothread();
Signature · 1 line
2.17.1
Reviewed-by on v1 3/4
#7 lore raw

Re: [PATCH v1 3/4] target/arm64: kvm debug set target_el when passing exception to guest

Quoted 1 line · Alex Bennée

When we are debugging the guest all exception come our way but might

"exceptions"

Quoted 1 line

be for the guests own debug exceptions. We use the ->do_interrupt()

"guest's"

Quoted 1 line

infrastructure to do this however we are missing a full setup of the

"to inject the exception into the guest. However, "

Quoted 1 line

exception structure causing an assert later down the line.

"structure, "

Quoted 19 lines
---
 target/arm/kvm64.c | 1 +
 1 file changed, 1 insertion(+)
target/arm/kvm64.c +1 -1
index 346e1f1a73..9ceff1884c 100644
@@ -984,6 +984,7 @@ bool kvm_arm_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *debug_exit)
     cs->exception_index = EXCP_BKPT;
     env->exception.syndrome = debug_exit->hsr;
     env->exception.vaddress = debug_exit->far;
+    env->exception.target_el = 1;
     qemu_mutex_lock_iothread();
     cc->do_interrupt(cs);
     qemu_mutex_unlock_iothread();
--
Quoted 2 lines

2.17.1

thanks
-- PMM

#8 lore raw

PATCH 4/4 tests/guest-debug: fix scoping of failcount

In reply to Alex Bennée

You should declare you are using a global version of a variable before you attempt to modify it in a function.

---
 tests/guest-debug/test-gdbstub.py | 1 +
 1 file changed, 1 insertion(+)
tests/guest-debug/test-gdbstub.py +1 -0
index 474d2c5c65..7bfc95b187 100644
@@ -16,6 +16,7 @@ def report(cond, msg):
         print ("PASS: %s" % (msg))
     else:
         print ("FAIL: %s" % (msg))
+        global failcount
         failcount += 1
 
 
Signature · 1 line
2.17.1
Reviewed-by on v1 4/4
#9 lore raw

Re: [Qemu-devel] [PATCH v1 4/4] tests/guest-debug: fix scoping of failcount

Quoted 13 lines · Alex Bennée

You should declare you are using a global version of a variable before you attempt to modify it in a function.

---
 tests/guest-debug/test-gdbstub.py | 1 +
 1 file changed, 1 insertion(+)
tests/guest-debug/test-gdbstub.py +0 -0
index 474d2c5c65..7bfc95b187 100644

tests/guest-debug/test-gdbstub.py def report(cond, msg): · line 20

Quoted 5 lines
tests/guest-debug/test-gdbstub.py +1 -0
@@ -16,6 +16,7 @@ def report(cond, msg):
         print ("PASS: %s" % (msg))
     else:
         print ("FAIL: %s" % (msg))
+        global failcount
         failcount += 1

Incidentally, if we ever get above 127 tests in this file, the "exit(failcount)" at the bottom of the script will not DTRT :-)

thanks
-- PMM