Received: by 10.192.165.148 with SMTP id m20csp2078284imm; Thu, 26 Apr 2018 06:02:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx48bOvXafZ9kqCRvp4M6Yzb72WuSFPaXBoJxKpQ/71fhKjSz7zRu4vA9k55LgcO9wZI64Hra X-Received: by 10.99.176.71 with SMTP id z7mr26774070pgo.74.1524747760093; Thu, 26 Apr 2018 06:02:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524747760; cv=none; d=google.com; s=arc-20160816; b=OcaqIT1cXCCLA39TJRdWkwsKWMx/drZ1HoLFWuN+EsvpBW0jhmU1CT0+x1K3OmPon3 xqf+5V98y2Vx95cvpgewQ9OS7pMnoCDALdHjrB4DmpzSOwYiF0PAhmzos8TUpZTxz3xg WTjVTkGIp4BOP3iABCuPVI5dojLq6Qs7zAIpD2jfKEOU1iE4lF8KrUjvOHnk3euYI2if jBWXfxujgsDes8mz/Ve2ZTpqzt/PaHR5glg6vcPehwpBu7ccTfV1IX1bQmslC4cs8gQw oBkQwm6r6VflVDb6Y0oTzCJqpDeOQnjVROrWj1lcMZKOVIJ9U5OjZurEcqpSbDOjGemo Z3Rg== 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=CalI1fHsx0jyvKaFcH/W4cYN1/UueuABR+NoZXnjdxo=; b=f0wbsvVSr1w2dgmqTt1iUaBJX/462Sgsb4W4pN9u4Onr/zdUjCSnoxhX9Qf6zOxX6C KoAzc4dQRwyLMfSAae+MJzfCg0thNYXUEnVet0SYXyT4QQraqw0ujknUBH5P+HVhu025 etp+f97jkPYCXsv+DU9wx4Jo6oWaiklSIl+x/cyXfNgDTV5CYAjuY+5uI7KntmNnqOJI BJuTtOl2RFWy9NyJvqQkMNC2adK0QcOF9H3EuFES9DAqNHcEpTMY+QyC0diGChCUYEbI zd6A3tT/p0vZWFV1j6MpPEZfw5Qcdn0uXAL7X0lImoF569pF0jIP2t/qBbmXpaMnrEbB 1LdA== 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 q200si15105916pfq.307.2018.04.26.06.02.24; Thu, 26 Apr 2018 06:02:40 -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 S932078AbeDZM7C (ORCPT + 99 others); Thu, 26 Apr 2018 08:59:02 -0400 Received: from terminus.zytor.com ([198.137.202.136]:42409 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756262AbeDZM61 (ORCPT ); Thu, 26 Apr 2018 08:58:27 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w3QCvjCW1896425; Thu, 26 Apr 2018 05:57:45 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w3QCvj1Y1896422; Thu, 26 Apr 2018 05:57:45 -0700 Date: Thu, 26 Apr 2018 05:57: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: frederic@kernel.org, mike.marciniszyn@intel.com, linux-kernel@vger.kernel.org, hpa@zytor.com, kaike.wan@intel.com, tglx@linutronix.de, dennis.dalessandro@intel.com, fweisbec@gmail.com, anna-maria@linutronix.de, john.fleck@intel.com, ira.weiny@intel.com, mingo@kernel.org, peterz@infradead.org Reply-To: frederic@kernel.org, mike.marciniszyn@intel.com, linux-kernel@vger.kernel.org, hpa@zytor.com, kaike.wan@intel.com, tglx@linutronix.de, dennis.dalessandro@intel.com, fweisbec@gmail.com, anna-maria@linutronix.de, john.fleck@intel.com, ira.weiny@intel.com, mingo@kernel.org, peterz@infradead.org 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: 1f71addd34f4c442bec7d7c749acc1beb58126f2 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: 1f71addd34f4c442bec7d7c749acc1beb58126f2 Gitweb: https://git.kernel.org/tip/1f71addd34f4c442bec7d7c749acc1beb58126f2 Author: Thomas Gleixner AuthorDate: Tue, 24 Apr 2018 21:22:18 +0200 Committer: Thomas Gleixner CommitDate: Thu, 26 Apr 2018 14:53:32 +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 646645e981f9..d31bec177fa5 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -804,12 +804,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)