Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753451Ab0HZMbc (ORCPT ); Thu, 26 Aug 2010 08:31:32 -0400 Received: from mail.windriver.com ([147.11.1.11]:39856 "EHLO mail.windriver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751962Ab0HZMba (ORCPT ); Thu, 26 Aug 2010 08:31:30 -0400 Message-ID: <4C765FD3.9060904@windriver.com> Date: Thu, 26 Aug 2010 20:36:35 +0800 From: DDD User-Agent: Thunderbird 2.0.0.24 (X11/20100317) MIME-Version: 1.0 To: Peter Zijlstra CC: mingo@elte.hu, fweisbec@gmail.com, acme@redhat.com, paulus@samba.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf: fix possible divide-by-zero in perf_swevent_overflow() References: <1282824438-13970-1-git-send-email-dongdong.deng@windriver.com> <1282824727.1975.747.camel@laptop> In-Reply-To: <1282824727.1975.747.camel@laptop> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 26 Aug 2010 12:31:06.0202 (UTC) FILETIME=[8DE173A0:01CB451A] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4553 Lines: 121 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, but add a checking is good to us and harmless. :-) Thanks, Dongdong ------------[ cut here ]------------ WARNING: at /buildarea/ddeng/build/linux/drivers/misc/kgdbts.c:703 run_simple_test+0x1fc/0x2a0() Hardware name: Moon Creek platform Modules linked in: Pid: 668, comm: sh Tainted: G W 2.6.36-rc1-00133-g47ade1d #43 Call Trace: [] warn_slowpath_common+0x6d/0xa0 [] ? run_simple_test+0x1fc/0x2a0 [] ? run_simple_test+0x1fc/0x2a0 [] warn_slowpath_null+0x15/0x20 [] run_simple_test+0x1fc/0x2a0 [] kgdbts_put_char+0x14/0x20 [] gdb_serial_stub+0x678/0xbd0 [] ? default_send_IPI_allbutself+0x7d/0x90 [] kgdb_cpu_enter+0x197/0x470 [] kgdb_handle_exception+0x47/0x140 [] ? _raw_read_unlock+0x10/0x30 [] __kgdb_notify+0x38/0x170 [] ? sock_queue_rcv_skb+0xe0/0x130 [] kgdb_notify+0xe/0x20 [] notifier_call_chain+0x35/0x70 [] ? do_divide_error+0x0/0xa0 [] __atomic_notifier_call_chain+0x28/0x50 [] atomic_notifier_call_chain+0x1a/0x20 [] notify_die+0x2d/0x30 [] do_divide_error+0x54/0xa0 [] ? div64_u64+0x55/0x80 [] ? udp_rcv+0x12/0x20 [] ? ip_local_deliver_finish+0x127/0x240 [] ? udp_rcv+0x12/0x20 [] ? ip_local_deliver+0x87/0x90 [] ? perf_output_begin+0x1fe/0x230 [] ? ip_rcv_finish+0xc3/0x320 [] error_code+0x66/0x6c [] ? do_divide_error+0x0/0xa0 [] ? div64_u64+0x55/0x80 [] perf_swevent_set_period+0x7c/0x100 [] perf_swevent_overflow+0x87/0x90 [] perf_swevent_add+0xbf/0xd0 [] perf_bp_event+0x5e/0x80 [] ? e1000_clean+0xf7/0x260 [] hw_breakpoint_exceptions_notify+0x111/0x170 [] notifier_call_chain+0x35/0x70 [] __atomic_notifier_call_chain+0x28/0x50 [] atomic_notifier_call_chain+0x1a/0x20 [] notify_die+0x2d/0x30 [] do_debug+0x68/0x270 [] ? smp_apic_timer_interrupt+0x74/0x140 [] debug_stack_correct+0x29/0x30 [] ? hw_perf_event_init+0x1bb/0x820 [] ? kgdbts_break_test+0x0/0x30 [] ? configure_kgdbts+0x1d0/0x4c0 [] ? param_attr_store+0x0/0x20 [] param_set_kgdbts_var+0x4d/0xb0 [] ? param_set_kgdbts_var+0x0/0xb0 [] param_attr_store+0x17/0x20 [] module_attr_store+0x2c/0x40 [] sysfs_write_file+0x94/0xf0 [] vfs_write+0x96/0x130 [] ? sysfs_write_file+0x0/0xf0 [] sys_write+0x46/0xd0 [] system_call_done+0x0/0x4 ---[ end trace e0a820ecc2c65c24 ]--- > >> This patch checks event->hw.last_period before invoke >> perf_swevent_set_period() and replaces "event->hw" with "hwc". >> >> Signed-off-by: Dongdong Deng >> Cc: Peter Zijlstra >> Cc: Frederic Weisbecker >> Cc: Arnaldo Carvalho de Melo >> Cc: Paul Mackerras >> --- >> kernel/perf_event.c | 4 ++-- >> 1 files changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/kernel/perf_event.c b/kernel/perf_event.c >> index 403d180..ccba741 100644 >> --- a/kernel/perf_event.c >> +++ b/kernel/perf_event.c >> @@ -4050,8 +4050,8 @@ static void perf_swevent_overflow(struct perf_event *event, u64 overflow, >> struct hw_perf_event *hwc = &event->hw; >> int throttle = 0; >> >> - data->period = event->hw.last_period; >> - if (!overflow) >> + data->period = hwc->last_period; >> + if (!overflow && hwc->last_period) >> overflow = perf_swevent_set_period(event); >> >> if (hwc->interrupts == MAX_INTERRUPTS) > > > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/