gdbsx: fix 3 bugs
cover gdbsx: fix 3 bugs
Release manager requests:
patch 1 should be in 4.4.0
patch 3 and 4 would be good to be in 4.4.0
patch 2 is optional.
While tracking down a bug in seabios/grub I found the bug in patch 1.
There are 2 ways that gfn will not be INVALID_GFN and yet mfn will be INVALID_MFN.
1) p2m_is_readonly(gfntype) and writing memory.
2) the requested vaddr does not exist.
This may only be an issue for a HVM guest that is in real mode (I.E. no page tables).
Patch 2 is debug logging that was used to find the 2nd way.
Patch 3 and 4 are more of a cleanup bug fix.
Don Slutz (4):
dbg_rw_guest_mem: need to call put_gfn in error path.
dbg_rw_guest_mem: Enable debug log output
xg_read_mem: Report on error. XEN_DOMCTL_gdbsx_guestmemio: always do the copyback.
tools/debugger/gdbsx/xg/xg_main.c | 6 ++++-- xen/arch/x86/debug.c | 44 ++++++++++++++++++++++++++++++--------- xen/arch/x86/domctl.c | 3 +-- 3 files changed, 39 insertions(+), 14 deletions(-)
Signature · 1 line
1.8.4
PATCH 1/4 dbg_rw_guest_mem: need to call put_gfn in error path.
Using a 1G hvm domU (in grub) and gdbsx:
(gdb) set arch i8086
warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default i8086 settings.
The target architecture is assumed to be i8086
(gdb) target remote localhost:9999
Remote debugging using localhost:9999
Remote debugging from host 127.0.0.10x0000d475 in ?? ()
(gdb) x/1xh 0x6ae9168b
Will reproduce this bug.
With a debug=y build you will get:
Assertion '!preempt_count()' failed at preempt.c:37
For a debug=n build you will get a dom0 VCPU hung (at some point) in:
[ffff82c4c0126eec] _write_lock+0x3c/0x50
ffff82c4c01e43a0 __get_gfn_type_access+0x150/0x230
ffff82c4c0158885 dbg_rw_mem+0x115/0x360
ffff82c4c0158fc8 arch_do_domctl+0x4b8/0x22f0
ffff82c4c01709ed get_page+0x2d/0x100
ffff82c4c01031aa do_domctl+0x2ba/0x11e0
ffff82c4c0179662 do_mmuext_op+0x8d2/0x1b20
ffff82c4c0183598 __update_vcpu_system_time+0x288/0x340
ffff82c4c015c719 continue_nonidle_domain+0x9/0x30
ffff82c4c012938b add_entry+0x4b/0xb0
ffff82c4c02223f9 syscall_enter+0xa9/0xaeAnd gdb output:
(gdb) x/1xh 0x6ae9168b0x6ae9168b: 0x3024
(gdb) x/1xh 0x6ae9168b0x6ae9168b: Ignoring packet error, continuing...
Reply contains invalid hex digit 116
The 1st one worked because the p2m.lock is recursive and the PCPU had not yet changed.
crash reports (for example):
crash> mm_rwlock_t 0xffff83083f913010
struct mm_rwlock_t {
lock = {
raw = {
lock = 2147483647
},
debug = {<No data fields>} },
unlock_level = 0,
recurse_count = 1,
locker = 1,
locker_function = 0xffff82c4c022c640 <__func__.13514> "__get_gfn_type_access"
}
--- xen/arch/x86/debug.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
xen/arch/x86/debug.c +4 -1
@@ -161,8 +161,11 @@ dbg_rw_guest_mem(dbgva_t addr, dbgbyte_t *buf, int len, struct domain *dp, mfn = (has_hvm_container_domain (dp) ?dbg_hvm_va2mfn (addr, dp, toaddr, &gfn) :dbg_pv_va2mfn (addr, dp, pgd3)); -if ( mfn ==INVALID_MFN ) +if ( mfn ==INVALID_MFN ) { +if ( gfn !=INVALID_GFN ) +put_gfn (dp, gfn);break ; + } va =map_domain_page (mfn); va = va + (addr & (PAGE_SIZE -1 ));
Signature · 1 line
1.8.4
Re: [BUGFIX][PATCH 1/4] dbg_rw_guest_mem: need to call put_gfn in error path.
Quoted 70 lines · Don Slutz
Using a 1G hvm domU (in grub) and gdbsx:
(gdb) set arch i8086
warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default i8086 settings.The target architecture is assumed to be i8086
(gdb) target remote localhost:9999
Remote debugging using localhost:9999
Remote debugging from host 127.0.0.10x0000d475in ?? ()
(gdb) x/1xh0x6ae9168bWill reproduce this bug.
With a debug=y build you will get:
Assertion '!preempt_count()' failed at preempt.c:37
For a debug=n build you will get a dom0 VCPU hung (at some point) in:
[ffff82c4c0126eec] _write_lock+0x3c/0x50 ffff82c4c01e43a0 __get_gfn_type_access+0x150/0x230 ffff82c4c0158885 dbg_rw_mem+0x115/0x360 ffff82c4c0158fc8 arch_do_domctl+0x4b8/0x22f0 ffff82c4c01709ed get_page+0x2d/0x100 ffff82c4c01031aa do_domctl+0x2ba/0x11e0 ffff82c4c0179662 do_mmuext_op+0x8d2/0x1b20 ffff82c4c0183598 __update_vcpu_system_time+0x288/0x340 ffff82c4c015c719 continue_nonidle_domain+0x9/0x30 ffff82c4c012938b add_entry+0x4b/0xb0 ffff82c4c02223f9 syscall_enter+0xa9/0xaeAnd gdb output:
(gdb) x/1xh
0x6ae9168b0x6ae9168b:0x3024
(gdb) x/1xh0x6ae9168b0x6ae9168b: Ignoring packet error, continuing...
Reply contains invalid hex digit 116The 1st one worked because the p2m.lock is recursive and the PCPU had not yet changed.
crash reports (for example):
crash>
mm_rwlock_t0xffff83083f913010
structmm_rwlock_t{lock = { raw = { lock = 2147483647 }, debug = {<No data fields>}},
unlock_level= 0,
recurse_count= 1,
locker = 1,
locker_function=0xffff82c4c022c640<__func__.13514> "__get_gfn_type_access"
}Signed-off-by Don Slutz <[email protected]>--- xen/arch/x86/debug.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)xen/arch/x86/debug.c +0
-0
xen/arch/x86/debug.c dbg_rw_guest_mem(dbgva_t addr, dbgbyte_t *buf, int len, struct domain *dp, · line 164
Quoted 5 lines
xen/arch/x86/debug.c +1
-1@@ -161,8 +161,11 @@ dbg_rw_guest_mem(dbgva_t addr, dbgbyte_t *buf, int len, struct domain *dp, mfn = (has_hvm_container_domain (dp) ?dbg_hvm_va2mfn (addr, dp, toaddr, &gfn) :dbg_pv_va2mfn (addr, dp, pgd3)); -if ( mfn ==INVALID_MFN ) +if ( mfn ==INVALID_MFN ) {
Xen coding style would have this brace on the next line.
Content-wise, I think it would be better to fix up the error path in dbg_hvm_va2mfn() so it doesn't exit with INVALID_MFN having taken a reference on the gfn.
~Andrew
Quoted 7 lines
xen/arch/x86/debug.c +3
-0+if ( gfn !=INVALID_GFN ) +put_gfn (dp, gfn);break ; + } va =map_domain_page (mfn); va = va + (addr & (PAGE_SIZE -1 ));
Re: [BUGFIX][PATCH 1/4] dbg_rw_guest_mem: need to call put_gfn in error path.
Quoted 66 lines · Andrew Cooper
Quoted 65 lines · Don Slutz
Using a 1G hvm domU (in grub) and gdbsx:
(gdb) set arch i8086
warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default i8086 settings.The target architecture is assumed to be i8086
(gdb) target remote localhost:9999
Remote debugging using localhost:9999
Remote debugging from host 127.0.0.10x0000d475in ?? ()
(gdb) x/1xh0x6ae9168bWill reproduce this bug.
With a debug=y build you will get:
Assertion '!preempt_count()' failed at preempt.c:37
For a debug=n build you will get a dom0 VCPU hung (at some point) in:
[ffff82c4c0126eec] _write_lock+0x3c/0x50 ffff82c4c01e43a0 __get_gfn_type_access+0x150/0x230 ffff82c4c0158885 dbg_rw_mem+0x115/0x360 ffff82c4c0158fc8 arch_do_domctl+0x4b8/0x22f0 ffff82c4c01709ed get_page+0x2d/0x100 ffff82c4c01031aa do_domctl+0x2ba/0x11e0 ffff82c4c0179662 do_mmuext_op+0x8d2/0x1b20 ffff82c4c0183598 __update_vcpu_system_time+0x288/0x340 ffff82c4c015c719 continue_nonidle_domain+0x9/0x30 ffff82c4c012938b add_entry+0x4b/0xb0 ffff82c4c02223f9 syscall_enter+0xa9/0xaeAnd gdb output:
(gdb) x/1xh
0x6ae9168b0x6ae9168b:0x3024
(gdb) x/1xh0x6ae9168b0x6ae9168b: Ignoring packet error, continuing...
Reply contains invalid hex digit 116The 1st one worked because the p2m.lock is recursive and the PCPU had not yet changed.
crash reports (for example):
crash>
mm_rwlock_t0xffff83083f913010struct mm_rwlock_t { lock = { raw = { lock = 2147483647 }, debug = {<No data fields>} }, unlock_level = 0, recurse_count = 1, locker = 1, locker_function = 0xffff82c4c022c640 <__func__.13514> "__get_gfn_type_access" }Signed-off-by Don Slutz <[email protected]>--- xen/arch/x86/debug.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 11 lines
xen/arch/x86/debug.c dbg_rw_guest_mem(dbgva_t addr, dbgbyte_t *buf, int len, struct domain *dp, · line 164
Quoted 10 lines
xen/arch/x86/debug.c +1
-1@@ -161,8 +161,11 @@ dbg_rw_guest_mem(dbgva_t addr, dbgbyte_t *buf, int len, struct domain *dp, mfn = (has_hvm_container_domain (dp) ?dbg_hvm_va2mfn (addr, dp, toaddr, &gfn) :dbg_pv_va2mfn (addr, dp, pgd3)); -if ( mfn ==INVALID_MFN ) +if ( mfn ==INVALID_MFN ) {Xen coding style would have this brace on the next line.
Will fix.
Quoted 3 lines
Content-wise, I think it would be better to fix up the error path in
dbg_hvm_va2mfn()so it doesn't exit withINVALID_MFNhaving taken a reference on the gfn.
That would only fix "p2m_is_readonly(gfntype) and writing memory" case (see cover letter). To fix "the requested vaddr does not exist" case, I would need to add a check for INVALID_MFN in dbg_hvm_va2mfn() also. As It currently stands it is a smaller fix.
-Don Slutz
Quoted 9 lines
~Andrew
Quoted 7 lines
xen/arch/x86/debug.c +3
-0+if ( gfn !=INVALID_GFN ) +put_gfn (dp, gfn);break ; + } va =map_domain_page (mfn); va = va + (addr & (PAGE_SIZE -1 ));
Re: [BUGFIX][PATCH 1/4] dbg_rw_guest_mem: need to call put_gfn in error path.
Quoted 89 lines · Don Slutz
Quoted 68 lines · Andrew Cooper
Quoted 67 lines · Don Slutz
Using a 1G hvm domU (in grub) and gdbsx:
(gdb) set arch i8086
warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration
of GDB. Attempting to continue with the default i8086 settings.The target architecture is assumed to be i8086
(gdb) target remote localhost:9999
Remote debugging using localhost:9999
Remote debugging from host 127.0.0.10x0000d475in ?? ()
(gdb) x/1xh0x6ae9168bWill reproduce this bug.
With a debug=y build you will get:
Assertion '!preempt_count()' failed at preempt.c:37
For a debug=n build you will get a dom0 VCPU hung (at some point) in:
[ffff82c4c0126eec] _write_lock+0x3c/0x50 ffff82c4c01e43a0 __get_gfn_type_access+0x150/0x230 ffff82c4c0158885 dbg_rw_mem+0x115/0x360 ffff82c4c0158fc8 arch_do_domctl+0x4b8/0x22f0 ffff82c4c01709ed get_page+0x2d/0x100 ffff82c4c01031aa do_domctl+0x2ba/0x11e0 ffff82c4c0179662 do_mmuext_op+0x8d2/0x1b20 ffff82c4c0183598 __update_vcpu_system_time+0x288/0x340 ffff82c4c015c719 continue_nonidle_domain+0x9/0x30 ffff82c4c012938b add_entry+0x4b/0xb0 ffff82c4c02223f9 syscall_enter+0xa9/0xaeAnd gdb output:
(gdb) x/1xh
0x6ae9168b0x6ae9168b:0x3024
(gdb) x/1xh0x6ae9168b0x6ae9168b: Ignoring packet error, continuing...
Reply contains invalid hex digit 116The 1st one worked because the p2m.lock is recursive and the PCPU had not yet changed.
crash reports (for example):
crash>
mm_rwlock_t0xffff83083f913010struct mm_rwlock_t { lock = { raw = { lock = 2147483647 }, debug = {<No data fields>} }, unlock_level = 0, recurse_count = 1, locker = 1, locker_function = 0xffff82c4c022c640 <__func__.13514>"
__get_gfn_type_access"
}Signed-off-by Don Slutz <[email protected]>--- xen/arch/x86/debug.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)Quoted 12 lines
xen/arch/x86/debug.c dbg_rw_guest_mem(dbgva_t addr, dbgbyte_t *buf, · line 165
Quoted 11 lines
xen/arch/x86/debug.c +1
-1@@ -161,8 +161,11 @@ dbg_rw_guest_mem(dbgva_t addr, dbgbyte_t *buf, int len, struct domain *dp, mfn = (has_hvm_container_domain (dp) ?dbg_hvm_va2mfn (addr, dp, toaddr, &gfn) :dbg_pv_va2mfn (addr, dp, pgd3)); -if ( mfn ==INVALID_MFN ) +if ( mfn ==INVALID_MFN ) {Xen coding style would have this brace on the next line.
Will fix.
Quoted 3 lines
Content-wise, I think it would be better to fix up the error path in
dbg_hvm_va2mfn()so it doesn't exit withINVALID_MFNhaving taken a reference on the gfn.
Quoted 6 lines
That would only fix "
p2m_is_readonly(gfntype)and writing memory" case (see cover letter). To fix "the requested vaddr does not exist" case, I would need to add a check forINVALID_MFNindbg_hvm_va2mfn()also. As It currently stands it is a smaller fix.-Don Slutz
Size really doesn't matter.
What does matter is that the caller of dbg_hvm_va2mfn() should not have to cleanup a reference taken when it returns an error.
Anyway, "the requested vaddr does not exist" is covered by paging_gva_to_gfn(), which will exit before taking the ref on the gfn.
The following (completely untested) patch ought to do:
xen/arch/x86/debug.c +0 -0
@@ -63,10 +63,17 @@ dbg_hvm_va2mfn(dbgva_t vaddr, struct domain *dp, int
toaddr,
if ( p2m_is_readonly(gfntype) && toaddr )
{
DBGP2("kdb:p2m_is_readonly: gfntype:%x\n", gfntype);
- return INVALID_MFN;
+ mfn = INVALID_MFN;
}
DBGP2("X: vaddr:%lx domid:%d mfn:%lx\n", vaddr, dp->domain_id, mfn);+
+ if ( mfn == INVALID_MFN )
+ {
+ put_gfn(dp, *gfn);
+ *gfn = INVALID_GFN;
+ }
+
return mfn;
}
Re: [BUGFIX][PATCH 1/4] dbg_rw_guest_mem: need to call put_gfn in error path.
Quoted 93 lines · Andrew Cooper
Quoted 92 lines · Don Slutz
Quoted 68 lines · Andrew Cooper
Quoted 67 lines · Don Slutz
Using a 1G hvm domU (in grub) and gdbsx:
(gdb) set arch i8086
warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration
of GDB. Attempting to continue with the default i8086 settings.The target architecture is assumed to be i8086
(gdb) target remote localhost:9999
Remote debugging using localhost:9999
Remote debugging from host 127.0.0.10x0000d475in ?? ()
(gdb) x/1xh0x6ae9168bWill reproduce this bug.
With a debug=y build you will get:
Assertion '!preempt_count()' failed at preempt.c:37
For a debug=n build you will get a dom0 VCPU hung (at some point) in:
[ffff82c4c0126eec] _write_lock+0x3c/0x50 ffff82c4c01e43a0 __get_gfn_type_access+0x150/0x230 ffff82c4c0158885 dbg_rw_mem+0x115/0x360 ffff82c4c0158fc8 arch_do_domctl+0x4b8/0x22f0 ffff82c4c01709ed get_page+0x2d/0x100 ffff82c4c01031aa do_domctl+0x2ba/0x11e0 ffff82c4c0179662 do_mmuext_op+0x8d2/0x1b20 ffff82c4c0183598 __update_vcpu_system_time+0x288/0x340 ffff82c4c015c719 continue_nonidle_domain+0x9/0x30 ffff82c4c012938b add_entry+0x4b/0xb0 ffff82c4c02223f9 syscall_enter+0xa9/0xaeAnd gdb output:
(gdb) x/1xh
0x6ae9168b0x6ae9168b:0x3024
(gdb) x/1xh0x6ae9168b0x6ae9168b: Ignoring packet error, continuing...
Reply contains invalid hex digit 116The 1st one worked because the p2m.lock is recursive and the PCPU had not yet changed.
crash reports (for example):
crash>
mm_rwlock_t0xffff83083f913010struct mm_rwlock_t { lock = { raw = { lock = 2147483647 }, debug = {<No data fields>} }, unlock_level = 0, recurse_count = 1, locker = 1, locker_function = 0xffff82c4c022c640 <__func__.13514>"
__get_gfn_type_access"
}Signed-off-by Don Slutz <[email protected]>--- xen/arch/x86/debug.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)Quoted 12 lines
xen/arch/x86/debug.c dbg_rw_guest_mem(dbgva_t addr, dbgbyte_t *buf, · line 165
Quoted 11 lines
xen/arch/x86/debug.c +1
-1@@ -161,8 +161,11 @@ dbg_rw_guest_mem(dbgva_t addr, dbgbyte_t *buf, int len, struct domain *dp, mfn = (has_hvm_container_domain (dp) ?dbg_hvm_va2mfn (addr, dp, toaddr, &gfn) :dbg_pv_va2mfn (addr, dp, pgd3)); -if ( mfn ==INVALID_MFN ) +if ( mfn ==INVALID_MFN ) {Xen coding style would have this brace on the next line.
Will fix.
Quoted 3 lines
Content-wise, I think it would be better to fix up the error path in
dbg_hvm_va2mfn()so it doesn't exit withINVALID_MFNhaving taken a reference on the gfn.That would only fix "
p2m_is_readonly(gfntype)and writing memory" case (see cover letter). To fix "the requested vaddr does not exist" case, I would need to add a check forINVALID_MFNindbg_hvm_va2mfn()also. As It currently stands it is a smaller fix.
Quoted 8 lines
Quoted 1 line
-Don Slutz
Size really doesn't matter.
What does matter is that the caller of
dbg_hvm_va2mfn()should not have to cleanup a reference taken when it returns an error.Anyway, "the requested vaddr does not exist" is covered by
paging_gva_to_gfn(), which will exit before taking the ref on the gfn.
This is a false statement. A valid GFN is returned in this case. The lock is taken by get_gfn().
Quoted 17 lines
The following (completely untested) patch ought to do:
xen/arch/x86/debug.c +1
-1@@ -63,10 +63,17 @@ dbg_hvm_va2mfn(dbgva_t vaddr, struct domain *dp, int toaddr, if ( p2m_is_readonly(gfntype) && toaddr ) {DBGP2 ("kdb:p2m_is_readonly: gfntype:%x\n" , gfntype); -return INVALID_MFN ; + mfn =INVALID_MFN ; }
xen/arch/x86/debug.c dbg_hvm_va2mfn(dbgva_t vaddr, struct domain *dp, int · line 79
Quoted 10 lines
xen/arch/x86/debug.c +7
-0DBGP2 ("X: vaddr:%lx domid:%d mfn:%lx\n" , vaddr, dp->domain_id, mfn); + +if ( mfn ==INVALID_MFN ) + { +put_gfn (dp, *gfn); + *gfn =INVALID_GFN ; + } +return mfn; }
However this patch (which I have now tested) works fine. I will post it soon as part of v2 of this patch set.
-Don Slutz
Re: [BUGFIX][PATCH 1/4] dbg_rw_guest_mem: need to call put_gfn in error path.
Quoted 6 lines · On Mon, 06 Jan 2014 14:50:58 -0500 Don Slutz <[email protected]> wrote:
Quoted 5 lines · Andrew Cooper
Quoted 4 lines · Don Slutz
Quoted 3 lines · Andrew Cooper
Quoted 2 lines · Don Slutz
Using a 1G hvm domU (in grub) and gdbsx:
......
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Content-wise, I think it would be better to fix up the error path in
dbg_hvm_va2mfn()so it doesn't exit withINVALID_MFNhaving taken a reference on the gfn.
Right, that is similar to what I had done when I had noticed this early this year. I had just changed to nolock query since the domain is paused during this call, but in hindsight it's better to do locked query. So I prefer doing in dbg_hvm_va2mfn() too.
http://lists.xen.org/archives/html/xen-devel/2013-01/msg00781.html
Will wait for your v2 you said you will be submitting.
thanks,
mukesh
PATCH 2/4 dbg_rw_guest_mem: Enable debug log output
In reply to Don SlutzThis also fixes the old debug output to compile and work if DBGP1 and DBGP2 are defined like DBGP3.
--- xen/arch/x86/debug.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-)
xen/arch/x86/debug.c +31 -10
@@ -41,6 +41,12 @@#define DBGP2 (...) ((void)0)#endif +#ifdef XEN_GDBSX_DEBUG3 +#define DBGP3 (...) gdprintk(XENLOG_DEBUG, __VA_ARGS__) +#else +#define DBGP3 (...) ((void)0) +#endif +/* Returns: mfn for the given (hvm guest) vaddr */ static unsigned long dbg_hvm_va2mfn(dbgva_t vaddr, struct domain *dp, int toaddr,
@@ -60,6 +66,7 @@ dbg_hvm_va2mfn(dbgva_t vaddr, struct domain *dp, int toaddr, } mfn =mfn_x (get_gfn (dp, *gfn, &gfntype)); +DBGP3 ("L: vaddr:%lx domid:%d mfn:%lx\n" , vaddr, dp->domain_id, mfn);if (p2m_is_readonly (gfntype) && toaddr ) {DBGP2 ("kdb:p2m_is_readonly: gfntype:%x\n" , gfntype);
@@ -102,8 +109,8 @@ dbg_pv_va2mfn(dbgva_t vaddr, struct domain *dp, uint64_t pgd3val) l4e = l4t[l4_table_offset (vaddr)];unmap_domain_page (l4t); mfn =l4e_get_pfn (l4e); -DBGP2 ("l4t:%p l4to:%lx l4e:%lx mfn:%lx\n" , l4t, -l4_table_offset (vaddr), l4e, mfn); +DBGP2 ("l4t:%p l4to:%lx l4e:%" PRIpte" mfn:%lx\n" , + l4t,l4_table_offset (vaddr),l4e_get_intpte (l4e), mfn);if ( !(l4e_get_flags (l4e) & _PAGE_PRESENT) ) {DBGP1 ("l4 PAGE not present. vaddr:%lx cr3:%lx\n" , vaddr, cr3);
@@ -114,8 +121,8 @@ dbg_pv_va2mfn(dbgva_t vaddr, struct domain *dp, uint64_t pgd3val) l3e = l3t[l3_table_offset (vaddr)];unmap_domain_page (l3t); mfn =l3e_get_pfn (l3e); -DBGP2 ("l3t:%p l3to:%lx l3e:%lx mfn:%lx\n" , l3t, -l3_table_offset (vaddr), l3e, mfn); +DBGP2 ("l3t:%p l3to:%lx l3e:%" PRIpte" mfn:%lx\n" , + l3t,l3_table_offset (vaddr),l3e_get_intpte (l3e), mfn);if ( !(l3e_get_flags (l3e) & _PAGE_PRESENT) || (l3e_get_flags (l3e) & _PAGE_PSE) ) {
@@ -128,8 +135,8 @@ dbg_pv_va2mfn(dbgva_t vaddr, struct domain *dp, uint64_t pgd3val) l2e = l2t[l2_table_offset (vaddr)];unmap_domain_page (l2t); mfn =l2e_get_pfn (l2e); -DBGP2 ("l2t:%p l2to:%lx l2e:%lx mfn:%lx\n" , l2t,l2_table_offset (vaddr), - l2e, mfn); +DBGP2 ("l2t:%p l2to:%lx l2e:%" PRIpte" mfn:%lx\n" , + l2t,l2_table_offset (vaddr),l2e_get_intpte (l2e), mfn);if ( !(l2e_get_flags (l2e) & _PAGE_PRESENT) || (l2e_get_flags (l2e) & _PAGE_PSE) ) {
@@ -140,8 +147,8 @@ dbg_pv_va2mfn(dbgva_t vaddr, struct domain *dp, uint64_t pgd3val) l1e = l1t[l1_table_offset (vaddr)];unmap_domain_page (l1t); mfn =l1e_get_pfn (l1e); -DBGP2 ("l1t:%p l1to:%lx l1e:%lx mfn:%lx\n" , l1t,l1_table_offset (vaddr), - l1e, mfn); +DBGP2 ("l1t:%p l1to:%lx l1e:%" PRIpte" mfn:%lx\n" , + l1t,l1_table_offset (vaddr),l1e_get_intpte (l1e), mfn);return mfn_valid (mfn) ? mfn :INVALID_MFN ; }
@@ -162,8 +169,11 @@ dbg_rw_guest_mem(dbgva_t addr, dbgbyte_t *buf, int len, struct domain *dp, ?dbg_hvm_va2mfn (addr, dp, toaddr, &gfn) : dbg_pv_va2mfn(addr, dp, pgd3));if ( mfn ==INVALID_MFN ) { -if ( gfn !=INVALID_GFN ) +if ( gfn !=INVALID_GFN ) {put_gfn (dp, gfn); +DBGP3 ("R: addr:%lx pagecnt=%ld domid:%d mfn:%lx\n" , + addr, pagecnt, dp->domain_id, mfn); + }break ; }
@@ -181,8 +191,11 @@ dbg_rw_guest_mem(dbgva_t addr, dbgbyte_t *buf, int len, struct domain *dp, }unmap_domain_page (va); -if ( gfn !=INVALID_GFN ) +if ( gfn !=INVALID_GFN ) {put_gfn (dp, gfn); +DBGP3 ("R: addr:%lx pagecnt=%ld domid:%d mfn:%lx\n" , + addr, pagecnt, dp->domain_id, mfn); + } addr += pagecnt; buf += pagecnt;
@@ -226,3 +239,11 @@ dbg_rw_mem(dbgva_t addr, dbgbyte_t *buf, int len, domid_t domid, int toaddr,return len; } +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
1.8.4
Re: [PATCH 2/4] dbg_rw_guest_mem: Enable debug log output
Quoted 5 lines · Don Slutz
This also fixes the old debug output to compile and work if DBGP1 and DBGP2 are defined like DBGP3.
xen/arch/x86/debug.c +0
-0@@ -226,3 +239,11 @@ dbg_rw_mem(dbgva_t addr, dbgbyte_t *buf, int len, domid_t domid, int toaddr,return len;
xen/arch/x86/debug.c dbg_rw_mem(dbgva_t addr, dbgbyte_t *buf, int len, domid_t domid, int toaddr, · line 249
Quoted 10 lines
xen/arch/x86/debug.c +8
-0} +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
??
Re: [PATCH 2/4] dbg_rw_guest_mem: Enable debug log output
Quoted 8 lines · Konrad Rzeszutek Wilk
Quoted 7 lines · Don Slutz
This also fixes the old debug output to compile and work if DBGP1 and DBGP2 are defined like DBGP3.
xen/arch/x86/debug.c +0
-0@@ -226,3 +239,11 @@ dbg_rw_mem(dbgva_t addr, dbgbyte_t *buf, int len, domid_t domid, int toaddr,return len; }
Quoted 9 lines
xen/arch/x86/debug.c dbg_rw_mem(dbgva_t addr, dbgbyte_t *buf, int len, domid_t domid, int toaddr, · line 249
Quoted 8 lines
xen/arch/x86/debug.c +8
-0+/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ ??
I take that as "Why add this"?
Dealing with many different styles of code, I find it helps to have this emacs add. From CODING_STYLE:
Emacs local variables
---------------------
A comment block containing local variables for emacs is permitted at the end of files. It should be:
/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
-Don Slutz
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/4] dbg_rw_guest_mem: Enable debug log output
Quoted 18 lines · Don Slutz
Quoted 5 lines · Konrad Rzeszutek Wilk
Review dbg_rw_mem(dbgva_t addr, dbgbyte_t *buf, int
Quoted 4 lines · Don Slutz
This also fixes the old debug output to compile and work if DBGP1 and DBGP2 are defined like DBGP3.
(quoted diff) +0
-0@@ -226,3 +239,11 @@ dbg_rw_mem(dbgva_t addr, dbgbyte_t *buf, intlen,
domid_tdomid, int toaddr,Quoted 11 lines
Quoted 11 lines
xen/arch/x86/debug.c +8
-0return len; } +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Quoted 8 lines
Quoted 1 line
??
I take that as "Why add this"?
Dealing with many different styles of code, I find it helps to have this
emacs add. FromCODING_STYLE:
Sure. But then this should be a separate patch. The way both in Xen and Linux is to have one logical change per patch.
I would recommend you split this out from this patch.
Quoted 17 lines
Emacs local variables
---------------------A comment block containing local variables for emacs is permitted at
the end of files. It should be:/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/-Don Slutz
Re: [PATCH 2/4] dbg_rw_guest_mem: Enable debug log output
In reply to Don SlutzQuoted 20 lines · Don Slutz
Quoted 8 lines · Konrad Rzeszutek Wilk
Quoted 7 lines · Don Slutz
This also fixes the old debug output to compile and work if DBGP1 and DBGP2 are defined like DBGP3.
xen/arch/x86/debug.c +0
-0@@ -226,3 +239,11 @@ dbg_rw_mem(dbgva_t addr, dbgbyte_t *buf, int len, domid_t domid, int toaddr,return len; }Quoted 9 lines
xen/arch/x86/debug.c dbg_rw_mem(dbgva_t addr, dbgbyte_t *buf, int len, domid_t domid, int toaddr, · line 249
Quoted 8 lines
xen/arch/x86/debug.c +8
-0+/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ ??
Quoted 4 lines
I take that as "Why add this"?
Dealing with many different styles of code, I find it helps to have this emacs add.
Yes, but why is it in the optional debug patch?
Re: [PATCH 2/4] dbg_rw_guest_mem: Enable debug log output
Quoted 20 lines · Ian Campbell
Quoted 19 lines · Don Slutz
Quoted 17 lines · Konrad Rzeszutek Wilk
Quoted 5 lines · Don Slutz
This also fixes the old debug output to compile and work if DBGP1 and DBGP2 are defined like DBGP3.
xen/arch/x86/debug.c +0
-0@@ -226,3 +239,11 @@ dbg_rw_mem(dbgva_t addr, dbgbyte_t *buf, int len, domid_t domid, int toaddr,return len;xen/arch/x86/debug.c dbg_rw_mem(dbgva_t addr, dbgbyte_t *buf, int len, domid_t domid, int toaddr, · line 249
Quoted 10 lines
xen/arch/x86/debug.c +8
-0} +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ ??
Quoted 7 lines
Quoted 4 lines
I take that as "Why add this"?
Dealing with many different styles of code, I find it helps to have this emacs add.
Yes, but why is it in the optional debug patch?
Because I did not think that it needs to be in 4.4.0. I have no issue with moving it into the 1st patch. Will wait for guidance.
-Don Slutz
Re: [PATCH 2/4] dbg_rw_guest_mem: Enable debug log output
Quoted 1 line · Don Slutz
Because I did not think that it needs to be in 4.4.0.
Oh, did you mean it was optional in the sense of could be deferred from 4.4.0 to 4.5.0 versus being entirely discardable?
Quoted 1 line
I have no issue with moving it into the 1st patch.
As usual a separate patch for a separate change would be best.
Ian.
Re: [PATCH 2/4] dbg_rw_guest_mem: Enable debug log output
Quoted 4 lines · Ian Campbell
Quoted 1 line · Don Slutz
Because I did not think that it needs to be in 4.4.0.
Oh, did you mean it was optional in the sense of could be deferred from 4.4.0 to 4.5.0 versus being entirely discardable?
Yes, that is what I was trying to say.
Quoted 2 lines
Quoted 2 lines
I have no issue with moving it into the 1st patch.
Will make this change it's own patch.
-Don Slutz
Quoted 4 lines
As usual a separate patch for a separate change would be best.
Ian.
Re: [PATCH 2/4] dbg_rw_guest_mem: Enable debug log output
In reply to Don SlutzQuoted 13 lines · On Sat, 4 Jan 2014 12:52:14 -0500 Don Slutz <[email protected]> wrote:
This also fixes the old debug output to compile and work if DBGP1 and DBGP2 are defined like DBGP3.
Signed-off-by Don Slutz <[email protected]>--- xen/arch/x86/debug.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-)xen/arch/x86/debug.c +0
-0
xen/arch/x86/debug.c line 49
Quoted 9 lines
xen/arch/x86/debug.c +6
-0@@ -41,6 +41,12 @@#define DBGP2 (...) ((void)0)#endif +#ifdef XEN_GDBSX_DEBUG3 +#define DBGP3 (...) gdprintk(XENLOG_DEBUG, __VA_ARGS__) +#else +#define DBGP3 (...) ((void)0) +#endif +
Umm... some hostorical perspective... this file is shared by both gdbsx, and kdb, and possibly any future debug type tools. While gdbsx got merged, kdb did not. So how about, just define say dbg_debug to replace kdbdbg, (please don't call it "debug" - I hate using words that grep million results), and then just change DBGP*. Also looks like DBGP is not used anywhere, so we only need two...
static volatile int dbg_debug;
#define DBGP(...) {(dbg_debug) ? printk(__VA_ARGS__) : 0;} #define DBGP1(...) {(dbg_debug > 1) ? printk(__VA_ARGS__) : 0;}
This allows us to not need XEN_GDBSX_DEBUG3, and also the debug can be enabled dynamically without recompile (in my case, via kdb).
thanks,
mukesh
PATCH 3/4 xg_read_mem: Report on error.
In reply to Don SlutzI had coded this with XGERR, but gdb will try to read memory without a direct request from the user. So the error message can be confusing.
--- tools/debugger/gdbsx/xg/xg_main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/debugger/gdbsx/xg/xg_main.c +4 -2
@@ -775,7 +775,7 @@ xg_read_mem(uint64_t guestva, char *tobuf, int tobuf_len, uint64_t pgd3val) {struct xen_domctl_gdbsx_memio *iop = &domctl.u.gdbsx_guest_memio;union {uint64_t llbuf8;char buf8[8 ];} u = {0 }; -int i; +int i, rc;XGTRC ("E:gva:%llx tobuf:%lx len:%d\n" , guestva, tobuf, tobuf_len);
@@ -786,7 +786,9 @@ xg_read_mem(uint64_t guestva, char *tobuf, int tobuf_len, uint64_t pgd3val) iop->len = tobuf_len; iop->gwr =0 ;/* not writing to guest */ -_domctl_hcall (XEN_DOMCTL_gdbsx_guestmemio, tobuf, tobuf_len); +if ( (rc =_domctl_hcall (XEN_DOMCTL_gdbsx_guestmemio, tobuf, tobuf_len)) ) +XGTRC ("ERROR: failed to read %d bytes. errno:%d rc:%d\n" , + iop->remain, errno, rc);for (i=0 ; i <XGMIN (8 , tobuf_len); u.buf8[i]=tobuf[i], i++);XGTRC ("X:remain:%d buf8:0x%llx\n" , iop->remain, u.llbuf8);
Signature · 1 line
1.8.4
Re: [BUGFIX][PATCH 3/4] xg_read_mem: Report on error.
Quoted 5 lines · On Sat, 4 Jan 2014 12:52:15 -0500 Don Slutz <[email protected]> wrote:
I had coded this with XGERR, but gdb will try to read memory without a direct request from the user. So the error message can be confusing.
Signed-off-by Don Slutz <[email protected]>
Quoted 29 lines
--- tools/debugger/gdbsx/xg/xg_main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/tools/debugger/gdbsx/xg/xg_main.cindex 5736b86..a192478 100644tools/debugger/gdbsx/xg/xg_main.c +4
-2@@ -775,7 +775,7 @@ xg_read_mem(uint64_t guestva, char *tobuf, int tobuf_len, uint64_t pgd3val) {struct xen_domctl_gdbsx_memio *iop = &domctl.u.gdbsx_guest_memio;union {uint64_t llbuf8;char buf8[8 ];} u = {0 }; -int i; +int i, rc;XGTRC ("E:gva:%llx tobuf:%lx len:%d\n" , guestva, tobuf, tobuf_len);@@ -786,7 +786,9 @@ xg_read_mem(uint64_t guestva, char *tobuf, int tobuf_len, uint64_t pgd3val) iop->len = tobuf_len; iop->gwr =0 ;/* not writing to guest */ -_domctl_hcall (XEN_DOMCTL_gdbsx_guestmemio, tobuf, tobuf_len); +if ( (rc =_domctl_hcall (XEN_DOMCTL_gdbsx_guestmemio, tobuf, tobuf_len)) ) +XGTRC ("ERROR: failed to read %d bytes. errno:%d rc:%d\n" , + iop->remain, errno, rc);for (i=0 ; i <XGMIN (8 , tobuf_len); u.buf8[i]=tobuf[i], i++);XGTRC("X:remain:%d buf8:0x%llx\n", iop->remain, u.llbuf8);
PATCH 4/4 XEN_DOMCTL_gdbsx_guestmemio: always do the copyback.
In reply to Don SlutzThe gdbsx code expects that domctl->u.gdbsx_guest_memio.remain is returned.
Without this gdb does not report an error.
With this patch and using a 1G hvm domU:
(gdb) x/1xh 0x6ae9168b0x6ae9168b: Cannot access memory at address 0x6ae9168b
--- xen/arch/x86/domctl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/x86/domctl.c +1 -2
@@ -997,8 +997,7 @@ long arch_do_domctl( domctl->u.gdbsx_guest_memio.len; ret =gdbsx_guest_mem_io (domctl->domain, &domctl->u.gdbsx_guest_memio); -if ( !ret ) - copyback =1 ; + copyback =1 ; }break ;
Signature · 1 line
1.8.4
Re: [BUGFIX][PATCH 4/4] XEN_DOMCTL_gdbsx_guestmemio: always do the copyback.
Quoted 20 lines · Don Slutz
The gdbsx code expects that
domctl->u.gdbsx_guest_memio.remainis returned.Without this gdb does not report an error.
With this patch and using a 1G hvm domU:
(gdb) x/1xh
0x6ae9168b0x6ae9168b: Cannot access memory at address0x6ae9168bSigned-off-by Don Slutz <[email protected]>--- xen/arch/x86/domctl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)xen/arch/x86/domctl.c +0
-0
xen/arch/x86/domctl.c long arch_do_domctl( · line 1000
Quoted 6 lines
xen/arch/x86/domctl.c +1
-2@@ -997,8 +997,7 @@ long arch_do_domctl( domctl->u.gdbsx_guest_memio.len; ret =gdbsx_guest_mem_io (domctl->domain, &domctl->u.gdbsx_guest_memio); -if ( !ret ) - copyback =1 ; + copyback =1 ;
This whole hypercall implementation looks suspect.
gdbsx_guest_mem_io() itself writes to the 'remain' field, making the statement crossing the top of this context redundant.
Furthermore, ret is strictly 0 in the case that 'remain' is 0, or -EFAULT if 'remain' is non-0.
While this does change the ABI of a hypercall, I think it is reasonable to do, as domctl.h does imply that 'remain' is an output parameter, without specifying anything about its behaviour in the case of an error.
~Andrew
Re: [BUGFIX][PATCH 4/4] XEN_DOMCTL_gdbsx_guestmemio: always do the copyback.
Quoted 4 lines · Andrew Cooper
While this does change the ABI of a hypercall, I think it is reasonable to do, as
domctl.hdoes imply that 'remain' is an output parameter, without specifying anything about its behaviour in the case of an error.
The domctl ABI is subject to change anyway.
We don't seem to have had any cause to bump XEN_DOMCTL_INTERFACE_VERSION during the 4.4 dev cycle yet. I don't think this change warrants it either.
Ian.
Re: [BUGFIX][PATCH 4/4] XEN_DOMCTL_gdbsx_guestmemio: always do the copyback.
In reply to Don SlutzQuoted 21 lines · On Sat, 4 Jan 2014 12:52:16 -0500 Don Slutz <[email protected]> wrote:
The gdbsx code expects that
domctl->u.gdbsx_guest_memio.remainis returned.Without this gdb does not report an error.
With this patch and using a 1G hvm domU:
(gdb) x/1xh
0x6ae9168b0x6ae9168b: Cannot access memory at address0x6ae9168bSigned-off-by Don Slutz <[email protected]>--- xen/arch/x86/domctl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)xen/arch/x86/domctl.c +0
-0
xen/arch/x86/domctl.c long arch_do_domctl( · line 1003
Quoted 9 lines
xen/arch/x86/domctl.c +1
-2@@ -997,8 +997,7 @@ long arch_do_domctl( domctl->u.gdbsx_guest_memio.len; ret =gdbsx_guest_mem_io (domctl->domain, &domctl->u.gdbsx_guest_memio); -if ( !ret ) - copyback =1 ; + copyback =1 ; }break ;
Ooopsy... my thought was that an application should not even look at remain if the hcall/syscall failed, but forgot when writing the gdbsx itself :). Think of it this way, if the call didn't even make it to xen, and some reason the ioctl returned non-zero rc, then remain would still be zero. So I think we should fix gdbsx instead of here:
xg_write_mem():
if ((rc=_domctl_hcall(XEN_DOMCTL_gdbsx_guestmemio, frombuf, buflen)))
{
XGERR("ERROR: failed to write %d bytes. errno:%d rc:%d\n",
iop->remain, errno, rc);
return iop->len;
} Similarly in xg_read_mem().
Hope that makes sense. Don't mean to create work for you for my mistake, so if you don't have time, I can submit a patch for this too.
thanks
Mukesh
Re: [BUGFIX][PATCH 4/4] XEN_DOMCTL_gdbsx_guestmemio: always do the copyback.
Quoted 40 lines · Mukesh Rathor
Quoted 21 lines · On Sat, 4 Jan 2014 12:52:16 -0500 Don Slutz <[email protected]> wrote:
The gdbsx code expects that
domctl->u.gdbsx_guest_memio.remainis returned.Without this gdb does not report an error.
With this patch and using a 1G hvm domU:
(gdb) x/1xh
0x6ae9168b0x6ae9168b: Cannot access memory at address0x6ae9168bSigned-off-by Don Slutz <[email protected]>--- xen/arch/x86/domctl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)xen/arch/x86/domctl.c +0
-0xen/arch/x86/domctl.c long arch_do_domctl( · line 1003
Quoted 9 lines
xen/arch/x86/domctl.c +1
-2@@ -997,8 +997,7 @@ long arch_do_domctl( domctl->u.gdbsx_guest_memio.len; ret =gdbsx_guest_mem_io (domctl->domain, &domctl->u.gdbsx_guest_memio); -if ( !ret ) - copyback =1 ; + copyback =1 ; }break ;Ooopsy... my thought was that an application should not even look at remain if the hcall/syscall failed, but forgot when writing the gdbsx itself :). Think of it this way, if the call didn't even make it to xen, and some reason the ioctl returned non-zero rc, then remain would still be zero. So I think we should fix gdbsx instead of here:
Quoted 5 lines
xg_write_mem():
if ((rc=_domctl_hcall(XEN_DOMCTL_gdbsx_guestmemio, frombuf, buflen))) {
XGERR("ERROR: failed to write %d bytes. errno:%d rc:%d\n",
iop->remain, errno, rc);
Isn't this still using iop->remain on failure which is what you say shouldn't be done?
Quoted 10 lines
return iop->len; }Similarly in
xg_read_mem().Hope that makes sense. Don't mean to create work for you for my mistake, so if you don't have time, I can submit a patch for this too.
thanks
Mukesh
Re: [BUGFIX][PATCH 4/4] XEN_DOMCTL_gdbsx_guestmemio: always do the copyback.
Quoted 26 lines · Ian Campbell
Quoted 25 lines · Mukesh Rathor
Quoted 22 lines · On Sat, 4 Jan 2014 12:52:16 -0500 Don Slutz <[email protected]> wrote:
The gdbsx code expects that
domctl->u.gdbsx_guest_memio.remainis returned.Without this gdb does not report an error.
With this patch and using a 1G hvm domU:
(gdb) x/1xh
0x6ae9168b0x6ae9168b: Cannot access memory at address0x6ae9168bSigned-off-by Don Slutz <[email protected]>--- xen/arch/x86/domctl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)xen/arch/x86/domctl.c +0
-0@@ -997,8 +997,7 @@ long arch_do_domctl( domctl->u.gdbsx_guest_memio.len;
Quoted 14 lines
Quoted 9 lines
xen/arch/x86/domctl.c long arch_do_domctl( · line 1002
Quoted 8 lines
xen/arch/x86/domctl.c +1
-2ret =gdbsx_guest_mem_io (domctl->domain, &domctl->u.gdbsx_guest_memio); -if ( !ret ) - copyback =1 ; + copyback =1 ; }break ;Quoted 5 lines
Ooopsy... my thought was that an application should not even look at remain if the hcall/syscall failed, but forgot when writing the gdbsx itself :). Think of it this way, if the call didn't even make it to xen, and some reason the ioctl returned non-zero rc, then remain would still be zero.
Thinking about this for a second longer -- how does this interface deal with partial success?
It seems natural to me for it to return an error and also update ->remain, but perhaps you have a different scheme in mind?
Re: [BUGFIX][PATCH 4/4] XEN_DOMCTL_gdbsx_guestmemio: always do the copyback.
Quoted 40 lines · Ian Campbell
Quoted 26 lines · Ian Campbell
Quoted 25 lines · Mukesh Rathor
Quoted 22 lines · On Sat, 4 Jan 2014 12:52:16 -0500 Don Slutz <[email protected]> wrote:
The gdbsx code expects that
domctl->u.gdbsx_guest_memio.remainis returned.Without this gdb does not report an error.
With this patch and using a 1G hvm domU:
(gdb) x/1xh
0x6ae9168b0x6ae9168b: Cannot access memory at address0x6ae9168bSigned-off-by Don Slutz <[email protected]>--- xen/arch/x86/domctl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)xen/arch/x86/domctl.c +0
-0@@ -997,8 +997,7 @@ long arch_do_domctl( domctl->u.gdbsx_guest_memio.len;Quoted 13 lines
Quoted 8 lines
xen/arch/x86/domctl.c long arch_do_domctl( · line 1003
Quoted 8 lines
xen/arch/x86/domctl.c +1
-2ret =gdbsx_guest_mem_io (domctl->domain, &domctl->u.gdbsx_guest_memio); -if ( !ret ) - copyback =1 ; + copyback =1 ; }break ;Quoted 5 lines
Ooopsy... my thought was that an application should not even look at remain if the hcall/syscall failed, but forgot when writing the gdbsx itself :). Think of it this way, if the call didn't even make it to xen, and some reason the ioctl returned non-zero rc, then remain would still be zero.
Quoted 7 lines
Thinking about this for a second longer -- how does this interface deal with partial success?
It seems natural to me for it to return an error and also update ->remain, but perhaps you have a different scheme in mind?
I had assumed that this patch (which is not need to "fix" the bugs I found), was to be dropped in v2. However I will agree that currently there is no way to know about partial success. The untested change:
xen/arch/x86/domctl.c +1 -1
@@ -43,7 +43,7 @@ static int gdbsx_guest_mem_io( iop->remain =dbg_rw_mem ( (dbgva_t )iop->gva, (dbgbyte_t *)l_uva, iop->len, domid, iop->gwr, iop->pgd3val); -return (iop->remain ? -EFAULT :0 ); +return 0 ; } long arch_do_domctl(
Would appear to allow partial success to be reported and also meet with remain not to be looked at with an error.
-Don Slutz
Re: [BUGFIX][PATCH 4/4] XEN_DOMCTL_gdbsx_guestmemio: always do the copyback.
Quoted 9 lines · On Tue, 07 Jan 2014 11:24:15 -0500 Don Slutz <[email protected]> wrote:
Quoted 8 lines · Ian Campbell
Quoted 7 lines · Ian Campbell
Quoted 6 lines · Mukesh Rathor
Quoted 3 lines · On Sat, 4 Jan 2014 12:52:16 -0500 Don Slutz <[email protected]> wrote:
The gdbsx code expects that
domctl->u.gdbsx_guest_memio.remainis returned.
.....
Quoted 19 lines
I had assumed that this patch (which is not need to "fix" the bugs I found), was to be dropped in v2. However I will agree that currently there is no way to know about partial success. The untested change:
xen/arch/x86/domctl.c +1
-1@@ -43,7 +43,7 @@ static int gdbsx_guest_mem_io( iop->remain =dbg_rw_mem ( (dbgva_t )iop->gva, (dbgbyte_t *)l_uva, iop->len, domid, iop->gwr, iop->pgd3val); -return (iop->remain ? -EFAULT :0 ); +return 0 ; } long arch_do_domctl(
Quoted 2 lines
Would appear to allow partial success to be reported and also meet with remain not to be looked at with an error.
No, the partial success is relevant in other cases, like EAGAIN, but not EFAULT. If we make it pre-emptible in future to return EAGAIN, we'd need to make sure remain was honored. Again, think of it this way, if the first copyin failed, remain would have not been initialized.
So, because now the only cause of unfinished copy from dbg_rw_mem is EFAULT, we should leave above xen code alone, and just change gdbsx.
thanks
mukesh
Re: [BUGFIX][PATCH 4/4] XEN_DOMCTL_gdbsx_guestmemio: always do the copyback.
Quoted 41 lines · Mukesh Rathor
Quoted 9 lines · On Tue, 07 Jan 2014 11:24:15 -0500 Don Slutz <[email protected]> wrote:
Quoted 8 lines · Ian Campbell
Quoted 7 lines · Ian Campbell
Quoted 6 lines · Mukesh Rathor
Quoted 3 lines · On Sat, 4 Jan 2014 12:52:16 -0500 Don Slutz <[email protected]> wrote:
The gdbsx code expects that
domctl->u.gdbsx_guest_memio.remainis returned......
Quoted 19 lines
I had assumed that this patch (which is not need to "fix" the bugs I found), was to be dropped in v2. However I will agree that currently there is no way to know about partial success. The untested change:
xen/arch/x86/domctl.c +1
-1@@ -43,7 +43,7 @@ static int gdbsx_guest_mem_io( iop->remain =dbg_rw_mem ( (dbgva_t )iop->gva, (dbgbyte_t *)l_uva, iop->len, domid, iop->gwr, iop->pgd3val); -return (iop->remain ? -EFAULT :0 ); +return 0 ; } long arch_do_domctl(Quoted 2 lines
Would appear to allow partial success to be reported and also meet with remain not to be looked at with an error.
No, the partial success is relevant in other cases, like EAGAIN, but not EFAULT. If we make it pre-emptible in future to return EAGAIN, we'd need to make sure remain was honored. Again, think of it this way, if the first copyin failed, remain would have not been initialized.
Quoted 5 lines
So, because now the only cause of unfinished copy from
dbg_rw_memis EFAULT, we should leave above xen code alone, and just change gdbsx.thanks
mukesh
Since it did not look like we would get to an agreement soon on this, I have sent out v2 series.
Not at all clear this patch should be in 4.4.0 (domctl api change, high risk, no clear use case (as far as I know gdb does not do anything with partial success)).
On this topic; you seem to be overlooking the page crossing case.
Using the info that page 1f is good and 20 is bad, a domctl request for 1ffff for 2 bytes would call on dbg_rw_mem(), dbg_rw_guest_mem() which calculate pagecnt == 1, get a valid mfn and return that byte. The 2nd time pagecnt is also 1, but we get INVALID_MFN, so dbg_rw_guest_mem(0 returns 1. dbg_rw_mem(0 also returns 1. gdbsx_guest_mem_io() returns -EFAULT so no copyback.
At this point of the 2 requested byte, 1 byte is valid and 1 is not. Since copyback is not done, remain is 0. So the caller get the error and does not have this "partial success" information.
The 1st version of this patch I proposed, the copyback is done, so the caller gets remain == 1 and the valid byte and an error.
The 2nd version of this patch (which has now been tested) sets remian == 1, the valid byte, and no error.
Hope this helps.
-Don Slutz
Re: [BUGFIX][PATCH 4/4] XEN_DOMCTL_gdbsx_guestmemio: always do the copyback.
Quoted 3 lines · On Tue, 07 Jan 2014 20:02:41 -0500 Don Slutz <[email protected]> wrote:
Quoted 2 lines · Mukesh Rathor
On Tue, 07 Jan 2014 11:24:15 -0500
Don Slutz <[email protected]> wrote:
....
Quoted 10 lines
Using the info that page 1f is good and 20 is bad, a domctl request for 1ffff for 2 bytes would call on
dbg_rw_mem(),dbg_rw_guest_mem()which calculate pagecnt == 1, get a valid mfn and return that byte. The 2nd time pagecnt is also 1, but we getINVALID_MFN, so dbg_rw_guest_mem(0 returns 1. dbg_rw_mem(0 also returns 1.gdbsx_guest_mem_io()returns-EFAULTso no copyback.At this point of the 2 requested byte, 1 byte is valid and 1 is not. Since copyback is not done, remain is 0. So the caller get the error and does not have this "partial success" information.
Again, the application cannot and should not rely on the validity of the field in case of failing hcall/syscall, since the failure point is not known to the application, unless the failure is EAGAIN.
Hope that makes sense.
Mukesh
Re: [BUGFIX][PATCH 4/4] XEN_DOMCTL_gdbsx_guestmemio: always do the copyback.
In reply to Ian CampbellQuoted 40 lines · Ian Campbell
Quoted 39 lines · Mukesh Rathor
Quoted 21 lines · On Sat, 4 Jan 2014 12:52:16 -0500 Don Slutz <[email protected]> wrote:
The gdbsx code expects that
domctl->u.gdbsx_guest_memio.remainis returned.Without this gdb does not report an error.
With this patch and using a 1G hvm domU:
(gdb) x/1xh
0x6ae9168b0x6ae9168b: Cannot access memory at address0x6ae9168bSigned-off-by Don Slutz <[email protected]>--- xen/arch/x86/domctl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)xen/arch/x86/domctl.c +0
-0xen/arch/x86/domctl.c long arch_do_domctl( · line 1003
Quoted 9 lines
xen/arch/x86/domctl.c +1
-2@@ -997,8 +997,7 @@ long arch_do_domctl( domctl->u.gdbsx_guest_memio.len; ret =gdbsx_guest_mem_io (domctl->domain, &domctl->u.gdbsx_guest_memio); -if ( !ret ) - copyback =1 ; + copyback =1 ; }break ;Ooopsy... my thought was that an application should not even look at remain if the hcall/syscall failed, but forgot when writing the gdbsx itself :). Think of it this way, if the call didn't even make it to xen, and some reason the ioctl returned non-zero rc, then remain would still be zero. So I think we should fix gdbsx instead of here:
Quoted 7 lines
Quoted 5 lines
xg_write_mem():
if ((rc=_domctl_hcall(XEN_DOMCTL_gdbsx_guestmemio, frombuf, buflen))) {
XGERR("ERROR: failed to write %d bytes. errno:%d rc:%d\n",
iop->remain, errno, rc);Isn't this still using
iop->remainon failure which is what you say shouldn't be done?
I agree, which is why I took it as a guide line. What I have tested with is:
tools/debugger/gdbsx/xg/xg_main.c +10 -4
@@ -787,8 +787,11 @@ xg_read_mem(uint64_t guestva, char *tobuf, int tobuf_len, uint64_t pgd3val) iop->gwr =0 ;/* not writing to guest */ if ( (rc =_domctl_hcall (XEN_DOMCTL_gdbsx_guestmemio, tobuf, tobuf_len)) ) -XGTRC ("ERROR: failed to read %d bytes. errno:%d rc:%d\n" , - iop->remain, errno, rc); + { +XGTRC ("ERROR: failed to read bytes. errno:%d rc:%d\n" , + errno, rc); +return tobuf_len; + }for (i=0 ; i <XGMIN (8 , tobuf_len); u.buf8[i]=tobuf[i], i++);XGTRC ("X:remain:%d buf8:0x%llx\n" , iop->remain, u.llbuf8);
@@ -818,8 +821,11 @@ xg_write_mem(uint64_t guestva, char *frombuf, int buflen, uint64_t pgd3val) iop->gwr =1 ;/* writing to guest */ if ((rc=_domctl_hcall (XEN_DOMCTL_gdbsx_guestmemio, frombuf, buflen))) -XGERR ("ERROR: failed to write %d bytes. errno:%d rc:%d\n" , - iop->remain, errno, rc); + { +XGERR ("ERROR: failed to write bytes to %llx. errno:%d rc:%d\n" , + guestva, errno, rc); +return buflen; + }return iop->remain; }
works fine and I plan it to be part of v2.
-Don
Quoted 11 lines
Quoted 10 lines
return iop->len; }Similarly in
xg_read_mem().Hope that makes sense. Don't mean to create work for you for my mistake, so if you don't have time, I can submit a patch for this too.
thanks
Mukesh
Re: [BUGFIX][PATCH 4/4] XEN_DOMCTL_gdbsx_guestmemio: always do the copyback.
Quoted 4 lines · On Tue, 07 Jan 2014 11:26:36 -0500 Don Slutz <[email protected]> wrote:
Quoted 3 lines · Ian Campbell
Quoted 2 lines · Mukesh Rathor
On Sat, 4 Jan 2014 12:52:16 -0500
Don Slutz <[email protected]> wrote:
.....
tools/debugger/gdbsx/xg/xg_main.c xg_read_mem(uint64_t guestva, char *tobuf, int tobuf_len, uint64_t pgd3val) · line 792
Quoted 12 lines
+++
b/tools/debugger/gdbsx/xg/xg_main.c(quoted diff) +0
-0@@ -787,8 +787,11 @@ xg_read_mem(uint64_t guestva, char *tobuf, int
tobuf_len,uint64_tpgd3val)iop->gwr= 0; /* not writing to
guest */if ( (rc = _domctl_hcall(XEN_DOMCTL_gdbsx_guestmemio, tobuf,
tobuf_len)) )tools/debugger/gdbsx/xg/xg_main.c +3
-2-XGTRC ("ERROR: failed to read %d bytes. errno:%d rc:%d\n" , - iop->remain, errno, rc); + { +XGTRC ("ERROR: failed to read bytes. errno:%d rc:%d\n" , + errno, rc);
Probably would fit in just one line.
XGTRC("ERROR: failed to read bytes. errno:%d rc:%d\n", errno, rc);Quoted 23 lines
tools/debugger/gdbsx/xg/xg_main.c +2
-0+return tobuf_len; + }for (i=0 ; i <XGMIN (8 , tobuf_len); u.buf8[i]=tobuf[i], i++);XGTRC ("X:remain:%d buf8:0x%llx\n" , iop->remain, u.llbuf8);@@ -818,8 +821,11 @@ xg_write_mem(uint64_t guestva, char *frombuf,int buflen,
uint64_tpgd3val)iop->gwr= 1; /* writing to guest
*/if ((rc=_domctl_hcall(XEN_DOMCTL_gdbsx_guestmemio, frombuf,
buflen)))tools/debugger/gdbsx/xg/xg_main.c +2
-2-XGERR ("ERROR: failed to write %d bytes. errno:%d rc:%d\n" , - iop->remain, errno, rc); + { + XGERR("ERROR: failed to write bytes to %llx. errno:%drc:%d\n",
tools/debugger/gdbsx/xg/xg_main.c +3
-0+ guestva, errno, rc); +return buflen; + }return iop->remain; }
Quoted 1 line
works fine and I plan it to be part of v2.
Yes, this is it.
thanks
Mukesh
Re: [BUGFIX][PATCH 4/4] XEN_DOMCTL_gdbsx_guestmemio: always do the copyback.
In reply to Ian CampbellQuoted 42 lines · On Tue, 7 Jan 2014 10:00:24 +0000 Ian Campbell <[email protected]> wrote:
Quoted 41 lines · Mukesh Rathor
Quoted 21 lines · On Sat, 4 Jan 2014 12:52:16 -0500 Don Slutz <[email protected]> wrote:
The gdbsx code expects that
domctl->u.gdbsx_guest_memio.remainis returned.Without this gdb does not report an error.
With this patch and using a 1G hvm domU:
(gdb) x/1xh
0x6ae9168b0x6ae9168b: Cannot access memory at address0x6ae9168bSigned-off-by Don Slutz <[email protected]>--- xen/arch/x86/domctl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)xen/arch/x86/domctl.c +0
-0xen/arch/x86/domctl.c long arch_do_domctl( · line 1003
Quoted 9 lines
xen/arch/x86/domctl.c +1
-2@@ -997,8 +997,7 @@ long arch_do_domctl( domctl->u.gdbsx_guest_memio.len; ret =gdbsx_guest_mem_io (domctl->domain, &domctl->u.gdbsx_guest_memio); -if ( !ret ) - copyback =1 ; + copyback =1 ; }break ;Ooopsy... my thought was that an application should not even look at remain if the hcall/syscall failed, but forgot when writing the gdbsx itself :). Think of it this way, if the call didn't even make it to xen, and some reason the ioctl returned non-zero rc, then remain would still be zero. So I think we should fix gdbsx instead of here:
Quoted 8 lines
Quoted 5 lines
xg_write_mem():
if ((rc=_domctl_hcall(XEN_DOMCTL_gdbsx_guestmemio, frombuf,
buflen))) {
XGERR("ERROR: failed to write %d bytes. errno:%d rc:%d\n",
iop->remain, errno, rc);Isn't this still using
iop->remainon failure which is what you say shouldn't be done?
Right, it was just a guidline code with bad cut and paste of XGERR().. so picky :) :)...
Mukesh
Quoted 3 lines · Don Slutz
Release manager requests:
patch 1 should be in 4.4.0
patch 3 and 4 would be good to be in 4.4.0
(as acting RM in George's absence):
In all three cases what is missing is the "why" and the appropriate analysis from
http://wiki.xen.org/wiki/Xen_Roadmap/4.4#Exception_guidelines_for_after_the_code_freeze
i.e. what is the impact of the bug (i..e what are the advantages of the fix) and what are the risks of this changing causing further breakage? I'm not really in a position to evaluate the risk of a change in gdbsx, so someone needs to tell me.
I think given that gdbsx is a somewhat "peripheral" bit of code and that it is targeted at developers (who might be better able to tolerate any resulting issues and more able to apply subsequent fixups than regular users) we can accept a larger risk than we would with a change to the hypervisor itself etc (that's assuming that all of these changes cannot potentially impact non-debugger usecases which I expect is the case from the function names but I would like to see confirmed).
Apart from a release ack 4 of these would need an Ack from Mukesh IMHO. TBH if he is happy with them then I see no reason not to give a release ack as well.
Quoted 29 lines
patch 2 is optional.
While tracking down a bug in seabios/grub I found the bug in patch 1.
There are 2 ways that gfn will not be
INVALID_GFNand yet mfn will beINVALID_MFN.1)
p2m_is_readonly(gfntype)and writing memory.
2) the requested vaddr does not exist.This may only be an issue for a HVM guest that is in real mode (I.E. no page tables).
Patch 2 is debug logging that was used to find the 2nd way.
Patch 3 and 4 are more of a cleanup bug fix.
Don Slutz (4):
dbg_rw_guest_mem: need to callput_gfnin error path.
dbg_rw_guest_mem: Enable debug log output
xg_read_mem: Report on error.XEN_DOMCTL_gdbsx_guestmemio: always do the copyback.tools/debugger/gdbsx/xg/xg_main.c | 6 ++++-- xen/arch/x86/debug.c | 44 ++++++++++++++++++++++++++++++--------- xen/arch/x86/domctl.c | 3 +-- 3 files changed, 39 insertions(+), 14 deletions(-)
Quoted 24 lines · On Mon, 6 Jan 2014 15:45:48 +0000 Ian Campbell <[email protected]> wrote:
Quoted 3 lines · Don Slutz
Release manager requests:
patch 1 should be in 4.4.0
patch 3 and 4 would be good to be in 4.4.0(as acting RM in George's absence):
In all three cases what is missing is the "why" and the appropriate analysis from
http://wiki.xen.org/wiki/Xen_Roadmap/4.4#Exception_guidelines_for_after_the_code_freeze
i.e. what is the impact of the bug (i..e what are the advantages of the fix) and what are the risks of this changing causing further breakage? I'm not really in a position to evaluate the risk of a change in gdbsx, so someone needs to tell me.I think given that gdbsx is a somewhat "peripheral" bit of code and that it is targeted at developers (who might be better able to tolerate any resulting issues and more able to apply subsequent fixups than regular users) we can accept a larger risk than we would with a change to the hypervisor itself etc (that's assuming that all of these changes cannot potentially impact non-debugger usecases which I expect is the case from the function names but I would like to see confirmed).
Quoted 3 lines
Apart from a release ack 4 of these would need an Ack from Mukesh IMHO. TBH if he is happy with them then I see no reason not to give a release ack as well.
Right Ian, at present I believe the only user of this file is gdbsx so 4.4 would be very low risk. The issue is in a rare use case, so it could wait till 4.5 too if you'd rather not. Ok either way... :)..
thanks
mukesh