Skip to contentSkip to conversation

tracing: kmem: convert call_site addresses to user friendly symbols

PATCH Superseded George G. Davis 3 participants 4 messages Jul 20, 2019 – Jul 22, 2019 Tracing

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tracing: kmem: convert call_site addresses to user friendly symbols

While attempting to debug slub freelist pointer corruption bugs caused by a module, I discovered that the kmem call_site addresses are not at all user friendly for modules unless you manage to save a copy of kallsyms for the running kernel beforehand.

So convert kmem call_site addresses to user friendly symbols which is especially helpful for module callers when you don't have a copy of kallsyms for the running kernel.

---
 include/trace/events/kmem.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/trace/events/kmem.h +3 -3
index eb57e3037deb..ae18e61fa1c0 100644
@@ -35,7 +35,7 @@ DECLARE_EVENT_CLASS(kmem_alloc,
 		__entry->gfp_flags	= gfp_flags;
 	),
 
-	TP_printk("call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s",
+	TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s",
 		__entry->call_site,
 		__entry->ptr,
 		__entry->bytes_req,
@@ -88,7 +88,7 @@ DECLARE_EVENT_CLASS(kmem_alloc_node,
 		__entry->node		= node;
 	),
 
-	TP_printk("call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s node=%d",
+	TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s node=%d",
 		__entry->call_site,
 		__entry->ptr,
 		__entry->bytes_req,
@@ -131,7 +131,7 @@ DECLARE_EVENT_CLASS(kmem_free,
 		__entry->ptr		= ptr;
 	),
 
-	TP_printk("call_site=%lx ptr=%p", __entry->call_site, __entry->ptr)
+	TP_printk("call_site=%pS ptr=%p", __entry->call_site, __entry->ptr)
 );
 
 DEFINE_EVENT(kmem_free, kfree,
Signature · 1 line
2.7.4
#1 lore raw
Thank you for the patch! Perhaps something to improve:

Hi "George,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.2 next-20190719]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/George-G-Davis/tracing-kmem-convert-call_site-addresses-to-user-friendly-symbols/20190721-094536
config: arm-omap2plus_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=arm

If you fix the issue, kindly add following tag

All warnings (new ones prefixed by >>):

In file included from include/trace/define_trace.h:102:0,

                    from include/trace/events/kmem.h:321,
                    from mm/slab_common.c:27:
   include/trace/events/kmem.h: In function 'trace_raw_output_kmem_alloc':
>> include/trace/events/kmem.h:38:12: warning: format '%p' expects argument of type 'void *', but argument 3 has type 'long unsigned int' [-Wformat=]
     TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s",
               ^
   include/trace/trace_events.h:360:22: note: in definition of macro 'DECLARE_EVENT_CLASS'
     trace_seq_printf(s, print);     \
                         ^~~~~
>> include/trace/events/kmem.h:38:2: note: in expansion of macro 'TP_printk'
     TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s",
     ^~~~~~~~~
   In file included from include/trace/trace_events.h:394:0,
                    from include/trace/define_trace.h:102,
                    from include/trace/events/kmem.h:321,
                    from mm/slab_common.c:27:
   include/trace/events/kmem.h:38:24: note: format string is defined here
     TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s",
                          ~^
                          %ld
   In file included from include/trace/define_trace.h:102:0,
                    from include/trace/events/kmem.h:321,
                    from mm/slab_common.c:27:
   include/trace/events/kmem.h: In function 'trace_raw_output_kmem_alloc_node':
   include/trace/events/kmem.h:91:12: warning: format '%p' expects argument of type 'void *', but argument 3 has type 'long unsigned int' [-Wformat=]
     TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s node=%d",
               ^
   include/trace/trace_events.h:360:22: note: in definition of macro 'DECLARE_EVENT_CLASS'
     trace_seq_printf(s, print);     \
                         ^~~~~
   include/trace/events/kmem.h:91:2: note: in expansion of macro 'TP_printk'
     TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s node=%d",
     ^~~~~~~~~
   In file included from include/trace/trace_events.h:394:0,
                    from include/trace/define_trace.h:102,
                    from include/trace/events/kmem.h:321,
                    from mm/slab_common.c:27:
   include/trace/events/kmem.h:91:24: note: format string is defined here
     TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s node=%d",
                          ~^
                          %ld
   In file included from include/trace/define_trace.h:102:0,
                    from include/trace/events/kmem.h:321,
                    from mm/slab_common.c:27:
   include/trace/events/kmem.h: In function 'trace_raw_output_kmem_free':
   include/trace/events/kmem.h:134:12: warning: format '%p' expects argument of type 'void *', but argument 3 has type 'long unsigned int' [-Wformat=]
     TP_printk("call_site=%pS ptr=%p", __entry->call_site, __entry->ptr)
               ^
   include/trace/trace_events.h:360:22: note: in definition of macro 'DECLARE_EVENT_CLASS'
     trace_seq_printf(s, print);     \
                         ^~~~~
   include/trace/events/kmem.h:134:2: note: in expansion of macro 'TP_printk'
     TP_printk("call_site=%pS ptr=%p", __entry->call_site, __entry->ptr)
     ^~~~~~~~~
   In file included from include/trace/trace_events.h:394:0,
                    from include/trace/define_trace.h:102,
                    from include/trace/events/kmem.h:321,
                    from mm/slab_common.c:27:
   include/trace/events/kmem.h:134:24: note: format string is defined here
     TP_printk("call_site=%pS ptr=%p", __entry->call_site, __entry->ptr)
                          ~^
                          %ld

vim +38 include/trace/events/kmem.h

    13	
    14		TP_PROTO(unsigned long call_site,
    15			 const void *ptr,
    16			 size_t bytes_req,
    17			 size_t bytes_alloc,
    18			 gfp_t gfp_flags),
    19	
    20		TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags),
    21	
    22		TP_STRUCT__entry(
    23			__field(	unsigned long,	call_site	)
    24			__field(	const void *,	ptr		)
    25			__field(	size_t,		bytes_req	)
    26			__field(	size_t,		bytes_alloc	)
    27			__field(	gfp_t,		gfp_flags	)
    28		),
    29	
    30		TP_fast_assign(
    31			__entry->call_site	= call_site;
    32			__entry->ptr		= ptr;
    33			__entry->bytes_req	= bytes_req;
    34			__entry->bytes_alloc	= bytes_alloc;
    35			__entry->gfp_flags	= gfp_flags;
    36		),
    37	
  > 38		TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s",
    39			__entry->call_site,
    40			__entry->ptr,
    41			__entry->bytes_req,
    42			__entry->bytes_alloc,
    43			show_gfp_flags(__entry->gfp_flags))
    44	);
    45	

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

maintainer
#2 lore raw
In reply to George G. Davis

Looking at the kbuild report...

include/trace/events/kmem.h DECLARE_EVENT_CLASS(kmem_alloc, · line 38

Quoted 10 lines · On Fri, 19 Jul 2019 22:22:40 -0400 "George G. Davis" <[email protected]>…
include/trace/events/kmem.h +1 -1
index eb57e3037deb..ae18e61fa1c0 100644
@@ -35,7 +35,7 @@ DECLARE_EVENT_CLASS(kmem_alloc,
 		__entry->gfp_flags	= gfp_flags;
 	),
 
-	TP_printk("call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s",
+	TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s",

Note, %lx expects an unsigned long, %pS expects a pointer.

include/trace/events/kmem.h DECLARE_EVENT_CLASS(kmem_alloc, · line 39

Quoted 1 line
include/trace/events/kmem.h +0 -0
 		__entry->call_site,

You need to change the above to: (void *)__entry->call_site,

-- Steve

Quoted 2 lines
include/trace/events/kmem.h +0 -0
 		__entry->ptr,
 		__entry->bytes_req,
#3 lore raw

Hello Steve,

Quoted 14 lines · Steven Rostedt

Looking at the kbuild report...

Quoted 8 lines · On Fri, 19 Jul 2019 22:22:40 -0400 "George G. Davis" <[email protected]>…
include/trace/events/kmem.h +0 -0
index eb57e3037deb..ae18e61fa1c0 100644
@@ -35,7 +35,7 @@ DECLARE_EVENT_CLASS(kmem_alloc,
 		__entry->gfp_flags	= gfp_flags;
 	),
 
Quoted 8 lines

include/trace/events/kmem.h DECLARE_EVENT_CLASS(kmem_alloc, · line 38

Quoted 2 lines
include/trace/events/kmem.h +1 -1
-	TP_printk("call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s",
+	TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s",

Note, %lx expects an unsigned long, %pS expects a pointer.

include/trace/events/kmem.h DECLARE_EVENT_CLASS(kmem_alloc, · line 39

Quoted 1 line
include/trace/events/kmem.h +0 -0
 		__entry->call_site,

You need to change the above to: (void *)__entry->call_site,

Oops, I should have paid more attention. Fixed.

Thanks!

Quoted 5 lines

-- Steve

Quoted 2 lines
include/trace/events/kmem.h +0 -0
 		__entry->ptr,
 		__entry->bytes_req,
Signature · 2 lines
Regards,
George