lkml.org 
[lkml]   [2010]   [Aug]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: [PATCH] perf: fix possible divide-by-zero in perf_swevent_overflow()
From
Date
On Thu, 2010-08-26 at 20:36 +0800, DDD wrote:
> Peter Zijlstra wrote:
> > On Thu, 2010-08-26 at 20:07 +0800, Dongdong Deng wrote:
> >> The event->hw.last_period is possible to zero, thus it will
> >> cause divide_by_zero later in perf_swevent_set_period().
> >
> > How can it be zero?
>
> When I am running the kgdbts to test the hw_breakpoint_layer with kgdb,
> I get a call trace as following and this problem is hardly to reproduce.
>
> Maybe the root cause was from kgdb/hw_breakpoint_layer,

Yeah, I think there's a bug in the hw_breakpoint stuff, does something
like the below fix it?


> but add a checking is good to us and harmless. :-)

Except that code path is already too bloated and should be reduced not
added to and conditionals are expensive.


---
kernel/hw_breakpoint.c | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/kernel/hw_breakpoint.c b/kernel/hw_breakpoint.c
index d71a987..f57ebee 100644
--- a/kernel/hw_breakpoint.c
+++ b/kernel/hw_breakpoint.c
@@ -600,9 +600,20 @@ static int __init init_hw_breakpoint(void)
}
core_initcall(init_hw_breakpoint);

+static int hw_breakpoint_enable(struct perf_event *event)
+{
+ struct hw_perf_event *hwc = &event->hw;
+
+ if (hwc->sample_period) {
+ hwc->last_period = hwc->sample_period;
+ perf_swevent_set_period(event);
+ }
+
+ return arch_install_hw_breakpoint(event);
+}

struct pmu perf_ops_bp = {
- .enable = arch_install_hw_breakpoint,
+ .enable = hw_breakpoint_enable,
.disable = arch_uninstall_hw_breakpoint,
.read = hw_breakpoint_pmu_read,
};


\
 
 \ /
  Last update: 2010-08-26 15:01    [W:0.061 / U:14.000 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site