From patchwork Thu Jun 8 23:44:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 103435 Delivered-To: patches@linaro.org Received: by 10.140.91.77 with SMTP id y71csp2677791qgd; Thu, 8 Jun 2017 16:51:09 -0700 (PDT) X-Received: by 10.99.172.17 with SMTP id v17mr41202804pge.234.1496965869603; Thu, 08 Jun 2017 16:51:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496965869; cv=none; d=google.com; s=arc-20160816; b=0uFycEu/Wws4uH0f2Yssjq23E8Ui8sQiORdIv8sP3POn2/7pMN8A8AZ6W2T7K8gCS8 aHqwq9cNkcOuDSmR2tzrlO8Lc+Y1zKc3eh/zqOdDjeeePKZMBW53fWDx7chRPvcKFNKs wvXFUFxo1RSmLtq20NU3tPTiOpC0BtcB5fCDdWufrUvDGyDDokTUBw/sKnKqbxeurhyF 76v2whqQOiqEHsfx1SSfRlNjZuPI+LsQDCsaPl3v3BaGe9tO6aZ/vD149ax2nrHD1JU9 xmjOAs27VAKDCmeFOafON1WJjpOLBV8/EcjGevuEoDKUAk26DC9o7qZJlQOoiXIE5Lmy b7jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=P6Z1iOyxQBLRyPZe09EyceQVC4iWS7ZuJ35jqxv5oWs=; b=yDbbDDTArtMSvajQF0caUtP7yHWvw+/vjKd9WbpLqnZx/J358oo4SxmwvNP074IrTg 9o6GKDeORBJAin/nErMvhgTYVaJc6AgWuwing6ZWCOzJ+iqetfAv9CqYdQwlGbGe6+eB HAfjZxbdia6R3sDlDYzz57PA8Occuz8SCvLkCBDqsmAqFzjPqa3cNbR1yEc6Bw/rnKIP szRkgoWoHcb74Bdi2Gd3FtAWJ4v8Q2Yn0NuS89w5tHhBobQz0hJ23JT7PoJGzC+4CHHd OX4BHHo8jts81wAo/L4mYEeP7FYt+s4J4SBbJNqGbqW+fQ+6Q0tZ+cPvnjfz0DwoyxxD RYaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id u127sor3680180pgc.2.2017.06.08.16.51.09 for (Google Transport Security); Thu, 08 Jun 2017 16:51:09 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=P6Z1iOyxQBLRyPZe09EyceQVC4iWS7ZuJ35jqxv5oWs=; b=Tke+4hhNoNEZDMHl3n1NPI35lezo8ZC1NKbTOAje/iuv6k6Z4Rlm8Nyv/CaetfeXNa UU/+tulXIbjvahDAF4XB7Vipj1DseTVQnnVKu4Y7V4vgWI19mfG1tf3uAD/wPhINuDtS 5fbTi82uqNRnM7si97d9YeVMRSkTq7yK74XW0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=P6Z1iOyxQBLRyPZe09EyceQVC4iWS7ZuJ35jqxv5oWs=; b=r2IhNQeBEu5OCsBGLzhRoe8KPZiYXkLUG1FtpR/JPBHobP1YeXwwBwXVMtRlZ36PzX gwL6QIzVlJPzaNFXJQVGL91BfB5wciadZFzbrRXzj7vUhM5ruVyT5+HUvzFAro5gSUc8 fOxhdUAoiWTeI+/bTSvh0l0BDWZWRe5IHujK30WIPztmayBo8k/n+YOXYxqvrvD8OuIW iF6VPZUmFHkJ2MxtTO5IAFREGu+KvsbOuvwgR/O+urW3iWHkpB+MUp0ChMqXpp5F0Joe H1u6ALRqvHUfT8WctbdcEbXUC7i8FC/BhYk3WPxXrIboAEamX98k71wGmwSi/XaU0XWh 3cow== X-Gm-Message-State: AODbwcCyBxW0VWgpFw4Sr2eMow35UlhK0wPgKXyLf5MtnbSeAQ2+HGXW kPh5+MFLqdP/ke+x2Hc= X-Received: by 10.99.107.136 with SMTP id g130mr39139735pgc.3.1496965869308; Thu, 08 Jun 2017 16:51:09 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id b86sm14462850pfc.27.2017.06.08.16.51.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Jun 2017 16:51:08 -0700 (PDT) From: John Stultz To: lkml Cc: Will Deacon , Thomas Gleixner , Ingo Molnar , Miroslav Lichvar , Richard Cochran , Prarit Bhargava , Stephen Boyd , Kevin Brodsky , Daniel Mentz , "stable #4 . 8+" , John Stultz Subject: [PATCH 3/3 v3] arm64: vdso: Fix nsec handling for CLOCK_MONOTONIC_RAW Date: Thu, 8 Jun 2017 16:44:22 -0700 Message-Id: <1496965462-20003-4-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496965462-20003-1-git-send-email-john.stultz@linaro.org> References: <1496965462-20003-1-git-send-email-john.stultz@linaro.org> From: Will Deacon Recently vDSO support for CLOCK_MONOTONIC_RAW was added in 49eea433b326 ("arm64: Add support for CLOCK_MONOTONIC_RAW in clock_gettime() vDSO"). Noticing that the core timekeeping code never set tkr_raw.xtime_nsec, the vDSO implementation didn't bother exposing it via the data page and instead took the unshifted tk->raw_time.tv_nsec value which was then immediately shifted left in the vDSO code. Unfortunately, by accellerating the MONOTONIC_RAW clockid, it uncovered potential 1ns time inconsistencies caused by the timekeeping core not handing sub-ns resolution. Now that the core code has been fixed and is actually setting tkr_raw.xtime_nsec, we need to take that into account in the vDSO by adding it to the shifted raw_time value, in order to fix the user-visible inconsistency. Rather than do that at each use (and expand the data page in the process), instead perform the shift/addition operation when populating the data page and remove the shift from the vDSO code entirely. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Cc: Kevin Brodsky Cc: Will Deacon Cc: Daniel Mentz Cc: stable #4.8+ Reported-by: John Stultz Acked-by: Kevin Brodsky Tested-by: Daniel Mentz Signed-off-by: Will Deacon [jstultz: minor whitespace tweak, tried to improve commit message to make it more clear this fixes a regression] Signed-off-by: John Stultz --- v2: Tweak commit message to address Ingo's feedback --- arch/arm64/kernel/vdso.c | 5 +++-- arch/arm64/kernel/vdso/gettimeofday.S | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index 41b6e31..d0cb007 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -221,10 +221,11 @@ void update_vsyscall(struct timekeeper *tk) /* tkr_mono.cycle_last == tkr_raw.cycle_last */ vdso_data->cs_cycle_last = tk->tkr_mono.cycle_last; vdso_data->raw_time_sec = tk->raw_time.tv_sec; - vdso_data->raw_time_nsec = tk->raw_time.tv_nsec; + vdso_data->raw_time_nsec = (tk->raw_time.tv_nsec << + tk->tkr_raw.shift) + + tk->tkr_raw.xtime_nsec; vdso_data->xtime_clock_sec = tk->xtime_sec; vdso_data->xtime_clock_nsec = tk->tkr_mono.xtime_nsec; - /* tkr_raw.xtime_nsec == 0 */ vdso_data->cs_mono_mult = tk->tkr_mono.mult; vdso_data->cs_raw_mult = tk->tkr_raw.mult; /* tkr_mono.shift == tkr_raw.shift */ diff --git a/arch/arm64/kernel/vdso/gettimeofday.S b/arch/arm64/kernel/vdso/gettimeofday.S index e00b467..76320e9 100644 --- a/arch/arm64/kernel/vdso/gettimeofday.S +++ b/arch/arm64/kernel/vdso/gettimeofday.S @@ -256,7 +256,6 @@ monotonic_raw: seqcnt_check fail=monotonic_raw /* All computations are done with left-shifted nsecs. */ - lsl x14, x14, x12 get_nsec_per_sec res=x9 lsl x9, x9, x12