[SRU][O:linux-azure][PATCH 1/1] Revert "UBUNTU: SAUCE: clocksource: hyper-v: Use InvariantTSC and enable TSC page for a TDX VM without paravisor"
John Cabaj
john.cabaj at canonical.com
Thu Mar 27 19:58:12 UTC 2025
BugLink: https://bugs.launchpad.net/bugs/2104836
This reverts commit 8e5f337e87d07427d229736d7b9678aa2472e1e2.
Upstream 7f828d5fff7d: "clocksource: hyper-v: Use lapic timer
in a TDX VM without paravisor" has since been committed to Ubuntu
kernels 6.8 and newer, which removes the need for this SAUCE patch.
Signed-off-by: John Cabaj <john.cabaj at canonical.com>
---
arch/x86/entry/vdso/vma.c | 11 +++--------
arch/x86/kernel/cpu/mshyperv.c | 8 ++++++++
drivers/clocksource/hyperv_timer.c | 16 ++--------------
3 files changed, 13 insertions(+), 22 deletions(-)
diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c
index fe831afea305..6d83ceb7f1ba 100644
--- a/arch/x86/entry/vdso/vma.c
+++ b/arch/x86/entry/vdso/vma.c
@@ -17,7 +17,6 @@
#include <linux/time_namespace.h>
#include <asm/pvclock.h>
-#include <asm/mshyperv.h>
#include <asm/vgtod.h>
#include <asm/proto.h>
#include <asm/vdso.h>
@@ -190,13 +189,9 @@ static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
}
} else if (sym_offset == image->sym_hvclock_page) {
pfn = hv_get_tsc_pfn();
- if (pfn && vclock_was_used(VDSO_CLOCKMODE_HVCLOCK)) {
- if (ms_hyperv.paravisor_present)
- return vmf_insert_pfn(vma, vmf->address, pfn);
- else
- return vmf_insert_pfn_prot(vma, vmf->address,
- pfn, pgprot_decrypted(vma->vm_page_prot));
- }
+
+ if (pfn && vclock_was_used(VDSO_CLOCKMODE_HVCLOCK))
+ return vmf_insert_pfn(vma, vmf->address, pfn);
} else if (sym_offset == image->sym_timens_page) {
struct page *timens_page = find_timens_vvar_page(vma);
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 290dcae609c8..e8e25d6e64cd 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -507,6 +507,14 @@ static void __init ms_hyperv_init_platform(void)
ms_hyperv.hints &= ~HV_X64_APIC_ACCESS_RECOMMENDED;
if (!ms_hyperv.paravisor_present) {
+ /*
+ * Mark the Hyper-V TSC page feature as disabled
+ * in a TDX VM without paravisor so that the
+ * Invariant TSC, which is a better clocksource
+ * anyway, is used instead.
+ */
+ ms_hyperv.features &= ~HV_MSR_REFERENCE_TSC_AVAILABLE;
+
/*
* The Invariant TSC is expected to be available
* in a TDX VM without paravisor, but if not,
diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c
index 513f1510fc4a..b39dee7b93af 100644
--- a/drivers/clocksource/hyperv_timer.c
+++ b/drivers/clocksource/hyperv_timer.c
@@ -22,7 +22,6 @@
#include <linux/irq.h>
#include <linux/acpi.h>
#include <linux/hyperv.h>
-#include <linux/set_memory.h>
#include <clocksource/hyperv_timer.h>
#include <asm/hyperv-tlfs.h>
#include <asm/mshyperv.h>
@@ -405,8 +404,8 @@ static __always_inline u64 read_hv_clock_msr(void)
static union {
struct ms_hyperv_tsc_page page;
- u8 reserved[SZ_2M];
-} tsc_pg __bss_decrypted __aligned(SZ_2M);
+ u8 reserved[PAGE_SIZE];
+} tsc_pg __bss_decrypted __aligned(PAGE_SIZE);
static struct ms_hyperv_tsc_page *tsc_page = &tsc_pg.page;
static unsigned long tsc_pfn;
@@ -547,7 +546,6 @@ static __always_inline void hv_setup_sched_clock(void *sched_clock) {}
static void __init hv_init_tsc_clocksource(void)
{
union hv_reference_tsc_msr tsc_msr;
- int ret;
/*
* If Hyper-V offers TSC_INVARIANT, then the virtualized TSC correctly
@@ -567,12 +565,6 @@ static void __init hv_init_tsc_clocksource(void)
hv_read_reference_counter = read_hv_clock_tsc;
- if (hv_isolation_type_tdx() && !ms_hyperv.paravisor_present) {
- ret = set_memory_decrypted((unsigned long)tsc_page, SZ_2M/PAGE_SIZE);
- BUG_ON(ret);
- memset(tsc_page, 0, PAGE_SIZE);
- }
-
/*
* TSC page mapping works differently in root compared to guest.
* - In guest partition the guest PFN has to be passed to the
@@ -596,10 +588,6 @@ static void __init hv_init_tsc_clocksource(void)
tsc_pfn = HVPFN_DOWN(virt_to_phys(tsc_page));
tsc_msr.enable = 1;
tsc_msr.pfn = tsc_pfn;
-
- if (hv_isolation_type_tdx() && !ms_hyperv.paravisor_present)
- tsc_msr.pfn = PHYS_PFN(cc_mkdec(PFN_PHYS(tsc_msr.pfn)));
-
hv_set_msr(HV_MSR_REFERENCE_TSC, tsc_msr.as_uint64);
clocksource_register_hz(&hyperv_cs_tsc, NSEC_PER_SEC/100);
--
2.43.0
More information about the kernel-team
mailing list