Skip to content

Commit 3f1756d

Browse files
committed
tracing: More reverting of "tracing: Centralize preemptirq tracepoints and unify their usage"
Joel Fernandes created a nice patch that cleaned up the duplicate hooks used by lockdep and irqsoff latency tracer. It made both use tracepoints. But the latency tracer is triggering warnings when using tracepoints to call into the latency tracer's routines. Mainly, they can be called from NMI context. If that happens, then the SRCU may not work properly because on some architectures, SRCU is not safe to be called in both NMI and non-NMI context. This is a partial revert of the clean up patch c3bc8fd ("tracing: Centralize preemptirq tracepoints and unify their usage") that adds back the direct calls into the latency tracer. It also only calls the trace events when not in NMI. Link: http://lkml.kernel.org/r/20180809210654.622445925@goodmis.org Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org> Fixes: c3bc8fd ("tracing: Centralize preemptirq tracepoints and unify their usage") Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent f27107f commit 3f1756d

3 files changed

Lines changed: 38 additions & 50 deletions

File tree

‎kernel/trace/trace.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,21 @@ static inline int tracing_alloc_snapshot_instance(struct trace_array *tr)
18271827
}
18281828
#endif
18291829

1830+
#ifdef CONFIG_PREEMPT_TRACER
1831+
void tracer_preempt_on(unsigned long a0, unsigned long a1);
1832+
void tracer_preempt_off(unsigned long a0, unsigned long a1);
1833+
#else
1834+
static inline void tracer_preempt_on(unsigned long a0, unsigned long a1) { }
1835+
static inline void tracer_preempt_off(unsigned long a0, unsigned long a1) { }
1836+
#endif
1837+
#ifdef CONFIG_IRQSOFF_TRACER
1838+
void tracer_hardirqs_on(unsigned long a0, unsigned long a1);
1839+
void tracer_hardirqs_off(unsigned long a0, unsigned long a1);
1840+
#else
1841+
static inline void tracer_hardirqs_on(unsigned long a0, unsigned long a1) { }
1842+
static inline void tracer_hardirqs_off(unsigned long a0, unsigned long a1) { }
1843+
#endif
1844+
18301845
extern struct trace_iterator *tracepoint_print_iter;
18311846

18321847
#endif /* _LINUX_KERNEL_TRACE_H */

‎kernel/trace/trace_irqsoff.c‎

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -605,40 +605,18 @@ static void irqsoff_tracer_stop(struct trace_array *tr)
605605
/*
606606
* We are only interested in hardirq on/off events:
607607
*/
608-
static void tracer_hardirqs_on(void *none, unsigned long a0, unsigned long a1)
608+
void tracer_hardirqs_on(unsigned long a0, unsigned long a1)
609609
{
610610
unsigned int pc = preempt_count();
611611

612-
/*
613-
* Tracepoint probes are expected to be called with preempt disabled,
614-
* We don't care about being called with preempt disabled but we need
615-
* to know in the future if that changes so we can remove the next
616-
* preempt_enable.
617-
*/
618-
WARN_ON_ONCE(pc < PREEMPT_DISABLE_OFFSET);
619-
620-
/* Use PREEMPT_DISABLE_OFFSET to handle !CONFIG_PREEMPT cases */
621-
pc -= PREEMPT_DISABLE_OFFSET;
622-
623612
if (!preempt_trace(pc) && irq_trace())
624613
stop_critical_timing(a0, a1, pc);
625614
}
626615

627-
static void tracer_hardirqs_off(void *none, unsigned long a0, unsigned long a1)
616+
void tracer_hardirqs_off(unsigned long a0, unsigned long a1)
628617
{
629618
unsigned int pc = preempt_count();
630619

631-
/*
632-
* Tracepoint probes are expected to be called with preempt disabled,
633-
* We don't care about being called with preempt disabled but we need
634-
* to know in the future if that changes so we can remove the next
635-
* preempt_enable.
636-
*/
637-
WARN_ON_ONCE(pc < PREEMPT_DISABLE_OFFSET);
638-
639-
/* Use PREEMPT_DISABLE_OFFSET to handle !CONFIG_PREEMPT cases */
640-
pc -= PREEMPT_DISABLE_OFFSET;
641-
642620
if (!preempt_trace(pc) && irq_trace())
643621
start_critical_timing(a0, a1, pc);
644622
}
@@ -647,15 +625,11 @@ static int irqsoff_tracer_init(struct trace_array *tr)
647625
{
648626
trace_type = TRACER_IRQS_OFF;
649627

650-
register_trace_irq_disable(tracer_hardirqs_off, NULL);
651-
register_trace_irq_enable(tracer_hardirqs_on, NULL);
652628
return __irqsoff_tracer_init(tr);
653629
}
654630

655631
static void irqsoff_tracer_reset(struct trace_array *tr)
656632
{
657-
unregister_trace_irq_disable(tracer_hardirqs_off, NULL);
658-
unregister_trace_irq_enable(tracer_hardirqs_on, NULL);
659633
__irqsoff_tracer_reset(tr);
660634
}
661635

@@ -681,15 +655,15 @@ static struct tracer irqsoff_tracer __read_mostly =
681655
#endif /* CONFIG_IRQSOFF_TRACER */
682656

683657
#ifdef CONFIG_PREEMPT_TRACER
684-
static void tracer_preempt_on(void *none, unsigned long a0, unsigned long a1)
658+
void tracer_preempt_on(unsigned long a0, unsigned long a1)
685659
{
686660
int pc = preempt_count();
687661

688662
if (preempt_trace(pc) && !irq_trace())
689663
stop_critical_timing(a0, a1, pc);
690664
}
691665

692-
static void tracer_preempt_off(void *none, unsigned long a0, unsigned long a1)
666+
void tracer_preempt_off(unsigned long a0, unsigned long a1)
693667
{
694668
int pc = preempt_count();
695669

@@ -701,15 +675,11 @@ static int preemptoff_tracer_init(struct trace_array *tr)
701675
{
702676
trace_type = TRACER_PREEMPT_OFF;
703677

704-
register_trace_preempt_disable(tracer_preempt_off, NULL);
705-
register_trace_preempt_enable(tracer_preempt_on, NULL);
706678
return __irqsoff_tracer_init(tr);
707679
}
708680

709681
static void preemptoff_tracer_reset(struct trace_array *tr)
710682
{
711-
unregister_trace_preempt_disable(tracer_preempt_off, NULL);
712-
unregister_trace_preempt_enable(tracer_preempt_on, NULL);
713683
__irqsoff_tracer_reset(tr);
714684
}
715685

@@ -740,21 +710,11 @@ static int preemptirqsoff_tracer_init(struct trace_array *tr)
740710
{
741711
trace_type = TRACER_IRQS_OFF | TRACER_PREEMPT_OFF;
742712

743-
register_trace_irq_disable(tracer_hardirqs_off, NULL);
744-
register_trace_irq_enable(tracer_hardirqs_on, NULL);
745-
register_trace_preempt_disable(tracer_preempt_off, NULL);
746-
register_trace_preempt_enable(tracer_preempt_on, NULL);
747-
748713
return __irqsoff_tracer_init(tr);
749714
}
750715

751716
static void preemptirqsoff_tracer_reset(struct trace_array *tr)
752717
{
753-
unregister_trace_irq_disable(tracer_hardirqs_off, NULL);
754-
unregister_trace_irq_enable(tracer_hardirqs_on, NULL);
755-
unregister_trace_preempt_disable(tracer_preempt_off, NULL);
756-
unregister_trace_preempt_enable(tracer_preempt_on, NULL);
757-
758718
__irqsoff_tracer_reset(tr);
759719
}
760720

‎kernel/trace/trace_preemptirq.c‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/uaccess.h>
1010
#include <linux/module.h>
1111
#include <linux/ftrace.h>
12+
#include "trace.h"
1213

1314
#define CREATE_TRACE_POINTS
1415
#include <trace/events/preemptirq.h>
@@ -20,7 +21,9 @@ static DEFINE_PER_CPU(int, tracing_irq_cpu);
2021
void trace_hardirqs_on(void)
2122
{
2223
if (this_cpu_read(tracing_irq_cpu)) {
23-
trace_irq_enable_rcuidle(CALLER_ADDR0, CALLER_ADDR1);
24+
if (!in_nmi())
25+
trace_irq_enable_rcuidle(CALLER_ADDR0, CALLER_ADDR1);
26+
tracer_hardirqs_on(CALLER_ADDR0, CALLER_ADDR1);
2427
this_cpu_write(tracing_irq_cpu, 0);
2528
}
2629

@@ -32,7 +35,9 @@ void trace_hardirqs_off(void)
3235
{
3336
if (!this_cpu_read(tracing_irq_cpu)) {
3437
this_cpu_write(tracing_irq_cpu, 1);
35-
trace_irq_disable_rcuidle(CALLER_ADDR0, CALLER_ADDR1);
38+
tracer_hardirqs_off(CALLER_ADDR0, CALLER_ADDR1);
39+
if (!in_nmi())
40+
trace_irq_disable_rcuidle(CALLER_ADDR0, CALLER_ADDR1);
3641
}
3742

3843
lockdep_hardirqs_off(CALLER_ADDR0);
@@ -42,7 +47,9 @@ EXPORT_SYMBOL(trace_hardirqs_off);
4247
__visible void trace_hardirqs_on_caller(unsigned long caller_addr)
4348
{
4449
if (this_cpu_read(tracing_irq_cpu)) {
45-
trace_irq_enable_rcuidle(CALLER_ADDR0, caller_addr);
50+
if (!in_nmi())
51+
trace_irq_enable_rcuidle(CALLER_ADDR0, caller_addr);
52+
tracer_hardirqs_on(CALLER_ADDR0, caller_addr);
4653
this_cpu_write(tracing_irq_cpu, 0);
4754
}
4855

@@ -54,7 +61,9 @@ __visible void trace_hardirqs_off_caller(unsigned long caller_addr)
5461
{
5562
if (!this_cpu_read(tracing_irq_cpu)) {
5663
this_cpu_write(tracing_irq_cpu, 1);
57-
trace_irq_disable_rcuidle(CALLER_ADDR0, caller_addr);
64+
tracer_hardirqs_off(CALLER_ADDR0, caller_addr);
65+
if (!in_nmi())
66+
trace_irq_disable_rcuidle(CALLER_ADDR0, caller_addr);
5867
}
5968

6069
lockdep_hardirqs_off(CALLER_ADDR0);
@@ -66,11 +75,15 @@ EXPORT_SYMBOL(trace_hardirqs_off_caller);
6675

6776
void trace_preempt_on(unsigned long a0, unsigned long a1)
6877
{
69-
trace_preempt_enable_rcuidle(a0, a1);
78+
if (!in_nmi())
79+
trace_preempt_enable_rcuidle(a0, a1);
80+
tracer_preempt_on(a0, a1);
7081
}
7182

7283
void trace_preempt_off(unsigned long a0, unsigned long a1)
7384
{
74-
trace_preempt_disable_rcuidle(a0, a1);
85+
if (!in_nmi())
86+
trace_preempt_disable_rcuidle(a0, a1);
87+
tracer_preempt_off(a0, a1);
7588
}
7689
#endif

0 commit comments

Comments
 (0)