| .. | .. |
|---|
| 20 | 20 | */ |
|---|
| 21 | 21 | |
|---|
| 22 | 22 | #include <linux/types.h> |
|---|
| 23 | | -#include <linux/version.h> |
|---|
| 24 | 23 | #include <linux/vmalloc.h> |
|---|
| 25 | 24 | #include <linux/mm.h> |
|---|
| 26 | 25 | #include <linux/clockchips.h> |
|---|
| .. | .. |
|---|
| 87 | 86 | |
|---|
| 88 | 87 | static void hv_apic_eoi_write(u32 reg, u32 val) |
|---|
| 89 | 88 | { |
|---|
| 89 | + struct hv_vp_assist_page *hvp = hv_vp_assist_page[smp_processor_id()]; |
|---|
| 90 | + |
|---|
| 91 | + if (hvp && (xchg(&hvp->apic_assist, 0) & 0x1)) |
|---|
| 92 | + return; |
|---|
| 93 | + |
|---|
| 90 | 94 | wrmsr(HV_X64_MSR_EOI, val, 0); |
|---|
| 91 | 95 | } |
|---|
| 92 | 96 | |
|---|
| .. | .. |
|---|
| 190 | 194 | |
|---|
| 191 | 195 | static bool __send_ipi_one(int cpu, int vector) |
|---|
| 192 | 196 | { |
|---|
| 193 | | - struct cpumask mask = CPU_MASK_NONE; |
|---|
| 197 | + int vp = hv_cpu_number_to_vp_number(cpu); |
|---|
| 194 | 198 | |
|---|
| 195 | | - cpumask_set_cpu(cpu, &mask); |
|---|
| 196 | | - return __send_ipi_mask(&mask, vector); |
|---|
| 199 | + trace_hyperv_send_ipi_one(cpu, vector); |
|---|
| 200 | + |
|---|
| 201 | + if (!hv_hypercall_pg || (vp == VP_INVAL)) |
|---|
| 202 | + return false; |
|---|
| 203 | + |
|---|
| 204 | + if ((vector < HV_IPI_LOW_VECTOR) || (vector > HV_IPI_HIGH_VECTOR)) |
|---|
| 205 | + return false; |
|---|
| 206 | + |
|---|
| 207 | + if (vp >= 64) |
|---|
| 208 | + return __send_ipi_mask_ex(cpumask_of(cpu), vector); |
|---|
| 209 | + |
|---|
| 210 | + return !hv_do_fast_hypercall16(HVCALL_SEND_IPI, vector, BIT_ULL(vp)); |
|---|
| 197 | 211 | } |
|---|
| 198 | 212 | |
|---|
| 199 | 213 | static void hv_send_ipi(int cpu, int vector) |
|---|
| .. | .. |
|---|
| 256 | 270 | } |
|---|
| 257 | 271 | |
|---|
| 258 | 272 | if (ms_hyperv.hints & HV_X64_APIC_ACCESS_RECOMMENDED) { |
|---|
| 259 | | - pr_info("Hyper-V: Using MSR based APIC access\n"); |
|---|
| 273 | + pr_info("Hyper-V: Using enlightened APIC (%s mode)", |
|---|
| 274 | + x2apic_enabled() ? "x2apic" : "xapic"); |
|---|
| 275 | + /* |
|---|
| 276 | + * When in x2apic mode, don't use the Hyper-V specific APIC |
|---|
| 277 | + * accessors since the field layout in the ICR register is |
|---|
| 278 | + * different in x2apic mode. Furthermore, the architectural |
|---|
| 279 | + * x2apic MSRs function just as well as the Hyper-V |
|---|
| 280 | + * synthetic APIC MSRs, so there's no benefit in having |
|---|
| 281 | + * separate Hyper-V accessors for x2apic mode. The only |
|---|
| 282 | + * exception is hv_apic_eoi_write, because it benefits from |
|---|
| 283 | + * lazy EOI when available, but the same accessor works for |
|---|
| 284 | + * both xapic and x2apic because the field layout is the same. |
|---|
| 285 | + */ |
|---|
| 260 | 286 | apic_set_eoi_write(hv_apic_eoi_write); |
|---|
| 261 | | - apic->read = hv_apic_read; |
|---|
| 262 | | - apic->write = hv_apic_write; |
|---|
| 263 | | - apic->icr_write = hv_apic_icr_write; |
|---|
| 264 | | - apic->icr_read = hv_apic_icr_read; |
|---|
| 287 | + if (!x2apic_enabled()) { |
|---|
| 288 | + apic->read = hv_apic_read; |
|---|
| 289 | + apic->write = hv_apic_write; |
|---|
| 290 | + apic->icr_write = hv_apic_icr_write; |
|---|
| 291 | + apic->icr_read = hv_apic_icr_read; |
|---|
| 292 | + } |
|---|
| 265 | 293 | } |
|---|
| 266 | 294 | } |
|---|