Received: by 10.192.165.148 with SMTP id m20csp4165011imm; Mon, 30 Apr 2018 13:01:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrw7aeDE1SpoGGV8kJtqsuolcP4UwJVbPxjN6+vyRn90HU0Rw9IwS5NxlKW5xpM0b6p/PMH X-Received: by 10.98.71.8 with SMTP id u8mr13213737pfa.89.1525118488106; Mon, 30 Apr 2018 13:01:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525118488; cv=none; d=google.com; s=arc-20160816; b=oG0P2ydDZRa/h2RvjgKq/2Hgob//difpq7vEjlduDfTHaV/Q9DDtd04374FqYhN4Sa 1k5J5vxnn+N9NRP54mT55BD06iZ/GS2sgWi14aTD/ZsTMVnUWXoJZtRvOjxzjMrK2lQn 4WRO8ycSgmgb8prOassT7kliJribHxj6mAz8Y8klI+9weAqeEerGWmH6+nJNx0N1i4y2 IU1fZADubarbd6itKPEfUeW4sL7Q/yKUzpMPCLkxwuDE+ynF8vS0U4+xNwSgANo5GqB/ CTNjyxwmeatoxZnoJ1xsnNhxya6sQ226osq7rU+3elbDzbpKtJ+jy975rDcTMZ66WemY 7FJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=5vURY7NeJWYWvIpPKK6l3Z8N12Wq1S+9oLIwmo///oc=; b=LteI3Pb0PSsL4h7bMRFeNUfAw21dT+QEktYeP3T9UvGFA95E//b8SGci08gIa5ej7E deLgwxw91kFCamKkkny/WzlnDFNUcFusSAEIge9tO59oPZPjZi3bzRrccWkOwUIH/0jY bhjUBS9cu5v918dyU3jBiK+uXD0kARZRXLgm6k2oDHYiJm3CN7QCXngufoVIC5ByZKMD cnV5kYaLteT5Ce2YjtXAlTJedErj6Xo1PyUEYFEb2nRAyw5VyU5yStOS4ZJPZTqDD6xy bc930Dm5lmhvX3v28iifE6HkJOwAFZCFa7UwpH2fOqtmWuLsPSpXcSymkKz1WYErIpgu 9kwg== 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 a23-v6si6601731pgv.429.2018.04.30.13.01.13; Mon, 30 Apr 2018 13:01:28 -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 S1755978AbeD3T7z (ORCPT + 99 others); Mon, 30 Apr 2018 15:59:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:34672 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756035AbeD3T1p (ORCPT ); Mon, 30 Apr 2018 15:27:45 -0400 Received: from localhost (unknown [104.132.1.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BE41322DCB; Mon, 30 Apr 2018 19:27:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BE41322DCB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Wan Kaike" , Thomas Gleixner , Frederic Weisbecker , "Marciniszyn Mike" , Anna-Maria Gleixner , linux-rdma@vger.kernel.org, "Dalessandro Dennis" , "Fleck John" , Peter Zijlstra , Frederic Weisbecker , "Weiny Ira" Subject: [PATCH 4.14 88/91] tick/sched: Do not mess with an enqueued hrtimer Date: Mon, 30 Apr 2018 12:25:10 -0700 Message-Id: <20180430184008.883885070@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184004.216234025@linuxfoundation.org> References: <20180430184004.216234025@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Gleixner commit 1f71addd34f4c442bec7d7c749acc1beb58126f2 upstream. 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 Signed-off-by: Greg Kroah-Hartman --- kernel/time/tick-sched.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -820,12 +820,13 @@ static ktime_t tick_nohz_stop_sched_tick goto out; } - 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); + } + out: /* * Update the estimated sleep length until the next timer