Received: by 10.192.165.148 with SMTP id m20csp768397imm; Wed, 25 Apr 2018 07:24:25 -0700 (PDT) X-Google-Smtp-Source: AIpwx48wU2mnFFu1MHsgIqvBfEQmVDAEqB3s8LRNe9Fc1oLo9QBDBxYyKKRXNYVLx/uJvR9uWg5X X-Received: by 10.99.126.9 with SMTP id z9mr24426077pgc.437.1524666265147; Wed, 25 Apr 2018 07:24:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524666265; cv=none; d=google.com; s=arc-20160816; b=iXWEj3Ga0mmp1oZtAIcotqGAfdbMVEyKPIAZPWbJ/fWSNwT50LClo8iGGYIng3pzSj kLSsM7m5WhCeFtLM9GZV6CQXDAqW+KF473kXw69BKAkDVmHf0BBLLEcel78FoBYWo6/1 y0X/Id7bIFZm/ZeFclEWO/yS/OqpauTHPfSKhkBgAGiKbQEMfxR0OLgAMBz1vLbSf5kE gU4T+jSM3un9qIJBeJp/PiQclhttuLzlv96AeiHc6MHbe9tlxUvZ/+czpQ4KcvgjGi5t x1rCZetWzqBrz/Poeqbw4AAB9XLAUK3Mi07Zwy3G/ySsHWQmNNO4OeSx52fos5HStXA2 QIQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=UyAsKikLAjqD/hBUgNV38xHGlc8W2ndbI0D3jyaG/0M=; b=TP381SXcfx47Ksm3hPzPE+QnSesBE60IKsbzhimmg6hMHcKMq4VGM6Mg4TD1sV5iKa HyRmEqTAb717YuOzDZU2YFHo4wiSFM6NvZ9wA60mx/ofz5DHLeoaTAzJjA9kjHPlVa5h /xwi2NVsDTw/nTvWf/8q2sPPYUvW4bdwsuVjxaHYv0Ic/h7CXfYurcxCZ24hiM+fvAdB aW0SV5DpYL6sGOOhDgCaeyA7JfhvpYBM/5bx2RJ3/zEqWh3xMu8a7fkjCM0mBWt4uxX2 AFmRkcJ2meh005s4jvpoeUxvjFgOgR0wdiF6vX7nI21zvAFU64a65uSl0xQ8VrTVonJV LoYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m1si13895339pgm.413.2018.04.25.07.24.10; Wed, 25 Apr 2018 07:24:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754646AbeDYOWL (ORCPT + 99 others); Wed, 25 Apr 2018 10:22:11 -0400 Received: from terminus.zytor.com ([198.137.202.136]:56255 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753508AbeDYOWH (ORCPT ); Wed, 25 Apr 2018 10:22:07 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w3PELj4D1513984; Wed, 25 Apr 2018 07:21:45 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w3PELjZQ1513981; Wed, 25 Apr 2018 07:21:45 -0700 Date: Wed, 25 Apr 2018 07:21:45 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Thomas Gleixner Message-ID: Cc: fweisbec@gmail.com, linux-kernel@vger.kernel.org, ira.weiny@intel.com, peterz@infradead.org, john.fleck@intel.com, mike.marciniszyn@intel.com, tglx@linutronix.de, frederic@kernel.org, hpa@zytor.com, anna-maria@linutronix.de, mingo@kernel.org, dennis.dalessandro@intel.com, kaike.wan@intel.com Reply-To: dennis.dalessandro@intel.com, kaike.wan@intel.com, hpa@zytor.com, anna-maria@linutronix.de, mingo@kernel.org, frederic@kernel.org, ira.weiny@intel.com, fweisbec@gmail.com, linux-kernel@vger.kernel.org, peterz@infradead.org, mike.marciniszyn@intel.com, john.fleck@intel.com, tglx@linutronix.de In-Reply-To: References: To: linux-tip-commits@vger.kernel.org Subject: [tip:timers/urgent] tick/sched: Do not mess with an enqueued hrtimer Git-Commit-ID: 51fc4be41c7ea7a00f6a17ad15ac9ea684d07921 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 51fc4be41c7ea7a00f6a17ad15ac9ea684d07921 Gitweb: https://git.kernel.org/tip/51fc4be41c7ea7a00f6a17ad15ac9ea684d07921 Author: Thomas Gleixner AuthorDate: Tue, 24 Apr 2018 21:22:18 +0200 Committer: Thomas Gleixner CommitDate: Wed, 25 Apr 2018 16:11:58 +0200 tick/sched: Do not mess with an enqueued hrtimer Kaike reported that in tests rdma hrtimers occasionaly stopped working. He did great debugging, which provided enough context to decode the problem. CPU 3 CPU 2 idle start sched_timer expires = 712171000000 queue->next = sched_timer start rdmavt timer. expires = 712172915662 lock(baseof(CPU3)) tick_nohz_stop_tick() tick = 716767000000 timerqueue_add(tmr) hrtimer_set_expires(sched_timer, tick); sched_timer->expires = 716767000000 <---- FAIL if (tmr->expires < queue->next->expires) hrtimer_start(sched_timer) queue->next = tmr; lock(baseof(CPU3)) unlock(baseof(CPU3)) timerqueue_remove() timerqueue_add() ts->sched_timer is queued and queue->next is pointing to it, but then ts->sched_timer.expires is modified. This not only corrupts the ordering of the timerqueue RB tree, it also makes CPU2 see the new expiry time of timerqueue->next->expires when checking whether timerqueue->next needs to be updated. So CPU2 sees that the rdma timer is earlier than timerqueue->next and sets the rdma timer as new next. Depending on whether it had also seen the new time at RB tree enqueue, it might have queued the rdma timer at the wrong place and then after removing the sched_timer the RB tree is completely hosed. The problem was introduced with a commit which tried to solve inconsistency between the hrtimer in the tick_sched data and the underlying hardware clockevent. It split out hrtimer_set_expires() to store the new tick time in both the NOHZ and the NOHZ + HIGHRES case, but missed the fact that in the NOHZ + HIGHRES case the hrtimer might still be queued. Use hrtimer_start(timer, tick...) for the NOHZ + HIGHRES case which sets timer->expires after canceling the timer and move the hrtimer_set_expires() invocation into the NOHZ only code path which is not affected as it merily uses the hrtimer as next event storage so code pathes can be shared with the NOHZ + HIGHRES case. Fixes: d4af6d933ccf ("nohz: Fix spurious warning when hrtimer and clockevent get out of sync") Reported-by: "Wan Kaike" Signed-off-by: Thomas Gleixner Acked-by: Frederic Weisbecker Cc: "Marciniszyn Mike" Cc: Anna-Maria Gleixner Cc: linux-rdma@vger.kernel.org Cc: "Dalessandro Dennis" Cc: "Fleck John" Cc: stable@vger.kernel.org Cc: Peter Zijlstra Cc: Frederic Weisbecker Cc: "Weiny Ira" Cc: "linux-rdma@vger.kernel.org" Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1804241637390.1679@nanos.tec.linutronix.de Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1804242119210.1597@nanos.tec.linutronix.de --- kernel/time/tick-sched.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index e35a6fced00c..da9455a6b42b 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -795,12 +795,12 @@ static void tick_nohz_stop_tick(struct tick_sched *ts, int cpu) return; } - hrtimer_set_expires(&ts->sched_timer, tick); - - if (ts->nohz_mode == NOHZ_MODE_HIGHRES) - hrtimer_start_expires(&ts->sched_timer, HRTIMER_MODE_ABS_PINNED); - else + if (ts->nohz_mode == NOHZ_MODE_HIGHRES) { + hrtimer_start(&ts->sched_timer, tick, HRTIMER_MODE_ABS_PINNED); + } else { + hrtimer_set_expires(&ts->sched_timer, tick); tick_program_event(tick, 1); + } } static void tick_nohz_retain_tick(struct tick_sched *ts)