Received: by 10.192.165.148 with SMTP id m20csp4140563imm; Mon, 30 Apr 2018 12:30:11 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoInLLU349Tel621RFGGQolhWz9w1Y9AxdbxQCJ1A/RtKtlqyXnMMPOR+CGh4URmqP6TcYf X-Received: by 2002:a63:6d8a:: with SMTP id i132-v6mr11144791pgc.314.1525116611634; Mon, 30 Apr 2018 12:30:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525116611; cv=none; d=google.com; s=arc-20160816; b=BAA2r7txiNijo01KuBmEf3Ve9yU8+r88EqZ4YIxF7kt+znwuDH2e1rprT46dvTh7q/ GA47wkfd++B54SvJvOH6MS/8HzxBjF8GkkYYc/z/IAG3QTJJWVcYsfvpwvUp+pBgM034 ScuBFf9VRJb2j1ImswlmiZe3LrRHAVxdSLpK93WaWXwXxCqOwmeOT/p9oRzMQczOOUx+ iudTEIPNMsFgjCxzpc4CAjiIMEhcegm1LZhe5y2oSPpCCjDPaOua2KaCceU1El9Ce57b 24cGuyEKQYdZroxeTcw7uSTc9Py4wYkEGW05ERls/Z/yrQhREm4PgZ9qLHpZfcwGe+cZ 9TnQ== 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=uO2AL9Yk/MsCuhSVB1nFqMQ9bmYh9YGCreAmxKoWQxE=; b=WbgPnwIrbe4sfsytQa8Tze8dew06Ff54oaFyvVNINeUztfV38K5J8VtxYIyw7if9r5 3VqEUcHJf5EZKqp0zePCZ69JRwrV+53JbRRkxBePVmuqODxZiJBqSwXII0J36pQboRCw /0jECYfhJ+bG9ldbY0INW3hkj3u4uCBLank7A/tm+7hFG9kY4ccNCBcnGrk+f8JziB5T HVquPMMCTEz2UVVZbmrxeoGZz5kcIUxesIJo2XitBabsYe1tKPNkMYG61NATgUVtpyp9 QafhrhE/3s4QC9vX837RjbXyvqGzbf1icUpb2Fm+ZQIqG0coNyH8/jHQjBTq3XAXwWJH 9pOQ== 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 v2-v6si6543381pgf.75.2018.04.30.12.29.57; Mon, 30 Apr 2018 12:30:11 -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 S932538AbeD3T3e (ORCPT + 99 others); Mon, 30 Apr 2018 15:29:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:37502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932468AbeD3T3C (ORCPT ); Mon, 30 Apr 2018 15:29:02 -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 338E722DAC; Mon, 30 Apr 2018 19:29:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 338E722DAC 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.16 111/113] tick/sched: Do not mess with an enqueued hrtimer Date: Mon, 30 Apr 2018 12:25:22 -0700 Message-Id: <20180430184019.880363152@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184015.043892819@linuxfoundation.org> References: <20180430184015.043892819@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.16-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 @@ -797,12 +797,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