Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clocksource/drivers/hyperv: Allocate Hyper-V TSC page statically

Prepare to add Hyper-V sched clock callback and move Hyper-V Reference TSC
initialization much earlier in the boot process. Earlier initialization is
needed so that it happens while the timestamp value is still 0 and no
discontinuity in the timestamp will occur when pv_ops.time.sched_clock
calculates its offset.

The earlier initialization requires that the Hyper-V TSC page be allocated
statically instead of with vmalloc(), so fixup the references to the TSC
page and the method of getting its physical address.

Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lkml.kernel.org/r/20190814123216.32245-2-Tianyu.Lan@microsoft.com

authored by

Tianyu Lan and committed by
Thomas Gleixner
adb87ff4 dce3e8fd

+5 -9
+1 -1
arch/x86/entry/vdso/vma.c
··· 122 122 123 123 if (tsc_pg && vclock_was_used(VCLOCK_HVCLOCK)) 124 124 return vmf_insert_pfn(vma, vmf->address, 125 - vmalloc_to_pfn(tsc_pg)); 125 + virt_to_phys(tsc_pg) >> PAGE_SHIFT); 126 126 } 127 127 128 128 return VM_FAULT_SIGBUS;
+4 -8
drivers/clocksource/hyperv_timer.c
··· 214 214 215 215 #ifdef CONFIG_HYPERV_TSCPAGE 216 216 217 - static struct ms_hyperv_tsc_page *tsc_pg; 217 + static struct ms_hyperv_tsc_page tsc_pg __aligned(PAGE_SIZE); 218 218 219 219 struct ms_hyperv_tsc_page *hv_get_tsc_page(void) 220 220 { 221 - return tsc_pg; 221 + return &tsc_pg; 222 222 } 223 223 EXPORT_SYMBOL_GPL(hv_get_tsc_page); 224 224 225 225 static u64 notrace read_hv_sched_clock_tsc(void) 226 226 { 227 - u64 current_tick = hv_read_tsc_page(tsc_pg); 227 + u64 current_tick = hv_read_tsc_page(&tsc_pg); 228 228 229 229 if (current_tick == U64_MAX) 230 230 hv_get_time_ref_count(current_tick); ··· 280 280 if (!(ms_hyperv.features & HV_MSR_REFERENCE_TSC_AVAILABLE)) 281 281 return false; 282 282 283 - tsc_pg = vmalloc(PAGE_SIZE); 284 - if (!tsc_pg) 285 - return false; 286 - 287 283 hyperv_cs = &hyperv_cs_tsc; 288 - phys_addr = page_to_phys(vmalloc_to_page(tsc_pg)); 284 + phys_addr = virt_to_phys(&tsc_pg); 289 285 290 286 /* 291 287 * The Hyper-V TLFS specifies to preserve the value of reserved