hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/arch/x86/hyperv/hv_apic.c
....@@ -20,7 +20,6 @@
2020 */
2121
2222 #include <linux/types.h>
23
-#include <linux/version.h>
2423 #include <linux/vmalloc.h>
2524 #include <linux/mm.h>
2625 #include <linux/clockchips.h>
....@@ -87,6 +86,11 @@
8786
8887 static void hv_apic_eoi_write(u32 reg, u32 val)
8988 {
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
+
9094 wrmsr(HV_X64_MSR_EOI, val, 0);
9195 }
9296
....@@ -190,10 +194,20 @@
190194
191195 static bool __send_ipi_one(int cpu, int vector)
192196 {
193
- struct cpumask mask = CPU_MASK_NONE;
197
+ int vp = hv_cpu_number_to_vp_number(cpu);
194198
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));
197211 }
198212
199213 static void hv_send_ipi(int cpu, int vector)
....@@ -256,11 +270,25 @@
256270 }
257271
258272 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
+ */
260286 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
+ }
265293 }
266294 }