guest debug support patches
These two patches should really be one patch. However, when I try:
bk export -tpatch -r1.1294.1,1.1307,1.1308,1.1309,1.1310,1.1311
The output includes a large number of files that I haven't touched. My guess is that there is a bug in the graph re-labelling in bk.
Thus patch1 is the output of:
bk export -tpatch -r1.1294.1.1
And patch2 is the output of:
bk export -tpatch -r1.1307,1.1308,1.1309,1.1310,1.1311
These patches have three real changes:
1) xen/arch/x86/traps.c in do_int3 and do_debug if the trap was hit in kernel-mode on domain other than dom0 the domain is paused
2) builddomain is re-factored into setdomaininfo, the parts of what was arch_final_setup_guest that should only be set once are skipped by means of a new exec_domain flag EDF_DONEINIT
3) xc_ptrace.c implements the ptrace interface via dom0 ops
known limitations:
- Although the hypervisor-side code should work on x86_64, the user-side xc_ptrace is currently strictly x86_32, fixing this is a SMOP
- xc_ptrace assumes the guest is UP - I intend to fix this right after I get 5.3 booting SMP as a guest - I would wait until this was fixed were it not for the fact that the resolves can get annoying
- the patch doesn't include the gdbserver side support, I'm not sure how best to handle this as most GDB maintainers move at a glacial pace when it comes to incorporating outside patches
Comments and suggestions are welcome.
signed off by Kip Macy kmacy at fsmware.com
# This is a BitKeeper generated diff -Nru style patch. #
# ChangeSet
# 2005/03/09 15:04:40-08:00 [email protected]
# add debug support
#
# BitKeeper/etc/logging_ok
# 2005/03/09 15:00:56-08:00 [email protected] +1 -0
# Logging to [email protected] accepted
#
# tools/libxc/xc_ptrace.c # 2005/03/09 15:00:37-08:00 [email protected] +324 -0 # # xen/include/xen/sched.h # 2005/03/09 15:00:37-08:00 [email protected] +2 -1 # final_setup_guest->set_info_guset # add per ed init done flag # # xen/include/xen/domain.h # 2005/03/09 15:00:37-08:00 [email protected] +1 -1 # arch_final_setup_guest -> arch_set_info_guest # # xen/include/public/dom0_ops.h # 2005/03/09 15:00:37-08:00 [email protected] +7 -7 # builddomain->setdomaininfo # # xen/common/domain.c # 2005/03/09 15:00:37-08:00 [email protected] +15 -13 # final_setup_guest -> set_info_guest # # xen/common/dom0_ops.c # 2005/03/09 15:00:37-08:00 [email protected] +3 -3 # builddomain->setdomaininfo # # tools/libxc/xc_ptrace.c # 2005/03/09 15:00:37-08:00 [email protected] +0 -0 # BitKeeper file /t/niners/users/xen/050304/xen-unstable.bk/tools/libxc/xc_ptrace.c # # xen/arch/x86/traps.c # 2005/03/09 15:00:36-08:00 [email protected] +11 -1 # pause guest on int3 # # xen/arch/x86/domain.c # 2005/03/09 15:00:36-08:00 [email protected] +27 -19 # arch_final_setup_guest -> arch_set_info_guest # # xen/arch/ia64/domain.c # 2005/03/09 15:00:36-08:00 [email protected] +1 -1 # update interface # # tools/libxc/xc_vmx_build.c # 2005/03/09 15:00:36-08:00 [email protected] +3 -3 # use setdomaininfo # # tools/libxc/xc_plan9_build.c # 2005/03/09 15:00:36-08:00 [email protected] +5 -4 # use setdomaininfo # # tools/libxc/xc_linux_restore.c # 2005/03/09 15:00:36-08:00 [email protected] +3 -3 # use setdomaininfo # # tools/libxc/xc_linux_build.c # 2005/03/09 15:00:36-08:00 [email protected] +4 -3 # use setdomaininfo call # # tools/libxc/Makefile # 2005/03/09 15:00:36-08:00 [email protected] +1 -0 # compile ptrace # diff -Nru a/tools/libxc/Makefile b/tools/libxc/Makefile --- a/tools/libxc/Makefile 2005-03-11 10:38:24 -08:00 +++ b/tools/libxc/Makefile 2005-03-11 10:38:24 -08:00 @@ -28,6 +28,7 @@ SRCS += xc_misc.c SRCS += xc_physdev.c SRCS += xc_private.c +SRCS += xc_ptrace.c SRCS += xc_rrobin.c SRCS += xc_vmx_build.c
tools/libxc/xc_linux_build.c +4 -3
@@ -369,6 +369,7 @@ op.cmd =DOM0_GETDOMAININFO ; op.u.getdomaininfo.domain = (domid_t )domid; + launch_op.u.setdomaininfo.exec_domain =0 ; op.u.getdomaininfo.exec_domain =0 ; op.u.getdomaininfo.ctxt = ctxt; if ( (do_dom0_op(xc_handle, &op) < 0) ||
@@ -459,10 +460,10 @@memset ( &launch_op,0 ,sizeof (launch_op) ); - launch_op.u.builddomain.domain = (domid_t )domid; - launch_op.u.builddomain.ctxt = ctxt; + launch_op.u.setdomaininfo.domain = (domid_t )domid; + launch_op.u.setdomaininfo.ctxt = ctxt; - launch_op.cmd =DOM0_BUILDDOMAIN ; + launch_op.cmd =DOM0_SETDOMAININFO ; rc =do_dom0_op (xc_handle, &launch_op);return rc;
tools/libxc/xc_linux_restore.c +3 -3
@@ -631,9 +631,9 @@xcio_info (ioctxt,"Domain ready to be built.\n" ); - op.cmd =DOM0_BUILDDOMAIN ; - op.u.builddomain.domain = (domid_t )dom; - op.u.builddomain.ctxt = &ctxt; + op.cmd =DOM0_SETDOMAININFO ; + op.u.setdomaininfo.domain = (domid_t )dom; + op.u.setdomaininfo.ctxt = &ctxt; rc =do_dom0_op (xc_handle, &op);if ( rc !=0 )
tools/libxc/xc_plan9_build.c +5 -4
@@ -533,10 +533,11 @@memset (&launch_op,0 ,sizeof (launch_op)); - launch_op.u.builddomain.domain = (domid_t ) domid; -// launch_op.u.builddomain.num_vifs = 1; - launch_op.u.builddomain.ctxt = ctxt; - launch_op.cmd =DOM0_BUILDDOMAIN ; + launch_op.u.setdomaininfo.domain = (domid_t ) domid; + launch_op.u.setdomaininfo.exec_domain =0 ; +// launch_op.u.setdomaininfo.num_vifs = 1; + launch_op.u.setdomaininfo.ctxt = ctxt; + launch_op.cmd =DOM0_SETDOMAININFO ; rc =do_dom0_op (xc_handle, &launch_op);fprintf (stderr,"RC is %d\n" , rc);
tools/libxc/xc_ptrace.c new file +324 -0
324 lines not on this page · raw message
tools/libxc/xc_vmx_build.c +3 -3
@@ -603,10 +603,10 @@memset ( &launch_op,0 ,sizeof (launch_op) ); - launch_op.u.builddomain.domain = (domid_t )domid; - launch_op.u.builddomain.ctxt = ctxt; + launch_op.u.setdomaininfo.domain = (domid_t )domid; + launch_op.u.setdomaininfo.ctxt = ctxt; - launch_op.cmd =DOM0_BUILDDOMAIN ; + launch_op.cmd =DOM0_SETDOMAININFO ; rc =do_dom0_op (xc_handle, &launch_op);return rc;
xen/arch/ia64/domain.c +1 -1
@@ -200,7 +200,7 @@return ; } -int arch_final_setup_guest (struct exec_domain *p,full_execution_context_t *c) +int arch_set_info_guest (struct exec_domain *p,full_execution_context_t *c) {dummy ();return 1 ;
xen/arch/x86/domain.c +27 -19
77 lines not on this page · raw message
xen/arch/x86/traps.c +11 -1
@@ -221,8 +221,18 @@DEBUGGER_trap_fatal (TRAP_int3, regs);show_registers (regs);panic ("CPU%d FATAL TRAP: vector = 3 (Int3)\n" ,smp_processor_id ()); - } + } +else if (KERNEL_MODE (ed, regs) && ed->domain->id !=0 ) + { + regs->eflags &= ~X86_EFLAGS_TF ; +if ( !test_and_set_bit (EDF_CTRLPAUSE , &ed->ed_flags) ) { +while (ed == current) +__enter_scheduler (); +domain_pause_by_systemcontroller (ed->domain); + } +return 0 ; + } ti = current->arch.traps +3 ; tb->flags =TBF_EXCEPTION ; tb->cs = ti->cs;
xen/common/dom0_ops.c +3 -3
@@ -111,13 +111,13 @@switch ( op->cmd ) { -case DOM0_BUILDDOMAIN : +case DOM0_SETDOMAININFO : { -struct domain *d =find_domain_by_id (op->u.builddomain.domain); +struct domain *d =find_domain_by_id (op->u.setdomaininfo.domain); ret = -EINVAL ;if ( d !=NULL ) { - ret =final_setup_guest (d, &op->u.builddomain); + ret =set_info_guest (d, &op->u.setdomaininfo);put_domain (d); } }
xen/common/domain.c +15 -13
@@ -260,34 +260,36 @@* than domain 0. ie. the domains that are being built by the userspace dom0 * domain builder. */ -int final_setup_guest (struct domain *p,dom0_builddomain_t *builddomain) +int set_info_guest (struct domain *p,dom0_setdomaininfo_t *setdomain) {int rc =0 ;full_execution_context_t *c; +struct exec_domain *ed = p->exec_domain[setdomain->exec_domain]; + +if (ed ==NULL ) +return -EINVAL ; + +if (test_bit (DF_CONSTRUCTED , &p->d_flags) && + !test_bit (EDF_CTRLPAUSE , &ed->ed_flags)) +return -EINVAL ;if ( (c =xmalloc (full_execution_context_t)) ==NULL )return -ENOMEM ; -if (test_bit (DF_CONSTRUCTED , &p->d_flags) ) - { - rc = -EINVAL ; - goto out; - } - -if (copy_from_user (c, builddomain->ctxt,sizeof (*c)) ) +if (copy_from_user (c, setdomain->ctxt,sizeof (*c)) ) { rc = -EFAULT ; goto out; } - -if ( (rc =arch_final_setup_guest (p->exec_domain[0 ],c)) !=0 ) + +if ( (rc =arch_set_info_guest (p->exec_domain[setdomain->exec_domain],c)) !=0 ) goto out;/* Set up the shared info structure. */ update_dom_time (p); - +set_bit (DF_CONSTRUCTED , &p->d_flags); - + out:if ( c !=NULL )xfree (c);
@@ -334,7 +336,7 @@sched_add_domain (ed); -if ( (rc =arch_final_setup_guest (ed, c)) !=0 ) { +if ( (rc =arch_set_info_guest (ed, c)) !=0 ) {sched_rem_domain (ed); goto out; }
xen/include/public/dom0_ops.h +7 -7
@@ -109,16 +109,16 @@u64 cpu_time;/* 40 */ }PACKED dom0_getdomaininfo_t;/* 48 bytes */ -#define DOM0_BUILDDOMAIN 13 +#define DOM0_SETDOMAININFO 13typedef struct {/* IN variables. */ -domid_t domain;/* 0 */ -u16 __pad0;/* 2 */ -u32 __pad1;/* 4 */ +domid_t domain;/* 0 */ +u16 exec_domain;/* 2 */ +u32 __pad0;/* 4 */ /* IN/OUT parameters */ -full_execution_context_t *ctxt;/* 8 */ +full_execution_context_t *ctxt;/* 8 */ MEMORY_PADDING ; -} PACKED dom0_builddomain_t; /* 16 bytes */ +} PACKED dom0_setdomaininfo_t; /* 16 bytes */#define DOM0_IOPL 14 typedef struct {
@@ -426,7 +426,7 @@dom0_getmemlist_t getmemlist;dom0_schedctl_t schedctl;dom0_adjustdom_t adjustdom; -dom0_builddomain_t builddomain; +dom0_setdomaininfo_t setdomaininfo;dom0_getdomaininfo_t getdomaininfo;dom0_getpageframeinfo_t getpageframeinfo;dom0_iopl_t iopl;
xen/include/xen/domain.h +1 -1
@@ -18,7 +18,7 @@extern void arch_do_boot_vcpu (struct exec_domain *ed); -extern int arch_final_setup_guest ( +extern int arch_set_info_guest (struct exec_domain *d,full_execution_context_t *c);extern void free_perdomain_pt (struct domain *d);
xen/include/xen/sched.h +2 -1
@@ -220,7 +220,7 @@ unsigned long image_start, unsigned long image_len, unsigned long initrd_start, unsigned long initrd_len, char *cmdline); -extern int final_setup_guest (struct domain *d,dom0_builddomain_t *); +extern int set_info_guest (struct domain *d,dom0_setdomaininfo_t *);struct domain *find_domain_by_id (domid_t dom);struct domain *find_last_domain (void );
@@ -316,6 +316,7 @@#define EDF_RUNNING 12/* Currently running on a CPU. */ #define EDF_CPUPINNED 13/* Disables auto-migration. */ #define EDF_MIGRATED 14/* Domain migrated between CPUs. */ +#define EDF_DONEINIT 15/* Initialization completed . */ static inline int domain_runnable (struct exec_domain *d) {
# This is a BitKeeper generated diff -Nru style patch. #
# ChangeSet
# 2005/03/10 20:28:04-08:00 [email protected]
# bug fixes to ptrace emulation
#
# BitKeeper/etc/logging_ok
# 2005/03/10 20:28:04-08:00 [email protected] +1 -0
# Logging to [email protected] accepted
#
# xen/arch/x86/traps.c # 2005/03/10 20:27:44-08:00 [email protected] +20 -9 # handle trace trap as well as int3 # # xen/arch/x86/domain.c # 2005/03/10 20:27:44-08:00 [email protected] +8 -8 # move register copying above segment check # # tools/libxc/xc_ptrace.c # 2005/03/10 20:27:44-08:00 [email protected] +34 -17 # fix mask handling of pts # fix single-stepping # simplify PEEK and POKE operations # # tools/libxc/xc_linux_build.c # 2005/03/10 20:27:44-08:00 [email protected] +1 -1 # move setting of exec_domain to more sensible location # diff -Nru a/tools/libxc/xc_linux_build.c b/tools/libxc/xc_linux_build.c --- a/tools/libxc/xc_linux_build.c 2005-03-11 10:38:12 -08:00 +++ b/tools/libxc/xc_linux_build.c 2005-03-11 10:38:12 -08:00 @@ -369,7 +369,6 @@
op.cmd = DOM0_GETDOMAININFO;
op.u.getdomaininfo.domain = (domid_t)domid;
- launch_op.u.setdomaininfo.exec_domain = 0;
op.u.getdomaininfo.exec_domain = 0;
op.u.getdomaininfo.ctxt = ctxt;
if ( (do_dom0_op(xc_handle, &op) < 0) ||
@@ -461,6 +460,7 @@
memset( &launch_op, 0, sizeof(launch_op) );
launch_op.u.setdomaininfo.domain = (domid_t)domid;
+ launch_op.u.setdomaininfo.exec_domain = 0;
launch_op.u.setdomaininfo.ctxt = ctxt;
launch_op.cmd = DOM0_SETDOMAININFO;tools/libxc/xc_ptrace.c +34 -17
126 lines not on this page · raw message
xen/arch/x86/domain.c +8 -8
@@ -431,6 +431,14 @@unsigned long phys_basetab;int i, rc; +memcpy (&ed->arch.user_ctxt, + &c->cpu_ctxt, +sizeof (ed->arch.user_ctxt)); + +memcpy (&ed->arch.i387, + &c->fpu_ctxt, +sizeof (ed->arch.i387)); +/* * This is sufficient! If the descriptor DPL differs from CS RPL then we'll * #GP. If DS, ES, FS, GS are DPL 0 then they'll be cleared automatically.
@@ -440,14 +448,6 @@if ( ((ed->arch.user_ctxt.cs &3 ) ==0 ) || ((ed->arch.user_ctxt.ss &3 ) ==0 ) )return -EINVAL ; - -memcpy (&ed->arch.user_ctxt, - &c->cpu_ctxt, -sizeof (ed->arch.user_ctxt)); - -memcpy (&ed->arch.i387, - &c->fpu_ctxt, -sizeof (ed->arch.i387));if (test_bit (EDF_DONEINIT , &ed->ed_flags))return 0 ;
xen/arch/x86/traps.c +20 -9
@@ -225,14 +225,13 @@ }else if (KERNEL_MODE (ed, regs) && ed->domain->id !=0 ) { - regs->eflags &= ~X86_EFLAGS_TF ;if ( !test_and_set_bit (EDF_CTRLPAUSE , &ed->ed_flags) ) {while (ed == current)__enter_scheduler ();domain_pause_by_systemcontroller (ed->domain); } -return 0 ; + goto out; } ti = current->arch.traps +3 ; tb->flags =TBF_EXCEPTION ;
@@ -241,6 +240,7 @@if (TI_GET_IF (ti) ) ed->vcpu_info->evtchn_upcall_mask =1 ; + out:return 0 ; }
@@ -694,8 +694,8 @@ asmlinkage int do_debug(struct xen_regs *regs) {unsigned long condition; -struct exec_domain *d = current; -struct trap_bounce *tb = &d->arch.trap_bounce; +struct exec_domain *ed = current; +struct trap_bounce *tb = &ed->arch.trap_bounce;DEBUGGER_trap_entry (TRAP_debug, regs);
@@ -703,7 +703,7 @@/* Mask out spurious debug traps due to lazy DR7 setting */ if ( (condition & (DR_TRAP0 |DR_TRAP1 |DR_TRAP2 |DR_TRAP3 )) && - (d->arch.debugreg[7 ] ==0 ) ) + (ed->arch.debugreg[7 ] ==0 ) ) { __asm__("mov %0,%%db7" : :"r" (0UL )); goto out;
@@ -720,14 +720,25 @@* breakpoint, which can't happen to us. */ goto out; - } + } +else if (KERNEL_MODE (ed, regs) && ed->domain->id !=0 ) + { + regs->eflags &= ~EF_TF ; +if ( !test_and_set_bit (EDF_CTRLPAUSE , &ed->ed_flags) ) { +while (ed == current) +__enter_scheduler (); +domain_pause_by_systemcontroller (ed->domain); + } + + goto out; + }/* Save debug status register where guest OS can peek at it */ - d->arch.debugreg[6 ] = condition; + ed->arch.debugreg[6 ] = condition; tb->flags =TBF_EXCEPTION ; - tb->cs = d->arch.traps[1 ].cs; - tb->eip = d->arch.traps[1 ].address; + tb->cs = ed->arch.traps[1 ].cs; + tb->eip = ed->arch.traps[1 ].address; out:return EXCRET_not_a_fault;