linux-user mmap debug cleanup
v2 cover linux-user mmap debug cleanup
Hi,
This is a quick re-spin of the mmap tracing. I don't bother with pretty formatting the protection/type flags as they were incomplete and not hard to extract from just dumping the hex values. This makes most of the patches much simpler. I've also dropped the home-made pattern_glob routine.
The following patches need review:
01 - linux user convert target_mprotect debug to trace 02 - linux user convert target_mmap debug to tracepoin 04 - linux user log page table changes under d page 06 - trace replace hand crafted pattern_glob with g_pa
Alex Bennée (6):
linux-user: convert target_mprotect debug to tracepoint
linux-user: convert target_mmap debug to tracepoint
linux-user: add target_mmap_complete tracepoint
linux-user: log page table changes under -d page
linux-user: convert target_munmap debug to a tracepoint
trace: replace hand-crafted pattern_glob with g_pattern_match_simple
include/exec/log.h | 5 +++- bsd-user/main.c | 2 +- linux-user/main.c | 2 +- linux-user/mmap.c | 56 ++++++++--------------------------------- trace/control.c | 35 +------------------------- linux-user/trace-events | 6 +++++ 6 files changed, 23 insertions(+), 83 deletions(-)
Signature · 1 line
2.20.1
PATCH v2 1/6 linux-user: convert target_mprotect debug to tracepoint
It is a pain to re-compile when you need to debug and tracepoints are a fairly low impact way to instrument QEMU.
---
v2
- don't both with ascii conversion
--- linux-user/mmap.c | 10 ++-------- linux-user/trace-events | 3 +++ 2 files changed, 5 insertions(+), 8 deletions(-)
linux-user/mmap.c +2 -8
@@ -17,7 +17,7 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ #include "qemu/osdep.h" - +#include "trace.h" #include "qemu.h" //#define DEBUG_MMAP
@@ -66,13 +66,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)abi_ulong end, host_start, host_end, addr;int prot1, ret; -#ifdef DEBUG_MMAP -printf ("mprotect: start=0x" TARGET_ABI_FMT_lx -"len=0x" TARGET_ABI_FMT_lx" prot=%c%c%c\n" , start, len, - prot &PROT_READ ?'r' :'-' , - prot &PROT_WRITE ?'w' :'-' , - prot &PROT_EXEC ?'x' :'-' ); -#endif +trace_target_mprotect (start, len, prot);if ((start & ~TARGET_PAGE_MASK ) !=0 )return -TARGET_EINVAL ;
linux-user/trace-events +3 -0
@@ -11,3 +11,6 @@ user_handle_signal(void *env, int target_sig) "env=%p signal %d" user_host_signal(void *env, int host_sig, int target_sig) "env=%p signal %d (target %d(" user_queue_signal(void *env, int target_sig) "env=%p signal %d" user_s390x_restore_sigregs(void *env, uint64_t sc_psw_addr, uint64_t env_psw_addr) "env=%p frame psw.addr 0x%"PRIx64 " current psw.addr 0x%"PRIx64 + +# mmap.c +target_mprotect(uint64_t start, uint64_t len, int flags) "start=0x%"PRIx64 " len=0x%"PRIx64 " prot=0x%x"
Signature · 1 line
2.20.1
Re: [PATCH v2 1/6] linux-user: convert target_mprotect debug to tracepoint
Quoted 5 lines · Alex Bennée
It is a pain to re-compile when you need to debug and tracepoints are a fairly low impact way to instrument QEMU.
Signed-off-by Alex Bennée <[email protected]>
Quoted 7 lines
---
v2
- don't both with ascii conversion--- linux-user/mmap.c | 10 ++-------- linux-user/trace-events | 3 +++ 2 files changed, 5 insertions(+), 8 deletions(-)
r~
Re: [PATCH v2 1/6] linux-user: convert target_mprotect debug to tracepoint
In reply to Alex BennéeLe 05/12/2019 à 13:25, Alex Bennée a écrit :
Quoted 5 lines
It is a pain to re-compile when you need to debug and tracepoints are a fairly low impact way to instrument QEMU.
Signed-off-by Alex Bennée <[email protected]>
Quoted 7 lines
---
v2
- don't both with ascii conversion--- linux-user/mmap.c | 10 ++-------- linux-user/trace-events | 3 +++ 2 files changed, 5 insertions(+), 8 deletions(-)
PATCH v2 2/6 linux-user: convert target_mmap debug to tracepoint
In reply to Alex BennéeIt is a pain to re-compile when you need to debug and tracepoints are a fairly low impact way to instrument QEMU.
--- linux-user/mmap.c | 27 +-------------------------- linux-user/trace-events | 1 + 2 files changed, 2 insertions(+), 26 deletions(-)
linux-user/mmap.c +1 -26
@@ -363,32 +363,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_len;mmap_lock (); -#ifdef DEBUG_MMAP - { -printf ("mmap: start=0x" TARGET_ABI_FMT_lx -" len=0x" TARGET_ABI_FMT_lx" prot=%c%c%c flags=" , - start, len, - prot &PROT_READ ?'r' :'-' , - prot &PROT_WRITE ?'w' :'-' , - prot &PROT_EXEC ?'x' :'-' ); -if (flags &MAP_FIXED ) -printf ("MAP_FIXED " ); -if (flags &MAP_ANONYMOUS ) -printf ("MAP_ANON " ); -switch (flags &MAP_TYPE ) { -case MAP_PRIVATE : -printf ("MAP_PRIVATE " ); -break ; -case MAP_SHARED : -printf ("MAP_SHARED " ); -break ; -default : -printf ("[MAP_TYPE=0x%x] " , flags &MAP_TYPE ); -break ; - } -printf ("fd=%d offset=" TARGET_ABI_FMT_lx"\n" , fd, offset); - } -#endif +trace_target_mmap (start, len, prot, flags, fd, offset);if (!len) { errno =EINVAL ;
linux-user/trace-events +1 -0
@@ -14,3 +14,4 @@ user_s390x_restore_sigregs(void *env, uint64_t sc_psw_addr, uint64_t env_psw_add # mmap.c target_mprotect(uint64_t start, uint64_t len, int flags) "start=0x%"PRIx64 " len=0x%"PRIx64 " prot=0x%x" +target_mmap(uint64_t start, uint64_t len, int pflags, int mflags, int fd, uint64_t offset) "start=0x%"PRIx64 " len=0x%"PRIx64 " prot=0x%x flags=0x%x fd=%d offset=0x%"PRIx64
Signature · 1 line
2.20.1
Re: [PATCH v2 2/6] linux-user: convert target_mmap debug to tracepoint
Quoted 8 lines · Alex Bennée
It is a pain to re-compile when you need to debug and tracepoints are a fairly low impact way to instrument QEMU.
Signed-off-by Alex Bennée <[email protected]>--- linux-user/mmap.c | 27 +-------------------------- linux-user/trace-events | 1 + 2 files changed, 2 insertions(+), 26 deletions(-)
r~
Re: [PATCH v2 2/6] linux-user: convert target_mmap debug to tracepoint
In reply to Alex BennéeLe 05/12/2019 à 13:25, Alex Bennée a écrit :
Quoted 9 lines
It is a pain to re-compile when you need to debug and tracepoints are a fairly low impact way to instrument QEMU.
Signed-off-by Alex Bennée <[email protected]>--- linux-user/mmap.c | 27 +-------------------------- linux-user/trace-events | 1 + 2 files changed, 2 insertions(+), 26 deletions(-)
PATCH v2 3/6 linux-user: add target_mmap_complete tracepoint
In reply to Alex BennéeFor full details we also want to see where the mmaps end up.
--- linux-user/mmap.c | 2 +- linux-user/trace-events | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
linux-user/mmap.c +1 -1
@@ -538,8 +538,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, the_end1:page_set_flags (start, start + len, prot |PAGE_VALID ); the_end: +trace_target_mmap_complete (start);#ifdef DEBUG_MMAP -printf ("ret=0x" TARGET_ABI_FMT_lx"\n" , start);page_dump (stdout);printf ("\n" );#endif
linux-user/trace-events +1 -0
@@ -15,3 +15,4 @@ user_s390x_restore_sigregs(void *env, uint64_t sc_psw_addr, uint64_t env_psw_add # mmap.c target_mprotect(uint64_t start, uint64_t len, int flags) "start=0x%"PRIx64 " len=0x%"PRIx64 " prot=0x%x" target_mmap(uint64_t start, uint64_t len, int pflags, int mflags, int fd, uint64_t offset) "start=0x%"PRIx64 " len=0x%"PRIx64 " prot=0x%x flags=0x%x fd=%d offset=0x%"PRIx64 +target_mmap_complete(uint64_t retaddr) "retaddr=0x%"PRIx64
Signature · 1 line
2.20.1
Re: [PATCH v2 3/6] linux-user: add target_mmap_complete tracepoint
Le 05/12/2019 à 13:25, Alex Bennée a écrit :
Quoted 8 lines
For full details we also want to see where the mmaps end up.
Signed-off-by Alex Bennée <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- linux-user/mmap.c | 2 +- linux-user/trace-events | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
PATCH v2 4/6 linux-user: log page table changes under -d page
In reply to Alex BennéeThe CPU_LOG_PAGE flag is woefully underused and could stand to do extra duty tracking page changes. If the user doesn't want to see the details as things change they still have the tracepoints available.
We push the locking into log_page_dump and pass a reason for the banner text.
---
v2
- reworded banner text
- moved locking into helper
- converted stray calls of page_dump
--- include/exec/log.h | 5 ++++- bsd-user/main.c | 2 +- linux-user/main.c | 2 +- linux-user/mmap.c | 8 ++++---- 4 files changed, 10 insertions(+), 7 deletions(-)
include/exec/log.h +4 -1
@@ -50,9 +50,12 @@ static inline void log_disas(void *code, unsigned long size)#if defined(CONFIG_USER_ONLY )/* page_dump() output to the log file: */ -static inline void log_page_dump (void ) +static inline void log_page_dump (const char *operation) { +qemu_log_lock (); +qemu_log ("page layout changed following %s\n" , operation);page_dump (qemu_logfile); +qemu_log_unlock (); }#endif #endif
bsd-user/main.c +1 -1
@@ -963,7 +963,7 @@ int main(int argc, char **argv)if (qemu_loglevel_mask (CPU_LOG_PAGE )) {qemu_log ("guest_base 0x%lx\n" , guest_base); -log_page_dump (); +log_page_dump ("binary load" );qemu_log ("start_brk 0x" TARGET_ABI_FMT_lx"\n" , info->start_brk);qemu_log ("end_code 0x" TARGET_ABI_FMT_lx"\n" , info->end_code);
linux-user/main.c +1 -1
@@ -826,7 +826,7 @@ int main(int argc, char **argv, char **envp)if (qemu_loglevel_mask (CPU_LOG_PAGE )) {qemu_log ("guest_base 0x%lx\n" , guest_base); -log_page_dump (); +log_page_dump ("binary load" );qemu_log ("start_brk 0x" TARGET_ABI_FMT_lx"\n" , info->start_brk);qemu_log ("end_code 0x" TARGET_ABI_FMT_lx"\n" , info->end_code);
linux-user/mmap.c +4 -4
@@ -18,6 +18,7 @@*/ #include "qemu/osdep.h" #include "trace.h" +#include "exec/log.h" #include "qemu.h" //#define DEBUG_MMAP
@@ -539,10 +540,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,page_set_flags (start, start + len, prot |PAGE_VALID ); the_end:trace_target_mmap_complete (start); -#ifdef DEBUG_MMAP -page_dump (stdout); -printf ("\n" ); -#endif +if (qemu_loglevel_mask (CPU_LOG_PAGE )) { +log_page_dump (__func__); + }tb_invalidate_phys_range (start, start + len);mmap_unlock ();return start;
Signature · 1 line
2.20.1
Re: [PATCH v2 4/6] linux-user: log page table changes under -d page
Quoted 14 lines · Alex Bennée
The
CPU_LOG_PAGEflag is woefully underused and could stand to do extra duty tracking page changes. If the user doesn't want to see the details as things change they still have the tracepoints available.We push the locking into
log_page_dumpand pass a reason for the banner text.Signed-off-by Alex Bennée <[email protected]>---
v2
- reworded banner text
- moved locking into helper
- converted stray calls ofpage_dump
Quoted 6 lines
--- include/exec/log.h | 5 ++++- bsd-user/main.c | 2 +- linux-user/main.c | 2 +- linux-user/mmap.c | 8 ++++---- 4 files changed, 10 insertions(+), 7 deletions(-)
r~
Re: [PATCH v2 4/6] linux-user: log page table changes under -d page
In reply to Alex BennéeLe 05/12/2019 à 13:25, Alex Bennée a écrit :
Quoted 14 lines
The
CPU_LOG_PAGEflag is woefully underused and could stand to do extra duty tracking page changes. If the user doesn't want to see the details as things change they still have the tracepoints available.We push the locking into
log_page_dumpand pass a reason for the banner text.Signed-off-by Alex Bennée <[email protected]>---
v2
- reworded banner text
- moved locking into helper
- converted stray calls ofpage_dump
Quoted 6 lines
--- include/exec/log.h | 5 ++++- bsd-user/main.c | 2 +- linux-user/main.c | 2 +- linux-user/mmap.c | 8 ++++---- 4 files changed, 10 insertions(+), 7 deletions(-)
PATCH v2 5/6 linux-user: convert target_munmap debug to a tracepoint
In reply to Alex BennéeConvert the final bit of DEBUG_MMAP to a tracepoint and remove the last remanents of the #ifdef hackery.
--- linux-user/mmap.c | 9 ++------- linux-user/trace-events | 1 + 2 files changed, 3 insertions(+), 7 deletions(-)
linux-user/mmap.c +2 -7
@@ -21,8 +21,6 @@#include "exec/log.h" #include "qemu.h" -//#define DEBUG_MMAP -static pthread_mutex_t mmap_mutex =PTHREAD_MUTEX_INITIALIZER ;static __threadint mmap_lock_count;
@@ -597,11 +595,8 @@ int target_munmap(abi_ulong start, abi_ulong len)abi_ulong end, real_start, real_end, addr;int prot, ret; -#ifdef DEBUG_MMAP -printf ("munmap: start=0x" TARGET_ABI_FMT_lx" len=0x" - TARGET_ABI_FMT_lx"\n" , - start, len); -#endif +trace_target_munmap (start, len); +if (start & ~TARGET_PAGE_MASK )return -TARGET_EINVAL ; len =TARGET_PAGE_ALIGN (len);
linux-user/trace-events +1 -0
@@ -16,3 +16,4 @@ user_s390x_restore_sigregs(void *env, uint64_t sc_psw_addr, uint64_t env_psw_add target_mprotect(uint64_t start, uint64_t len, int flags) "start=0x%"PRIx64 " len=0x%"PRIx64 " prot=0x%x" target_mmap(uint64_t start, uint64_t len, int pflags, int mflags, int fd, uint64_t offset) "start=0x%"PRIx64 " len=0x%"PRIx64 " prot=0x%x flags=0x%x fd=%d offset=0x%"PRIx64 target_mmap_complete(uint64_t retaddr) "retaddr=0x%"PRIx64 +target_munmap(uint64_t start, uint64_t len) "start=0x%"PRIx64" len=0x%"PRIx64
Signature · 1 line
2.20.1
Re: [PATCH v2 5/6] linux-user: convert target_munmap debug to a tracepoint
Le 05/12/2019 à 13:25, Alex Bennée a écrit :
Quoted 10 lines
Convert the final bit of
DEBUG_MMAPto a tracepoint and remove the last remanents of the #ifdef hackery.Signed-off-by Alex Bennée <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- linux-user/mmap.c | 9 ++------- linux-user/trace-events | 1 + 2 files changed, 3 insertions(+), 7 deletions(-)
Re: [PATCH v2 5/6] linux-user: convert target_munmap debug to a tracepoint
Quoted 12 lines · Laurent Vivier
Quoted 10 lines · Alex Bennée
Convert the final bit of
DEBUG_MMAPto a tracepoint and remove the last remanents of the #ifdef hackery.Signed-off-by Alex Bennée <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- linux-user/mmap.c | 9 ++------- linux-user/trace-events | 1 + 2 files changed, 3 insertions(+), 7 deletions(-)
Quoted 1 line
Reviewed-by Laurent Vivier <[email protected]>
Are you going to take this series via your tree or would you like me to put the PR together?
Signature · 1 line
Alex Bennée
Re: [PATCH v2 5/6] linux-user: convert target_munmap debug to a tracepoint
Le 16/12/2019 à 13:00, Alex Bennée a écrit :
Quoted 15 lines
Quoted 12 lines · Laurent Vivier
Quoted 10 lines · Alex Bennée
Convert the final bit of
DEBUG_MMAPto a tracepoint and remove the last remanents of the #ifdef hackery.Signed-off-by Alex Bennée <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- linux-user/mmap.c | 9 ++------- linux-user/trace-events | 1 + 2 files changed, 3 insertions(+), 7 deletions(-)
Quoted 5 lines
Quoted 1 line
Reviewed-by Laurent Vivier <[email protected]>Are you going to take this series via your tree or would you like me to put the PR together?
As you prefer.
Thanks,
Laurent
Re: [PATCH v2 5/6] linux-user: convert target_munmap debug to a tracepoint
Quoted 16 lines · Laurent Vivier
Quoted 15 lines · Alex Bennée
Quoted 12 lines · Laurent Vivier
Quoted 10 lines · Alex Bennée
Convert the final bit of
DEBUG_MMAPto a tracepoint and remove the last remanents of the #ifdef hackery.Signed-off-by Alex Bennée <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- linux-user/mmap.c | 9 ++------- linux-user/trace-events | 1 + 2 files changed, 3 insertions(+), 7 deletions(-)
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Reviewed-by Laurent Vivier <[email protected]>Are you going to take this series via your tree or would you like me to put the PR together?
As you prefer.
Very well queued to pullreq/testing-logging-misc, thanks.
Quoted 3 lines
Thanks,
Laurent
Signature · 1 line
Alex Bennée
PATCH v2 6/6 trace: replace hand-crafted pattern_glob with g_pattern_match_simple
In reply to Alex BennéeWe already use g_pattern_match elsewhere so remove the duplication.
--- trace/control.c | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-)
trace/control.c +1 -34
@@ -98,38 +98,6 @@ TraceEvent *trace_event_name(const char *name)return NULL ; } -static bool pattern_glob (const char *pat,const char *ev) -{ -while (*pat !='\0' && *ev !='\0' ) { -if (*pat == *ev) { - pat++; - ev++; - } -else if (*pat =='*' ) { -if (pattern_glob (pat, ev+1 )) { -return true; - }else if (pattern_glob (pat+1 , ev)) { -return true; - }else { -return false; - } - }else { -return false; - } - } - -while (*pat =='*' ) { - pat++; - } - -if (*pat =='\0' && *ev =='\0' ) { -return true; - }else { -return false; - } -} - -void trace_event_iter_init (TraceEventIter *iter,const char *pattern) { iter->event =0 ;
@@ -148,8 +116,7 @@ TraceEvent *trace_event_iter_next(TraceEventIter *iter) iter->group++; }if (!iter->pattern || -pattern_glob (iter->pattern, -trace_event_get_name (ev))) { +g_pattern_match_simple (iter->pattern,trace_event_get_name (ev))) {return ev; } }
Signature · 1 line
2.20.1
Re: [PATCH v2 6/6] trace: replace hand-crafted pattern_glob with g_pattern_match_simple
Quoted 6 lines · Alex Bennée
We already use
g_pattern_matchelsewhere so remove the duplication.Signed-off-by Alex Bennée <[email protected]>--- trace/control.c | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-)
r~
Re: [PATCH v2 6/6] trace: replace hand-crafted pattern_glob with g_pattern_match_simple
In reply to Alex BennéeQuoted 6 lines · Alex Bennée
We already use
g_pattern_matchelsewhere so remove the duplication.Signed-off-by Alex Bennée <[email protected]>--- trace/control.c | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-)
Is g_pattern_match() a superset of pattern_glob()? Existing patterns should continue to work.
Stefan
Re: [PATCH v2 6/6] trace: replace hand-crafted pattern_glob with g_pattern_match_simple
Quoted 10 lines · Stefan Hajnoczi
Quoted 6 lines · Alex Bennée
We already use
g_pattern_matchelsewhere so remove the duplication.Signed-off-by Alex Bennée <[email protected]>--- trace/control.c | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-)Is
g_pattern_match()a superset ofpattern_glob()? Existing patterns should continue to work.
Yes - it supports more than pattern_glob and a bit less than the system glob():
The g_pattern_match* functions match a string against a pattern containing '*' and '?' wildcards with similar semantics as the standard glob() function: '*' matches an arbitrary, possibly empty, string, '?' matches an arbitrary character.
Note that in contrast to glob(), the '/' character can be matched by the wildcards, there are no '[...]' character ranges and '*' and '?' can not be escaped to include them literally in a pattern.
If you give me some example existing pattern forms we can add them to test-logging. I manually tested both single and double * patterns while working on the rest of the series.
Quoted 2 lines
Stefan
--
Alex Bennée
Re: [PATCH v2 6/6] trace: replace hand-crafted pattern_glob with g_pattern_match_simple
In reply to Alex BennéeQuoted 6 lines · Alex Bennée
We already use
g_pattern_matchelsewhere so remove the duplication.Signed-off-by Alex Bennée <[email protected]>--- trace/control.c | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-)