Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2637243lqp; Mon, 25 Mar 2024 05:18:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUFjV50W9myMvkzmI9HDgM01BnAfR92NGy1WmNo3LpwjfmZW6r6GDeHEjiLL6238tYpzH04qf1vOl6XlvvGd4PcoA1hXMnyq38+1zpv8g== X-Google-Smtp-Source: AGHT+IGL3QSVvZUWNxfG6DjKIzQesmjInoP3fu/rtHq1V/UuayD5viDA9den57lnA/AmjFXVJDIc X-Received: by 2002:a05:6214:2681:b0:691:6311:eeff with SMTP id gm1-20020a056214268100b006916311eeffmr9090739qvb.21.1711369111308; Mon, 25 Mar 2024 05:18:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711369111; cv=pass; d=google.com; s=arc-20160816; b=HLBNtUk1aVMxQZ5kcVy4VlU7uqv1saA4qTt28tL1BEY5ct9BZnj0LQz/1L0wlSGB0k d+RgxpfX0pcoU0oBFZq979S/vKcyXOUgqEpm4R+JYXCsYJk9jilLCTOi4hFpBODC46B2 c5HHZKtuO3OVc4thHIKZttg5awRudItG5dzUR3cC0aAxG0D0A8juTuJKbm1HHQZqhgRL Js1zsxgx+7P5NfALy6gmTqAhd/MSNsLEgHdi9OcYru9IWDwqGtZs8/fOMdyyppfui2LT hVQTG5X/3z4EhwIjRQUrvLBvJmEyuxyuEVtoZthtWZxC82xWQrO1mF+Z/QnfwsEjFSHQ 6xrg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:organization:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=RwBIK+x7sawqGRMxWkkLlsg2WCr67/t+dMS8uTY/SH4=; fh=wgq3SFFcpYoLsYNr1Fy+HYH2+WGNJgTNu+AnKLa6P2U=; b=KKfX7yMpDPxuvqtNBI8U4qBVLPk17bqBRbeY2S50a6xtzuxi4YH/ZsUy/+Y7HgjV5D GKkuxc4c6b4GBBiB5mCKXZNWYNI4Rg22jfJB2jpbV6/DG6WXjUeLfNsAjIHoQDt2+Bgt Gb03ul5xu2VoreNRIL+yVAlEvhxOPVQ9H84iE31K9t3/dCSt2tbkF0mz1yF9U1nWLMi7 6NsB0Oj3hih3B5BsDeTmu144vs/oUr0EBqzoTk8bJX6gesm1nb+5Tw6mEjVVjKnk6mKR cwgrrjQs+oceT38Z66wl1iakLKDomwYPUuA+FN/PMgzUbL2706spROV1kKA6Z3PbvRoQ wV/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=axHArCxd; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-116590-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116590-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c7-20020a056214224700b0068ff1888580si8084287qvc.97.2024.03.25.05.18.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 05:18:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116590-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=axHArCxd; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-116590-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116590-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id CED511C33A7B for ; Mon, 25 Mar 2024 12:18:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01590147C8A; Mon, 25 Mar 2024 08:53:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="axHArCxd" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 40E1815EFDE; Mon, 25 Mar 2024 06:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711348879; cv=none; b=BkeO8AxC+ap8l7zMes2aj+Es4rLB6ydfAADSvfh34cowfrNeThDwXnjCmDSnJCaqBxNus/ZYmSkCTR8dfTyhjUeO9E2IKY1mQfNAF2rjBvg2dxTJc4nZP3GJBQNVdHSCZM3b9ZNJs/Y3AHKZa4gbjWnAnxPukSLvUaBCHwL727c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711348879; c=relaxed/simple; bh=Exf/ex05wg/ZdHrQtagsjpQZFoomRp7dCTSrSntMNmc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HNxqlXLfCbZDGXBL2O+exk8c1nf1LfRptNoboCsNYST/kydEjhwoxFmb3XkSxg52b4/0UfvgSAwDEnj46kjO/XkSP6I2DxEOA52cUCOcF26hNnbxdFlkdYDghec+I6z2tMnv+9z3Q+EUbvYa+7QPVODbzlORAxJQjE5Ea9Yttu8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=axHArCxd; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711348878; x=1742884878; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Exf/ex05wg/ZdHrQtagsjpQZFoomRp7dCTSrSntMNmc=; b=axHArCxdlLJWcdpUdFpdUKDb4vGFMy8xAeYle9WYj4wO9bYvG0qfdVB+ e519CX6ze37Otw54tKE+4S5TEfFzN1kkyHo5LuP30R3udjLM+5En+xL05 JX2dw4TKgWIbI2ZBqsuM9eGRWj0h1Qlsr71U6qh29hUykxzWK+CwNb777 a2kJX2K4lHYWJgK9IHChPfcU287b7Ne3lNeHhYfz/LcdeAGexjyG9jbS9 WR1rC31mVvhcTVuc7p2PGV/TJ8t8calE2Pl9bUuvI2nj91QyYDKaLyYxR lgAQcSl4FRyahAaRgXzLlA4RbxPCVk/pany5AANWQGquvMYwMf34SDG8g w==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="17065180" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="17065180" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2024 23:41:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="38629593" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.251.211.155]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2024 23:41:11 -0700 From: Adrian Hunter To: Thomas Gleixner Cc: Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , "Naveen N. Rao" , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andy Lutomirski , Vincenzo Frascino , John Stultz , Stephen Boyd , Peter Zijlstra , Randy Dunlap , Bjorn Helgaas , Arnd Bergmann , Anna-Maria Behnsen , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH V2 06/19] vdso: Add vdso_data::max_cycles Date: Mon, 25 Mar 2024 08:40:10 +0200 Message-Id: <20240325064023.2997-7-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325064023.2997-1-adrian.hunter@intel.com> References: <20240325064023.2997-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: 8bit Add vdso_data::max_cycles in preparation to use it to detect potential multiplication overflow. Suggested-by: Thomas Gleixner Signed-off-by: Adrian Hunter --- include/vdso/datapage.h | 4 ++++ kernel/time/vsyscall.c | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/include/vdso/datapage.h b/include/vdso/datapage.h index 5d5c0b8efff2..6c3d67d6b758 100644 --- a/include/vdso/datapage.h +++ b/include/vdso/datapage.h @@ -67,6 +67,7 @@ struct vdso_timestamp { * @seq: timebase sequence counter * @clock_mode: clock mode * @cycle_last: timebase at clocksource init + * @max_cycles: maximum cycles which won't overflow 64bit multiplication * @mask: clocksource mask * @mult: clocksource multiplier * @shift: clocksource shift @@ -98,6 +99,9 @@ struct vdso_data { s32 clock_mode; u64 cycle_last; +#ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT + u64 max_cycles; +#endif u64 mask; u32 mult; u32 shift; diff --git a/kernel/time/vsyscall.c b/kernel/time/vsyscall.c index f0d5062d9cbc..9193d6133e5d 100644 --- a/kernel/time/vsyscall.c +++ b/kernel/time/vsyscall.c @@ -22,10 +22,16 @@ static inline void update_vdso_data(struct vdso_data *vdata, u64 nsec, sec; vdata[CS_HRES_COARSE].cycle_last = tk->tkr_mono.cycle_last; +#ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT + vdata[CS_HRES_COARSE].max_cycles = tk->tkr_mono.clock->max_cycles; +#endif vdata[CS_HRES_COARSE].mask = tk->tkr_mono.mask; vdata[CS_HRES_COARSE].mult = tk->tkr_mono.mult; vdata[CS_HRES_COARSE].shift = tk->tkr_mono.shift; vdata[CS_RAW].cycle_last = tk->tkr_raw.cycle_last; +#ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT + vdata[CS_RAW].max_cycles = tk->tkr_raw.clock->max_cycles; +#endif vdata[CS_RAW].mask = tk->tkr_raw.mask; vdata[CS_RAW].mult = tk->tkr_raw.mult; vdata[CS_RAW].shift = tk->tkr_raw.shift; -- 2.34.1