From patchwork Thu Jun 1 03:07:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 100813 Delivered-To: patches@linaro.org Received: by 10.140.96.100 with SMTP id j91csp612373qge; Wed, 31 May 2017 20:08:06 -0700 (PDT) X-Received: by 10.84.169.3 with SMTP id g3mr38258064plb.37.1496286486489; Wed, 31 May 2017 20:08:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496286486; cv=none; d=google.com; s=arc-20160816; b=jZBJplq/VyRUP6Zu7PiUw4/VbPzo0hZSpZWExURtTQd0YzjMRmWZzszx8sN46SI6UJ CwJwoeD8HWjFk12pqc+4xGwwZzw0O3LjMG9ZatfS9arUGbjFEN45ouetnJVcv6Gz/wPl iTeSL6cLBlH5XqwBvofu/uId3WaLV5xlpfv8qO7OYC7qXlJef6+c/MtFK+53IsgPCH40 Mycj8Ea7A1msa6UUQYgwBhfZ3lZZ59KQC6+7lbqrbKqgIG/ODjJpsL8B4a1KiMhUmz+D kyWYBZlJDMxldNVPJTmFaQo99WQAJA2QOFbRWtuPFLy4S7smbwjNE5uNikcBruK5ZICo QnPg== 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=VsiJDF9iiwpO5ltGB7OuRF1s9Ozmx5dFK7JSjE8hZfW2ww5ENiJWyH6ygavFPxMxmX ikCX2rcGLGJpOhc4BMmARZUvH+vVFvLlfwYWLJ/mMuzU5lL/Vd64IKxxeHRjeaRS+7/A c2u7b/0+rsWo2dl4Op5eUd9YS/h1HHE1xdjz9IxbDSW8KqLLv8TAGhuIRKl9L5zUxoa7 HE9lBbXKiejq0LfStG4KRLKDHIdqtD2mCWlYj3JQ9G5+XLAXrp+7lzLCs8ve5s7MyONx IS3RyLeG51cKSWZyQf00F83Zm+QL8r3TPsOkFjFVaXiE0+nnNNFKKGjGvZagRm0+x2/X ZMhA== 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 2607:f8b0:400e:c00::233 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-pf0-x233.google.com (mail-pf0-x233.google.com. [2607:f8b0:400e:c00::233]) by mx.google.com with ESMTPS id v130si18096946pgb.188.2017.05.31.20.08.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 May 2017 20:08:06 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::233 as permitted sender) client-ip=2607:f8b0:400e:c00::233; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::233 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-pf0-x233.google.com with SMTP id n23so24596515pfb.2 for ; Wed, 31 May 2017 20:08:06 -0700 (PDT) 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=OA3Jqoo8GeGqdbe7l95fzOuQvvvSH0B/6ZTJ64fMTCaJZNBDOvpD7FGINQpQkloCcd DC7Ux5d3l4Xe3XWCgGnQ+V9kg5l0vAamwD7GXyQ1vgnz2CHzaPMD9w90HSSJt/ZioxPj sXXC0f1zPafIjANycq4yNx6GGdan11BosVTHY= 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=gtK1tmnZ5Er70sF/TxxSOhzH+cja9fgDjXqybc9Y96j3B/pQY/Aiq3v3I6y8xPafGK 2cQfQqWwJl42Us2tQHsRnxiIyTIBv48nvoPmkEuIR6ez0uo/FGYkZkz3taNiauPdPmhd NHuGQJM/A5fYjqn7Ts4cZQWlHI1/FifMw+fukuUQNqv2HIBpl6vUqOrY3D5B1j1ez9Go lLdgTJlQELdr49Bx5HlbiC2bwRieWAtElfgItiBgrML3nOG7L2RU9RaMjpVmXmPiCTIW e8t8ZL3nEpN4zjMCEopIlSqylYSKz0ZvjGe4Rj3luduG0Zvntj3mnk/XF4Hk1njuSQKn Rq+w== X-Gm-Message-State: AODbwcChx4PH7HBbZgAjt7xbQZI6xIus+QvhIBgZpYPIns1eqoOXEz9G cVXTZp2VPPl2L0oTeTI= X-Received: by 10.98.214.14 with SMTP id r14mr34019730pfg.156.1496286486149; Wed, 31 May 2017 20:08:06 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id s68sm29137756pgc.5.2017.05.31.20.08.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 May 2017 20:08:05 -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 v2] arm64: vdso: Fix nsec handling for CLOCK_MONOTONIC_RAW Date: Wed, 31 May 2017 20:07:58 -0700 Message-Id: <1496286478-13584-4-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496286478-13584-1-git-send-email-john.stultz@linaro.org> References: <1496286478-13584-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