mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-03 18:20:25 +02:00 
			
		
		
		
	stacktrace: move filter_irq_stacks() to kernel/stacktrace.c
filter_irq_stacks() has little to do with the stackdepot implementation, except that it is usually used by users (such as KASAN) of stackdepot to reduce the stack trace. However, filter_irq_stacks() itself is not useful without a stack trace as obtained by stack_trace_save() and friends. Therefore, move filter_irq_stacks() to kernel/stacktrace.c, so that new users of filter_irq_stacks() do not have to start depending on STACKDEPOT only for filter_irq_stacks(). Link: https://lkml.kernel.org/r/20210923104803.2620285-1-elver@google.com Signed-off-by: Marco Elver <elver@google.com> Acked-by: Dmitry Vyukov <dvyukov@google.com> Cc: Alexander Potapenko <glider@google.com> Cc: Jann Horn <jannh@google.com> Cc: Aleksandr Nogikh <nogikh@google.com> Cc: Taras Madan <tarasmadan@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
		
							parent
							
								
									a1554c0026
								
							
						
					
					
						commit
						f39f21b3dd
					
				
					 4 changed files with 31 additions and 26 deletions
				
			
		| 
						 | 
					@ -25,8 +25,6 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries,
 | 
				
			||||||
unsigned int stack_depot_fetch(depot_stack_handle_t handle,
 | 
					unsigned int stack_depot_fetch(depot_stack_handle_t handle,
 | 
				
			||||||
			       unsigned long **entries);
 | 
								       unsigned long **entries);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
unsigned int filter_irq_stacks(unsigned long *entries, unsigned int nr_entries);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef CONFIG_STACKDEPOT
 | 
					#ifdef CONFIG_STACKDEPOT
 | 
				
			||||||
int stack_depot_init(void);
 | 
					int stack_depot_init(void);
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,6 +21,7 @@ unsigned int stack_trace_save_tsk(struct task_struct *task,
 | 
				
			||||||
unsigned int stack_trace_save_regs(struct pt_regs *regs, unsigned long *store,
 | 
					unsigned int stack_trace_save_regs(struct pt_regs *regs, unsigned long *store,
 | 
				
			||||||
				   unsigned int size, unsigned int skipnr);
 | 
									   unsigned int size, unsigned int skipnr);
 | 
				
			||||||
unsigned int stack_trace_save_user(unsigned long *store, unsigned int size);
 | 
					unsigned int stack_trace_save_user(unsigned long *store, unsigned int size);
 | 
				
			||||||
 | 
					unsigned int filter_irq_stacks(unsigned long *entries, unsigned int nr_entries);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Internal interfaces. Do not use in generic code */
 | 
					/* Internal interfaces. Do not use in generic code */
 | 
				
			||||||
#ifdef CONFIG_ARCH_STACKWALK
 | 
					#ifdef CONFIG_ARCH_STACKWALK
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,6 +13,7 @@
 | 
				
			||||||
#include <linux/export.h>
 | 
					#include <linux/export.h>
 | 
				
			||||||
#include <linux/kallsyms.h>
 | 
					#include <linux/kallsyms.h>
 | 
				
			||||||
#include <linux/stacktrace.h>
 | 
					#include <linux/stacktrace.h>
 | 
				
			||||||
 | 
					#include <linux/interrupt.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * stack_trace_print - Print the entries in the stack trace
 | 
					 * stack_trace_print - Print the entries in the stack trace
 | 
				
			||||||
| 
						 | 
					@ -373,3 +374,32 @@ unsigned int stack_trace_save_user(unsigned long *store, unsigned int size)
 | 
				
			||||||
#endif /* CONFIG_USER_STACKTRACE_SUPPORT */
 | 
					#endif /* CONFIG_USER_STACKTRACE_SUPPORT */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* !CONFIG_ARCH_STACKWALK */
 | 
					#endif /* !CONFIG_ARCH_STACKWALK */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline bool 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);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * filter_irq_stacks - Find first IRQ stack entry in trace
 | 
				
			||||||
 | 
					 * @entries:	Pointer to stack trace array
 | 
				
			||||||
 | 
					 * @nr_entries:	Number of entries in the storage array
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Return: Number of trace entries until IRQ stack starts.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					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;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					EXPORT_SYMBOL_GPL(filter_irq_stacks);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,7 +20,6 @@
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <linux/gfp.h>
 | 
					#include <linux/gfp.h>
 | 
				
			||||||
#include <linux/interrupt.h>
 | 
					 | 
				
			||||||
#include <linux/jhash.h>
 | 
					#include <linux/jhash.h>
 | 
				
			||||||
#include <linux/kernel.h>
 | 
					#include <linux/kernel.h>
 | 
				
			||||||
#include <linux/mm.h>
 | 
					#include <linux/mm.h>
 | 
				
			||||||
| 
						 | 
					@ -371,26 +370,3 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries,
 | 
				
			||||||
	return __stack_depot_save(entries, nr_entries, alloc_flags, true);
 | 
						return __stack_depot_save(entries, nr_entries, alloc_flags, true);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL_GPL(stack_depot_save);
 | 
					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;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
EXPORT_SYMBOL_GPL(filter_irq_stacks);
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue