From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936002Ab3DHUT2 (ORCPT ); Mon, 8 Apr 2013 16:19:28 -0400 Received: from mail-oa0-f52.google.com ([209.85.219.52]:34465 "EHLO mail-oa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935945Ab3DHUT0 (ORCPT ); Mon, 8 Apr 2013 16:19:26 -0400 Message-ID: <5163264B.3050707@linaro.org> Date: Mon, 08 Apr 2013 13:19:23 -0700 From: John Stultz User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 To: Prarit Bhargava CC: linux-kernel@vger.kernel.org, Thomas Gleixner Subject: Re: [PATCH] hrtimer, add expiry time overflow check in hrtimer_interrupt References: <1365425235-26191-1-git-send-email-prarit@redhat.com> In-Reply-To: <1365425235-26191-1-git-send-email-prarit@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/08/2013 05:47 AM, Prarit Bhargava wrote: > 2nd submit: I did quite a bit of testing with this patch and I don't see any > ill effects. I've tested across several large and small x86 systems, and a > ppc system for good measure. > > P. > > ----8<--- > ` > The settimeofday01 test in the LTP testsuite effectively does > > gettimeofday(current time); > settimeofday(Jan 1, 1970 + 100 seconds); > settimeofday(current time); > > This test causes a stack trace to be displayed on the console during the > setting of timeofday to Jan 1, 1970 + 100 seconds: > > [ 131.066751] ------------[ cut here ]------------ > [ 131.096448] WARNING: at kernel/time/clockevents.c:209 clockevents_program_event+0x135/0x140() > [ 131.104935] Hardware name: Dinar > [ 131.108150] Modules linked in: sg nfsv3 nfs_acl nfsv4 auth_rpcgss nfs dns_resolver fscache lockd sunrpc nf_conntrack_netbios_ns nf_conntrack_broadcast ipt_MASQUERADE ip6table_mangle ip6t_REJECT nf_conntrack_ipv6 nf_defrag_ipv6 iptable_nat nf_nat_ipv4 nf_nat iptable_mangle ipt_REJECT nf_conntrack_ipv4 nf_defrag_ipv4 xt_conntrack nf_conntrack ebtable_filter ebtables ip6table_filter ip6_tables iptable_filter ip_tables kvm_amd kvm sp5100_tco bnx2 i2c_piix4 crc32c_intel k10temp fam15h_power ghash_clmulni_intel amd64_edac_mod pcspkr serio_raw edac_mce_amd edac_core microcode xfs libcrc32c sr_mod sd_mod cdrom ata_generic crc_t10dif pata_acpi radeon i2c_algo_bit drm_kms_helper ttm drm ahci pata_atiixp libahci libata usb_storage i2c_core dm_mirror dm_region_hash dm_log dm_mod > [ 131.176784] Pid: 0, comm: swapper/28 Not tainted 3.8.0+ #6 > [ 131.182248] Call Trace: > [ 131.184684] [] warn_slowpath_common+0x7f/0xc0 > [ 131.191312] [] warn_slowpath_null+0x1a/0x20 > [ 131.197131] [] clockevents_program_event+0x135/0x140 > [ 131.203721] [] tick_program_event+0x24/0x30 > [ 131.209534] [] hrtimer_interrupt+0x131/0x230 > [ 131.215437] [] ? cpufreq_p4_target+0x130/0x130 > [ 131.221509] [] smp_apic_timer_interrupt+0x69/0x99 > [ 131.227839] [] apic_timer_interrupt+0x6d/0x80 > [ 131.233816] [] ? sched_clock_cpu+0xc5/0x120 > [ 131.240267] [] ? cpuidle_wrap_enter+0x50/0xa0 > [ 131.246252] [] ? cpuidle_wrap_enter+0x49/0xa0 > [ 131.252238] [] cpuidle_enter_tk+0x10/0x20 > [ 131.257877] [] cpuidle_idle_call+0xa9/0x260 > [ 131.263692] [] cpu_idle+0xaf/0x120 > [ 131.268727] [] start_secondary+0x255/0x257 > [ 131.274449] ---[ end trace 1151a50552231615 ]--- > > When we change the system time to a low value like this, the value of > timekeeper->offs_real will be a negative value. > > It seems that the WARN occurs because an hrtimer has been started in the time > between the releasing of the timekeeper lock and the IPI call (via a call to > on_each_cpu) in clock_was_set() in the do_settimeofday() code. The end result > is that a REALTIME_CLOCK timer has been added with softexpires = expires = > KTIME_MAX. The hrtimer_interrupt() fires/is called and the loop at > kernel/hrtimer.c:1289 is executed. In this loop the code subtracts the > clock base's offset (which was set to timekeeper->offs_real in > do_settimeofday()) from the current hrtimer_cpu_base->expiry value (which > was KTIME_MAX): > > KTIME_MAX - (a negative value) = overflow > > A simple check for an overflow can resolve this problem. Using KTIME_MAX > instead of the overflow value will result in the hrtimer function being run, > and the reprogramming of the timer after that. > > Signed-off-by: Prarit Bhargava > Cc: Thomas Gleixner > Cc: John Stultz Prarit: Should this be tagged for -stable? thanks -john