Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
H. Peter Anvin | e08cae4 | 2010-05-07 16:57:28 -0700 | [diff] [blame] | 2 | #ifndef _ASM_X86_MSHYPER_H |
| 3 | #define _ASM_X86_MSHYPER_H |
Ky Srinivasan | a2a47c6 | 2010-05-06 12:08:41 -0700 | [diff] [blame] | 4 | |
H. Peter Anvin | e08cae4 | 2010-05-07 16:57:28 -0700 | [diff] [blame] | 5 | #include <linux/types.h> |
Thomas Gleixner | 26fcd95 | 2017-06-23 10:50:38 +0200 | [diff] [blame] | 6 | #include <linux/atomic.h> |
Vitaly Kuznetsov | 806c892 | 2017-08-02 18:09:17 +0200 | [diff] [blame] | 7 | #include <linux/nmi.h> |
Vitaly Kuznetsov | fc53662 | 2017-08-02 18:09:14 +0200 | [diff] [blame] | 8 | #include <asm/io.h> |
H. Peter Anvin | e08cae4 | 2010-05-07 16:57:28 -0700 | [diff] [blame] | 9 | #include <asm/hyperv.h> |
| 10 | |
K. Y. Srinivasan | 8de8af7 | 2017-01-19 11:51:47 -0700 | [diff] [blame] | 11 | /* |
| 12 | * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent |
| 13 | * is set by CPUID(HVCPUID_VERSION_FEATURES). |
| 14 | */ |
| 15 | enum hv_cpuid_function { |
| 16 | HVCPUID_VERSION_FEATURES = 0x00000001, |
| 17 | HVCPUID_VENDOR_MAXFUNCTION = 0x40000000, |
| 18 | HVCPUID_INTERFACE = 0x40000001, |
| 19 | |
| 20 | /* |
| 21 | * The remaining functions depend on the value of |
| 22 | * HVCPUID_INTERFACE |
| 23 | */ |
| 24 | HVCPUID_VERSION = 0x40000002, |
| 25 | HVCPUID_FEATURES = 0x40000003, |
| 26 | HVCPUID_ENLIGHTENMENT_INFO = 0x40000004, |
| 27 | HVCPUID_IMPLEMENTATION_LIMITS = 0x40000005, |
| 28 | }; |
| 29 | |
H. Peter Anvin | e08cae4 | 2010-05-07 16:57:28 -0700 | [diff] [blame] | 30 | struct ms_hyperv_info { |
| 31 | u32 features; |
Denis V. Lunev | cc2dd40 | 2015-08-01 16:08:20 -0700 | [diff] [blame] | 32 | u32 misc_features; |
H. Peter Anvin | e08cae4 | 2010-05-07 16:57:28 -0700 | [diff] [blame] | 33 | u32 hints; |
Vitaly Kuznetsov | dd01859 | 2017-06-25 10:06:41 -0700 | [diff] [blame] | 34 | u32 max_vp_index; |
| 35 | u32 max_lp_index; |
H. Peter Anvin | e08cae4 | 2010-05-07 16:57:28 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | extern struct ms_hyperv_info ms_hyperv; |
Ky Srinivasan | a2a47c6 | 2010-05-06 12:08:41 -0700 | [diff] [blame] | 39 | |
K. Y. Srinivasan | 3f646ed | 2017-01-18 16:45:00 -0700 | [diff] [blame] | 40 | /* |
| 41 | * Declare the MSR used to setup pages used to communicate with the hypervisor. |
| 42 | */ |
| 43 | union hv_x64_msr_hypercall_contents { |
| 44 | u64 as_uint64; |
| 45 | struct { |
| 46 | u64 enable:1; |
| 47 | u64 reserved:11; |
| 48 | u64 guest_physical_address:52; |
| 49 | }; |
| 50 | }; |
| 51 | |
K. Y. Srinivasan | 352c962 | 2017-01-18 16:45:01 -0700 | [diff] [blame] | 52 | /* |
K. Y. Srinivasan | 63ed4e0 | 2017-01-19 11:51:46 -0700 | [diff] [blame] | 53 | * TSC page layout. |
| 54 | */ |
| 55 | |
| 56 | struct ms_hyperv_tsc_page { |
| 57 | volatile u32 tsc_sequence; |
| 58 | u32 reserved1; |
| 59 | volatile u64 tsc_scale; |
| 60 | volatile s64 tsc_offset; |
| 61 | u64 reserved2[509]; |
| 62 | }; |
| 63 | |
| 64 | /* |
K. Y. Srinivasan | 352c962 | 2017-01-18 16:45:01 -0700 | [diff] [blame] | 65 | * The guest OS needs to register the guest ID with the hypervisor. |
| 66 | * The guest ID is a 64 bit entity and the structure of this ID is |
| 67 | * specified in the Hyper-V specification: |
| 68 | * |
| 69 | * msdn.microsoft.com/en-us/library/windows/hardware/ff542653%28v=vs.85%29.aspx |
| 70 | * |
| 71 | * While the current guideline does not specify how Linux guest ID(s) |
| 72 | * need to be generated, our plan is to publish the guidelines for |
| 73 | * Linux and other guest operating systems that currently are hosted |
| 74 | * on Hyper-V. The implementation here conforms to this yet |
| 75 | * unpublished guidelines. |
| 76 | * |
| 77 | * |
| 78 | * Bit(s) |
| 79 | * 63 - Indicates if the OS is Open Source or not; 1 is Open Source |
| 80 | * 62:56 - Os Type; Linux is 0x100 |
| 81 | * 55:48 - Distro specific identification |
| 82 | * 47:16 - Linux kernel version number |
| 83 | * 15:0 - Distro specific identification |
| 84 | * |
| 85 | * |
| 86 | */ |
| 87 | |
K. Y. Srinivasan | 9b06e10 | 2017-02-04 08:46:23 -0700 | [diff] [blame] | 88 | #define HV_LINUX_VENDOR_ID 0x8100 |
K. Y. Srinivasan | 352c962 | 2017-01-18 16:45:01 -0700 | [diff] [blame] | 89 | |
| 90 | /* |
| 91 | * Generate the guest ID based on the guideline described above. |
| 92 | */ |
| 93 | |
| 94 | static inline __u64 generate_guest_id(__u64 d_info1, __u64 kernel_version, |
| 95 | __u64 d_info2) |
| 96 | { |
| 97 | __u64 guest_id = 0; |
| 98 | |
K. Y. Srinivasan | 9b06e10 | 2017-02-04 08:46:23 -0700 | [diff] [blame] | 99 | guest_id = (((__u64)HV_LINUX_VENDOR_ID) << 48); |
K. Y. Srinivasan | 352c962 | 2017-01-18 16:45:01 -0700 | [diff] [blame] | 100 | guest_id |= (d_info1 << 48); |
| 101 | guest_id |= (kernel_version << 16); |
| 102 | guest_id |= d_info2; |
| 103 | |
| 104 | return guest_id; |
| 105 | } |
| 106 | |
K. Y. Srinivasan | e810e48 | 2017-01-19 11:51:50 -0700 | [diff] [blame] | 107 | |
| 108 | /* Free the message slot and signal end-of-message if required */ |
| 109 | static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type) |
| 110 | { |
| 111 | /* |
| 112 | * On crash we're reading some other CPU's message page and we need |
| 113 | * to be careful: this other CPU may already had cleared the header |
| 114 | * and the host may already had delivered some other message there. |
| 115 | * In case we blindly write msg->header.message_type we're going |
| 116 | * to lose it. We can still lose a message of the same type but |
| 117 | * we count on the fact that there can only be one |
| 118 | * CHANNELMSG_UNLOAD_RESPONSE and we don't care about other messages |
| 119 | * on crash. |
| 120 | */ |
| 121 | if (cmpxchg(&msg->header.message_type, old_msg_type, |
| 122 | HVMSG_NONE) != old_msg_type) |
| 123 | return; |
| 124 | |
| 125 | /* |
| 126 | * Make sure the write to MessageType (ie set to |
| 127 | * HVMSG_NONE) happens before we read the |
| 128 | * MessagePending and EOMing. Otherwise, the EOMing |
| 129 | * will not deliver any more messages since there is |
| 130 | * no empty slot |
| 131 | */ |
| 132 | mb(); |
| 133 | |
| 134 | if (msg->header.message_flags.msg_pending) { |
| 135 | /* |
| 136 | * This will cause message queue rescan to |
| 137 | * possibly deliver another msg from the |
| 138 | * hypervisor |
| 139 | */ |
| 140 | wrmsrl(HV_X64_MSR_EOM, 0); |
| 141 | } |
| 142 | } |
| 143 | |
K. Y. Srinivasan | d5116b4 | 2017-01-19 11:51:51 -0700 | [diff] [blame] | 144 | #define hv_init_timer(timer, tick) wrmsrl(timer, tick) |
| 145 | #define hv_init_timer_config(config, val) wrmsrl(config, val) |
| 146 | |
K. Y. Srinivasan | 155e4a2 | 2017-01-19 11:51:54 -0700 | [diff] [blame] | 147 | #define hv_get_simp(val) rdmsrl(HV_X64_MSR_SIMP, val) |
| 148 | #define hv_set_simp(val) wrmsrl(HV_X64_MSR_SIMP, val) |
| 149 | |
K. Y. Srinivasan | 8e307bf | 2017-01-19 11:51:55 -0700 | [diff] [blame] | 150 | #define hv_get_siefp(val) rdmsrl(HV_X64_MSR_SIEFP, val) |
| 151 | #define hv_set_siefp(val) wrmsrl(HV_X64_MSR_SIEFP, val) |
| 152 | |
K. Y. Srinivasan | 06d1d98 | 2017-01-19 11:51:56 -0700 | [diff] [blame] | 153 | #define hv_get_synic_state(val) rdmsrl(HV_X64_MSR_SCONTROL, val) |
| 154 | #define hv_set_synic_state(val) wrmsrl(HV_X64_MSR_SCONTROL, val) |
| 155 | |
K. Y. Srinivasan | 7297ff0 | 2017-01-19 11:51:57 -0700 | [diff] [blame] | 156 | #define hv_get_vp_index(index) rdmsrl(HV_X64_MSR_VP_INDEX, index) |
| 157 | |
K. Y. Srinivasan | 37e11d5 | 2017-01-19 11:51:58 -0700 | [diff] [blame] | 158 | #define hv_get_synint_state(int_num, val) rdmsrl(int_num, val) |
| 159 | #define hv_set_synint_state(int_num, val) wrmsrl(int_num, val) |
| 160 | |
K. Y. Srinivasan | bc2b033 | 2013-02-03 17:22:39 -0800 | [diff] [blame] | 161 | void hyperv_callback_vector(void); |
Seiji Aguchi | cf910e8 | 2013-06-20 11:46:53 -0400 | [diff] [blame] | 162 | #ifdef CONFIG_TRACING |
| 163 | #define trace_hyperv_callback_vector hyperv_callback_vector |
| 164 | #endif |
K. Y. Srinivasan | bc2b033 | 2013-02-03 17:22:39 -0800 | [diff] [blame] | 165 | void hyperv_vector_handler(struct pt_regs *regs); |
Thomas Gleixner | 76d388c | 2014-03-05 13:42:14 +0100 | [diff] [blame] | 166 | void hv_setup_vmbus_irq(void (*handler)(void)); |
| 167 | void hv_remove_vmbus_irq(void); |
K. Y. Srinivasan | bc2b033 | 2013-02-03 17:22:39 -0800 | [diff] [blame] | 168 | |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 169 | void hv_setup_kexec_handler(void (*handler)(void)); |
| 170 | void hv_remove_kexec_handler(void); |
Vitaly Kuznetsov | b4370df | 2015-08-01 16:08:09 -0700 | [diff] [blame] | 171 | void hv_setup_crash_handler(void (*handler)(struct pt_regs *regs)); |
| 172 | void hv_remove_crash_handler(void); |
K. Y. Srinivasan | 8730046 | 2017-01-18 16:45:02 -0700 | [diff] [blame] | 173 | |
| 174 | #if IS_ENABLED(CONFIG_HYPERV) |
Vitaly Kuznetsov | dee863b | 2017-02-04 09:57:13 -0700 | [diff] [blame] | 175 | extern struct clocksource *hyperv_cs; |
Vitaly Kuznetsov | fc53662 | 2017-08-02 18:09:14 +0200 | [diff] [blame] | 176 | extern void *hv_hypercall_pg; |
| 177 | |
| 178 | static inline u64 hv_do_hypercall(u64 control, void *input, void *output) |
| 179 | { |
| 180 | u64 input_address = input ? virt_to_phys(input) : 0; |
| 181 | u64 output_address = output ? virt_to_phys(output) : 0; |
| 182 | u64 hv_status; |
Vitaly Kuznetsov | fc53662 | 2017-08-02 18:09:14 +0200 | [diff] [blame] | 183 | |
| 184 | #ifdef CONFIG_X86_64 |
| 185 | if (!hv_hypercall_pg) |
| 186 | return U64_MAX; |
| 187 | |
| 188 | __asm__ __volatile__("mov %4, %%r8\n" |
| 189 | "call *%5" |
Josh Poimboeuf | f5caf62 | 2017-09-20 16:24:33 -0500 | [diff] [blame] | 190 | : "=a" (hv_status), ASM_CALL_CONSTRAINT, |
Vitaly Kuznetsov | fc53662 | 2017-08-02 18:09:14 +0200 | [diff] [blame] | 191 | "+c" (control), "+d" (input_address) |
| 192 | : "r" (output_address), "m" (hv_hypercall_pg) |
| 193 | : "cc", "memory", "r8", "r9", "r10", "r11"); |
| 194 | #else |
| 195 | u32 input_address_hi = upper_32_bits(input_address); |
| 196 | u32 input_address_lo = lower_32_bits(input_address); |
| 197 | u32 output_address_hi = upper_32_bits(output_address); |
| 198 | u32 output_address_lo = lower_32_bits(output_address); |
| 199 | |
| 200 | if (!hv_hypercall_pg) |
| 201 | return U64_MAX; |
| 202 | |
| 203 | __asm__ __volatile__("call *%7" |
| 204 | : "=A" (hv_status), |
Josh Poimboeuf | f5caf62 | 2017-09-20 16:24:33 -0500 | [diff] [blame] | 205 | "+c" (input_address_lo), ASM_CALL_CONSTRAINT |
Vitaly Kuznetsov | fc53662 | 2017-08-02 18:09:14 +0200 | [diff] [blame] | 206 | : "A" (control), |
| 207 | "b" (input_address_hi), |
| 208 | "D"(output_address_hi), "S"(output_address_lo), |
| 209 | "m" (hv_hypercall_pg) |
| 210 | : "cc", "memory"); |
| 211 | #endif /* !x86_64 */ |
| 212 | return hv_status; |
| 213 | } |
Vitaly Kuznetsov | dee863b | 2017-02-04 09:57:13 -0700 | [diff] [blame] | 214 | |
Vitaly Kuznetsov | 806c892 | 2017-08-02 18:09:17 +0200 | [diff] [blame] | 215 | #define HV_HYPERCALL_RESULT_MASK GENMASK_ULL(15, 0) |
Vitaly Kuznetsov | 6a8edbd | 2017-08-02 18:09:15 +0200 | [diff] [blame] | 216 | #define HV_HYPERCALL_FAST_BIT BIT(16) |
Vitaly Kuznetsov | 806c892 | 2017-08-02 18:09:17 +0200 | [diff] [blame] | 217 | #define HV_HYPERCALL_VARHEAD_OFFSET 17 |
| 218 | #define HV_HYPERCALL_REP_COMP_OFFSET 32 |
| 219 | #define HV_HYPERCALL_REP_COMP_MASK GENMASK_ULL(43, 32) |
| 220 | #define HV_HYPERCALL_REP_START_OFFSET 48 |
| 221 | #define HV_HYPERCALL_REP_START_MASK GENMASK_ULL(59, 48) |
Vitaly Kuznetsov | 6a8edbd | 2017-08-02 18:09:15 +0200 | [diff] [blame] | 222 | |
| 223 | /* Fast hypercall with 8 bytes of input and no output */ |
| 224 | static inline u64 hv_do_fast_hypercall8(u16 code, u64 input1) |
| 225 | { |
| 226 | u64 hv_status, control = (u64)code | HV_HYPERCALL_FAST_BIT; |
Vitaly Kuznetsov | 6a8edbd | 2017-08-02 18:09:15 +0200 | [diff] [blame] | 227 | |
| 228 | #ifdef CONFIG_X86_64 |
| 229 | { |
| 230 | __asm__ __volatile__("call *%4" |
Josh Poimboeuf | f5caf62 | 2017-09-20 16:24:33 -0500 | [diff] [blame] | 231 | : "=a" (hv_status), ASM_CALL_CONSTRAINT, |
Vitaly Kuznetsov | 6a8edbd | 2017-08-02 18:09:15 +0200 | [diff] [blame] | 232 | "+c" (control), "+d" (input1) |
| 233 | : "m" (hv_hypercall_pg) |
| 234 | : "cc", "r8", "r9", "r10", "r11"); |
| 235 | } |
| 236 | #else |
| 237 | { |
| 238 | u32 input1_hi = upper_32_bits(input1); |
| 239 | u32 input1_lo = lower_32_bits(input1); |
| 240 | |
| 241 | __asm__ __volatile__ ("call *%5" |
| 242 | : "=A"(hv_status), |
| 243 | "+c"(input1_lo), |
Josh Poimboeuf | f5caf62 | 2017-09-20 16:24:33 -0500 | [diff] [blame] | 244 | ASM_CALL_CONSTRAINT |
Vitaly Kuznetsov | 6a8edbd | 2017-08-02 18:09:15 +0200 | [diff] [blame] | 245 | : "A" (control), |
| 246 | "b" (input1_hi), |
| 247 | "m" (hv_hypercall_pg) |
| 248 | : "cc", "edi", "esi"); |
| 249 | } |
| 250 | #endif |
| 251 | return hv_status; |
| 252 | } |
| 253 | |
Vitaly Kuznetsov | 806c892 | 2017-08-02 18:09:17 +0200 | [diff] [blame] | 254 | /* |
| 255 | * Rep hypercalls. Callers of this functions are supposed to ensure that |
| 256 | * rep_count and varhead_size comply with Hyper-V hypercall definition. |
| 257 | */ |
| 258 | static inline u64 hv_do_rep_hypercall(u16 code, u16 rep_count, u16 varhead_size, |
| 259 | void *input, void *output) |
| 260 | { |
| 261 | u64 control = code; |
| 262 | u64 status; |
| 263 | u16 rep_comp; |
| 264 | |
| 265 | control |= (u64)varhead_size << HV_HYPERCALL_VARHEAD_OFFSET; |
| 266 | control |= (u64)rep_count << HV_HYPERCALL_REP_COMP_OFFSET; |
| 267 | |
| 268 | do { |
| 269 | status = hv_do_hypercall(control, input, output); |
| 270 | if ((status & HV_HYPERCALL_RESULT_MASK) != HV_STATUS_SUCCESS) |
| 271 | return status; |
| 272 | |
| 273 | /* Bits 32-43 of status have 'Reps completed' data. */ |
| 274 | rep_comp = (status & HV_HYPERCALL_REP_COMP_MASK) >> |
| 275 | HV_HYPERCALL_REP_COMP_OFFSET; |
| 276 | |
| 277 | control &= ~HV_HYPERCALL_REP_START_MASK; |
| 278 | control |= (u64)rep_comp << HV_HYPERCALL_REP_START_OFFSET; |
| 279 | |
| 280 | touch_nmi_watchdog(); |
| 281 | } while (rep_comp < rep_count); |
| 282 | |
| 283 | return status; |
| 284 | } |
| 285 | |
Vitaly Kuznetsov | 7415aea | 2017-08-02 18:09:18 +0200 | [diff] [blame] | 286 | /* |
| 287 | * Hypervisor's notion of virtual processor ID is different from |
| 288 | * Linux' notion of CPU ID. This information can only be retrieved |
| 289 | * in the context of the calling CPU. Setup a map for easy access |
| 290 | * to this information. |
| 291 | */ |
| 292 | extern u32 *hv_vp_index; |
Vitaly Kuznetsov | a3b7424 | 2017-10-06 17:48:54 +0200 | [diff] [blame] | 293 | extern u32 hv_max_vp_index; |
Vitaly Kuznetsov | 7415aea | 2017-08-02 18:09:18 +0200 | [diff] [blame] | 294 | |
| 295 | /** |
| 296 | * hv_cpu_number_to_vp_number() - Map CPU to VP. |
| 297 | * @cpu_number: CPU number in Linux terms |
| 298 | * |
| 299 | * This function returns the mapping between the Linux processor |
| 300 | * number and the hypervisor's virtual processor number, useful |
| 301 | * in making hypercalls and such that talk about specific |
| 302 | * processors. |
| 303 | * |
| 304 | * Return: Virtual processor number in Hyper-V terms |
| 305 | */ |
| 306 | static inline int hv_cpu_number_to_vp_number(int cpu_number) |
| 307 | { |
| 308 | return hv_vp_index[cpu_number]; |
| 309 | } |
K. Y. Srinivasan | 73638cd | 2017-01-19 11:51:49 -0700 | [diff] [blame] | 310 | |
Vitaly Kuznetsov | d6f3609 | 2017-01-28 12:37:14 -0700 | [diff] [blame] | 311 | void hyperv_init(void); |
Vitaly Kuznetsov | 2ffd9e3 | 2017-08-02 18:09:19 +0200 | [diff] [blame] | 312 | void hyperv_setup_mmu_ops(void); |
| 313 | void hyper_alloc_mmu(void); |
K. Y. Srinivasan | 7ed4325 | 2017-10-29 11:33:41 -0700 | [diff] [blame] | 314 | void hyperv_report_panic(struct pt_regs *regs, long err); |
K. Y. Srinivasan | 8730046 | 2017-01-18 16:45:02 -0700 | [diff] [blame] | 315 | bool hv_is_hypercall_page_setup(void); |
Ky Srinivasan | a2a47c6 | 2010-05-06 12:08:41 -0700 | [diff] [blame] | 316 | void hyperv_cleanup(void); |
Vitaly Kuznetsov | 79cadff | 2017-08-02 18:09:13 +0200 | [diff] [blame] | 317 | #else /* CONFIG_HYPERV */ |
| 318 | static inline void hyperv_init(void) {} |
| 319 | static inline bool hv_is_hypercall_page_setup(void) { return false; } |
| 320 | static inline void hyperv_cleanup(void) {} |
Vitaly Kuznetsov | 2ffd9e3 | 2017-08-02 18:09:19 +0200 | [diff] [blame] | 321 | static inline void hyperv_setup_mmu_ops(void) {} |
Vitaly Kuznetsov | 79cadff | 2017-08-02 18:09:13 +0200 | [diff] [blame] | 322 | #endif /* CONFIG_HYPERV */ |
| 323 | |
Vitaly Kuznetsov | bd2a9ad | 2017-03-03 14:21:40 +0100 | [diff] [blame] | 324 | #ifdef CONFIG_HYPERV_TSCPAGE |
| 325 | struct ms_hyperv_tsc_page *hv_get_tsc_page(void); |
Vitaly Kuznetsov | 0733379 | 2017-03-03 14:21:41 +0100 | [diff] [blame] | 326 | static inline u64 hv_read_tsc_page(const struct ms_hyperv_tsc_page *tsc_pg) |
| 327 | { |
| 328 | u64 scale, offset, cur_tsc; |
| 329 | u32 sequence; |
| 330 | |
| 331 | /* |
| 332 | * The protocol for reading Hyper-V TSC page is specified in Hypervisor |
| 333 | * Top-Level Functional Specification ver. 3.0 and above. To get the |
| 334 | * reference time we must do the following: |
| 335 | * - READ ReferenceTscSequence |
| 336 | * A special '0' value indicates the time source is unreliable and we |
| 337 | * need to use something else. The currently published specification |
| 338 | * versions (up to 4.0b) contain a mistake and wrongly claim '-1' |
| 339 | * instead of '0' as the special value, see commit c35b82ef0294. |
| 340 | * - ReferenceTime = |
| 341 | * ((RDTSC() * ReferenceTscScale) >> 64) + ReferenceTscOffset |
| 342 | * - READ ReferenceTscSequence again. In case its value has changed |
| 343 | * since our first reading we need to discard ReferenceTime and repeat |
| 344 | * the whole sequence as the hypervisor was updating the page in |
| 345 | * between. |
| 346 | */ |
| 347 | do { |
| 348 | sequence = READ_ONCE(tsc_pg->tsc_sequence); |
| 349 | if (!sequence) |
| 350 | return U64_MAX; |
| 351 | /* |
| 352 | * Make sure we read sequence before we read other values from |
| 353 | * TSC page. |
| 354 | */ |
| 355 | smp_rmb(); |
| 356 | |
| 357 | scale = READ_ONCE(tsc_pg->tsc_scale); |
| 358 | offset = READ_ONCE(tsc_pg->tsc_offset); |
| 359 | cur_tsc = rdtsc_ordered(); |
| 360 | |
| 361 | /* |
| 362 | * Make sure we read sequence after we read all other values |
| 363 | * from TSC page. |
| 364 | */ |
| 365 | smp_rmb(); |
| 366 | |
| 367 | } while (READ_ONCE(tsc_pg->tsc_sequence) != sequence); |
| 368 | |
| 369 | return mul_u64_u64_shr(cur_tsc, scale, 64) + offset; |
| 370 | } |
| 371 | |
Vitaly Kuznetsov | bd2a9ad | 2017-03-03 14:21:40 +0100 | [diff] [blame] | 372 | #else |
| 373 | static inline struct ms_hyperv_tsc_page *hv_get_tsc_page(void) |
| 374 | { |
| 375 | return NULL; |
| 376 | } |
| 377 | #endif |
Ky Srinivasan | a2a47c6 | 2010-05-06 12:08:41 -0700 | [diff] [blame] | 378 | #endif |