Skip to content

Commit e211288

Browse files
rvkaKAGA-KOKO
authored andcommitted
x86/hyperv: Make vapic support x2apic mode
Now that there's Hyper-V IOMMU driver, Linux can switch to x2apic mode when supported by the vcpus. However, the apic access functions for Hyper-V enlightened apic assume xapic mode only. As a result, Linux fails to bring up secondary cpus when run as a guest in QEMU/KVM with both hv_apic and x2apic enabled. According to Michael Kelley, when in x2apic mode, the Hyper-V synthetic apic MSRs behave exactly the same as the corresponding architectural x2apic MSRs, so there's no need to override the apic accessors. The only exception is hv_apic_eoi_write, which benefits from lazy EOI when available; however, its implementation works for both xapic and x2apic modes. Fixes: 29217a4 ("iommu/hyper-v: Add Hyper-V stub IOMMU driver") Fixes: 6b48cb5 ("X86/Hyper-V: Enlighten APIC access") Suggested-by: Michael Kelley <[email protected]> Signed-off-by: Roman Kagan <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Vitaly Kuznetsov <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 1869dbe commit e211288

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

arch/x86/hyperv/hv_apic.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,21 @@ void __init hv_apic_init(void)
260260
}
261261

262262
if (ms_hyperv.hints & HV_X64_APIC_ACCESS_RECOMMENDED) {
263-
pr_info("Hyper-V: Using MSR based APIC access\n");
263+
pr_info("Hyper-V: Using enlightened APIC (%s mode)",
264+
x2apic_enabled() ? "x2apic" : "xapic");
265+
/*
266+
* With x2apic, architectural x2apic MSRs are equivalent to the
267+
* respective synthetic MSRs, so there's no need to override
268+
* the apic accessors. The only exception is
269+
* hv_apic_eoi_write, because it benefits from lazy EOI when
270+
* available, but it works for both xapic and x2apic modes.
271+
*/
264272
apic_set_eoi_write(hv_apic_eoi_write);
265-
apic->read = hv_apic_read;
266-
apic->write = hv_apic_write;
267-
apic->icr_write = hv_apic_icr_write;
268-
apic->icr_read = hv_apic_icr_read;
273+
if (!x2apic_enabled()) {
274+
apic->read = hv_apic_read;
275+
apic->write = hv_apic_write;
276+
apic->icr_write = hv_apic_icr_write;
277+
apic->icr_read = hv_apic_icr_read;
278+
}
269279
}
270280
}

0 commit comments

Comments
 (0)