Skip to content

Commit 2dc1733

Browse files
committed
Merge branch 'x86-hyperv-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86/hyperv changes from Ingo Molnar: "These changes enable Linux guests to boot as 'Modern VM' guest kernels on MS-Hyperv hosts" * 'x86-hyperv-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86, hyperv: Move a variable to avoid an unused variable warning x86, hyperv: Fix build error due to missing <asm/apic.h> include x86, hyperv: Correctly guard the local APIC calibration code x86, hyperv: Get the local APIC timer frequency from the hypervisor
2 parents 69019d7 + 4c08edd commit 2dc1733

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

arch/x86/include/uapi/asm/hyperv.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@
2727
#define HV_X64_MSR_VP_RUNTIME_AVAILABLE (1 << 0)
2828
/* Partition Reference Counter (HV_X64_MSR_TIME_REF_COUNT) available*/
2929
#define HV_X64_MSR_TIME_REF_COUNT_AVAILABLE (1 << 1)
30+
31+
/*
32+
* There is a single feature flag that signifies the presence of the MSR
33+
* that can be used to retrieve both the local APIC Timer frequency as
34+
* well as the TSC frequency.
35+
*/
36+
37+
/* Local APIC timer frequency MSR (HV_X64_MSR_APIC_FREQUENCY) is available */
38+
#define HV_X64_MSR_APIC_FREQUENCY_AVAILABLE (1 << 11)
39+
40+
/* TSC frequency MSR (HV_X64_MSR_TSC_FREQUENCY) is available */
41+
#define HV_X64_MSR_TSC_FREQUENCY_AVAILABLE (1 << 11)
42+
3043
/*
3144
* Basic SynIC MSRs (HV_X64_MSR_SCONTROL through HV_X64_MSR_EOM
3245
* and HV_X64_MSR_SINT0 through HV_X64_MSR_SINT15) available
@@ -136,6 +149,12 @@
136149
/* MSR used to read the per-partition time reference counter */
137150
#define HV_X64_MSR_TIME_REF_COUNT 0x40000020
138151

152+
/* MSR used to retrieve the TSC frequency */
153+
#define HV_X64_MSR_TSC_FREQUENCY 0x40000022
154+
155+
/* MSR used to retrieve the local APIC timer frequency */
156+
#define HV_X64_MSR_APIC_FREQUENCY 0x40000023
157+
139158
/* Define the virtual APIC registers */
140159
#define HV_X64_MSR_EOI 0x40000070
141160
#define HV_X64_MSR_ICR 0x40000071

arch/x86/kernel/cpu/mshyperv.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/clocksource.h>
1616
#include <linux/module.h>
1717
#include <linux/hardirq.h>
18+
#include <linux/efi.h>
1819
#include <linux/interrupt.h>
1920
#include <asm/processor.h>
2021
#include <asm/hypervisor.h>
@@ -23,6 +24,8 @@
2324
#include <asm/desc.h>
2425
#include <asm/idle.h>
2526
#include <asm/irq_regs.h>
27+
#include <asm/i8259.h>
28+
#include <asm/apic.h>
2629

2730
struct ms_hyperv_info ms_hyperv;
2831
EXPORT_SYMBOL_GPL(ms_hyperv);
@@ -76,6 +79,30 @@ static void __init ms_hyperv_init_platform(void)
7679
printk(KERN_INFO "HyperV: features 0x%x, hints 0x%x\n",
7780
ms_hyperv.features, ms_hyperv.hints);
7881

82+
#ifdef CONFIG_X86_LOCAL_APIC
83+
if (ms_hyperv.features & HV_X64_MSR_APIC_FREQUENCY_AVAILABLE) {
84+
/*
85+
* Get the APIC frequency.
86+
*/
87+
u64 hv_lapic_frequency;
88+
89+
rdmsrl(HV_X64_MSR_APIC_FREQUENCY, hv_lapic_frequency);
90+
hv_lapic_frequency = div_u64(hv_lapic_frequency, HZ);
91+
lapic_timer_frequency = hv_lapic_frequency;
92+
printk(KERN_INFO "HyperV: LAPIC Timer Frequency: %#x\n",
93+
lapic_timer_frequency);
94+
95+
/*
96+
* On Hyper-V, when we are booting off an EFI firmware stack,
97+
* we do not have many legacy devices including PIC, PIT etc.
98+
*/
99+
if (efi_enabled(EFI_BOOT)) {
100+
printk(KERN_INFO "HyperV: Using null_legacy_pic\n");
101+
legacy_pic = &null_legacy_pic;
102+
}
103+
}
104+
#endif
105+
79106
if (ms_hyperv.features & HV_X64_MSR_TIME_REF_COUNT_AVAILABLE)
80107
clocksource_register_hz(&hyperv_cs, NSEC_PER_SEC/100);
81108
}

0 commit comments

Comments
 (0)