Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp193993ybt; Tue, 30 Jun 2020 18:15:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaW+vyXqpsD0gA7AbTWxHlRP2jrAKDvbGMCbi/BDMEUYnM3MAM5eCrhCyewnFnosgQ6Toy X-Received: by 2002:a17:907:42d0:: with SMTP id nz24mr21935165ejb.135.1593566112192; Tue, 30 Jun 2020 18:15:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593566112; cv=none; d=google.com; s=arc-20160816; b=RpRR1p0BNekFKyHgyiDI+ebGgKgw/7EJ3bimYj6msMBHY2vgndrV6WNqcuX9gTJW7Y 0p0MzbODJXziD/c2vEBB5vCx8ro84ytjyy3ol+q6vP1oFvWOPHLNhqpgfLwzpKqdeUv1 Laq13k1gE8CgN//Jwi+Duq0rmQYlWPUfL+T9Hi/jq3oK9vNjKa8ZGcAzsUH4kx7Mrec0 ST+CEMZEI0Tp2cDkMut5Auh+s51mVnYg/xpyK0U+LymO7RlB5rJ1NHDo6JUvXU2K3NHd UhXsCkEBlO3fBRwjpoTMGyjVs/1VAzgYjZBorpIgUNyHZkzPAOgIbWCM7WN+jBMZPXGb PRVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=70M61pnFJ+jZ3nztCs1XJoduY/IOmK1/pgPjlQsb3lc=; b=I0dXIo5uA+hNz+4O+uEszlNiDzaVzffHo3SxRcVCy1MZDA73V57vOOcEpp1ks2fm1N zPnLrYZ5I15ulbQR/7k1k3eqMGxQDZq+Ay4lNPJyC+NO+7h2ruZ6NpvruCInXBQVnV16 k7sZP1us1pHjKwXANA698adoUw5hGWfyWJhIhIbdiLjlj8pVP+ewJ67HHqNMgg26kZlU //6EGaPc3nqNMWkFkD1dP9X/5I6tPzP5szvRelgaMWIoU+DeNHM7BOC2cBwXvZ4NUjkD 1nf5XAPUSAJFScGQv1YoMTwIrOyfo+bSWOYS6PgXTBgPLKfNAEVR6g99AxXrwdykDHpF ynvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qUcDog9B; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n2si2854483edt.572.2020.06.30.18.14.49; Tue, 30 Jun 2020 18:15:12 -0700 (PDT) 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=@kernel.org header.s=default header.b=qUcDog9B; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726208AbgGABKk (ORCPT + 99 others); Tue, 30 Jun 2020 21:10:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:56846 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726114AbgGABKi (ORCPT ); Tue, 30 Jun 2020 21:10:38 -0400 Received: from lenoir.home (lfbn-ncy-1-996-218.w90-101.abo.wanadoo.fr [90.101.73.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 820BD20780; Wed, 1 Jul 2020 01:10:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593565837; bh=R+CWRWxBdgS789CBMsWjf9pbxc6lgAm7ICA8umueBE0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qUcDog9BnsFUNsBklcERwb/RghMXgW32y9k4yslt55zQpHYGouEz/aXaCWtce6ARs ngVpx6oqm9qoD5Pyta8EWHQkFF00MRz/b5ET7qoJoAmV9H8KMdkV4X4BOpKFCAlwtP EvRaIuT6IaepEdph6deD3H5lidtI5oqBnRocllyI= From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Anna-Maria Gleixner , Peter Zijlstra , Juri Lelli Subject: [RFC PATCH 01/10] timer: Prevent base->clk from moving backward Date: Wed, 1 Jul 2020 03:10:21 +0200 Message-Id: <20200701011030.14324-2-frederic@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200701011030.14324-1-frederic@kernel.org> References: <20200701011030.14324-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a timer is enqueued with a negative delta (ie: expiry is below base->clk), it gets added to the wheel as expiring now (base->clk). Yet the value that gets stored in base->next_expiry, while calling trigger_dyntick_cpu(), is the initial timer->expires value. The resulting state becomes: base->next_expiry < base->clk On the next timer enqueue, forward_timer_base() may accidentally rewind base->clk. As a possible outcome, timers may expire way too early, the worst case being that the highest wheel levels get spuriously processed again. To prevent from that, make sure that base->next_expiry doesn't get below base->clk. Signed-off-by: Frederic Weisbecker Cc: Peter Zijlstra Cc: Anna-Maria Gleixner Cc: Juri Lelli --- kernel/time/timer.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 398e6eadb861..9a838d38dbe6 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -584,7 +584,15 @@ trigger_dyntick_cpu(struct timer_base *base, struct timer_list *timer) * Set the next expiry time and kick the CPU so it can reevaluate the * wheel: */ - base->next_expiry = timer->expires; + if (time_before(timer->expires, base->clk)) { + /* + * Prevent from forward_timer_base() moving the base->clk + * backward + */ + base->next_expiry = base->clk; + } else { + base->next_expiry = timer->expires; + } wake_up_nohz_cpu(base->cpu); } @@ -896,10 +904,13 @@ static inline void forward_timer_base(struct timer_base *base) * If the next expiry value is > jiffies, then we fast forward to * jiffies otherwise we forward to the next expiry value. */ - if (time_after(base->next_expiry, jnow)) + if (time_after(base->next_expiry, jnow)) { base->clk = jnow; - else + } else { + if (WARN_ON_ONCE(time_before(base->next_expiry, base->clk))) + return; base->clk = base->next_expiry; + } #endif } -- 2.26.2