Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S938630AbcLTTMe (ORCPT ); Tue, 20 Dec 2016 14:12:34 -0500 Received: from mail-eopbgr10104.outbound.protection.outlook.com ([40.107.1.104]:14991 "EHLO EUR02-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S964812AbcLTTM1 (ORCPT ); Tue, 20 Dec 2016 14:12:27 -0500 X-Greylist: delayed 11715 seconds by postgrey-1.27 at vger.kernel.org; Tue, 20 Dec 2016 14:12:14 EST Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; From: Roman Kagan To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , "K. Y. Srinivasan" , Vitaly Kuznetsov CC: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , , Haiyang Zhang , , , , "Denis V . Lunev" , Roman Kagan Subject: [PATCH 01/15] hyperv: consolidate TSC ref page definitions Date: Tue, 20 Dec 2016 18:55:48 +0300 Message-ID: <20161220155602.6298-2-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161220155602.6298-1-rkagan@virtuozzo.com> References: <20161220155602.6298-1-rkagan@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AM4PR01CA0030.eurprd01.prod.exchangelabs.com (10.164.74.168) To VI1PR0802MB2478.eurprd08.prod.outlook.com (10.175.26.21) X-MS-Office365-Filtering-Correlation-Id: 2ca04ced-be30-4945-42b9-08d428f0c9b3 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:VI1PR0802MB2478; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0802MB2478;3:eWPfaG1QHhXja6saiSJsOnojX3UhibubelsDrhVnGisbF/1o20olQZ4cQ+8p/gZ/+k+Jevueo2uGcJaIfrNcDc/QickQDi2sGgO4y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4NH9dGjx36M/Kq9bp4TghbZxjK6tkr6Luy9msb+4krK2OOP9e71gtZ9Pd8CsUN7APbPSEUz7UeGk9s27MBMeDvX/bsmUdccjYHB1fgMMgnL+369fSVqHGlndMkvmbMQDey X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6041248)(20161123564025)(20161123555025)(20161123560025)(20161123558021)(20161123562025)(6072148);SRVR:VI1PR0802MB2478;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0802MB2478; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0802MB2478;4:J+vj6UPez7xIN1m+6Jg4HWAqR881PpDSf8Sl2wDonAIzleYB8L6rCx5y6JdXVjHTlCXSD1yNRhlD5YLLTz/p16TfWRAN5WAYXxx0IHWadYOI3vVDtCmu+zcHfEId1tVmoOfLkXNY5PMoHXtiOh/VTCYIyojL1vHf6LsY09NGKJxudusM7TKBexsJtv5t2l3B34gqH7JAAOCu6KCoEnO3yRTrZgO1P6TwV4rg8ZPpMfniB5L/2aWABK4CK36l8pUgzTN6c8EYOdzd0z2+uaRHFuUAvNrxvdOlGRGT4aTTOu/elzykwFNMs5tGPVZn1s23HW7LIXN835LqEF63ZOicbtKjB28WgfEV4BUZ6KqhWcFoyfw9eGU6OFoNuwdLRP5NinOItM3hFJ7QokuBzbjmKo2SDWqaWAd1bV5aNAuD3wHlhKLaK6QPPftEjQ+oNrvJbZaecIorRe7r2fKUSfq7A6QSnK7WzgJz7UqwY9FYHqenwqh+iKGlXArolXqTLeURaxaQ3yLENF7LhNwoLJuB0R8R/Ev/Q8JIDKln2WcMN+Y9V/dpVVdMRwqSZMaQqvLg7nG1/QekxOeKt04WdCzQqRLFNWc+7sWvnXWMUpA+tms= X-Forefront-PRVS: 0162ACCC24 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(7916002)(39450400003)(199003)(189002)(6666003)(97736004)(189998001)(101416001)(5001770100001)(4001430100002)(5003940100001)(36756003)(81166006)(47776003)(50986999)(66066001)(1511001)(2950100002)(50466002)(76176999)(5660300001)(81156014)(2906002)(8666005)(305945005)(69596002)(48376002)(7736002)(92566002)(7416002)(106356001)(53416004)(25786008)(6116002)(105586002)(6486002)(2421001)(6506006)(1076002)(3846002)(86362001)(4326007)(68736007)(8676002)(50226002)(42186005)(107886002)(2561002)(38730400001)(6512006)(33646002);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0802MB2478;H:rkaganb.sw.ru;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;VI1PR0802MB2478;23:F+Km2DaHcOjGH6DjtS/7zBcBRxlwHZ6Yc698xqO?= =?us-ascii?Q?KeLEtNvNoAEYJzVtD4myVWbSfP+h2lG0fDhrutygQ/4BNWJ+4YIopcaq13Gi?= =?us-ascii?Q?/B2Mz+oE2qAL3dgTbDKKk12w6cCXzYkD5Xa+KYD4YCU+Fv3I2ZTCpckScSSA?= =?us-ascii?Q?/Z7q2FFbYbhUr5NkXWUUjo1S2E7FomdxNzYXaZShv4G0QHUGKc9E6dUAlQXR?= =?us-ascii?Q?Z6X/sUXimv+jIqZnbv1oh0l0x+e5Q/g5O2k+Y9wMj1GplRfhJsscusKZ8nQ5?= =?us-ascii?Q?1FNcR5BDulHXwHKB6+Hh0qVFsMwimMlT1eWUA01kQa151CTJ+/LPT/qJjtuI?= =?us-ascii?Q?SdZ0nmBkD/KJyvKLkvBLPEjdRrHsdXYLqgPTGFsr1pUvDMFTTec9FbTQGOVc?= =?us-ascii?Q?fuaGXj8iP1c6FfmyX+VsRpSJA2/DRQ0cNqUfRyWaidJoS/3ZzF2q8ad0JLdS?= =?us-ascii?Q?GxMhAprDl3Rq1U0XHR2deMDHwTFQ0xo/AE/P/vXcpiZy7n+hrkQxysPoiKjV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jeCiro31Cbq0TXE/hx46gjblnGc3Jn810cEGgvsg1Dr6cSJo47c0VOR/RsIRjowawb6slnnHOzpWWeF62LR6dQ==;20:fjdnLh3vB1ueQrlJKA2PFt8aPMBcF8Qh6/eqqZ/HR8uEcF29Qhmr2/R+MopKNY8K1OKJmQMYWEjhqwKrxDAZffckPoOsNgtlmNzUQXnqrpEqvXq4uQGom/pi2Dx3cwH3Thl8+RuWEM3YwGejzUNbv7iyFclpGUDf4b5R1Vz0I4o=;23:zQ6wUHcx+OBhGF45azRbH4pC3H778ZJWBleUXE+JpvvfhPCp3p8Pd2L5K1YWlvtqTaX7gWSAbe3nlkzQ1KjinIGkd/YuIpVDAZcbSia7unClF/Pxg757ntdQuN6XXvGp+gLHOBS5Ni9WVVQ5t58+dw== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Dec 2016 15:56:39.6994 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2478 X-OriginatorOrg: virtuozzo.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4464 Lines: 156 Consolidate the guest-side and kvm-side definitions for Hyper-V TSC reference page. While at this, rewrite read_hv_clock_tsc using the existing helpers. Signed-off-by: Roman Kagan --- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/include/uapi/asm/hyperv.h | 4 +-- drivers/hv/hyperv_vmbus.h | 8 ------ arch/x86/kvm/hyperv.c | 4 +-- drivers/hv/hv.c | 54 +++++++++++++++----------------------- 5 files changed, 26 insertions(+), 46 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 2e25038..2b85f49 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -713,7 +713,7 @@ struct kvm_hv { u64 hv_crash_param[HV_X64_MSR_CRASH_PARAMS]; u64 hv_crash_ctl; - HV_REFERENCE_TSC_PAGE tsc_ref; + struct hv_ref_tsc_page tsc_ref; }; struct kvm_arch { diff --git a/arch/x86/include/uapi/asm/hyperv.h b/arch/x86/include/uapi/asm/hyperv.h index 9b1a918..6098ab5 100644 --- a/arch/x86/include/uapi/asm/hyperv.h +++ b/arch/x86/include/uapi/asm/hyperv.h @@ -252,12 +252,12 @@ #define HV_STATUS_INVALID_CONNECTION_ID 18 #define HV_STATUS_INSUFFICIENT_BUFFERS 19 -typedef struct _HV_REFERENCE_TSC_PAGE { +struct hv_ref_tsc_page { __u32 tsc_sequence; __u32 res1; __u64 tsc_scale; __s64 tsc_offset; -} HV_REFERENCE_TSC_PAGE, *PHV_REFERENCE_TSC_PAGE; +}; /* Define the number of synthetic interrupt sources. */ #define HV_SYNIC_SINT_COUNT (16) diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index 0675b39..4516498 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -475,14 +475,6 @@ struct hv_context { extern struct hv_context hv_context; -struct ms_hyperv_tsc_page { - volatile u32 tsc_sequence; - u32 reserved1; - volatile u64 tsc_scale; - volatile s64 tsc_offset; - u64 reserved2[509]; -}; - struct hv_ring_buffer_debug_info { u32 current_interrupt_mask; u32 current_read_index; diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 1572c35..c7db112 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -806,7 +806,7 @@ static int kvm_hv_msr_set_crash_data(struct kvm_vcpu *vcpu, * These two equivalencies are implemented in this function. */ static bool compute_tsc_page_parameters(struct pvclock_vcpu_time_info *hv_clock, - HV_REFERENCE_TSC_PAGE *tsc_ref) + struct hv_ref_tsc_page *tsc_ref) { u64 max_mul; @@ -847,7 +847,7 @@ void kvm_hv_setup_tsc_page(struct kvm *kvm, u64 gfn; BUILD_BUG_ON(sizeof(tsc_seq) != sizeof(hv->tsc_ref.tsc_sequence)); - BUILD_BUG_ON(offsetof(HV_REFERENCE_TSC_PAGE, tsc_sequence) != 0); + BUILD_BUG_ON(offsetof(struct hv_ref_tsc_page, tsc_sequence) != 0); if (!(hv->hv_tsc_page & HV_X64_MSR_TSC_REFERENCE_ENABLE)) return; diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 446802a..a7256ec 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -137,41 +137,29 @@ EXPORT_SYMBOL_GPL(hv_do_hypercall); #ifdef CONFIG_X86_64 static cycle_t read_hv_clock_tsc(struct clocksource *arg) { - cycle_t current_tick; - struct ms_hyperv_tsc_page *tsc_pg = hv_context.tsc_page; + struct hv_ref_tsc_page *tsc_pg = hv_context.tsc_page; + u32 sequence; + u64 scale; + s64 offset; + + do { + sequence = tsc_pg->tsc_sequence; + virt_rmb(); + + if (!sequence) { + /* fallback to MSR */ + cycle_t current_tick; + rdmsrl(HV_X64_MSR_TIME_REF_COUNT, current_tick); + return current_tick; + } - if (tsc_pg->tsc_sequence != 0) { - /* - * Use the tsc page to compute the value. - */ + scale = tsc_pg->tsc_scale; + offset = tsc_pg->tsc_offset; - while (1) { - cycle_t tmp; - u32 sequence = tsc_pg->tsc_sequence; - u64 cur_tsc; - u64 scale = tsc_pg->tsc_scale; - s64 offset = tsc_pg->tsc_offset; - - rdtscll(cur_tsc); - /* current_tick = ((cur_tsc *scale) >> 64) + offset */ - asm("mulq %3" - : "=d" (current_tick), "=a" (tmp) - : "a" (cur_tsc), "r" (scale)); - - current_tick += offset; - if (tsc_pg->tsc_sequence == sequence) - return current_tick; - - if (tsc_pg->tsc_sequence != 0) - continue; - /* - * Fallback using MSR method. - */ - break; - } - } - rdmsrl(HV_X64_MSR_TIME_REF_COUNT, current_tick); - return current_tick; + virt_rmb(); + } while (tsc_pg->tsc_sequence != sequence); + + return mul_u64_u64_shr(rdtsc_ordered(), scale, 64) + offset; } static struct clocksource hyperv_cs_tsc = { -- 2.9.3