Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp6471492pxb; Wed, 17 Feb 2021 05:35:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJzf1puAXzR6emXqCI1Gexg4hHhu4igxY0gK1J0ssZTZHzuSmVylmL/Sw6iV/l1vBwCYrxvV X-Received: by 2002:a17:907:7691:: with SMTP id jv17mr2216522ejc.75.1613568940659; Wed, 17 Feb 2021 05:35:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613568940; cv=none; d=google.com; s=arc-20160816; b=PLUplvftgxZEAhZQd9hyMWEtuOG9ntsTPWUVu6L0CQ7NFBWNcpm2SOu6wij1MSXeOA WcV+oh5o05dYMhdrMAOcrRFTxwvkl/rmHw+fTeGvty3j/stN0Gat3EcD5utLLl3dyj65 X/X5Ef8O6a2+f2FEGH2rydeD3/4BMKi6KGil3JxLQQh3hOCA/XoQZ2R7hkRh2JvASNcu g1UG6emGXSdlYWi5nIO89A+n7DiBXtiNrlAkQ5xElFt3AZIpdbwKLp6veUuGXRww6FwB CNfR5mL4nPFxWB6D4qcIc71SEuN3SxKQ9CI3TUAQz/HUoMYSceMDR9Vo2LzmU3G+oy+w kC1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=VtN12CzgwYFqIF/QDBcNDpBXo5Kjz1t00AFsHjtn/Kk=; b=Yg/VjP05r2SUL15qPxaWGnQA5yOoqPlb7S5BSuxlkUhgJAH+IIYCiAF6RNwEmDQmAT KeD2wYLhKJhvtLIkTr4wzVPAIjquQ0KeQ7zjfvXYRT9CS5nIu50TwKfSfz8gFEewuOzW bFYXaVYChodMuyPhpA7XosNp+FeSOuXAdRDq8aWQwaZmfG78X4UCoVYZSRRz/i3kcAuw nwGygRTw/Ln3AIvZou+m6zwvTy6xod8rrG3TxDQUDGkSjtD/PFRNzJWgKt3bFY8FW6ye GuGV7djJewWttuQw9pF6vETHHcTJ4Xqaq++qEig2Q5jVoYUBBKQb5tLZpO0bVjs4IrJq +b1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=tRX34mJ5; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=ctiV8rBm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ko1si1642489ejc.48.2021.02.17.05.35.17; Wed, 17 Feb 2021 05:35:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=tRX34mJ5; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=ctiV8rBm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232927AbhBQNUn (ORCPT + 99 others); Wed, 17 Feb 2021 08:20:43 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:45190 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231710AbhBQNSQ (ORCPT ); Wed, 17 Feb 2021 08:18:16 -0500 Date: Wed, 17 Feb 2021 13:17:32 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1613567852; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VtN12CzgwYFqIF/QDBcNDpBXo5Kjz1t00AFsHjtn/Kk=; b=tRX34mJ5FdQGwS9nhC6VT607B5jqGPM/kR5UJ96TpL592W+BiiTp4Rx/ydQLW5dGcq2UBj BeaMPjVLQ00XA5+Cs+Ij5PsE5YvWdrmh4Ofrpk6T1O/igE8FpGvv65/P21Y5J1NUIxk/6M 6lmYiT+npfff6EQNQ0105hNxirEvoIRZ3HYgOveJscFnbm0n6suJV/jcjcrjmk+zZtbH59 Vq98RNFYYi2dtuDwWe6p/PNh9PUmJZiV5WYtvhfH67uEV65vlqylHPBJbYPwqWIKXeqKBR PAoCD7GGcM2P/r+1RTaZEHk2RIRbR/JVghCZ+9rsxCLprhcQYo2aUVihu2IlDg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1613567852; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VtN12CzgwYFqIF/QDBcNDpBXo5Kjz1t00AFsHjtn/Kk=; b=ctiV8rBm4yX0z6wJUIp3agwNEzhio01mq2hi8gqE+8o+9kCIKviNxTayFKwZZnDBvHtcPK dtiOg0gxt1xyB0Dg== From: "tip-bot2 for Juri Lelli" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/features: Fix hrtick reprogramming Cc: Juri Lelli , "Luis Claudio R. Goncalves" , Daniel Bristot de Oliveira , "Peter Zijlstra (Intel)" , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20210208073554.14629-2-juri.lelli@redhat.com> References: <20210208073554.14629-2-juri.lelli@redhat.com> MIME-Version: 1.0 Message-ID: <161356785232.20312.17400375620954205583.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/core branch of tip: Commit-ID: 156ec6f42b8d300dbbf382738ff35c8bad8f4c3a Gitweb: https://git.kernel.org/tip/156ec6f42b8d300dbbf382738ff35c8bad8f4c3a Author: Juri Lelli AuthorDate: Mon, 08 Feb 2021 08:35:53 +01:00 Committer: Ingo Molnar CommitterDate: Wed, 17 Feb 2021 14:12:42 +01:00 sched/features: Fix hrtick reprogramming Hung tasks and RCU stall cases were reported on systems which were not 100% busy. Investigation of such unexpected cases (no sign of potential starvation caused by tasks hogging the system) pointed out that the periodic sched tick timer wasn't serviced anymore after a certain point and that caused all machinery that depends on it (timers, RCU, etc.) to stop working as well. This issues was however only reproducible if HRTICK was enabled. Looking at core dumps it was found that the rbtree of the hrtimer base used also for the hrtick was corrupted (i.e. next as seen from the base root and actual leftmost obtained by traversing the tree are different). Same base is also used for periodic tick hrtimer, which might get "lost" if the rbtree gets corrupted. Much alike what described in commit 1f71addd34f4c ("tick/sched: Do not mess with an enqueued hrtimer") there is a race window between hrtimer_set_expires() in hrtick_start and hrtimer_start_expires() in __hrtick_restart() in which the former might be operating on an already queued hrtick hrtimer, which might lead to corruption of the base. Use hrtick_start() (which removes the timer before enqueuing it back) to ensure hrtick hrtimer reprogramming is entirely guarded by the base lock, so that no race conditions can occur. Signed-off-by: Juri Lelli Signed-off-by: Luis Claudio R. Goncalves Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Link: https://lkml.kernel.org/r/20210208073554.14629-2-juri.lelli@redhat.com --- kernel/sched/core.c | 8 +++----- kernel/sched/sched.h | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index cec507b..18d51ab 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -355,8 +355,9 @@ static enum hrtimer_restart hrtick(struct hrtimer *timer) static void __hrtick_restart(struct rq *rq) { struct hrtimer *timer = &rq->hrtick_timer; + ktime_t time = rq->hrtick_time; - hrtimer_start_expires(timer, HRTIMER_MODE_ABS_PINNED_HARD); + hrtimer_start(timer, time, HRTIMER_MODE_ABS_PINNED_HARD); } /* @@ -380,7 +381,6 @@ static void __hrtick_start(void *arg) void hrtick_start(struct rq *rq, u64 delay) { struct hrtimer *timer = &rq->hrtick_timer; - ktime_t time; s64 delta; /* @@ -388,9 +388,7 @@ void hrtick_start(struct rq *rq, u64 delay) * doesn't make sense and can cause timer DoS. */ delta = max_t(s64, delay, 10000LL); - time = ktime_add_ns(timer->base->get_time(), delta); - - hrtimer_set_expires(timer, time); + rq->hrtick_time = ktime_add_ns(timer->base->get_time(), delta); if (rq == this_rq()) __hrtick_restart(rq); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 2185b3b..0dfdd52 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1031,6 +1031,7 @@ struct rq { call_single_data_t hrtick_csd; #endif struct hrtimer hrtick_timer; + ktime_t hrtick_time; #endif #ifdef CONFIG_SCHEDSTATS