Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3001274ybi; Mon, 17 Jun 2019 14:24:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqxjYDPZKQ3pvvfRJ3dYX6Q98w7v5wFhxyOSV3WlN15YBLl14eAlTyUiCdVh3y10/moJZ/1B X-Received: by 2002:a17:902:b608:: with SMTP id b8mr12608171pls.303.1560806698009; Mon, 17 Jun 2019 14:24:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560806697; cv=none; d=google.com; s=arc-20160816; b=QgVD9WZKUUCR1klkW2Ulc7ATu1JbtHp7uu23evjyjNPIy43+napSTpyy7PGxwcx3IF aFtxjHH47PqPazH7tMQmoXVq3LYDgZSDzKKNIZNg1uB7KVZ+PVqDM/NV7q1gYjs1cusQ 73TVZauKs7jteutIpJb806R54IFv+YpYd2pIf6K1s8LsvwOFFGGwshcw5BeeAOBOHTG+ +fUI5dn9IX58NqAkw2tJ53FDoAokgfjiF1PosxX0JK/JJ937mdgraSe4P2435qVFLcAr hS7hx8PmMoETsiWrX7K3O/rXilfcTFvqyHNynFPRwJZktbxogVk3LG6F1cUzGY2S+7Ho rIqQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MTY8XtoulTBbS7ni0ej+NUqJSAxuOjT1MsBBm4yDv/I=; b=kXtmYeC6oW5jCpvL14pdIZqaY2lfYyyh7ErzrOEhR9RJpNLv+vzLbQqHbOTCKSvbTm m1YG53ClqRB1BBwpes+HSZjA5g58w3+BVFGU0NO4MDN6NpIw9oRyLya/fFNhCWp1yNpj Aa7bpsDbnos++ou0DpmVpGtyXJV1l5sRY+jaumoHy79AwGq3OebRUfKdEaM+rocqvwRV wycyyTnkamwB3W8MbXTVun309oWzIUtJ1HWKjf1x+E3WL/8JkifwwTm8NuOK17GiNDuV AVx1AE8s7LQevcGKRoCLEd7KKYGQsAC/CKaj1DMK7kc271PsrdeeYr4eecFHwYhcc60A +VzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0Zehl1di; 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 cg6si11855809plb.350.2019.06.17.14.24.42; Mon, 17 Jun 2019 14:24:57 -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; dkim=pass header.i=@kernel.org header.s=default header.b=0Zehl1di; 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 S1729671AbfFQVXL (ORCPT + 99 others); Mon, 17 Jun 2019 17:23:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:48110 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729663AbfFQVXJ (ORCPT ); Mon, 17 Jun 2019 17:23:09 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 22EC920673; Mon, 17 Jun 2019 21:23:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560806588; bh=JA+p7wrGBfD3DC0g1p9qRNUiBsLsU3ExILISMxqH+iM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0Zehl1di2IQktnyku2HnQAfgSISyC34D8YSfYu5t3Tl8d9SN7mXH/YIoWJYXfQ4zM G3W8kTH8f2LYTIR2TT4o4x0EYzljZbUAIvSvLsoNyIF6E6PBXb0tVKmtM5fT3ehCpb yQ8Lv0Gv87TkLH4qbm/UxQp48izm7JSao1nVLXqk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Jason A. Donenfeld" , Thomas Gleixner , Arnd Bergmann , Peter Zijlstra , Clemens Ladisch , Sultan Alsawaf , Waiman Long Subject: [PATCH 5.1 105/115] timekeeping: Repair ktime_get_coarse*() granularity Date: Mon, 17 Jun 2019 23:10:05 +0200 Message-Id: <20190617210805.365201879@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617210759.929316339@linuxfoundation.org> References: <20190617210759.929316339@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner commit e3ff9c3678b4d80e22d2557b68726174578eaf52 upstream. Jason reported that the coarse ktime based time getters advance only once per second and not once per tick as advertised. The code reads only the monotonic base time, which advances once per second. The nanoseconds are accumulated on every tick in xtime_nsec up to a second and the regular time getters take this nanoseconds offset into account, but the ktime_get_coarse*() implementation fails to do so. Add the accumulated xtime_nsec value to the monotonic base time to get the proper per tick advancing coarse tinme. Fixes: b9ff604cff11 ("timekeeping: Add ktime_get_coarse_with_offset") Reported-by: Jason A. Donenfeld Signed-off-by: Thomas Gleixner Tested-by: Jason A. Donenfeld Cc: Arnd Bergmann Cc: Peter Zijlstra Cc: Clemens Ladisch Cc: Sultan Alsawaf Cc: Waiman Long Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1906132136280.1791@nanos.tec.linutronix.de Signed-off-by: Greg Kroah-Hartman --- kernel/time/timekeeping.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -807,17 +807,18 @@ ktime_t ktime_get_coarse_with_offset(enu struct timekeeper *tk = &tk_core.timekeeper; unsigned int seq; ktime_t base, *offset = offsets[offs]; + u64 nsecs; WARN_ON(timekeeping_suspended); do { seq = read_seqcount_begin(&tk_core.seq); base = ktime_add(tk->tkr_mono.base, *offset); + nsecs = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift; } while (read_seqcount_retry(&tk_core.seq, seq)); - return base; - + return base + nsecs; } EXPORT_SYMBOL_GPL(ktime_get_coarse_with_offset);