Re: [PATCH 1/1] mm/page_owner: ignore everything below the IRQ entry point
On Mon, Dec 4, 2017 at 5:43 AM, Maninder Singh wrote: > Check whether the allocation happens in an IRQ handler. > This lets us strip everything below the IRQ entry point to reduce the > number of unique stack traces needed to be stored. > > so moved code of KASAN in generic file so that page_owner can also > do same filteration. > > Initial KASAN commit > id=be7635e7287e0e8013af3c89a6354a9e0182594c > > Signed-off-by: Vaneet Narang > Signed-off-by: Maninder Singh Reviewed-by: Alexander Potapenko > --- > include/linux/stacktrace.h | 25 + > mm/kasan/kasan.c | 22 -- > mm/page_owner.c| 1 + > 3 files changed, 26 insertions(+), 22 deletions(-) > > diff --git a/include/linux/stacktrace.h b/include/linux/stacktrace.h > index ba29a06..2c1a562 100644 > --- a/include/linux/stacktrace.h > +++ b/include/linux/stacktrace.h > @@ -3,6 +3,7 @@ > #define __LINUX_STACKTRACE_H > > #include > +#include > > struct task_struct; > struct pt_regs; > @@ -26,6 +27,28 @@ extern int save_stack_trace_tsk_reliable(struct > task_struct *tsk, > extern int snprint_stack_trace(char *buf, size_t size, > struct stack_trace *trace, int spaces); > > +static inline int in_irqentry_text(unsigned long ptr) > +{ > + return (ptr >= (unsigned long)&__irqentry_text_start && > + ptr < (unsigned long)&__irqentry_text_end) || > + (ptr >= (unsigned long)&__softirqentry_text_start && > +ptr < (unsigned long)&__softirqentry_text_end); > +} > + > +static inline void filter_irq_stacks(struct stack_trace *trace) > +{ > + int i; > + > + if (!trace->nr_entries) > + return; > + for (i = 0; i < trace->nr_entries; i++) > + if (in_irqentry_text(trace->entries[i])) { > + /* Include the irqentry function into the stack. */ > + trace->nr_entries = i + 1; > + break; > + } > +} > + > #ifdef CONFIG_USER_STACKTRACE_SUPPORT > extern void save_stack_trace_user(struct stack_trace *trace); > #else > @@ -38,6 +61,8 @@ extern int snprint_stack_trace(char *buf, size_t size, > # define save_stack_trace_user(trace) do { } while (0) > # define print_stack_trace(trace, spaces) do { } while (0) > # define snprint_stack_trace(buf, size, trace, spaces) do { } while (0) > +# define filter_irq_stacks(trace) do { } while (0) > +# define in_irqentry_text(ptr) do { } while (0) > # define save_stack_trace_tsk_reliable(tsk, trace) ({ -ENOSYS; }) > #endif /* CONFIG_STACKTRACE */ > > diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c > index 405bba4..129e7b8 100644 > --- a/mm/kasan/kasan.c > +++ b/mm/kasan/kasan.c > @@ -412,28 +412,6 @@ void kasan_poison_object_data(struct kmem_cache *cache, > void *object) > KASAN_KMALLOC_REDZONE); > } > > -static inline int in_irqentry_text(unsigned long ptr) > -{ > - return (ptr >= (unsigned long)&__irqentry_text_start && > - ptr < (unsigned long)&__irqentry_text_end) || > - (ptr >= (unsigned long)&__softirqentry_text_start && > -ptr < (unsigned long)&__softirqentry_text_end); > -} > - > -static inline void filter_irq_stacks(struct stack_trace *trace) > -{ > - int i; > - > - if (!trace->nr_entries) > - return; > - for (i = 0; i < trace->nr_entries; i++) > - if (in_irqentry_text(trace->entries[i])) { > - /* Include the irqentry function into the stack. */ > - trace->nr_entries = i + 1; > - break; > - } > -} > - > static inline depot_stack_handle_t save_stack(gfp_t flags) > { > unsigned long entries[KASAN_STACK_DEPTH]; > diff --git a/mm/page_owner.c b/mm/page_owner.c > index 8602fb4..30e9cb2 100644 > --- a/mm/page_owner.c > +++ b/mm/page_owner.c > @@ -148,6 +148,7 @@ static noinline depot_stack_handle_t save_stack(gfp_t > flags) > depot_stack_handle_t handle; > > save_stack_trace(&trace); > + filter_irq_stacks(&trace); > if (trace.nr_entries != 0 && > trace.entries[trace.nr_entries-1] == ULONG_MAX) > trace.nr_entries--; > -- > 1.9.1 > -- Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Straße, 33 80636 München Geschäftsführer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg
Re: [PATCH 1/1] mm/page_owner: ignore everything below the IRQ entry point
Hi Maninder, Thank you for the patch! Yet something to improve: [auto build test ERROR on mmotm/master] [also build test ERROR on v4.15-rc2 next-20171204] [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/Maninder-Singh/mm-page_owner-ignore-everything-below-the-IRQ-entry-point/20171205-122901 base: git://git.cmpxchg.org/linux-mmotm.git master config: tile-allmodconfig (attached as .config) compiler: tilegx-linux-gcc (GCC) 5.5.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 make.cross ARCH=tile All error/warnings (new ones prefixed by >>): In file included from include/linux/interrupt.h:22:0, from include/linux/kernel_stat.h:9, from mm//swap.c:18: >> arch/tile/include/asm/sections.h:18:29: error: redefinition of >> 'arch_is_kernel_data' #define arch_is_kernel_data arch_is_kernel_data ^ >> arch/tile/include/asm/sections.h:38:19: note: in expansion of macro >> 'arch_is_kernel_data' static inline int arch_is_kernel_data(unsigned long addr) ^ In file included from include/linux/stacktrace.h:6:0, from include/linux/lockdep.h:29, from include/linux/spinlock_types.h:18, from include/linux/spinlock.h:82, from include/linux/mmzone.h:8, from include/linux/gfp.h:6, from include/linux/mm.h:10, from mm//swap.c:16: include/asm-generic/sections.h:70:19: note: previous definition of 'arch_is_kernel_data' was here static inline int arch_is_kernel_data(unsigned long addr) ^ vim +/arch_is_kernel_data +18 arch/tile/include/asm/sections.h 867e359b Chris Metcalf 2010-05-28 17 867e359b Chris Metcalf 2010-05-28 @18 #define arch_is_kernel_data arch_is_kernel_data 867e359b Chris Metcalf 2010-05-28 19 867e359b Chris Metcalf 2010-05-28 20 #include 867e359b Chris Metcalf 2010-05-28 21 4a556f4f Chris Metcalf 2013-08-07 22 extern char vdso_start[], vdso_end[]; 4a556f4f Chris Metcalf 2013-08-07 23 #ifdef CONFIG_COMPAT 4a556f4f Chris Metcalf 2013-08-07 24 extern char vdso32_start[], vdso32_end[]; 4a556f4f Chris Metcalf 2013-08-07 25 #endif 0707ad30 Chris Metcalf 2010-06-25 26 0707ad30 Chris Metcalf 2010-06-25 27 /* Not exactly sections, but PC comparison points in the code. */ 0707ad30 Chris Metcalf 2010-06-25 28 extern char __rt_sigreturn[], __rt_sigreturn_end[]; 2f9ac29e Chris Metcalf 2013-08-06 29 #ifdef __tilegx__ 2f9ac29e Chris Metcalf 2013-08-06 30 extern char __start_unalign_asm_code[], __end_unalign_asm_code[]; 2f9ac29e Chris Metcalf 2013-08-06 31 #else 0707ad30 Chris Metcalf 2010-06-25 32 extern char sys_cmpxchg[], __sys_cmpxchg_end[]; 0707ad30 Chris Metcalf 2010-06-25 33 extern char __sys_cmpxchg_grab_lock[]; 0707ad30 Chris Metcalf 2010-06-25 34 extern char __start_atomic_asm_code[], __end_atomic_asm_code[]; 0707ad30 Chris Metcalf 2010-06-25 35 #endif 867e359b Chris Metcalf 2010-05-28 36 40a3b8df Jiang Liu 2013-07-03 37 /* Handle the discontiguity between _sdata and _text. */ 867e359b Chris Metcalf 2010-05-28 @38 static inline int arch_is_kernel_data(unsigned long addr) 867e359b Chris Metcalf 2010-05-28 39 { 867e359b Chris Metcalf 2010-05-28 40 return addr >= (unsigned long)_sdata && 867e359b Chris Metcalf 2010-05-28 41 addr < (unsigned long)_end; 867e359b Chris Metcalf 2010-05-28 42 } 867e359b Chris Metcalf 2010-05-28 43 :: The code at line 18 was first introduced by commit :: 867e359b97c970a60626d5d76bbe2a8fadbf38fb arch/tile: core support for Tilera 32-bit chips. :: TO: Chris Metcalf :: CC: Chris Metcalf --- 0-DAY kernel test infrastructureOpen Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation .config.gz Description: application/gzip
Re: [PATCH 1/1] mm/page_owner: ignore everything below the IRQ entry point
Hi Maninder, Thank you for the patch! Yet something to improve: [auto build test ERROR on mmotm/master] [also build test ERROR on v4.15-rc2 next-20171204] [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/Maninder-Singh/mm-page_owner-ignore-everything-below-the-IRQ-entry-point/20171205-122901 base: git://git.cmpxchg.org/linux-mmotm.git master config: blackfin-allmodconfig (attached as .config) compiler: bfin-uclinux-gcc (GCC) 6.2.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 make.cross ARCH=blackfin All errors (new ones prefixed by >>): In file included from include/linux/interrupt.h:22:0, from include/linux/kernel_stat.h:9, from arch/blackfin/kernel/asm-offsets.c:11: >> arch/blackfin/include/asm/sections.h:35:19: error: redefinition of >> 'arch_is_kernel_text' static inline int arch_is_kernel_text(unsigned long addr) ^~~ In file included from include/linux/stacktrace.h:6:0, from include/linux/lockdep.h:29, from include/linux/rcupdate.h:42, from include/linux/rculist.h:11, from include/linux/pid.h:5, from include/linux/sched.h:14, from arch/blackfin/kernel/asm-offsets.c:10: include/asm-generic/sections.h:63:19: note: previous definition of 'arch_is_kernel_text' was here static inline int arch_is_kernel_text(unsigned long addr) ^~~ In file included from include/linux/interrupt.h:22:0, from include/linux/kernel_stat.h:9, from arch/blackfin/kernel/asm-offsets.c:11: >> arch/blackfin/include/asm/sections.h:48:19: error: redefinition of >> 'arch_is_kernel_data' static inline int arch_is_kernel_data(unsigned long addr) ^~~ In file included from include/linux/stacktrace.h:6:0, from include/linux/lockdep.h:29, from include/linux/rcupdate.h:42, from include/linux/rculist.h:11, from include/linux/pid.h:5, from include/linux/sched.h:14, from arch/blackfin/kernel/asm-offsets.c:10: include/asm-generic/sections.h:70:19: note: previous definition of 'arch_is_kernel_data' was here static inline int arch_is_kernel_data(unsigned long addr) ^~~ make[2]: *** [arch/blackfin/kernel/asm-offsets.s] Error 1 make[2]: Target '__build' not remade because of errors. make[1]: *** [prepare0] Error 2 make[1]: Target 'prepare' not remade because of errors. make: *** [sub-make] Error 2 vim +/arch_is_kernel_text +35 arch/blackfin/include/asm/sections.h e56770fb Mike Frysinger 2009-09-22 33 e56770fb Mike Frysinger 2009-09-22 34 /* Blackfin systems have discontinuous memory map and no virtualized memory */ e56770fb Mike Frysinger 2009-09-22 @35 static inline int arch_is_kernel_text(unsigned long addr) e56770fb Mike Frysinger 2009-09-22 36 { e56770fb Mike Frysinger 2009-09-22 37 return e56770fb Mike Frysinger 2009-09-22 38 (L1_CODE_LENGTH && e56770fb Mike Frysinger 2009-09-22 39 addr >= (unsigned long)_stext_l1 && e56770fb Mike Frysinger 2009-09-22 40 addr < (unsigned long)_etext_l1) e56770fb Mike Frysinger 2009-09-22 41 || e56770fb Mike Frysinger 2009-09-22 42 (L2_LENGTH && e56770fb Mike Frysinger 2009-09-22 43 addr >= (unsigned long)_stext_l2 && e56770fb Mike Frysinger 2009-09-22 44 addr < (unsigned long)_etext_l2); e56770fb Mike Frysinger 2009-09-22 45 } e56770fb Mike Frysinger 2009-09-22 46 #define arch_is_kernel_text(addr) arch_is_kernel_text(addr) e56770fb Mike Frysinger 2009-09-22 47 e56770fb Mike Frysinger 2009-09-22 @48 static inline int arch_is_kernel_data(unsigned long addr) e56770fb Mike Frysinger 2009-09-22 49 { e56770fb Mike Frysinger 2009-09-22 50 return e56770fb Mike Frysinger 2009-09-22 51 (L1_DATA_A_LENGTH && e56770fb Mike Frysinger 2009-09-22 52 addr >= (unsigned long)_sdata_l1 && e56770fb Mike Frysinger 2009-09-22 53 addr < (unsigned long)_ebss_l1) e56770fb Mike Frysinger 2009-09-22 54 || e56770fb Mike Frysinger 2009-09-22 55 (L1_DATA_B_LENGTH && e56770fb Mike Frysinger 2009-09-22 56 addr >= (unsigned long)_sdata_b_l1 && e56770fb Mike Frysinger 2009-09-22 57 addr < (unsigned long)_ebss_b_l1) e56770fb Mike Frysinger 2009-09-2