Skip to content

Commit be7635e

Browse files
ramosian-glidertorvalds
authored andcommitted
arch, ftrace: for KASAN put hard/soft IRQ entries into separate sections
KASAN needs to know 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. Move the definition of __irq_entry to <linux/interrupt.h> so that the users don't need to pull in <linux/ftrace.h>. Also introduce the __softirq_entry macro which is similar to __irq_entry, but puts the corresponding functions to the .softirqentry.text section. Signed-off-by: Alexander Potapenko <[email protected]> Acked-by: Steven Rostedt <[email protected]> Cc: Christoph Lameter <[email protected]> Cc: Pekka Enberg <[email protected]> Cc: David Rientjes <[email protected]> Cc: Joonsoo Kim <[email protected]> Cc: Andrey Konovalov <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Konstantin Serebryany <[email protected]> Cc: Dmitry Chernenkov <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 505f5dc commit be7635e

File tree

23 files changed

+51
-15
lines changed

23 files changed

+51
-15
lines changed

arch/arm/include/asm/exception.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#ifndef __ASM_ARM_EXCEPTION_H
88
#define __ASM_ARM_EXCEPTION_H
99

10-
#include <linux/ftrace.h>
10+
#include <linux/interrupt.h>
1111

1212
#define __exception __attribute__((section(".exception.text")))
1313
#ifdef CONFIG_FUNCTION_GRAPH_TRACER

arch/arm/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ SECTIONS
108108
*(.exception.text)
109109
__exception_text_end = .;
110110
IRQENTRY_TEXT
111+
SOFTIRQENTRY_TEXT
111112
TEXT_TEXT
112113
SCHED_TEXT
113114
LOCK_TEXT

arch/arm64/include/asm/exception.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#ifndef __ASM_EXCEPTION_H
1919
#define __ASM_EXCEPTION_H
2020

21-
#include <linux/ftrace.h>
21+
#include <linux/interrupt.h>
2222

2323
#define __exception __attribute__((section(".exception.text")))
2424
#ifdef CONFIG_FUNCTION_GRAPH_TRACER

arch/arm64/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ SECTIONS
103103
*(.exception.text)
104104
__exception_text_end = .;
105105
IRQENTRY_TEXT
106+
SOFTIRQENTRY_TEXT
106107
TEXT_TEXT
107108
SCHED_TEXT
108109
LOCK_TEXT

arch/blackfin/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ SECTIONS
3535
#endif
3636
LOCK_TEXT
3737
IRQENTRY_TEXT
38+
SOFTIRQENTRY_TEXT
3839
KPROBES_TEXT
3940
#ifdef CONFIG_ROMKERNEL
4041
__sinittext = .;

arch/c6x/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ SECTIONS
7272
SCHED_TEXT
7373
LOCK_TEXT
7474
IRQENTRY_TEXT
75+
SOFTIRQENTRY_TEXT
7576
KPROBES_TEXT
7677
*(.fixup)
7778
*(.gnu.warning)

arch/metag/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ SECTIONS
2424
LOCK_TEXT
2525
KPROBES_TEXT
2626
IRQENTRY_TEXT
27+
SOFTIRQENTRY_TEXT
2728
*(.text.*)
2829
*(.gnu.warning)
2930
}

arch/microblaze/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ SECTIONS {
3636
LOCK_TEXT
3737
KPROBES_TEXT
3838
IRQENTRY_TEXT
39+
SOFTIRQENTRY_TEXT
3940
. = ALIGN (4) ;
4041
_etext = . ;
4142
}

arch/mips/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ SECTIONS
5858
LOCK_TEXT
5959
KPROBES_TEXT
6060
IRQENTRY_TEXT
61+
SOFTIRQENTRY_TEXT
6162
*(.text.*)
6263
*(.fixup)
6364
*(.gnu.warning)

arch/nios2/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ SECTIONS
3939
SCHED_TEXT
4040
LOCK_TEXT
4141
IRQENTRY_TEXT
42+
SOFTIRQENTRY_TEXT
4243
KPROBES_TEXT
4344
} =0
4445
_etext = .;

arch/openrisc/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ SECTIONS
5050
LOCK_TEXT
5151
KPROBES_TEXT
5252
IRQENTRY_TEXT
53+
SOFTIRQENTRY_TEXT
5354
*(.fixup)
5455
*(.text.__*)
5556
_etext = .;

arch/parisc/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ SECTIONS
7272
LOCK_TEXT
7373
KPROBES_TEXT
7474
IRQENTRY_TEXT
75+
SOFTIRQENTRY_TEXT
7576
*(.text.do_softirq)
7677
*(.text.sys_exit)
7778
*(.text.do_sigaltstack)

arch/powerpc/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ SECTIONS
5555
LOCK_TEXT
5656
KPROBES_TEXT
5757
IRQENTRY_TEXT
58+
SOFTIRQENTRY_TEXT
5859

5960
#ifdef CONFIG_PPC32
6061
*(.got1)

arch/s390/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ SECTIONS
2828
LOCK_TEXT
2929
KPROBES_TEXT
3030
IRQENTRY_TEXT
31+
SOFTIRQENTRY_TEXT
3132
*(.fixup)
3233
*(.gnu.warning)
3334
} :text = 0x0700

arch/sh/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ SECTIONS
3939
LOCK_TEXT
4040
KPROBES_TEXT
4141
IRQENTRY_TEXT
42+
SOFTIRQENTRY_TEXT
4243
*(.fixup)
4344
*(.gnu.warning)
4445
_etext = .; /* End of text section */

arch/sparc/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ SECTIONS
4848
LOCK_TEXT
4949
KPROBES_TEXT
5050
IRQENTRY_TEXT
51+
SOFTIRQENTRY_TEXT
5152
*(.gnu.warning)
5253
} = 0
5354
_etext = .;

arch/tile/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ SECTIONS
4545
LOCK_TEXT
4646
KPROBES_TEXT
4747
IRQENTRY_TEXT
48+
SOFTIRQENTRY_TEXT
4849
__fix_text_end = .; /* tile-cpack won't rearrange before this */
4950
ALIGN_FUNCTION();
5051
*(.hottext*)

arch/x86/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ SECTIONS
101101
KPROBES_TEXT
102102
ENTRY_TEXT
103103
IRQENTRY_TEXT
104+
SOFTIRQENTRY_TEXT
104105
*(.fixup)
105106
*(.gnu.warning)
106107
/* End of text section */

include/asm-generic/vmlinux.lds.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@
456456
*(.entry.text) \
457457
VMLINUX_SYMBOL(__entry_text_end) = .;
458458

459-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
459+
#if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
460460
#define IRQENTRY_TEXT \
461461
ALIGN_FUNCTION(); \
462462
VMLINUX_SYMBOL(__irqentry_text_start) = .; \
@@ -466,6 +466,16 @@
466466
#define IRQENTRY_TEXT
467467
#endif
468468

469+
#if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
470+
#define SOFTIRQENTRY_TEXT \
471+
ALIGN_FUNCTION(); \
472+
VMLINUX_SYMBOL(__softirqentry_text_start) = .; \
473+
*(.softirqentry.text) \
474+
VMLINUX_SYMBOL(__softirqentry_text_end) = .;
475+
#else
476+
#define SOFTIRQENTRY_TEXT
477+
#endif
478+
469479
/* Section used for early init (in .S files) */
470480
#define HEAD_TEXT *(.head.text)
471481

include/linux/ftrace.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -811,16 +811,6 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
811811
*/
812812
#define __notrace_funcgraph notrace
813813

814-
/*
815-
* We want to which function is an entrypoint of a hardirq.
816-
* That will help us to put a signal on output.
817-
*/
818-
#define __irq_entry __attribute__((__section__(".irqentry.text")))
819-
820-
/* Limits of hardirq entrypoints */
821-
extern char __irqentry_text_start[];
822-
extern char __irqentry_text_end[];
823-
824814
#define FTRACE_NOTRACE_DEPTH 65536
825815
#define FTRACE_RETFUNC_DEPTH 50
826816
#define FTRACE_RETSTACK_ALLOC_SIZE 32
@@ -857,7 +847,6 @@ static inline void unpause_graph_tracing(void)
857847
#else /* !CONFIG_FUNCTION_GRAPH_TRACER */
858848

859849
#define __notrace_funcgraph
860-
#define __irq_entry
861850
#define INIT_FTRACE_GRAPH
862851

863852
static inline void ftrace_graph_init_task(struct task_struct *t) { }

include/linux/interrupt.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,4 +683,24 @@ extern int early_irq_init(void);
683683
extern int arch_probe_nr_irqs(void);
684684
extern int arch_early_irq_init(void);
685685

686+
#if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
687+
/*
688+
* We want to know which function is an entrypoint of a hardirq or a softirq.
689+
*/
690+
#define __irq_entry __attribute__((__section__(".irqentry.text")))
691+
#define __softirq_entry \
692+
__attribute__((__section__(".softirqentry.text")))
693+
694+
/* Limits of hardirq entrypoints */
695+
extern char __irqentry_text_start[];
696+
extern char __irqentry_text_end[];
697+
/* Limits of softirq entrypoints */
698+
extern char __softirqentry_text_start[];
699+
extern char __softirqentry_text_end[];
700+
701+
#else
702+
#define __irq_entry
703+
#define __softirq_entry
704+
#endif
705+
686706
#endif

kernel/softirq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static inline bool lockdep_softirq_start(void) { return false; }
227227
static inline void lockdep_softirq_end(bool in_hardirq) { }
228228
#endif
229229

230-
asmlinkage __visible void __do_softirq(void)
230+
asmlinkage __visible void __softirq_entry __do_softirq(void)
231231
{
232232
unsigned long end = jiffies + MAX_SOFTIRQ_TIME;
233233
unsigned long old_flags = current->flags;

kernel/trace/trace_functions_graph.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99
#include <linux/uaccess.h>
1010
#include <linux/ftrace.h>
11+
#include <linux/interrupt.h>
1112
#include <linux/slab.h>
1213
#include <linux/fs.h>
1314

0 commit comments

Comments
 (0)