Remove unconditional arch dependency on asm/debugger.h
v3 cover Remove unconditional arch dependency on asm/debugger.h
This series removes the unconditional requirement that all architectures implement asm/debugger.h. It additionally removes arm's debugger.h and disentangles some of the x86 gdbsx/gdbstub/generic debugger code.
Additionally, this series does the following:
- Provides generic stubs when !CONFIG_CRASH_DEBUG
- Adds stronger separation between gdbstub, gdbsx, and generic debugger code.
The patches in this v3 are quite a bit different than in v2, so per-patch changes are omitted. This difference in the patchset version is largely due to the need to decouple the debugger_trap_* functions.
Changes from v2:
- The first patch drops ARM's calls to the debugger stubs, removing the need to add fake values.
- No debugger.c is added, as it was unnecessary when code was moved into existing and appropriate files.
- debugger_trap_entry() expands inline into its few call sites
- debug.c becomes gdbsx.c
- All gdbsx functions move into gdbsx.c and become dependent on CONFIG_GDBSX (instead of CONFIG_CRASH_DEBUG as was the case for domain_pause_for_debugger(), for example)
It's worth noting that debugger.h is still not truly generic as debugger_trap_fatal() for x86 necessarily calls into the gdbstub… but further generalization is unnecessary while it is still only backed by the gdbstub.
As I'm not *exactly* an expert on this code, so feel free to inform me of my confusion where you see it.
Bobby Eshleman (6):
arm/traps: remove debugger_trap_fatal() calls x86/debugger: separate Xen and guest debugging debugger_trap_*
functions
arch/x86: rename debug.c to gdbsx.c
x86/gdbsx: expand dbg_rw_mem() inline
arch/x86: move domain_pause_for_debugger() to domain.h
x86: change asm/debugger.h to xen/debugger.h
xen/arch/arm/traps.c | 7 ----
xen/arch/x86/Makefile | 2 +-
xen/arch/x86/domain.c | 2 +-
xen/arch/x86/domctl.c | 12 +-----
xen/arch/x86/{debug.c => gdbsx.c} | 30 +++++++-------
xen/arch/x86/hvm/svm/svm.c | 2 +-
xen/arch/x86/hvm/vmx/realmode.c | 2 +-
xen/arch/x86/hvm/vmx/vmx.c | 2 +-
xen/arch/x86/nmi.c | 1 -
xen/arch/x86/traps.c | 51 ++++++++++++++----------
xen/common/domain.c | 2 +-
xen/common/gdbstub.c | 2 +-
xen/common/keyhandler.c | 2 +-
xen/common/shutdown.c | 2 +-
xen/drivers/char/console.c | 2 +-
xen/include/asm-arm/debugger.h | 15 -------
xen/include/asm-x86/debugger.h | 65 +------------------------------
xen/include/asm-x86/domain.h | 2 +
xen/include/asm-x86/gdbsx.h | 17 ++++++++
xen/include/xen/debugger.h | 51 ++++++++++++++++++++++++
20 files changed, 127 insertions(+), 144 deletions(-)
rename xen/arch/x86/{debug.c => gdbsx.c} (89%)
delete mode 100644 xen/include/asm-arm/debugger.h
create mode 100644 xen/include/asm-x86/gdbsx.h
create mode 100644 xen/include/xen/debugger.hSignature · 1 line
2.32.0
PATCH v3 1/6 arm/traps: remove debugger_trap_fatal() calls
ARM doesn't actually use debugger_trap_* anything, and is stubbed out.
This commit simply removes the unneeded calls.
--- xen/arch/arm/traps.c | 7 ------- 1 file changed, 7 deletions(-)
xen/arch/arm/traps.c +0 -7
@@ -41,7 +41,6 @@#include <asm/acpi.h> #include <asm/cpuerrata.h> #include <asm/cpufeature.h> -#include <asm/debugger.h> #include <asm/event.h> #include <asm/hsr.h> #include <asm/mmio.h>
@@ -1266,10 +1265,6 @@ int do_bug_frame(const struct cpu_user_regs *regs, vaddr_t pc)case BUGFRAME_bug:printk ("Xen BUG at %s%s:%d\n" , prefix, filename, lineno); - -if (debugger_trap_fatal (TRAP_invalid_op, regs) ) -return 0 ; -show_execution_state (regs);panic ("Xen BUG at %s%s:%d\n" , prefix, filename, lineno);
@@ -1281,8 +1276,6 @@ int do_bug_frame(const struct cpu_user_regs *regs, vaddr_t pc)printk ("Assertion '%s' failed at %s%s:%d\n" , predicate, prefix, filename, lineno); -if (debugger_trap_fatal (TRAP_invalid_op, regs) ) -return 0 ;show_execution_state (regs);panic ("Assertion '%s' failed at %s%s:%d\n" , predicate, prefix, filename, lineno);
Signature · 1 line
2.32.0
Re: [PATCH v3 1/6] arm/traps: remove debugger_trap_fatal() calls
Hi Bobby,
Quoted 1 line · Bobby Eshleman
ARM doesn't actually use debugger_trap_* anything, and is stubbed out.
I am guessing the plan was to add support for debugging support on Arm. But it never made it and it should be easy to re-introduce. So...
Quoted 3 lines
This commit simply removes the unneeded calls.
Signed-off-by Bobby Eshleman <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
PATCH v3 2/6 x86/debugger: separate Xen and guest debugging debugger_trap_* functions
In reply to Bobby EshlemanUnlike debugger_trap_fatal() and debugger_trap_immediate(), debugger_trap_entry() is specific to guest debugging and *NOT* the debugging of Xen itself. That is, it is part of gdbsx functionality and not the Xen gdstub. This is evidenced by debugger_trap_fatal()'s usage of domain_pause_for_debugger(). Because of this, debugger_trap_entry() does not belong alongside the generic Xen debugger functionality.
This commit fixes this by expanding inline debugger_trap_entry() into its usage in x86/traps.c and stubbing out domain_pause_for_debugger() when !CONFIG_GDBSX. Properly placing what was debugger_trap_entry() under the scope of gdbsx instead of gdbstub.
The function calls that caused an effective no-op and early exit out of debugger_trap_entry() are removed completely (when the trapnr is not int3/debug).
This commit is one of a series geared towards removing the unnecessary requirement that all architectures to implement <asm/debugger.h>.
--- xen/arch/x86/domain.c | 2 +- xen/arch/x86/traps.c | 48 ++++++++++++++++++++-------------- xen/include/asm-x86/debugger.h | 42 ++--------------------------- 3 files changed, 31 insertions(+), 61 deletions(-)
xen/arch/x86/domain.c +1 -1
@@ -2541,7 +2541,7 @@ __initcall(init_vcpu_kick_softirq);void domain_pause_for_debugger (void ) { -#ifdef CONFIG_CRASH_DEBUG +#ifdef CONFIG_GDBSX struct vcpu *curr = current;struct domain *d = curr->domain;
xen/arch/x86/traps.c +28 -20
112 lines not on this page · raw message
xen/include/asm-x86/debugger.h +2 -40
64 lines not on this page · raw message
Signature · 1 line
2.32.0
Re: [PATCH v3 2/6] x86/debugger: separate Xen and guest debugging debugger_trap_* functions
Quoted 15 lines · Bobby Eshleman
xen/arch/x86/traps.c +0
-3@@ -858,13 +858,20 @@ static void do_trap(struct cpu_user_regs *regs)if ( regs->error_code &X86_XEC_EXT ) goto hardware_trap; -if (debugger_trap_entry (trapnr, regs) ) -return ; -ASSERT (trapnr <32 );if (guest_mode (regs) ) {
xen/arch/x86/traps.c static void do_trap(struct cpu_user_regs *regs) · line 874
Quoted 10 lines
xen/arch/x86/traps.c +10
-0+struct vcpu *curr = current; +if ( (trapnr == TRAP_debug || trapnr == TRAP_int3) && +guest_kernel_mode (curr, regs) && + curr->domain->debugger_attached ) + { +if ( trapnr != TRAP_debug ) + curr->arch.gdbsx_vcpu_event = trapnr; +domain_pause_for_debugger (); +return ; + }
There's no need for this. Both TRAP_debug and TRAP_int3 have their own custom handers, and don't use do_trap().
xen/arch/x86/traps.c void do_int3(struct cpu_user_regs *regs) · line 1221
Quoted 5 lines
xen/arch/x86/traps.c +1
-0@@ -1215,6 +1218,12 @@ void do_int3(struct cpu_user_regs *regs)return ; } +else if (guest_kernel_mode (curr, regs) && curr->domain->debugger_attached )
if ( foo ) { ...; return; } else if ( bar ) is a dangerous anti-pattern.
This should just be a plain if().
xen/arch/x86/traps.c void do_debug(struct cpu_user_regs *regs) · line 1997
Quoted 5 lines
xen/arch/x86/traps.c +1
-0@@ -1994,6 +1994,11 @@ void do_debug(struct cpu_user_regs *regs)return ; } +else if (guest_kernel_mode (v, regs) && v->domain->debugger_attached )
Same here.
xen/arch/x86/traps.c void do_entry_CP(struct cpu_user_regs *regs) · line 2041
Quoted 13 lines
xen/arch/x86/traps.c +6
-0@@ -2028,6 +2030,12 @@ void do_entry_CP(struct cpu_user_regs *regs)*/ if (guest_mode (regs) ) { +struct vcpu *curr = current; +if (guest_kernel_mode (curr, regs) && curr->domain->debugger_attached ) + { +domain_pause_for_debugger (); +return ; + }gprintk (XENLOG_ERR ,"Hit #CP[%04x] in guest context %04x:%p\n" , ec, regs->cs,_p (regs->rip));ASSERT_UNREACHABLE ();
This path is fatal to Xen, because it should be impossible. If we ever get around to supporting CET for PV guests, #CP still isn't #DB/#BP so shouldn't pause for the debugger.
I can fix all of these on commit.
~Andrew
Re: [PATCH v3 2/6] x86/debugger: separate Xen and guest debugging debugger_trap_* functions
In reply to Bobby EshlemanQuoted 6 lines · Bobby Eshleman
Unlike
debugger_trap_fatal()anddebugger_trap_immediate(),debugger_trap_entry()is specific to guest debugging and *NOT* the debugging of Xen itself. That is, it is part of gdbsx functionality and not the Xen gdstub. This is evidenced by debugger_trap_fatal()'s usage ofdomain_pause_for_debugger(). Because of this,debugger_trap_entry()does not belong alongside the generic Xen debugger functionality.
I'm not convinced this is what the original intentions were. Instead I think this was meant to be a generic hook function which initially only cared to deal with the gdbsx needs.
Jan
Re: [PATCH v3 2/6] x86/debugger: separate Xen and guest debugging debugger_trap_* functions
Quoted 10 lines · Jan Beulich
Quoted 6 lines · Bobby Eshleman
Unlike
debugger_trap_fatal()anddebugger_trap_immediate(),debugger_trap_entry()is specific to guest debugging and *NOT* the debugging of Xen itself. That is, it is part of gdbsx functionality and not the Xen gdstub. This is evidenced by debugger_trap_fatal()'s usage ofdomain_pause_for_debugger(). Because of this,debugger_trap_entry()does not belong alongside the generic Xen debugger functionality.I'm not convinced this is what the original intentions were. Instead I think this was meant to be a generic hook function which initially only cared to deal with the gdbsx needs.
It doesn't exactly matter what the original intentions where - what we currently have is unused and and a clear source of confusion between two unrelated subsystems.
It is unclear that the gdbstub is even usable, given at least a decade of bitrot.
Keeping an empty static inline in the enabled case is nonsense, because at the point you need to edit Xen to insert some real debugging, there are better ways to do it in something which isn't even a catch-all despite appearing to be one.
~Andrew
Re: [PATCH v3 2/6] x86/debugger: separate Xen and guest debugging debugger_trap_* functions
Quoted 16 lines · Andrew Cooper
Quoted 10 lines · Jan Beulich
Quoted 6 lines · Bobby Eshleman
Unlike
debugger_trap_fatal()anddebugger_trap_immediate(),debugger_trap_entry()is specific to guest debugging and *NOT* the debugging of Xen itself. That is, it is part of gdbsx functionality and not the Xen gdstub. This is evidenced by debugger_trap_fatal()'s usage ofdomain_pause_for_debugger(). Because of this,debugger_trap_entry()does not belong alongside the generic Xen debugger functionality.I'm not convinced this is what the original intentions were. Instead I think this was meant to be a generic hook function which initially only cared to deal with the gdbsx needs.
It doesn't exactly matter what the original intentions where - what we currently have is unused and and a clear source of confusion between two unrelated subsystems.
Quoted 7 lines
It is unclear that the gdbstub is even usable, given at least a decade of bitrot.
Keeping an empty static inline in the enabled case is nonsense, because at the point you need to edit Xen to insert some real debugging, there are better ways to do it in something which isn't even a catch-all despite appearing to be one.
Perhaps I should have said explicitly that my remark isn't an objection to the code change, but a suggestion to weaken the claims made in the description.
Jan
PATCH v3 3/6 arch/x86: rename debug.c to gdbsx.c
In reply to Bobby EshlemanThis commit renames debug.c to gdbsx.c to clarify its purpose.
The function gdbsx_guest_mem_io() is moved from domctl.c to gdbsx.c.
Although gdbsx_guest_mem_io() is conditionally removed from its single call site in domctl.c upon !CONFIG_GDBSX and so no stub is technically necessary, this commit adds a stub that would preserve the functioning of that call site if the #ifdef CONFIG_GDBSX were to ever be removed or the function were to ever be called outside of such an ifdef block.
---
xen/arch/x86/Makefile | 2 +-
xen/arch/x86/domctl.c | 12 +-----------
xen/arch/x86/{debug.c => gdbsx.c} | 12 ++++++++++--
xen/include/asm-x86/debugger.h | 6 ------
xen/include/asm-x86/gdbsx.h | 17 +++++++++++++++++
5 files changed, 29 insertions(+), 20 deletions(-)
rename xen/arch/x86/{debug.c => gdbsx.c} (93%)
create mode 100644 xen/include/asm-x86/gdbsx.hxen/arch/x86/Makefile +1 -1
@@ -20,7 +20,7 @@ obj-y += cpuid.o obj-$(CONFIG_PV) += compat.o obj-$(CONFIG_PV32) += x86_64/compat.o obj-$(CONFIG_KEXEC) += crash.o -obj-$(CONFIG_GDBSX) += debug.o +obj-$(CONFIG_GDBSX) += gdbsx.o obj-y += delay.o obj-y += desc.o obj-bin-y += dmi_scan.init.o
xen/arch/x86/domctl.c +1 -11
@@ -20,6 +20,7 @@#include <xen/console.h> #include <xen/iocap.h> #include <xen/paging.h> +#include <asm/gdbsx.h> #include <asm/irq.h> #include <asm/hvm/emulate.h> #include <asm/hvm/hvm.h>
@@ -33,20 +34,9 @@#include <public/vm_event.h> #include <asm/mem_sharing.h> #include <asm/xstate.h> -#include <asm/debugger.h> #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) -{ - iop->remain =dbg_rw_mem (iop->gva,guest_handle_from_ptr (iop->uva, void), - iop->len, domid, iop->gwr, iop->pgd3val); - -return iop->remain ? -EFAULT :0 ; -} -#endif -static int update_domain_cpu_policy (struct domain *d,xen_domctl_cpu_policy_t *xdpc) {
xen/arch/x86/gdbsx.c renamed from xen/arch/x86/debug.c +10 -2
@@ -19,7 +19,7 @@#include <xen/mm.h> #include <xen/domain_page.h> #include <xen/guest_access.h> -#include <asm/debugger.h> +#include <asm/gdbsx.h> #include <asm/p2m.h> typedef unsigned long dbgva_t ;
@@ -158,7 +158,7 @@ static unsigned int dbg_rw_guest_mem(struct domain *dp, unsigned long addr,* pgd3: value of init_mm.pgd[3] in guest. see above. * Returns: number of bytes remaining to be copied. */ -unsigned int dbg_rw_mem (unsigned long gva,XEN_GUEST_HANDLE_PARAM (void ) buf, +static unsigned int dbg_rw_mem (unsigned long gva,XEN_GUEST_HANDLE_PARAM (void ) buf,unsigned int len,domid_t domid,bool toaddr,uint64_t pgd3) {
@@ -174,6 +174,14 @@ unsigned int dbg_rw_mem(unsigned long gva, XEN_GUEST_HANDLE_PARAM(void) buf,return len; } +int gdbsx_guest_mem_io (domid_t domid,struct xen_domctl_gdbsx_memio *iop) +{ + iop->remain =dbg_rw_mem (iop->gva,guest_handle_from_ptr (iop->uva, void), + iop->len, domid, iop->gwr, iop->pgd3val); + +return iop->remain ? -EFAULT :0 ; +} +/* * Local variables: * mode: C
xen/include/asm-x86/debugger.h +0 -6
@@ -54,10 +54,4 @@ static inline bool debugger_trap_fatal(#endif -#ifdef CONFIG_GDBSX -unsigned int dbg_rw_mem (unsigned long gva,XEN_GUEST_HANDLE_PARAM (void ) buf, -unsigned int len,domid_t domid,bool toaddr, -uint64_t pgd3); -#endif -#endif /* __X86_DEBUGGER_H__ */
xen/include/asm-x86/gdbsx.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef __X86_GDBX_H +#define __X86_GDBX_H__ + +#ifdef CONFIG_GDBSX + +int gdbsx_guest_mem_io (domid_t domid,struct xen_domctl_gdbsx_memio *iop); + +#else + +static inline int gdbsx_guest_mem_io (domid_t domid,struct xen_domctl_gdbsx_memio *iop) +{ +return -EOPNOTSUPP ; +} + +#endif + +#endif
Signature · 1 line
2.32.0
Re: [PATCH v3 3/6] arch/x86: rename debug.c to gdbsx.c
xen/arch/x86/Makefile obj-y += cpuid.o · line 23
Quoted 10 lines · Bobby Eshleman
xen/arch/x86/Makefile +1
-1@@ -20,7 +20,7 @@ obj-y += cpuid.o obj-$(CONFIG_PV) += compat.o obj-$(CONFIG_PV32) += x86_64/compat.o obj-$(CONFIG_KEXEC) += crash.o -obj-$(CONFIG_GDBSX) += debug.o +obj-$(CONFIG_GDBSX) += gdbsx.o
This wants moving now to retain alphabetical order.
xen/include/asm-x86/gdbsx.h line 2
Quoted 8 lines
xen/include/asm-x86/gdbsx.h new file +2
-0@@ -0,0 +1,17 @@ +#ifndef __X86_GDBX_H +#define __X86_GDBX_H__
Broken header guard.
xen/include/asm-x86/gdbsx.h line 9
Quoted 7 lines
xen/include/asm-x86/gdbsx.h new file +7
-0+ +#ifdef CONFIG_GDBSX + +int gdbsx_guest_mem_io (domid_t domid,struct xen_domctl_gdbsx_memio *iop); + +#else +
Need to include <xen/errno.h> to avoid breaking the !GDBSX build.
Can fix all on commit.
~Andrew
Re: [PATCH v3 3/6] arch/x86: rename debug.c to gdbsx.c
In reply to Bobby EshlemanQuoted 8 lines · Bobby Eshleman
xen/include/asm-x86/gdbsx.h new file +5
-0@@ -0,0 +1,17 @@ +#ifndef __X86_GDBX_H +#define __X86_GDBX_H__ + +#ifdef CONFIG_GDBSX +
xen/include/asm-x86/gdbsx.h line 15
Quoted 10 lines
xen/include/asm-x86/gdbsx.h new file +10
-0+int gdbsx_guest_mem_io (domid_t domid,struct xen_domctl_gdbsx_memio *iop); + +#else + +static inline int gdbsx_guest_mem_io (domid_t domid,struct xen_domctl_gdbsx_memio *iop) +{ +return -EOPNOTSUPP ; +} + +#endif
In addition to what Andrew has said, you also want to make sure
- domid_t is actually declared (need to include public/xen.h, I think),
- struct xen_domctl_gdbsx_memio has a forward declaration (ahead of the #ifdef).
This is so the header can actually be #include-d without needing to worry about prereq #include-s.
Jan
Re: [PATCH v3 3/6] arch/x86: rename debug.c to gdbsx.c
Quoted 29 lines · Jan Beulich
xen/include/asm-x86/gdbsx.h line 6
Quoted 9 lines · Bobby Eshleman
xen/include/asm-x86/gdbsx.h new file +6
-0@@ -0,0 +1,17 @@ +#ifndef __X86_GDBX_H +#define __X86_GDBX_H__ + +#ifdef CONFIG_GDBSX + +int gdbsx_guest_mem_io(domid_t domid, struct xen_domctl_gdbsx_memio*iop);
xen/include/asm-x86/gdbsx.h
Quoted 4 lines
xen/include/asm-x86/gdbsx.h new file +4
-0+ +#else + +static inline int gdbsx_guest_mem_io(domid_t domid, struct
xen_domctl_gdbsx_memio*iop)xen/include/asm-x86/gdbsx.h line 15
Quoted 5 lines
xen/include/asm-x86/gdbsx.h new file +5
-0+{ +return -EOPNOTSUPP ; +} + +#endif In addition to what Andrew has said, you also want to make sure
-domid_tis actually declared (need to includepublic/xen.h, I think),
- structxen_domctl_gdbsx_memiohas a forward declaration (ahead of the #ifdef).
This is so the header can actually be #include-d without needing to worry about prereq #include-s.
Quoted 2 lines
Jan
Roger that.
I'll be away from work on vacation until mid September but I'll get to these changes and the others when I get back, if there are some pending / still uncommitted.
Writing this from my phone, so sorry for gmail's email strangeness.
Quoted 1 line
PATCH v3 4/6 x86/gdbsx: expand dbg_rw_mem() inline
In reply to Bobby EshlemanBecause dbg_rw_mem() has only a single call site, this commit expands it inline.
--- xen/arch/x86/gdbsx.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-)
xen/arch/x86/gdbsx.c +11 -21
@@ -151,33 +151,23 @@ static unsigned int dbg_rw_guest_mem(struct domain *dp, unsigned long addr,return len; } -/* -* addr is guest addr -* buf is debugger buffer. -* if toaddr, then addr = buf (write to addr), else buf = addr (rd from guest) -* pgd3: value of init_mm.pgd[3] in guest. see above. -* Returns: number of bytes remaining to be copied. -*/ -static unsigned int dbg_rw_mem (unsigned long gva,XEN_GUEST_HANDLE_PARAM (void ) buf, -unsigned int len,domid_t domid,bool toaddr, -uint64_t pgd3) +int gdbsx_guest_mem_io (domid_t domid,struct xen_domctl_gdbsx_memio *iop) {struct domain *d =rcu_lock_domain_by_id (domid); -if ( d ) +if ( d && !d->is_dying ) { -if ( !d->is_dying ) - len =dbg_rw_guest_mem (d, gva, buf, len, toaddr, pgd3); -rcu_unlock_domain (d); + iop->remain =dbg_rw_guest_mem ( + d, iop->gva,guest_handle_from_ptr (iop->uva, void), + iop->len, domid, iop->pgd3val); + } +else + { + iop->remain = iop->len; } -return len; -} - -int gdbsx_guest_mem_io (domid_t domid,struct xen_domctl_gdbsx_memio *iop) -{ - iop->remain =dbg_rw_mem (iop->gva,guest_handle_from_ptr (iop->uva, void), - iop->len, domid, iop->gwr, iop->pgd3val); +if ( d ) +rcu_unlock_domain (d);return iop->remain ? -EFAULT :0 ; }
Signature · 1 line
2.32.0
Re: [PATCH v3 4/6] x86/gdbsx: expand dbg_rw_mem() inline
Quoted 2 lines · Bobby Eshleman
Because
dbg_rw_mem()has only a single call site, this commit expands it inline.
Missing a SoB.
Otherwise, looks ok.
Re: [PATCH v3 4/6] x86/gdbsx: expand dbg_rw_mem() inline
In reply to Bobby EshlemanQuoted 24 lines · Bobby Eshleman
xen/arch/x86/gdbsx.c +2
-12@@ -151,33 +151,23 @@ static unsigned int dbg_rw_guest_mem(struct domain *dp, unsigned long addr,return len; } -/* -* addr is guest addr -* buf is debugger buffer. -* if toaddr, then addr = buf (write to addr), else buf = addr (rd from guest) -* pgd3: value of init_mm.pgd[3] in guest. see above. -* Returns: number of bytes remaining to be copied. -*/ -static unsigned int dbg_rw_mem (unsigned long gva,XEN_GUEST_HANDLE_PARAM (void ) buf, -unsigned int len,domid_t domid,bool toaddr, -uint64_t pgd3) +int gdbsx_guest_mem_io (domid_t domid,struct xen_domctl_gdbsx_memio *iop) {struct domain *d =rcu_lock_domain_by_id (domid); -if ( d ) +if ( d && !d->is_dying ) { -if ( !d->is_dying )
xen/arch/x86/gdbsx.c static unsigned int dbg_rw_guest_mem(struct domain *dp, unsigned long addr, · line 167
Quoted 10 lines
xen/arch/x86/gdbsx.c +7
-2- len =dbg_rw_guest_mem (d, gva, buf, len, toaddr, pgd3); -rcu_unlock_domain (d); + iop->remain =dbg_rw_guest_mem ( + d, iop->gva,guest_handle_from_ptr (iop->uva, void), + iop->len, domid, iop->pgd3val); + } +else + { + iop->remain = iop->len; }
Nit: Generally we omit the braces in cases like this one.
Jan
PATCH v3 5/6 arch/x86: move domain_pause_for_debugger() to domain.h
In reply to Bobby Eshlemandomain_pause_for_debugger() was previously in debugger.h. This commit moves it to domain.h because its implementation is in domain.c.
---
Changes in v3:
- domain_pause_for_debugger() is now moved into debugger.h, not a new file debugger.c
xen/arch/x86/hvm/svm/svm.c | 2 +- xen/arch/x86/hvm/vmx/realmode.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 2 +- xen/arch/x86/nmi.c | 1 - xen/arch/x86/traps.c | 1 + xen/include/asm-x86/debugger.h | 2 -- xen/include/asm-x86/domain.h | 2 ++ 7 files changed, 6 insertions(+), 6 deletions(-)
xen/arch/x86/hvm/svm/svm.c +1 -1
@@ -36,6 +36,7 @@#include <asm/processor.h> #include <asm/amd.h> #include <asm/debugreg.h> +#include <asm/domain.h> #include <asm/msr.h> #include <asm/i387.h> #include <asm/iocap.h>
@@ -58,7 +59,6 @@#include <asm/hvm/trace.h> #include <asm/hap.h> #include <asm/apic.h> -#include <asm/debugger.h> #include <asm/hvm/monitor.h> #include <asm/monitor.h> #include <asm/xstate.h>
xen/arch/x86/hvm/vmx/realmode.c +1 -1
@@ -14,7 +14,7 @@#include <xen/sched.h> #include <xen/paging.h> #include <xen/softirq.h> -#include <asm/debugger.h> +#include <asm/domain.h> #include <asm/event.h> #include <asm/hvm/emulate.h> #include <asm/hvm/hvm.h>
xen/arch/x86/hvm/vmx/vmx.c +1 -1
@@ -27,6 +27,7 @@#include <xen/hypercall.h> #include <xen/perfc.h> #include <asm/current.h> +#include <asm/domain.h> #include <asm/io.h> #include <asm/iocap.h> #include <asm/regs.h>
@@ -51,7 +52,6 @@#include <asm/hvm/trace.h> #include <asm/hvm/monitor.h> #include <asm/xenoprof.h> -#include <asm/debugger.h> #include <asm/apic.h> #include <asm/hvm/nestedhvm.h> #include <asm/altp2m.h>
xen/arch/x86/nmi.c +0 -1
@@ -30,7 +30,6 @@#include <asm/msr.h> #include <asm/mpspec.h> #include <asm/nmi.h> -#include <asm/debugger.h> #include <asm/div64.h> #include <asm/apic.h>
xen/arch/x86/traps.c +1 -0
@@ -63,6 +63,7 @@#include <asm/i387.h> #include <asm/xstate.h> #include <asm/debugger.h> +#include <asm/domain.h> #include <asm/msr.h> #include <asm/nmi.h> #include <asm/xenoprof.h>
xen/include/asm-x86/debugger.h +0 -2
@@ -26,8 +26,6 @@#include <asm/regs.h> #include <asm/processor.h> -void domain_pause_for_debugger (void ); -#ifdef CONFIG_CRASH_DEBUG #include <xen/gdbstub.h>
xen/include/asm-x86/domain.h +2 -0
@@ -672,6 +672,8 @@ void update_guest_memory_policy(struct vcpu *v,void domain_cpu_policy_changed (struct domain *d); +void domain_pause_for_debugger (void ); +bool update_runstate_area (struct vcpu *);bool update_secondary_system_time (struct vcpu *,struct vcpu_time_info *);
Signature · 1 line
2.32.0
Re: [PATCH v3 5/6] arch/x86: move domain_pause_for_debugger() to domain.h
Quoted 11 lines · Bobby Eshleman
xen/arch/x86/hvm/svm/svm.c +1
-0@@ -36,6 +36,7 @@#include <asm/processor.h> #include <asm/amd.h> #include <asm/debugreg.h> +#include <asm/domain.h> #include <asm/msr.h> #include <asm/i387.h> #include <asm/iocap.h>
xen/arch/x86/hvm/svm/svm.c line 64
Quoted 7 lines
xen/arch/x86/hvm/svm/svm.c +0
-1@@ -58,7 +59,6 @@#include <asm/hvm/trace.h> #include <asm/hap.h> #include <asm/apic.h> -#include <asm/debugger.h> #include <asm/hvm/monitor.h> #include <asm/monitor.h> #include <asm/xstate.h>
While it's generally a good idea to explicitly #include headers that a source file depends upon, I'm not convinced in this case: sched.h includes xen/domain.h, which in turn includes asm/domain.h. And this dependency chain is very unlikely to go away, as sched.h needs to see full struct domain and struct vcpu, all of which come from */domain.h.
Jan
PATCH v3 6/6 x86: change asm/debugger.h to xen/debugger.h
In reply to Bobby EshlemanThis commit allows non-x86 architecture to omit the file asm/debugger.h if they do not require it. It changes debugger.h to be a general xen/debugger.h which, if CONFIG_CRASH_DEBUG, resolves to include asm/debugger.h.
It also changes all asm/debugger.h includes to xen/debugger.h.
Because it is no longer required, arm/debugger.h is removed.
---
Changes in v3:
- No longer introduces a fake TRAP_invalid_op for arm to consume, it is not necessary given the removal of the arm calls now precedes this patch.
- Instead of defining prototypes that arch/ is expected to implement, this version simply #includes <arch/debugger.h> when CONFIG_CRASH_DEBUG.
xen/arch/x86/traps.c | 2 +- xen/common/domain.c | 2 +- xen/common/gdbstub.c | 2 +- xen/common/keyhandler.c | 2 +- xen/common/shutdown.c | 2 +- xen/drivers/char/console.c | 2 +- xen/include/asm-arm/debugger.h | 15 ---------- xen/include/asm-x86/debugger.h | 15 ---------- xen/include/xen/debugger.h | 51 ++++++++++++++++++++++++++++++++++ 9 files changed, 57 insertions(+), 36 deletions(-) delete mode 100644 xen/include/asm-arm/debugger.h create mode 100644 xen/include/xen/debugger.h
xen/arch/x86/traps.c +1 -1
@@ -35,6 +35,7 @@#include <xen/shutdown.h> #include <xen/guest_access.h> #include <asm/regs.h> +#include <xen/debugger.h> #include <xen/delay.h> #include <xen/event.h> #include <xen/spinlock.h>
@@ -62,7 +63,6 @@#include <asm/uaccess.h> #include <asm/i387.h> #include <asm/xstate.h> -#include <asm/debugger.h> #include <asm/domain.h> #include <asm/msr.h> #include <asm/nmi.h>
xen/common/domain.c +1 -1
@@ -11,6 +11,7 @@#include <xen/err.h> #include <xen/param.h> #include <xen/sched.h> +#include <xen/debugger.h> #include <xen/domain.h> #include <xen/mm.h> #include <xen/event.h>
@@ -33,7 +34,6 @@#include <xen/xenoprof.h> #include <xen/irq.h> #include <xen/argo.h> -#include <asm/debugger.h> #include <asm/p2m.h> #include <asm/processor.h> #include <public/sched.h>
xen/common/gdbstub.c +1 -1
@@ -38,12 +38,12 @@#include <xen/serial.h> #include <xen/irq.h> #include <xen/watchdog.h> -#include <asm/debugger.h> #include <xen/init.h> #include <xen/param.h> #include <xen/smp.h> #include <xen/console.h> #include <xen/errno.h> +#include <xen/debugger.h> #include <xen/delay.h> #include <asm/byteorder.h>
xen/common/keyhandler.c +1 -1
@@ -3,6 +3,7 @@*/ #include <asm/regs.h> +#include <xen/debugger.h> #include <xen/delay.h> #include <xen/keyhandler.h> #include <xen/param.h>
@@ -20,7 +21,6 @@#include <xen/mm.h> #include <xen/watchdog.h> #include <xen/init.h> -#include <asm/debugger.h> #include <asm/div64.h> static unsigned char keypress_key;
xen/common/shutdown.c +1 -1
@@ -2,13 +2,13 @@#include <xen/lib.h> #include <xen/param.h> #include <xen/sched.h> +#include <xen/debugger.h> #include <xen/domain.h> #include <xen/delay.h> #include <xen/watchdog.h> #include <xen/shutdown.h> #include <xen/console.h> #include <xen/kexec.h> -#include <asm/debugger.h> #include <public/sched.h> /* opt_noreboot: If true, machine will need manual reset on error. */
xen/drivers/char/console.c +1 -1
@@ -15,6 +15,7 @@#include <xen/init.h> #include <xen/event.h> #include <xen/console.h> +#include <xen/debugger.h> #include <xen/param.h> #include <xen/serial.h> #include <xen/softirq.h>
@@ -26,7 +27,6 @@#include <xen/kexec.h> #include <xen/ctype.h> #include <xen/warning.h> -#include <asm/debugger.h> #include <asm/div64.h> #include <xen/hypercall.h> /* for do_console_io */ #include <xen/early_printk.h>
xen/include/asm-arm/debugger.h deleted +0 -15
@@ -1,15 +0,0 @@ -#ifndef __ARM_DEBUGGER_H__ -#define __ARM_DEBUGGER_H__ - -#define debugger_trap_fatal (v, r) (0) -#define debugger_trap_immediate () ((void) 0) - -#endif /* __ARM_DEBUGGER_H__ */ -/* -* Local variables: -* mode: C -* c-file-style: "BSD" -* c-basic-offset: 4 -* indent-tabs-mode: nil -* End: -*/
xen/include/asm-x86/debugger.h +0 -15
@@ -25,9 +25,6 @@#include <xen/sched.h> #include <asm/regs.h> #include <asm/processor.h> - -#ifdef CONFIG_CRASH_DEBUG -#include <xen/gdbstub.h> static inline bool debugger_trap_fatal(
@@ -40,16 +37,4 @@ 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 -#endif /* __X86_DEBUGGER_H__ */
xen/include/xen/debugger.h new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
2.32.0
Re: [PATCH v3 6/6] x86: change asm/debugger.h to xen/debugger.h
Quoted 33 lines · Bobby Eshleman
xen/include/xen/debugger.h new file +27
-0@@ -0,0 +1,51 @@ +/****************************************************************************** +* Generic hooks into arch-dependent Xen. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Each debugger should define two functions here: +* +* 1. debugger_trap_fatal(): +* Called when Xen is about to give up and crash. Typically you will use this +* hook to drop into a debug session. It can also be used to hook off +* deliberately caused traps (which you then handle and return non-zero). +* +* 2. debugger_trap_immediate(): +* Called if we want to drop into a debugger now. This is essentially the +* same as debugger_trap_fatal, except that we use the current register state +* rather than the state which was in effect when we took the trap. +* For example: if we're dying because of an unhandled exception, we call +* debugger_trap_fatal; if we're dying because of a panic() we call +* debugger_trap_immediate(). +*/ +
xen/include/xen/debugger.h line 37
Quoted 10 lines
xen/include/xen/debugger.h new file +10
-0+#ifndef __XEN_DEBUGGER_H__ +#define __XEN_DEBUGGER_H__ + +#ifdef CONFIG_CRASH_DEBUG + +#include <asm/debugger.h> + +#else + +#include <asm/regs.h>
This include should be deleted, and replaced with simply
struct cpu_user_regs;
~Andrew
Quoted 14 lines
xen/include/xen/debugger.h new file +14
-0+ +static inline bool debugger_trap_fatal ( +unsigned int vector,const struct cpu_user_regs *regs) +{ +return false; +} + +static inline void debugger_trap_immediate (void ) +{ +} + +#endif /* CONFIG_CRASH_DEBUG */ + +#endif /* __XEN_DEBUGGER_H__ */
Re: [PATCH v3 6/6] x86: change asm/debugger.h to xen/debugger.h
In reply to Bobby EshlemanHi,
Quoted 18 lines · Bobby Eshleman
This commit allows non-x86 architecture to omit the file
asm/debugger.hif they do not require it. It changesdebugger.hto be a generalxen/debugger.hwhich, ifCONFIG_CRASH_DEBUG, resolves to includeasm/debugger.h.It also changes all
asm/debugger.hincludes toxen/debugger.h.Because it is no longer required,
arm/debugger.his removed.Signed-off-by Bobby Eshleman <[email protected]>---
Changes in v3:
- No longer introduces a fakeTRAP_invalid_opfor arm to consume, it is not necessary given the removal of the arm calls now precedes this patch.
- Instead of defining prototypes thatarch/is expected to implement, this version simply #includes <arch/debugger.h> whenCONFIG_CRASH_DEBUG.
Quoted 7 lines
xen/arch/x86/traps.c | 2 +- xen/common/domain.c | 2 +- xen/common/gdbstub.c | 2 +- xen/common/keyhandler.c | 2 +- xen/common/shutdown.c | 2 +- xen/drivers/char/console.c | 2 +- xen/include/asm-arm/debugger.h | 15 ----------
For the Arm bits:
Cheers,
Signature · 1 line
Julien Grall