Message ID | 20191122112621.204798-4-glider@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add KernelMemorySanitizer infrastructure | expand |
On Fri, 22 Nov 2019 at 12:26, <glider@google.com> wrote: [...] > diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h > index 3efa97d482cb..24d49c732341 100644 > --- a/include/linux/stackdepot.h > +++ b/include/linux/stackdepot.h > @@ -19,4 +19,6 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, > unsigned int stack_depot_fetch(depot_stack_handle_t handle, > unsigned long **entries); > > +unsigned int filter_irq_stacks(unsigned long *entries, unsigned int nr_entries); > + > #endif > diff --git a/lib/stackdepot.c b/lib/stackdepot.c > index 6d1123123e56..eb95197b8743 100644 > --- a/lib/stackdepot.c > +++ b/lib/stackdepot.c > @@ -20,6 +20,7 @@ > */ > > #include <linux/gfp.h> > +#include <linux/interrupt.h> > #include <linux/jhash.h> > #include <linux/kernel.h> > #include <linux/mm.h> > @@ -314,3 +315,25 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, > return retval; > } > EXPORT_SYMBOL_GPL(stack_depot_save); > + > +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); > +} > + > +unsigned int filter_irq_stacks(unsigned long *entries, > + unsigned int nr_entries) > +{ > + unsigned int i; > + > + for (i = 0; i < nr_entries; i++) { > + if (in_irqentry_text(entries[i])) { > + /* Include the irqentry function into the stack. */ > + return i + 1; > + } > + } > + return nr_entries; > +} Does this need an EXPORT_SYMBOL_GPL ?
On Wed, Nov 27, 2019 at 3:23 PM Marco Elver <elver@google.com> wrote: > > On Fri, 22 Nov 2019 at 12:26, <glider@google.com> wrote: > [...] > > diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h > > index 3efa97d482cb..24d49c732341 100644 > > --- a/include/linux/stackdepot.h > > +++ b/include/linux/stackdepot.h > > @@ -19,4 +19,6 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, > > unsigned int stack_depot_fetch(depot_stack_handle_t handle, > > unsigned long **entries); > > > > +unsigned int filter_irq_stacks(unsigned long *entries, unsigned int nr_entries); > > + > > #endif > > diff --git a/lib/stackdepot.c b/lib/stackdepot.c > > index 6d1123123e56..eb95197b8743 100644 > > --- a/lib/stackdepot.c > > +++ b/lib/stackdepot.c > > @@ -20,6 +20,7 @@ > > */ > > > > #include <linux/gfp.h> > > +#include <linux/interrupt.h> > > #include <linux/jhash.h> > > #include <linux/kernel.h> > > #include <linux/mm.h> > > @@ -314,3 +315,25 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, > > return retval; > > } > > EXPORT_SYMBOL_GPL(stack_depot_save); > > + > > +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); > > +} > > + > > +unsigned int filter_irq_stacks(unsigned long *entries, > > + unsigned int nr_entries) > > +{ > > + unsigned int i; > > + > > + for (i = 0; i < nr_entries; i++) { > > + if (in_irqentry_text(entries[i])) { > > + /* Include the irqentry function into the stack. */ > > + return i + 1; > > + } > > + } > > + return nr_entries; > > +} > > Does this need an EXPORT_SYMBOL_GPL ? Yes, makes sense.
diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index 3efa97d482cb..24d49c732341 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -19,4 +19,6 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, unsigned int stack_depot_fetch(depot_stack_handle_t handle, unsigned long **entries); +unsigned int filter_irq_stacks(unsigned long *entries, unsigned int nr_entries); + #endif diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 6d1123123e56..eb95197b8743 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -20,6 +20,7 @@ */ #include <linux/gfp.h> +#include <linux/interrupt.h> #include <linux/jhash.h> #include <linux/kernel.h> #include <linux/mm.h> @@ -314,3 +315,25 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, return retval; } EXPORT_SYMBOL_GPL(stack_depot_save); + +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); +} + +unsigned int filter_irq_stacks(unsigned long *entries, + unsigned int nr_entries) +{ + unsigned int i; + + for (i = 0; i < nr_entries; i++) { + if (in_irqentry_text(entries[i])) { + /* Include the irqentry function into the stack. */ + return i + 1; + } + } + return nr_entries; +} diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 6814d6d6a023..154eba5700d8 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -15,7 +15,6 @@ */ #include <linux/export.h> -#include <linux/interrupt.h> #include <linux/init.h> #include <linux/kasan.h> #include <linux/kernel.h> @@ -39,28 +38,6 @@ #include "kasan.h" #include "../slab.h" -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 unsigned int filter_irq_stacks(unsigned long *entries, - unsigned int nr_entries) -{ - unsigned int i; - - for (i = 0; i < nr_entries; i++) { - if (in_irqentry_text(entries[i])) { - /* Include the irqentry function into the stack. */ - return i + 1; - } - } - return nr_entries; -} - static inline depot_stack_handle_t save_stack(gfp_t flags) { unsigned long entries[KASAN_STACK_DEPTH];
filter_irq_stacks() can be used by other tools (e.g. KMSAN), so it needs to be moved to a common location. lib/stackdepot.c seems a good place, as filter_irq_stacks() is usually applied to the output of stack_trace_save(). Signed-off-by: Alexander Potapenko <glider@google.com> To: Alexander Potapenko <glider@google.com> Cc: Vegard Nossum <vegard.nossum@oracle.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: linux-mm@kvack.org --- Change-Id: I65acecf64930a3658e8c2aa7423801082ded8602 --- include/linux/stackdepot.h | 2 ++ lib/stackdepot.c | 23 +++++++++++++++++++++++ mm/kasan/common.c | 23 ----------------------- 3 files changed, 25 insertions(+), 23 deletions(-)