Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1348675lqe; Mon, 8 Apr 2024 06:38:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV9lbTxu+nB4vSDWb5EUx8YANBoxJFUgKMDle/OJPz+J4zQ/7xwAPkJqZXseUyArGW7SqBNQsRZEbym3wbJgRa0fZB0BORnR1yAm4U9ZA== X-Google-Smtp-Source: AGHT+IFWFidAJUWxz2SdlJMZkAoKDE8pZcdx0Gr3YMLqsfbGyqPvjH7tZLN85qbpND5NrfYvqmyp X-Received: by 2002:a17:903:48b:b0:1e2:bdef:3971 with SMTP id jj11-20020a170903048b00b001e2bdef3971mr9825314plb.16.1712583515005; Mon, 08 Apr 2024 06:38:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712583514; cv=pass; d=google.com; s=arc-20160816; b=XWQMqTEjvjviG0c8EjbRNsjvj0gCPQKlGsTwo2zBa9UV3D73fJ/I5skdaww6oQonx7 XG8meiCnPIrY/hCKqBRbmEUunrzlMLautp/faDcSXxvWg9e5/otHrq0+kRwpV1L5jVjO uGEd+BQImDSScHcEBmJeYB/Tkw4i1qnfHlUGYUtHwqnL7bpf+emroyyErridc2i94qA5 NR3GwiqNWlzq4CGctF8coR5YyKyIdRPwAF+Xv7f0cY/HV3c6ICxIulJzwgneXJer2gLt hoFqz4me+wh7x9UXxKXvhn6X8nN9w/OX11kGCpuu2UCVhF3uE0G1iJh2lMBb8APZzi0R GVIA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=gjyX2yHQeZs8zwNtRJE49NPE7UtmWOE94hdhqmv8RbA=; fh=HIrP3i0WQwu8zLnKtb1acHgteo695uCSG6Yk5OndRkw=; b=NQVBxzukO+7tAD3QvXtBJqNkkjmPXy9EmyNvDu80/MX1KTMD9b9irslZ3TYIA/hy81 DMoI87dGG8XiR4PzRbNdK6J7NU8BIzOesIBWVKxcIGOVFB5UcOyFwpcK3r34sayBRznA xuBDIgLddauCPYxDCHM+kbuREP6XSaF2TG3RSgSukPKK8vDiQUWAMGTArlB8mRhbfmW1 wYCeUvb2gV+IanuehUxyPFguLr2mL8GqV0NjrJUJ4a6KKJL64GPuc4RtWjLgEv3RBmic RGOqtg6c1tzwvXYKfEO+NrUGQgKTBiz3/K2FJoJ3qyTBnP51P4OwrJA/q2B46HpEIKPZ jpKQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0sSo1BHW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-135400-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135400-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id iw6-20020a170903044600b001e278594757si6141516plb.212.2024.04.08.06.38.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 06:38:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135400-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0sSo1BHW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-135400-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135400-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id AAD84B293E9 for ; Mon, 8 Apr 2024 13:13:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 75BC977F1B; Mon, 8 Apr 2024 13:10:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0sSo1BHW"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vdg93hU8" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D57427F466; Mon, 8 Apr 2024 13:10:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712581844; cv=none; b=g5j7RJGlmGhW4vDHQwnYSesjZylID05ut8Oq6bfBAO6Xtsq2YWfDnfF6O54LpSVhLCXizDm8DlO+R/wiLfnPL88IBxI0aubjR67okeGHag0yhVmalDEsBUaC5mAFoMs0hyfzFB2dnt5jeASEvw3GvUDSuWVKW500K+JZmNuZ0XQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712581844; c=relaxed/simple; bh=93xazvMvcvDjb1ynzZlO5q4vfY+sl98A7uYQAWn7G5s=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=SVNoawF0vZUr9jJjgM6ZFuHh7mWxrxkBWCriL3rQf57TAub1U9Egmf9BtQabmp0JzjZAylrJQ6niBdluIUaBmRjNRpzRTZ9+9x4IS6cY2swjqqiR22O3iY3hfPwFNUSguL1FnTRjgoo/tm9Gn6+0dsu9172WeYxMa/J41morteU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=0sSo1BHW; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=vdg93hU8; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Mon, 08 Apr 2024 13:10:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712581841; 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=gjyX2yHQeZs8zwNtRJE49NPE7UtmWOE94hdhqmv8RbA=; b=0sSo1BHWlnSQ5Ms0TSCy/26vDL13iinlLLv6OfESbW+y5PB+/pE6Zv/hOT/AOEsM12uf0a DBuTQNoKfPeokAuqPcTxddV1CyVk+QE+d0l6h5oHiFQw5MgAE9DTSiPNp/v6oOe6Mbp1dj FqGQjj9YCI6zGJAv5hrgwckCmU4QhqdLoF1YTIeddQiXdVCH937vJ/W64PhZX8gJ28e2TW p/0GvESUFKX6cneJGWOQAk3v0hTn3LoZdDYkSSMxnLAMqYxJyL88zqR3PjI5HkKMTj6DVw 4CcNtij4iJ/epFe+6ZP5wLpngoI6aqYuHPlLtv6mhDsDwsOpihozDZ3igHS+2w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712581841; 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=gjyX2yHQeZs8zwNtRJE49NPE7UtmWOE94hdhqmv8RbA=; b=vdg93hU8CpOdYlEjqSQNtry5qcFg8aDQdhD7BUosbr7DrbOdNRv4dWoOpxfOBBwMoURNim d+EvRBdAvjVZDFCQ== From: "tip-bot2 for Adrian Hunter" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/core] vdso: Make delta calculation overflow safe Cc: Thomas Gleixner , Adrian Hunter , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240325064023.2997-8-adrian.hunter@intel.com> References: <20240325064023.2997-8-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171258184044.10875.9117228310710193606.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the timers/core branch of tip: Commit-ID: 456e3788bc7164c1c8298045e04068b8e3d8e413 Gitweb: https://git.kernel.org/tip/456e3788bc7164c1c8298045e04068b8e3d8e413 Author: Adrian Hunter AuthorDate: Mon, 25 Mar 2024 08:40:11 +02:00 Committer: Thomas Gleixner CommitterDate: Mon, 08 Apr 2024 15:03:07 +02:00 vdso: Make delta calculation overflow safe Kernel timekeeping is designed to keep the change in cycles (since the last timer interrupt) below max_cycles, which prevents multiplication overflow when converting cycles to nanoseconds. However, if timer interrupts stop, the calculation will eventually overflow. Add protection against that, enabled by config option CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT. Check against max_cycles, falling back to a slower higher precision calculation. Suggested-by: Thomas Gleixner Signed-off-by: Adrian Hunter Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/20240325064023.2997-8-adrian.hunter@intel.com --- lib/vdso/gettimeofday.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c index 9fa90e0..9c3a8d2 100644 --- a/lib/vdso/gettimeofday.c +++ b/lib/vdso/gettimeofday.c @@ -13,6 +13,18 @@ # define VDSO_DELTA_MASK(vd) (vd->mask) #endif +#ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT +static __always_inline bool vdso_delta_ok(const struct vdso_data *vd, u64 delta) +{ + return delta < vd->max_cycles; +} +#else +static __always_inline bool vdso_delta_ok(const struct vdso_data *vd, u64 delta) +{ + return true; +} +#endif + #ifndef vdso_shift_ns static __always_inline u64 vdso_shift_ns(u64 ns, u32 shift) { @@ -28,7 +40,10 @@ static __always_inline u64 vdso_calc_ns(const struct vdso_data *vd, u64 cycles, { u64 delta = (cycles - vd->cycle_last) & VDSO_DELTA_MASK(vd); - return vdso_shift_ns((delta * vd->mult) + base, vd->shift); + if (likely(vdso_delta_ok(vd, delta))) + return vdso_shift_ns((delta * vd->mult) + base, vd->shift); + + return mul_u64_u32_add_u64_shr(delta, vd->mult, base, vd->shift); } #endif /* vdso_calc_ns */