Skip to contentSkip to conversation

xen: make more debugger support code conditional

PATCH In review Juergen Gross 3 participants 7 messages Dec 19, 2019 – Dec 20, 2019

lore
Share & tools
lore
#0 lore raw

v3 cover xen: make more debugger support code conditional

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

Changes in V3:
- remove possibility to access hypervisor memory via gdbsx domctl
- default gdbsx support to on
- some code moving

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               |  8 +++++
 xen/arch/x86/Kconfig            |  1 -
 xen/arch/x86/Makefile           |  2 +-
 xen/arch/x86/debug.c            | 78 +++++------------------------------------
 xen/arch/x86/domain.c           | 13 +++++++
 xen/arch/x86/domctl.c           |  4 +++
 xen/arch/x86/hvm/vmx/realmode.c |  1 +
 xen/common/Kconfig              |  3 --
 xen/common/domain.c             | 14 --------
 xen/include/asm-x86/debugger.h  | 34 +++++++++++-------
 xen/include/xen/sched.h         |  1 -
 11 files changed, 58 insertions(+), 101 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 v3 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.

---
V3:
- move domain_pause_for_debugger() into arch/x86/domain.c (Andrew Cooper)

---
 xen/arch/x86/Kconfig            |  1 -
 xen/arch/x86/domain.c           | 13 +++++++++++++
 xen/arch/x86/hvm/vmx/realmode.c |  1 +
 xen/common/Kconfig              |  3 ---
 xen/common/domain.c             | 14 --------------
 xen/include/asm-x86/debugger.h  | 32 ++++++++++++++++++++------------
 xen/include/xen/sched.h         |  1 -
 7 files changed, 34 insertions(+), 31 deletions(-)
xen/arch/x86/Kconfig +0 -1
index 02bb05f42e..f853c04564 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/arch/x86/domain.c +13 -0
index 7cb7fd31dd..3a3fbde642 100644
@@ -2318,6 +2318,19 @@ static int __init init_vcpu_kick_softirq(void)
 }
 __initcall(init_vcpu_kick_softirq);
 
+void domain_pause_for_debugger(void)
+{
+#ifdef CONFIG_CRASH_DEBUG
+    struct vcpu *curr = current;
+    struct domain *d = curr->domain;
+
+    domain_pause_by_systemcontroller_nosync(d);
+
+    /* if gdbsx active, we just need to pause the domain */
+    if ( curr->arch.gdbsx_vcpu_event == 0 )
+        send_global_virq(VIRQ_DEBUGGER);
+#endif
+}
 
 /*
  * Local variables:
xen/arch/x86/hvm/vmx/realmode.c +1 -0
index bb0b4439df..bdbd9cb921 100644
@@ -14,6 +14,7 @@
 #include <xen/sched.h>
 #include <xen/paging.h>
 #include <xen/softirq.h>
+#include <asm/debugger.h>
 #include <asm/event.h>
 #include <asm/hvm/emulate.h>
 #include <asm/hvm/hvm.h>
xen/common/Kconfig +0 -3
index 2f516da101..b3d161d057 100644
@@ -57,9 +57,6 @@ config HAS_UBSAN
 config HAS_KEXEC
 	bool
 
-config HAS_GDBSX
-	bool
-
 config HAS_IOPORTS
 	bool
 
xen/common/domain.c +0 -14
index 611116c7fc..3a77d717db 100644
@@ -915,20 +915,6 @@ void vcpu_end_shutdown_deferral(struct vcpu *v)
         vcpu_check_shutdown(v);
 }
 
-#ifdef CONFIG_HAS_GDBSX
-void domain_pause_for_debugger(void)
-{
-    struct vcpu *curr = current;
-    struct domain *d = curr->domain;
-
-    domain_pause_by_systemcontroller_nosync(d);
-
-    /* if gdbsx active, we just need to pause the domain */
-    if ( curr->arch.gdbsx_vcpu_event == 0 )
-        send_global_virq(VIRQ_DEBUGGER);
-}
-#endif
-
 /* Complete domain destroy after RCU readers are not holding old references. */
 static void complete_domain_destroy(struct rcu_head *head)
 {
xen/include/asm-x86/debugger.h +20 -12
index b1b627f1fa..f58726daec 100644
@@ -33,6 +33,8 @@
 #include <asm/regs.h>
 #include <asm/processor.h>
 
+void domain_pause_for_debugger(void);
+
 #ifdef CONFIG_CRASH_DEBUG
 
 #include <xen/gdbstub.h>
@@ -47,18 +49,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 +74,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 +0 -1
index 9f7bc69293..0b41e936d5 100644
@@ -652,7 +652,6 @@ 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);
-void domain_pause_for_debugger(void);
 
 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 v3 1/2] xen: put more code under CONFIG_CRASH_DEBUG

Quoted 2 lines · Juergen Gross

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

s/with/without/ ? and I presume you are referring to debugger_trap_entry() ?

~Andrew

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

#3 lore raw

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

Quoted 5 lines · Andrew Cooper
Quoted 2 lines · Juergen Gross

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

s/with/without/ ? and I presume you are referring to debugger_trap_entry() ?

Yes and yes.

Juergen

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

Acked-by on v3 1/2
#4 lore raw

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

In reply to Juergen Gross
Quoted 7 lines · Juergen Gross

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.

In case you need it for sched.h:

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

#5 lore raw

PATCH v3 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.

Remove the possibility to read/write hypervisor memory, it was never used by gdbsx.

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

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

---
V3:
- default Kconfig option to Y (Andrew Cooper)
- remove hypervisor memory access (Andrew Cooper)

---
 xen/Kconfig.debug              |  8 +++++
 xen/arch/x86/Makefile          |  2 +-
 xen/arch/x86/debug.c           | 78 +++++-------------------------------------
 xen/arch/x86/domctl.c          |  4 +++
 xen/include/asm-x86/debugger.h |  2 ++
 5 files changed, 24 insertions(+), 70 deletions(-)
xen/Kconfig.debug +8 -0
index cf42e5e7a0..b3511e81a2 100644
@@ -20,6 +20,14 @@ 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
+	default y
+	---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 7da5a2631e..6783688b00 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 +9 -69

150 lines not on this page · raw message

xen/arch/x86/domctl.c +4 -0
index b461aadbd6..43cd38b43f 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)
 {
@@ -932,6 +934,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);
@@ -996,6 +999,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 f58726daec..a9ddb01433 100644
@@ -92,8 +92,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
#6 lore raw
In reply to Juergen Gross
Quoted 8 lines · Juergen Gross

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

Changes in V3:
- remove possibility to access hypervisor memory via gdbsx domctl
- default gdbsx support to on
- some code moving

Quoted 6 lines

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

LGTM.  Reviewed-by: Andrew Cooper <[email protected]>

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