Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp240352ybi; Wed, 29 May 2019 20:26:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqykR+ocjA1qw8aGelCEWhe/tV5ZwTqU0AlCPeq1Npqn7ks7fwm0QSngeKBvEXMDJNFUdFqQ X-Received: by 2002:a62:3085:: with SMTP id w127mr1440686pfw.170.1559186806601; Wed, 29 May 2019 20:26:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559186806; cv=none; d=google.com; s=arc-20160816; b=CdS8BkIfRcXfc3I20khSbCsMTPTR8CFiuYqXJ/qQ27VC4CI+ymDA4BE6Vp7zqx3+Fz ieTqwCt5Cmhe7QduFISXXh0uXT9JxHwjFUmYHqxSxwjTRXuAFhhqHPA7FX1aHyfH1Uiu Q7yb/pK37yJ1fioXRxZHQHo30+WbC20uIY3KL5CUM43HZBSznrpGdk4ec5HalIg+G4xO 43sejQ0s2ux5BKNKUqCZTHbfOlBymUFgRp0kF9vhtjGwLiyLG9zB4SNTGZpmXuce2J80 AkxglalbBig+RXJn5yM+A+j/yo1D8uzc6gT/DX0y2K3/Q70teRhdU5fQ9QHdfP6teeZ4 qwBg== 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=PDUC4qQuGN+sOdtULF5zDbvg8PVLdkfkLSP8gGLlH10=; b=A5GrgrWXsUHQHDbZYAgyh8XgqQLrkFzp1R6uLn+7L4nUxSNP/7Jg+EzBGziTqfTkfn XbkYsNfXTMHaNsfkNLMXy+2mPDTlEGCXmQq/rvuXeeg2WRqS7EKBb5vOvBNjqThxGb8t gykBV/PQA+TFbrcy+2oPY9UQj+ioRoKZ2PQ1aEuSvWd2vs4gn9W3Aw9D7G9Wv4U7Ouhf F9USpPbkAeuVzKfNMPRY8ziCu6LbPxi8P/sKhZrm2aKHdIQ4bZi1Tcf4rcMONV890SJK AWNrXFfzo062pgtenAM+EoxFWZ6+LE95Q4xMkY6YD9Ap7HzohKhBEKQYT1kehvnWHiXE ys9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=J8Jaawx7; 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 g8si1948560pgd.64.2019.05.29.20.26.30; Wed, 29 May 2019 20:26:46 -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=J8Jaawx7; 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 S1733040AbfE3DXR (ORCPT + 99 others); Wed, 29 May 2019 23:23:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:45326 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731059AbfE3DRU (ORCPT ); Wed, 29 May 2019 23:17:20 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (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 408862469F; Thu, 30 May 2019 03:17:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186240; bh=ulusacNnrQBiMj7ktZxXDLnB92u6HH8UujHdL43sXdU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J8Jaawx7HMBXjp5y23GDGaTk6+qz0U4YtKU/vvyHlVgB84LZR69DJH+B3gbmGo/vV cHqNUdVM9SKxyonYLKFGMekZDBnY2Goza8taot2MTT1suyVCEtZ6T9eIFRS7hVou6G xrL+XquymWYWbZYUa/EoA/bqFhnI7bpicev8wzzY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Catalin Marinas , Vincenzo Frascino , Will Deacon , Sasha Levin Subject: [PATCH 4.19 152/276] arm64: vdso: Fix clock_getres() for CLOCK_REALTIME Date: Wed, 29 May 2019 20:05:10 -0700 Message-Id: <20190530030535.080336468@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030523.133519668@linuxfoundation.org> References: <20190530030523.133519668@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 [ Upstream commit 81fb8736dd81da3fe94f28968dac60f392ec6746 ] clock_getres() in the vDSO library has to preserve the same behaviour of posix_get_hrtimer_res(). In particular, posix_get_hrtimer_res() does: sec = 0; ns = hrtimer_resolution; where 'hrtimer_resolution' depends on whether or not high resolution timers are enabled, which is a runtime decision. The vDSO incorrectly returns the constant CLOCK_REALTIME_RES. Fix this by exposing 'hrtimer_resolution' in the vDSO datapage and returning that instead. Reviewed-by: Catalin Marinas Signed-off-by: Vincenzo Frascino [will: Use WRITE_ONCE(), move adr off COARSE path, renumber labels, use 'w' reg] Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/include/asm/vdso_datapage.h | 1 + arch/arm64/kernel/asm-offsets.c | 2 +- arch/arm64/kernel/vdso.c | 3 +++ arch/arm64/kernel/vdso/gettimeofday.S | 7 +++---- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/vdso_datapage.h b/arch/arm64/include/asm/vdso_datapage.h index 2b9a63771eda8..f89263c8e11af 100644 --- a/arch/arm64/include/asm/vdso_datapage.h +++ b/arch/arm64/include/asm/vdso_datapage.h @@ -38,6 +38,7 @@ struct vdso_data { __u32 tz_minuteswest; /* Whacky timezone stuff */ __u32 tz_dsttime; __u32 use_syscall; + __u32 hrtimer_res; }; #endif /* !__ASSEMBLY__ */ diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index 323aeb5f2fe62..92fba851ce53a 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -99,7 +99,7 @@ int main(void) DEFINE(CLOCK_REALTIME, CLOCK_REALTIME); DEFINE(CLOCK_MONOTONIC, CLOCK_MONOTONIC); DEFINE(CLOCK_MONOTONIC_RAW, CLOCK_MONOTONIC_RAW); - DEFINE(CLOCK_REALTIME_RES, MONOTONIC_RES_NSEC); + DEFINE(CLOCK_REALTIME_RES, offsetof(struct vdso_data, hrtimer_res)); DEFINE(CLOCK_REALTIME_COARSE, CLOCK_REALTIME_COARSE); DEFINE(CLOCK_MONOTONIC_COARSE,CLOCK_MONOTONIC_COARSE); DEFINE(CLOCK_COARSE_RES, LOW_RES_NSEC); diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index 2d419006ad433..ec0bb588d7553 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -232,6 +232,9 @@ void update_vsyscall(struct timekeeper *tk) vdso_data->wtm_clock_sec = tk->wall_to_monotonic.tv_sec; vdso_data->wtm_clock_nsec = tk->wall_to_monotonic.tv_nsec; + /* Read without the seqlock held by clock_getres() */ + WRITE_ONCE(vdso_data->hrtimer_res, hrtimer_resolution); + if (!use_syscall) { /* tkr_mono.cycle_last == tkr_raw.cycle_last */ vdso_data->cs_cycle_last = tk->tkr_mono.cycle_last; diff --git a/arch/arm64/kernel/vdso/gettimeofday.S b/arch/arm64/kernel/vdso/gettimeofday.S index e8f60112818fc..856fee6d35129 100644 --- a/arch/arm64/kernel/vdso/gettimeofday.S +++ b/arch/arm64/kernel/vdso/gettimeofday.S @@ -308,13 +308,14 @@ ENTRY(__kernel_clock_getres) ccmp w0, #CLOCK_MONOTONIC_RAW, #0x4, ne b.ne 1f - ldr x2, 5f + adr vdso_data, _vdso_data + ldr w2, [vdso_data, #CLOCK_REALTIME_RES] b 2f 1: cmp w0, #CLOCK_REALTIME_COARSE ccmp w0, #CLOCK_MONOTONIC_COARSE, #0x4, ne b.ne 4f - ldr x2, 6f + ldr x2, 5f 2: cbz x1, 3f stp xzr, x2, [x1] @@ -328,8 +329,6 @@ ENTRY(__kernel_clock_getres) svc #0 ret 5: - .quad CLOCK_REALTIME_RES -6: .quad CLOCK_COARSE_RES .cfi_endproc ENDPROC(__kernel_clock_getres) -- 2.20.1