From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932870AbbLNW3s (ORCPT ); Mon, 14 Dec 2015 17:29:48 -0500 Received: from p3plsmtps2ded03.prod.phx3.secureserver.net ([208.109.80.60]:55432 "EHLO p3plsmtps2ded03.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753664AbbLNW2Y (ORCPT ); Mon, 14 Dec 2015 17:28:24 -0500 x-originating-ip: 72.167.245.219 From: "K. Y. Srinivasan" To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, vkuznets@redhat.com, jasowang@redhat.com Cc: Andrey Smetanin , "Denis V. Lunev" , "K. Y. Srinivasan" , Haiyang Zhang Subject: [PATCH RESEND 24/27] drivers/hv: correct tsc page sequence invalid value Date: Mon, 14 Dec 2015 16:01:55 -0800 Message-Id: <1450137718-26366-24-git-send-email-kys@microsoft.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1450137718-26366-1-git-send-email-kys@microsoft.com> References: <1450137698-26327-1-git-send-email-kys@microsoft.com> <1450137718-26366-1-git-send-email-kys@microsoft.com> X-CMAE-Envelope: MS4wfBBaso3cnwBoULYVrNHcgODVk6adbsox0n+Ld4AM11r4lc6YWmS4am0k1Q1EjrrLaDcenJ5JtsKGQIvLg4z/KoO9+6Drx4AwIolDPCTWXiiDjEk4NKLM MG8ADS0GA628ounJtm/7smq01mmrPljoaU0tWzukZvwb2W05HvpfxckMVu2NAfAI4H8br/uuBe03cGvDEKTd6iUv6RvWSu64yzxD1mL4yBa8sof+sdO0QsPr LKhwJwqJ1HQ/6IRyj/NdgO5e5mphU8i5NfVe+Pzl6XhLdBk8eL0/NtZOUT/dP6E2YQUj2PHX25Bqs5xl8NMd+zwyGrN0EKhKnf0Nxeb+OymZ9EpT7Zr+2dHr T1Uv6KH6ciwMgvjRrLZYdAnMsmTE9upbvRQGKbh8VMPAiJITCd3LrLwmMLeOVnU1ognOiYd7d8hMa34T5lzssLQRN5/Oggrtt4BE5Vg+Z980k83BC95ZdLn8 fJLuPx3J/2cpljA5cLsneQa9U7NckiMqAqMpHA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Smetanin Hypervisor Top Level Functional Specification v3/4 says that TSC page sequence value = -1(0xFFFFFFFF) is used to indicate that TSC page no longer reliable source of reference timer. Unfortunately, we found that Windows Hyper-V guest side implementation uses sequence value = 0 to indicate that Tsc page no longer valid. This is clearly visible inside Windows 2012R2 ntoskrnl.exe HvlGetReferenceTime() function dissassembly: HvlGetReferenceTime proc near xchg ax, ax loc_1401C3132: mov rax, cs:HvlpReferenceTscPage mov r9d, [rax] test r9d, r9d jz short loc_1401C3176 rdtsc mov rcx, cs:HvlpReferenceTscPage shl rdx, 20h or rdx, rax mov rax, [rcx+8] mov rcx, cs:HvlpReferenceTscPage mov r8, [rcx+10h] mul rdx mov rax, cs:HvlpReferenceTscPage add rdx, r8 mov ecx, [rax] cmp ecx, r9d jnz short loc_1401C3132 jmp short loc_1401C3184 loc_1401C3176: mov ecx, 40000020h rdmsr shl rdx, 20h or rdx, rax loc_1401C3184: mov rax, rdx retn HvlGetReferenceTime endp This patch aligns Tsc page invalid sequence value with Windows Hyper-V guest implementation which is more compatible with both Hyper-V hypervisor and KVM hypervisor. Signed-off-by: Andrey Smetanin Signed-off-by: Denis V. Lunev CC: "K. Y. Srinivasan" CC: Haiyang Zhang CC: Vitaly Kuznetsov Signed-off-by: Denis V. Lunev Signed-off-by: K. Y. Srinivasan --- drivers/hv/hv.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 7a06933..1db9556 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -140,7 +140,7 @@ 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; - if (tsc_pg->tsc_sequence != -1) { + if (tsc_pg->tsc_sequence != 0) { /* * Use the tsc page to compute the value. */ @@ -162,7 +162,7 @@ static cycle_t read_hv_clock_tsc(struct clocksource *arg) if (tsc_pg->tsc_sequence == sequence) return current_tick; - if (tsc_pg->tsc_sequence != -1) + if (tsc_pg->tsc_sequence != 0) continue; /* * Fallback using MSR method. -- 1.7.4.1