Skip to contentSkip to conversation

xen: make more debugger support code conditional

PATCH Superseded Juergen Gross 2 participants 5 messages Nov 14, 2019 – Nov 29, 2019

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover xen: make more debugger support code conditional

Support for debugging the hypervisor of guests via gdb/gdbsx should be configurable.

Changes in V2:
- split support for gdbstub and gdbsx (Andrew Cooper)

Juergen Gross (2):
xen: put more code under CONFIG_CRASH_DEBUG
xen: make gdbsx support configurable

 xen/Kconfig.debug              |  7 ++++++
 xen/arch/x86/Kconfig           |  1 -
 xen/arch/x86/Makefile          |  2 +-
 xen/arch/x86/debug.c           | 52 +-----------------------------------------
 xen/arch/x86/domctl.c          |  4 ++++
 xen/common/Kconfig             |  3 ---
 xen/common/domain.c            |  2 +-
 xen/include/asm-x86/debugger.h | 32 ++++++++++++++++----------
 xen/include/xen/sched.h        |  4 ++++
 9 files changed, 38 insertions(+), 69 deletions(-)
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH v2 1/2 xen: put more code under CONFIG_CRASH_DEBUG

Some code is not needed with CONFIG_CRASH_DEBUG, so only include it if CONFIG_CRASH_DEBUG is defined.

While at it remove CONFIG_HAS_GDBSX as it can easily be replaced by CONFIG_CRASH_DEBUG.

---
 xen/arch/x86/Kconfig           |  1 -
 xen/common/Kconfig             |  3 ---
 xen/common/domain.c            |  2 +-
 xen/include/asm-x86/debugger.h | 30 ++++++++++++++++++------------
 xen/include/xen/sched.h        |  4 ++++
 5 files changed, 23 insertions(+), 17 deletions(-)
xen/arch/x86/Kconfig +0 -1
index 28b3b4692a..c72da8964a 100644
@@ -13,7 +13,6 @@ config X86
 	select HAS_EHCI
 	select HAS_EX_TABLE
 	select HAS_FAST_MULTIPLY
-	select HAS_GDBSX
 	select HAS_IOPORTS
 	select HAS_KEXEC
 	select MEM_ACCESS_ALWAYS_ON
xen/common/Kconfig +0 -3
index f754741972..7bde6aff02 100644
@@ -57,9 +57,6 @@ config HAS_UBSAN
 config HAS_KEXEC
 	bool
 
-config HAS_GDBSX
-	bool
-
 config HAS_IOPORTS
 	bool
 
xen/common/domain.c +1 -1
index 611116c7fc..c06efedc8e 100644
@@ -915,7 +915,7 @@ void vcpu_end_shutdown_deferral(struct vcpu *v)
         vcpu_check_shutdown(v);
 }
 
-#ifdef CONFIG_HAS_GDBSX
+#ifdef CONFIG_CRASH_DEBUG
 void domain_pause_for_debugger(void)
 {
     struct vcpu *curr = current;
xen/include/asm-x86/debugger.h +18 -12
index b1b627f1fa..e23f2fa4a3 100644
@@ -47,18 +47,6 @@ static inline bool debugger_trap_fatal(
 /* Int3 is a trivial way to gather cpu_user_regs context. */
 #define debugger_trap_immediate() __asm__ __volatile__ ( "int3" );
 
-#else
-
-static inline bool debugger_trap_fatal(
-    unsigned int vector, struct cpu_user_regs *regs)
-{
-    return false;
-}
-
-#define debugger_trap_immediate() ((void)0)
-
-#endif
-
 static inline bool debugger_trap_entry(
     unsigned int vector, struct cpu_user_regs *regs)
 {
@@ -84,6 +72,24 @@ static inline bool debugger_trap_entry(
     return false;
 }
 
+#else
+
+static inline bool debugger_trap_fatal(
+    unsigned int vector, struct cpu_user_regs *regs)
+{
+    return false;
+}
+
+#define debugger_trap_immediate() ((void)0)
+
+static inline bool debugger_trap_entry(
+    unsigned int vector, struct cpu_user_regs *regs)
+{
+    return false;
+}
+
+#endif
+
 unsigned int dbg_rw_mem(void * __user addr, void * __user buf,
                         unsigned int len, domid_t domid, bool toaddr,
                         uint64_t pgd3);
xen/include/xen/sched.h +4 -0
index 9f7bc69293..d2d30ece7d 100644
@@ -652,7 +652,11 @@ void domain_destroy(struct domain *d);
 int domain_kill(struct domain *d);
 int domain_shutdown(struct domain *d, u8 reason);
 void domain_resume(struct domain *d);
+#ifdef CONFIG_CRASH_DEBUG
 void domain_pause_for_debugger(void);
+#else
+static inline void domain_pause_for_debugger(void) { }
+#endif
 
 int domain_soft_reset(struct domain *d);
 
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

Re: [Xen-devel] [PATCH v2 1/2] xen: put more code under CONFIG_CRASH_DEBUG

xen/include/xen/sched.h void domain_destroy(struct domain *d); · line 659

Quoted 13 lines · Juergen Gross
xen/include/xen/sched.h +4 -0
index 9f7bc69293..d2d30ece7d 100644
@@ -652,7 +652,11 @@ void domain_destroy(struct domain *d);
 int domain_kill(struct domain *d);
 int domain_shutdown(struct domain *d, u8 reason);
 void domain_resume(struct domain *d);
+#ifdef CONFIG_CRASH_DEBUG
 void domain_pause_for_debugger(void);
+#else
+static inline void domain_pause_for_debugger(void) { }
+#endif

This looked a tad weird.  It turns out we've got a trivial domain_pause_for_debugger() in common code, guarded by CONFIG_CRASH_DEBUG, which is actually an x86 check, seeing as gdbsx_vcpu_event doesn't exist on ARM.

I'd suggest moving domain_pause_for_debugger() into arch/x86/domain.c and moving this prototype into debugger.h

With an #include <asm/debugger.h> in vmx/realmode.c, it appears to build fine.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw

PATCH v2 2/2 xen: make gdbsx support configurable

In reply to Juergen Gross

Gdbsx support in the hypervisor is rarely used and it is opening a way for dom0 to modify the running hypervisor by very easy means.

Add a Kconfig option to control support of gdbsx. Default is off.

While at it correct a wrong comment in related code and remove dead code.

---
 xen/Kconfig.debug              |  7 ++++++
 xen/arch/x86/Makefile          |  2 +-
 xen/arch/x86/debug.c           | 52 +-----------------------------------------
 xen/arch/x86/domctl.c          |  4 ++++
 xen/include/asm-x86/debugger.h |  2 ++
 5 files changed, 15 insertions(+), 52 deletions(-)
xen/Kconfig.debug +7 -0
index 22573e74db..253910036e 100644
@@ -20,6 +20,13 @@ config CRASH_DEBUG
 	  If you want to attach gdb to Xen to debug Xen if it crashes
 	  then say Y.
 
+config GDBSX
+	bool "Guest debugging with gdbsx"
+	depends on X86
+	---help---
+	  If you want to enable support for debugging guests from dom0 via
+	  gdbsx then say Y.
+
 config DEBUG_INFO
 	bool "Compile Xen with debug info"
 	default y
xen/arch/x86/Makefile +1 -1
index 5e6b9d7028..46a6c9d72b 100644
@@ -19,7 +19,7 @@ obj-bin-y += copy_page.o
 obj-y += cpuid.o
 obj-$(CONFIG_PV) += compat.o x86_64/compat.o
 obj-$(CONFIG_KEXEC) += crash.o
-obj-y += debug.o
+obj-$(CONFIG_GDBSX) += debug.o
 obj-y += delay.o
 obj-y += desc.o
 obj-bin-y += dmi_scan.init.o
xen/arch/x86/debug.c +1 -51

118 lines not on this page · raw message

xen/arch/x86/domctl.c +4 -0
index 43e368d63b..90e36b9ad8 100644
@@ -36,6 +36,7 @@
 #include <asm/psr.h>
 #include <asm/cpuid.h>
 
+#ifdef CONFIG_GDBSX
 static int gdbsx_guest_mem_io(domid_t domid, struct xen_domctl_gdbsx_memio *iop)
 {
     void * __user gva = (void *)iop->gva, * __user uva = (void *)iop->uva;
@@ -45,6 +46,7 @@ static int gdbsx_guest_mem_io(domid_t domid, struct xen_domctl_gdbsx_memio *iop)
 
     return iop->remain ? -EFAULT : 0;
 }
+#endif
 
 static void domain_cpu_policy_changed(struct domain *d)
 {
@@ -912,6 +914,7 @@ long arch_do_domctl(
     }
 #endif
 
+#ifdef CONFIG_GDBSX
     case XEN_DOMCTL_gdbsx_guestmemio:
         domctl->u.gdbsx_guest_memio.remain = domctl->u.gdbsx_guest_memio.len;
         ret = gdbsx_guest_mem_io(domctl->domain, &domctl->u.gdbsx_guest_memio);
@@ -976,6 +979,7 @@ long arch_do_domctl(
         copyback = true;
         break;
     }
+#endif
 
     case XEN_DOMCTL_setvcpuextstate:
     case XEN_DOMCTL_getvcpuextstate:
xen/include/asm-x86/debugger.h +2 -0
index e23f2fa4a3..2dc05b32d6 100644
@@ -90,8 +90,10 @@ static inline bool debugger_trap_entry(
 
 #endif
 
+#ifdef CONFIG_GDBSX
 unsigned int dbg_rw_mem(void * __user addr, void * __user buf,
                         unsigned int len, domid_t domid, bool toaddr,
                         uint64_t pgd3);
+#endif
 
 #endif /* __X86_DEBUGGER_H__ */
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#4 lore raw

Re: [Xen-devel] [PATCH v2 2/2] xen: make gdbsx support configurable

Quoted 4 lines · Juergen Gross

Gdbsx support in the hypervisor is rarely used and it is opening a way for dom0 to modify the running hypervisor by very easy means.

Add a Kconfig option to control support of gdbsx. Default is off.

This would constitute a regression, and I (and others) do use gdbsx on occasion.

The bit we really don't want is gdbsx's ability to use DOMID_IDLE.

gdbsx itself does a getdomaininfo check before attaching to the domain, so doesn't actually accept an attempt to use DOMID_IDLE.  Therefore, I think we can safely get rid of this functionality, including XEN_DOMCTL_gdbsx_guestmemio's special case in the do_domctl() domid checks, without regressing anything.

With that deleted, gdbsx becomes strictly "debugging another guest", and I think reasonable to keep on by default.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel