From nobody Thu Apr 9 01:52:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05149C4332F for ; Tue, 1 Nov 2022 17:31:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229936AbiKARbJ (ORCPT ); Tue, 1 Nov 2022 13:31:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbiKARbF (ORCPT ); Tue, 1 Nov 2022 13:31:05 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F0C1B1C12E; Tue, 1 Nov 2022 10:31:04 -0700 (PDT) Received: from skinsburskii-cloud-desktop.internal.cloudapp.net (unknown [20.120.152.163]) by linux.microsoft.com (Postfix) with ESMTPSA id BA3F720B929F; Tue, 1 Nov 2022 10:31:04 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com BA3F720B929F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667323864; bh=VzS0zv6W20Ej0nTKmhHcYF4peM529wVUYDvHRYTK7Zc=; h=Subject:From:Cc:Date:In-Reply-To:References:From; b=OyhwJotSpjmdF+Oolz000h3Z0kXNjN6e/hid2wcKbrphgqXY6so+O9uyRXTZvDsHk bz4agA5yLzbTOoB5abTL+ykPmlkTgFOYZRIo+MNGwnatX9ygaMEXpsdltXiTK2IJO+ 7VnnAPds0Vrvx7hWsYI/94joKNq4piiP0uOjusvQ= Subject: [PATCH 1/4] drivers/clocksource/hyper-v: Introduce a pointer to TSC page From: Stanislav Kinsburskii Cc: Stanislav Kinsburskiy , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Daniel Lezcano , Thomas Gleixner , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 01 Nov 2022 17:31:04 +0000 Message-ID: <166732386464.9827.16622091938453285710.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> In-Reply-To: <166732356767.9827.4925884794177179249.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> References: <166732356767.9827.4925884794177179249.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stanislav Kinsburskiy Will be used later keep the address of the remapped page for the root partition. Signed-off-by: Stanislav Kinsburskiy CC: "K. Y. Srinivasan" CC: Haiyang Zhang CC: Wei Liu CC: Dexuan Cui CC: Daniel Lezcano CC: Thomas Gleixner CC: linux-hyperv@vger.kernel.org CC: linux-kernel@vger.kernel.org --- drivers/clocksource/hyperv_timer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyper= v_timer.c index 11332c82d1af..c4dbf40a3d3e 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -366,9 +366,11 @@ static union { u8 reserved[PAGE_SIZE]; } tsc_pg __aligned(PAGE_SIZE); =20 +static struct ms_hyperv_tsc_page *tsc_page =3D &tsc_pg.page; + struct ms_hyperv_tsc_page *hv_get_tsc_page(void) { - return &tsc_pg.page; + return tsc_page; } EXPORT_SYMBOL_GPL(hv_get_tsc_page); =20 @@ -406,7 +408,7 @@ static void suspend_hv_clock_tsc(struct clocksource *ar= g) =20 static void resume_hv_clock_tsc(struct clocksource *arg) { - phys_addr_t phys_addr =3D virt_to_phys(&tsc_pg); + phys_addr_t phys_addr =3D virt_to_phys(tsc_page); union hv_reference_tsc_msr tsc_msr; =20 /* Re-enable the TSC page */ From nobody Thu Apr 9 01:52:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDBA0C4332F for ; Tue, 1 Nov 2022 17:31:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230401AbiKARbP (ORCPT ); Tue, 1 Nov 2022 13:31:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230336AbiKARbK (ORCPT ); Tue, 1 Nov 2022 13:31:10 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 37BA81C12E; Tue, 1 Nov 2022 10:31:10 -0700 (PDT) Received: from skinsburskii-cloud-desktop.internal.cloudapp.net (unknown [20.120.152.163]) by linux.microsoft.com (Postfix) with ESMTPSA id 015D020B9F80; Tue, 1 Nov 2022 10:31:10 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 015D020B9F80 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667323870; bh=bFl7hxOTym7GqSMmVRUZEZkOBSvYSKk8SZ3l7c9kTt0=; h=Subject:From:Cc:Date:In-Reply-To:References:From; b=deE016wC5+YZS1tkfB6MHf6jU2aGMN8r/UhID9NTOJTMryK/FiDlGWJs5UkTizutP 6wKGTwsglpOa2Jt1Qn+bwUopxVBWRSqUkJrw70WULOF4cnK5DeOpjphyApNwtJNPCt ziWczGn7W8uQ1zWo0OrkGg2kHrDIGD2ljKfo5fP4= Subject: [PATCH 2/4] drivers/clocksource/hyper-v: Introduce TSC MSR register structure From: Stanislav Kinsburskii Cc: Stanislav Kinsburskiy , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Daniel Lezcano , Thomas Gleixner , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 01 Nov 2022 17:31:09 +0000 Message-ID: <166732386986.9827.12356845572628674464.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> In-Reply-To: <166732356767.9827.4925884794177179249.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> References: <166732356767.9827.4925884794177179249.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stanislav Kinsburskiy And rework the code to use it instead of the physical address. This is a cleanup and precursor patch for upcoming support for TSC page mapping into hyper-v root partition. Signed-off-by: Stanislav Kinsburskiy CC: "K. Y. Srinivasan" CC: Haiyang Zhang CC: Wei Liu CC: Dexuan Cui CC: Daniel Lezcano CC: Thomas Gleixner CC: linux-hyperv@vger.kernel.org CC: linux-kernel@vger.kernel.org --- drivers/clocksource/hyperv_timer.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyper= v_timer.c index c4dbf40a3d3e..d447bc99a399 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -367,6 +367,12 @@ static union { } tsc_pg __aligned(PAGE_SIZE); =20 static struct ms_hyperv_tsc_page *tsc_page =3D &tsc_pg.page; +static unsigned long tsc_pfn; + +static unsigned long hv_get_tsc_pfn(void) +{ + return tsc_pfn; +} =20 struct ms_hyperv_tsc_page *hv_get_tsc_page(void) { @@ -408,13 +414,12 @@ static void suspend_hv_clock_tsc(struct clocksource *= arg) =20 static void resume_hv_clock_tsc(struct clocksource *arg) { - phys_addr_t phys_addr =3D virt_to_phys(tsc_page); union hv_reference_tsc_msr tsc_msr; =20 /* Re-enable the TSC page */ tsc_msr.as_uint64 =3D hv_get_register(HV_REGISTER_REFERENCE_TSC); tsc_msr.enable =3D 1; - tsc_msr.pfn =3D __phys_to_pfn(phys_addr); + tsc_msr.pfn =3D tsc_pfn; hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64); } =20 @@ -498,7 +503,6 @@ static __always_inline void hv_setup_sched_clock(void *= sched_clock) {} static bool __init hv_init_tsc_clocksource(void) { union hv_reference_tsc_msr tsc_msr; - phys_addr_t phys_addr; =20 if (!(ms_hyperv.features & HV_MSR_REFERENCE_TSC_AVAILABLE)) return false; @@ -523,7 +527,7 @@ static bool __init hv_init_tsc_clocksource(void) } =20 hv_read_reference_counter =3D read_hv_clock_tsc; - phys_addr =3D virt_to_phys(hv_get_tsc_page()); + tsc_pfn =3D __phys_to_pfn(virt_to_phys(tsc_page)); =20 /* * The Hyper-V TLFS specifies to preserve the value of reserved @@ -534,7 +538,7 @@ static bool __init hv_init_tsc_clocksource(void) */ tsc_msr.as_uint64 =3D hv_get_register(HV_REGISTER_REFERENCE_TSC); tsc_msr.enable =3D 1; - tsc_msr.pfn =3D __phys_to_pfn(phys_addr); + tsc_msr.pfn =3D tsc_pfn; hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64); =20 clocksource_register_hz(&hyperv_cs_tsc, NSEC_PER_SEC/100); From nobody Thu Apr 9 01:52:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FECEC433FE for ; Tue, 1 Nov 2022 17:31:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230175AbiKARbY (ORCPT ); Tue, 1 Nov 2022 13:31:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230219AbiKARbQ (ORCPT ); Tue, 1 Nov 2022 13:31:16 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7A0821C134; Tue, 1 Nov 2022 10:31:15 -0700 (PDT) Received: from skinsburskii-cloud-desktop.internal.cloudapp.net (unknown [20.120.152.163]) by linux.microsoft.com (Postfix) with ESMTPSA id 4008D20B9F80; Tue, 1 Nov 2022 10:31:15 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4008D20B9F80 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667323875; bh=gzbi2cZL78wkI/YYwutmnQjWwUdGs2YRrCc1CbsM23M=; h=Subject:From:Cc:Date:In-Reply-To:References:From; b=Dp8fRevRUiByRldOLyNZVh3jh0kTfvjocg7HEKUIBtW5U6i32+7W9R6yp9Hp8K4Aa IEz5Ysl9V4PNsmYUWX9CrT+2gUJCmhqJ8k2/fLRLUT6jAFztmV0FuRAY3D5JiIegpV wS5aGv8KQovg4fkkfW6BNdMHQxpF7Sx7g5rH9LYM= Subject: [PATCH 3/4] drivers/clocksource/hyper-v: Use TSC PFN getter to map vvar page From: Stanislav Kinsburskii Cc: Stanislav Kinsburskiy , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Daniel Lezcano , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org Date: Tue, 01 Nov 2022 17:31:15 +0000 Message-ID: <166732387510.9827.8987757583900408743.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> In-Reply-To: <166732356767.9827.4925884794177179249.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> References: <166732356767.9827.4925884794177179249.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stanislav Kinsburskiy Instead of converting the virtual address to physical directly. This is a precursor patch for the upcoming support for TSC page mapping into hyper-v root partition, which address will be defined by the hypervisor and mapped into the kernel. Signed-off-by: Stanislav Kinsburskiy CC: Andy Lutomirski CC: Thomas Gleixner CC: Ingo Molnar CC: Borislav Petkov CC: Dave Hansen CC: x86@kernel.org CC: "H. Peter Anvin" CC: "K. Y. Srinivasan" CC: Haiyang Zhang CC: Wei Liu CC: Dexuan Cui CC: Daniel Lezcano CC: linux-kernel@vger.kernel.org CC: linux-hyperv@vger.kernel.org --- arch/x86/entry/vdso/vma.c | 7 +++---- drivers/clocksource/hyperv_timer.c | 3 ++- include/clocksource/hyperv_timer.h | 6 ++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c index 311eae30e089..6976416b2c9f 100644 --- a/arch/x86/entry/vdso/vma.c +++ b/arch/x86/entry/vdso/vma.c @@ -210,11 +210,10 @@ static vm_fault_t vvar_fault(const struct vm_special_= mapping *sm, pgprot_decrypted(vma->vm_page_prot)); } } else if (sym_offset =3D=3D image->sym_hvclock_page) { - struct ms_hyperv_tsc_page *tsc_pg =3D hv_get_tsc_page(); + pfn =3D hv_get_tsc_pfn(); =20 - if (tsc_pg && vclock_was_used(VDSO_CLOCKMODE_HVCLOCK)) - return vmf_insert_pfn(vma, vmf->address, - virt_to_phys(tsc_pg) >> PAGE_SHIFT); + if (pfn && vclock_was_used(VDSO_CLOCKMODE_HVCLOCK)) + return vmf_insert_pfn(vma, vmf->address, pfn); } else if (sym_offset =3D=3D image->sym_timens_page) { struct page *timens_page =3D find_timens_vvar_page(vma); =20 diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyper= v_timer.c index d447bc99a399..635c14c1e3bf 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -369,10 +369,11 @@ static union { static struct ms_hyperv_tsc_page *tsc_page =3D &tsc_pg.page; static unsigned long tsc_pfn; =20 -static unsigned long hv_get_tsc_pfn(void) +unsigned long hv_get_tsc_pfn(void) { return tsc_pfn; } +EXPORT_SYMBOL_GPL(hv_get_tsc_pfn); =20 struct ms_hyperv_tsc_page *hv_get_tsc_page(void) { diff --git a/include/clocksource/hyperv_timer.h b/include/clocksource/hyper= v_timer.h index b3f5d73ae1d6..3078d23faaea 100644 --- a/include/clocksource/hyperv_timer.h +++ b/include/clocksource/hyperv_timer.h @@ -32,6 +32,7 @@ extern void hv_stimer0_isr(void); =20 extern void hv_init_clocksource(void); =20 +extern unsigned long hv_get_tsc_pfn(void); extern struct ms_hyperv_tsc_page *hv_get_tsc_page(void); =20 static inline notrace u64 @@ -90,6 +91,11 @@ hv_read_tsc_page(const struct ms_hyperv_tsc_page *tsc_pg) } =20 #else /* CONFIG_HYPERV_TIMER */ +static inline unsigned long hv_get_tsc_pfn(void) +{ + return 0; +} + static inline struct ms_hyperv_tsc_page *hv_get_tsc_page(void) { return NULL; From nobody Thu Apr 9 01:52:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAF28C433FE for ; Tue, 1 Nov 2022 17:31:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231178AbiKARbi (ORCPT ); Tue, 1 Nov 2022 13:31:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231132AbiKARbW (ORCPT ); Tue, 1 Nov 2022 13:31:22 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B0C0F1D31C; Tue, 1 Nov 2022 10:31:20 -0700 (PDT) Received: from skinsburskii-cloud-desktop.internal.cloudapp.net (unknown [20.120.152.163]) by linux.microsoft.com (Postfix) with ESMTPSA id 71D84205D3EB; Tue, 1 Nov 2022 10:31:20 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 71D84205D3EB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667323880; bh=sOlQY2pUyFWi2wENkJfU10G+u5gRwNzGxceW9GYqOpg=; h=Subject:From:Cc:Date:In-Reply-To:References:From; b=GhH3juOSsp29jZ7OcIQ3lO2/LaU6A71FAtNf4jw0odfaQA3obTDa4r3TWcYI/VUES 1DcpI4yw0UeUiVgA5RCrLZRmtprO5L2OcRXsqWz8e/IkfkmJtVifwyiRRNe/KD4iTD LNcT1cU8e2ChnxXhIqIvKNZMilA+2iimbLm18JDM= Subject: [PATCH 4/4] drivers/clocksource/hyper-v: Add TSC page support for root partition From: Stanislav Kinsburskii Cc: Stanislav Kinsburskiy , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Daniel Lezcano , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 01 Nov 2022 17:31:20 +0000 Message-ID: <166732388036.9827.17503191387873469301.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> In-Reply-To: <166732356767.9827.4925884794177179249.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> References: <166732356767.9827.4925884794177179249.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stanislav Kinsburskiy It hyper-v root partition guest has to map the page, specified by the hypervisor (instead of providing the page to the hypervisor like it's done = in the guest partitions). However, it's too early to map the page when the clock is initialized, so, = the actual mapping is happening later. Signed-off-by: Stanislav Kinsburskiy CC: "K. Y. Srinivasan" CC: Haiyang Zhang CC: Wei Liu CC: Dexuan Cui CC: Thomas Gleixner CC: Ingo Molnar CC: Borislav Petkov CC: Dave Hansen CC: x86@kernel.org CC: "H. Peter Anvin" CC: Daniel Lezcano CC: linux-hyperv@vger.kernel.org CC: linux-kernel@vger.kernel.org --- arch/x86/hyperv/hv_init.c | 2 ++ drivers/clocksource/hyperv_timer.c | 34 +++++++++++++++++++++++++-------= -- include/clocksource/hyperv_timer.h | 1 + 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index f49bc3ec76e6..89954490af93 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -464,6 +464,8 @@ void __init hyperv_init(void) BUG_ON(!src); memcpy_to_page(pg, 0, src, HV_HYP_PAGE_SIZE); memunmap(src); + + hv_remap_tsc_clocksource(); } else { hypercall_msr.guest_physical_address =3D vmalloc_to_pfn(hv_hypercall_pg); wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyper= v_timer.c index 635c14c1e3bf..4118e4bc9194 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -508,9 +508,6 @@ static bool __init hv_init_tsc_clocksource(void) if (!(ms_hyperv.features & HV_MSR_REFERENCE_TSC_AVAILABLE)) return false; =20 - if (hv_root_partition) - return false; - /* * If Hyper-V offers TSC_INVARIANT, then the virtualized TSC correctly * handles frequency and offset changes due to live migration, @@ -528,16 +525,22 @@ static bool __init hv_init_tsc_clocksource(void) } =20 hv_read_reference_counter =3D read_hv_clock_tsc; - tsc_pfn =3D __phys_to_pfn(virt_to_phys(tsc_page)); =20 /* - * The Hyper-V TLFS specifies to preserve the value of reserved - * bits in registers. So read the existing value, preserve the - * low order 12 bits, and add in the guest physical address - * (which already has at least the low 12 bits set to zero since - * it is page aligned). Also set the "enable" bit, which is bit 0. + * TSC page mapping works differently in root and guest partitions. + * - In guest partition the guest PFN has to be passed to the + * hypervisor. + * - In root partition it's other way around: the guest has to map the + * PFN, provided by the hypervisor. + * But it can't be mapped right here as it's too early and MMU isn't + * ready yet. So, we only set the enable bit here and will remap the + * page later in hv_remap_tsc_clocksource(). */ tsc_msr.as_uint64 =3D hv_get_register(HV_REGISTER_REFERENCE_TSC); + if (hv_root_partition) + tsc_pfn =3D tsc_msr.pfn; + else + tsc_pfn =3D __phys_to_pfn(virt_to_phys(tsc_page)); tsc_msr.enable =3D 1; tsc_msr.pfn =3D tsc_pfn; hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64); @@ -572,3 +575,16 @@ void __init hv_init_clocksource(void) hv_sched_clock_offset =3D hv_read_reference_counter(); hv_setup_sched_clock(read_hv_sched_clock_msr); } + +void __init hv_remap_tsc_clocksource(void) +{ + if (!(ms_hyperv.features & HV_MSR_REFERENCE_TSC_AVAILABLE)) + return; + + if (!hv_root_partition) + return; + + tsc_page =3D memremap(__pfn_to_phys(tsc_pfn), PAGE_SIZE, MEMREMAP_WB); + if (!tsc_page) + pr_err("Failed to remap Hyper-V TSC page.\n"); +} diff --git a/include/clocksource/hyperv_timer.h b/include/clocksource/hyper= v_timer.h index 3078d23faaea..783701a2102d 100644 --- a/include/clocksource/hyperv_timer.h +++ b/include/clocksource/hyperv_timer.h @@ -31,6 +31,7 @@ extern void hv_stimer_global_cleanup(void); extern void hv_stimer0_isr(void); =20 extern void hv_init_clocksource(void); +extern void hv_remap_tsc_clocksource(void); =20 extern unsigned long hv_get_tsc_pfn(void); extern struct ms_hyperv_tsc_page *hv_get_tsc_page(void);