ARM: perf: do not handle deleted counter in irq handler to avoid oops
Subsystems (3)
PATCH 1/1 ARM: perf: do not handle deleted counter in irq handler to avoid oops
The patch adds one check in irq handler to skip handling deleted counter for avoiding oops.
When one counter is deleted, event reference(hw_events->events[idx]) will be cleared but the hw overflow status may be kept, so the hw event may be handled and oops will be triggered in irq handler if pmu irq from other events come.
The another candidate fix is to clear the overflow status for the event in arm_pmu->disable(), but looks it is a bit more complicated and has no obvious advantage than the fix in this patch.
--- arch/arm/kernel/perf_event_v7.c | 3 ++- arch/arm/kernel/perf_event_xscale.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
arch/arm/kernel/perf_event_v7.c +2 -1
@@ -1082,8 +1082,9 @@ static irqreturn_t armv7pmu_handle_irq(int irq_num, void *dev)/* * We have a single interrupt for all counters. Check that * each counter has overflowed before we process it. +* Do not handle deleted counter. */ -if (!armv7_pmnc_counter_has_overflowed (pmnc, idx)) +if (!armv7_pmnc_counter_has_overflowed (pmnc, idx) || !event)continue ; hwc = &event->hw;
arch/arm/kernel/perf_event_xscale.c +1 -1
@@ -592,7 +592,7 @@ xscale2pmu_handle_irq(int irq_num, void *dev)struct perf_event *event = cpuc->events[idx];struct hw_perf_event *hwc; -if (!xscale2_pmnc_counter_has_overflowed (pmnc, idx)) +if (!xscale2_pmnc_counter_has_overflowed (pmnc, idx) || !event)continue ; hwc = &event->hw;
Signature · 1 line
1.7.9
PATCH 1/1 ARM: perf: do not handle deleted counter in irq handler to avoid oops
Hi Ming Lei,
Thanks for the patch. I looked at this in the past since there was a buggy FPGA flying about that could fire spurious overflows but I didn't get round to doing anything with the patches.
Quoted 7 lines · Ming Lei
The patch adds one check in irq handler to skip handling deleted counter for avoiding oops.
When one counter is deleted, event
reference(hw_events->events[idx])will be cleared but the hw overflow status may be kept, so the hw event may be handled and oops will be triggered in irq handler if pmu irq from other events come.
Interesting, I'd not considered the case where the counter overflows while we are in the process of disabling it. That needs fixing.
Quoted 3 lines
The another candidate fix is to clear the overflow status for the event in
arm_pmu->disable(), but looks it is a bit more complicated and has no obvious advantage than the fix in this patch.
It's not much more complicated and it does have the advantage that we avoid taking an extra interrupt and also avoid the unlikely case where we take an interrupt in the context of a task using perf different from the one in which the counter overflowed, leading to false accounting.
Quoted 4 lines
--- arch/arm/kernel/perf_event_v7.c | 3 ++- arch/arm/kernel/perf_event_xscale.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
I have a couple of patches that solve this by (a) clearing the overflow flag when disabling the counter for ARMv7 and (b) adding the event checks to the interrupt handlers in case the hardware is misbehaving.
I'll post them shortly (you can add your signed-off-by to the second one if you like).
Cheers,
Will
PATCH 1/1 ARM: perf: do not handle deleted counter in irq handler to avoid oops
Hi Will,
Quoted 18 lines · Will Deacon
Hi Ming Lei,
Thanks for the patch. I looked at this in the past since there was a buggy FPGA flying about that could fire spurious overflows but I didn't get round to doing anything with the patches.
Quoted 7 lines · Ming Lei
The patch adds one check in irq handler to skip handling deleted counter for avoiding oops.
When one counter is deleted, event
reference(hw_events->events[idx])will be cleared but the hw overflow status may be kept, so the hw event may be handled and oops will be triggered in irq handler if pmu irq from other events come.Interesting, I'd not considered the case where the counter overflows while we are in the process of disabling it. That needs fixing.
Quoted 6 lines
Quoted 3 lines
The another candidate fix is to clear the overflow status for the event in
arm_pmu->disable(), but looks it is a bit more complicated and has no obvious advantage than the fix in this patch.It's not much more complicated and it does have the advantage that we avoid taking an extra interrupt and also avoid the unlikely case where we take an
The extra interrupt may not be triggered since it has been disabled in ->disable().
Even though it is routed to gic before disabling, the check added can handle the case well.
Quoted 2 lines
interrupt in the context of a task using perf different from the one in which the counter overflowed, leading to false accounting.
I have thought about the case. Even the first irq is triggered after the new counter is added on a new task context, there is still very few count accounted since the count read from hw counter is sure to be very similar with count written
to hw counter. That is why I mentioned clearing overflow flag in ->disable has no
obvious advantage.
But you can do it if you like, :-)
In fact, I have tried to clear overflow in armpmu->disable() on OMAP4 and found it is surely capable of fixing the oops.
Quoted 8 lines
Quoted 5 lines
---
?arch/arm/kernel/perf_event_v7.c ? ? | ? ?3 ++-
?arch/arm/kernel/perf_event_xscale.c | ? ?2 +-
?2 files changed, 3 insertions(+), 2 deletions(-)I have a couple of patches that solve this by (a) clearing the overflow flag when disabling the counter for ARMv7 and (b) adding the event checks to the
Maybe ARMv6 and xscale need to be fixed too if the overflow flag will be kept even after the counter is disabled.
Quoted 1 line
interrupt handlers in case the hardware is misbehaving.
thanks,
Signature · 1 line
Ming Lei
PATCH 1/1 ARM: perf: do not handle deleted counter in irq handler to avoid oops
Quoted 6 lines · Ming Lei
Quoted 2 lines · Will Deacon
I have a couple of patches that solve this by (a) clearing the overflow flag when disabling the counter for ARMv7 and (b) adding the event checks to the
Maybe ARMv6 and xscale need to be fixed too if the overflow flag will be kept even after the counter is disabled.
I don't think so - seems like we clear the overflow flag already for those PMUs in the disable path (note that we write ~mask).
Will
PATCH 1/1 ARM: perf: do not handle deleted counter in irq handler to avoid oops
Quoted 10 lines · Will Deacon
Quoted 6 lines · Ming Lei
Quoted 2 lines · Will Deacon
I have a couple of patches that solve this by (a) clearing the overflow flag when disabling the counter for ARMv7 and (b) adding the event checks to the
Maybe ARMv6 and xscale need to be fixed too if the overflow flag will be kept even after the counter is disabled.
I don't think so - seems like we clear the overflow flag already for those PMUs in the disable path (note that we write ~mask).
mask is only the counters enable bits, both v6 and xscale don't clear their overflow flag in disable callback.
thanks,
Signature · 1 line
Ming Lei
PATCH 1/1 ARM: perf: do not handle deleted counter in irq handler to avoid oops
Quoted 6 lines · Ming Lei
Quoted 5 lines · Will Deacon
Quoted 4 lines · Ming Lei
Quoted 2 lines · Will Deacon
I have a couple of patches that solve this by (a) clearing the overflow flag when disabling the counter for ARMv7 and (b) adding the event checks to the
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Maybe ARMv6 and xscale need to be fixed too if the overflow flag will be kept even after the counter is disabled.
I don't think so - seems like we clear the overflow flag already for those PMUs in the disable path (note that we write ~mask).
mask is only the counters enable bits, both v6 and xscale don't clear their overflow flag in disable callback.
Sure they do. When we read-modify-write the pmcr we &= ~mask, so we end up writing the overflow flags back if they are set, which is sufficient to clear them.
Will
PATCH 1/1 ARM: perf: do not handle deleted counter in irq handler to avoid oops
Quoted 13 lines · Will Deacon
Quoted 12 lines · Ming Lei
Quoted 10 lines · Will Deacon
Quoted 6 lines · Ming Lei
Quoted 2 lines · Will Deacon
I have a couple of patches that solve this by (a) clearing the overflow flag when disabling the counter for ARMv7 and (b) adding the event checks to the
Maybe ARMv6 and xscale need to be fixed too if the overflow flag will be kept even after the counter is disabled.
I don't think so - seems like we clear the overflow flag already for those PMUs in the disable path (note that we write ~mask).
Quoted 6 lines
Quoted 2 lines
mask is only the counters enable bits, both v6 and xscale don't clear their overflow flag in disable callback.
Sure they do. When we read-modify-write the pmcr we &= ~mask, so we end up writing the overflow flags back if they are set, which is sufficient to clear them.
Sorry for missing it, but looks xscale uses standalone overflow register and does not
clear its overflow flag.
thanks,
Signature · 1 line
Ming Lei
PATCH 1/1 ARM: perf: do not handle deleted counter in irq handler to avoid oops
Quoted 8 lines · Ming Lei
Quoted 3 lines · Will Deacon
Sure they do. When we read-modify-write the pmcr we &= ~mask, so we end up writing the overflow flags back if they are set, which is sufficient to clear them.
Sorry for missing it, but looks xscale uses standalone overflow register and does not
clear its overflow flag.
Hmmm, I don't know very much about the xscale PMUs (the perf code is based on the old OProfile code). The xscale2 overflow handler is certainly doing something with some overflow flags though, but then it checks the pmnc again for each counter...
I'd rather not touch that without knowing *exactly* what I'm doing. It may be that the current code deals with the flag but, even if it doesn't, the spurious interrupt isn't the end of the world. I have a board at home that advertises its PMU as xscale2, so I could test that this patch doesn't cause breakage.
Will
PATCH 1/1 ARM: perf: do not handle deleted counter in irq handler to avoid oops
Quoted 10 lines · Will Deacon
Quoted 4 lines · Ming Lei
Sorry for missing it, but looks xscale uses standalone overflow register and does not
clear its overflow flag.Hmmm, I don't know very much about the xscale PMUs (the perf code is based on the old OProfile code). The xscale2 overflow handler is certainly doing something with some overflow flags though, but then it checks the pmnc again for each counter...
Bah, I got curious and took the plunge into the excitingly titled `Intel XScale Core Developer's Manual'. It looks like the interrupt handler currently has a bug, so this should sort it out (I'll try and test it on my xscale board, but that has > 200 days of uptime so I'm reluctant to reboot it).
Will
Quoted 1 line
From
b3dc51a39347c000745939000faa1d7d50514fa2Mon Sep 17 00:00:00 2001
From: Will Deacon <[email protected]>
Date: Tue, 21 Feb 2012 17:14:34 +0000
Subject: [PATCH] ARM: perf: fix overflow handling for xscale2 PMUs
xscale2 PMUs indicate overflow not via the PMU control register, but by a separate overflow FLAG register instead.
This patch fixes the xscale2 PMU code to use this register to detect to overflow and ensures that we clear any pending overflow when disabling a counter.
--- arch/arm/kernel/perf_event_xscale.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)
arch/arm/kernel/perf_event_xscale.c +8 -2
@@ -598,7 +598,7 @@ xscale2pmu_handle_irq(int irq_num, void *dev)if (!event)continue ; -if (!xscale2_pmnc_counter_has_overflowed (pmnc, idx)) +if (!xscale2_pmnc_counter_has_overflowed (of_flags, idx))continue ; hwc = &event->hw;
@@ -669,7 +669,7 @@ xscale2pmu_enable_event(struct hw_perf_event *hwc, int idx)static void xscale2pmu_disable_event (struct hw_perf_event *hwc,int idx) { -unsigned long flags, ien, evtsel; +unsigned long flags, ien, evtsel, of_flags;struct pmu_hw_events *events = cpu_pmu->get_hw_events (); ien =xscale2pmu_read_int_enable ();
@@ -678,26 +678,31 @@ xscale2pmu_disable_event(struct hw_perf_event *hwc, int idx)switch (idx) {case XSCALE_CYCLE_COUNTER : ien &= ~XSCALE2_CCOUNT_INT_EN ; + of_flags =XSCALE2_CCOUNT_OVERFLOW ;break ;case XSCALE_COUNTER0 : ien &= ~XSCALE2_COUNT0_INT_EN ; evtsel &= ~XSCALE2_COUNT0_EVT_MASK ; evtsel |=XSCALE_PERFCTR_UNUSED <<XSCALE2_COUNT0_EVT_SHFT ; + of_flags =XSCALE2_COUNT0_OVERFLOW ;break ;case XSCALE_COUNTER1 : ien &= ~XSCALE2_COUNT1_INT_EN ; evtsel &= ~XSCALE2_COUNT1_EVT_MASK ; evtsel |=XSCALE_PERFCTR_UNUSED <<XSCALE2_COUNT1_EVT_SHFT ; + of_flags =XSCALE2_COUNT1_OVERFLOW ;break ;case XSCALE_COUNTER2 : ien &= ~XSCALE2_COUNT2_INT_EN ; evtsel &= ~XSCALE2_COUNT2_EVT_MASK ; evtsel |=XSCALE_PERFCTR_UNUSED <<XSCALE2_COUNT2_EVT_SHFT ; + of_flags =XSCALE2_COUNT2_OVERFLOW ;break ;case XSCALE_COUNTER3 : ien &= ~XSCALE2_COUNT3_INT_EN ; evtsel &= ~XSCALE2_COUNT3_EVT_MASK ; evtsel |=XSCALE_PERFCTR_UNUSED <<XSCALE2_COUNT3_EVT_SHFT ; + of_flags =XSCALE2_COUNT3_OVERFLOW ;break ;default :WARN_ONCE (1 ,"invalid counter number (%d)\n" , idx);
@@ -707,6 +712,7 @@ xscale2pmu_disable_event(struct hw_perf_event *hwc, int idx)raw_spin_lock_irqsave (&events->pmu_lock, flags);xscale2pmu_write_event_select (evtsel);xscale2pmu_write_int_enable (ien); +xscale2pmu_write_overflow_flags (of_flags);raw_spin_unlock_irqrestore (&events->pmu_lock, flags); }
Signature · 1 line
1.7.4.1