x86/hyperv: make vapic support x2apic mode
Subsystems (5)
PATCH v4 1/1 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.
---
v3 -> v4:
- adjust the log message [Vitaly, Michael]
v2 -> v3:
- do not introduce x2apic-capable hv_apic accessors; leave original x2apic accessors instead
v1 -> v2:
- add ifdefs to handle !CONFIG_X86_X2APIC
arch/x86/hyperv/hv_apic.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
arch/x86/hyperv/hv_apic.c +15 -5
@@ -260,11 +260,21 @@ void __init hv_apic_init(void) }if (ms_hyperv.hints &HV_X64_APIC_ACCESS_RECOMMENDED ) { -pr_info ("Hyper-V: Using MSR based APIC access\n" ); +pr_info ("Hyper-V: Using enlightened APIC (%s mode)" , +x2apic_enabled () ?"x2apic" :"xapic" ); +/* +* With x2apic, architectural x2apic MSRs are equivalent to the +* respective synthetic MSRs, so there's no need to override +* the apic accessors. The only exception is +* hv_apic_eoi_write, because it benefits from lazy EOI when +* available, but it works for both xapic and x2apic modes. +*/ apic_set_eoi_write (hv_apic_eoi_write); - apic->read = hv_apic_read; - apic->write = hv_apic_write; - apic->icr_write = hv_apic_icr_write; - apic->icr_read = hv_apic_icr_read; +if (!x2apic_enabled ()) { + apic->read = hv_apic_read; + apic->write = hv_apic_write; + apic->icr_write = hv_apic_icr_write; + apic->icr_read = hv_apic_icr_read; + } } }
Signature · 1 line
2.21.0
[tip: x86/urgent] x86/hyperv: Make vapic support x2apic mode
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: e211288b72f15259da86eed6eca680758dbe9e74 Gitweb: https://git.kernel.org/tip/e211288b72f15259da86eed6eca680758dbe9e74 Author: Roman Kagan <[email protected]> AuthorDate: Thu, 10 Oct 2019 12:33:05 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 15 Oct 2019 10:57:09 +02:00
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.
--- arch/x86/hyperv/hv_apic.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
arch/x86/hyperv/hv_apic.c +15 -5
@@ -260,11 +260,21 @@ void __init hv_apic_init(void) }if (ms_hyperv.hints &HV_X64_APIC_ACCESS_RECOMMENDED ) { -pr_info ("Hyper-V: Using MSR based APIC access\n" ); +pr_info ("Hyper-V: Using enlightened APIC (%s mode)" , +x2apic_enabled () ?"x2apic" :"xapic" ); +/* +* With x2apic, architectural x2apic MSRs are equivalent to the +* respective synthetic MSRs, so there's no need to override +* the apic accessors. The only exception is +* hv_apic_eoi_write, because it benefits from lazy EOI when +* available, but it works for both xapic and x2apic modes. +*/ apic_set_eoi_write (hv_apic_eoi_write); - apic->read = hv_apic_read; - apic->write = hv_apic_write; - apic->icr_write = hv_apic_icr_write; - apic->icr_read = hv_apic_icr_read; +if (!x2apic_enabled ()) { + apic->read = hv_apic_read; + apic->write = hv_apic_write; + apic->icr_write = hv_apic_icr_write; + apic->icr_read = hv_apic_icr_read; + } } }
[tip: x86/urgent] x86/hyperv: Make vapic support x2apic mode
In reply to Roman KaganThe following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: e211288b72f15259da86eed6eca680758dbe9e74 Gitweb: https://git.kernel.org/tip/e211288b72f15259da86eed6eca680758dbe9e74 Author: Roman Kagan <[email protected]> AuthorDate: Thu, 10 Oct 2019 12:33:05 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 15 Oct 2019 10:57:09 +02:00
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.
--- arch/x86/hyperv/hv_apic.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
arch/x86/hyperv/hv_apic.c +15 -5
@@ -260,11 +260,21 @@ void __init hv_apic_init(void) }if (ms_hyperv.hints &HV_X64_APIC_ACCESS_RECOMMENDED ) { -pr_info ("Hyper-V: Using MSR based APIC access\n" ); +pr_info ("Hyper-V: Using enlightened APIC (%s mode)" , +x2apic_enabled () ?"x2apic" :"xapic" ); +/* +* With x2apic, architectural x2apic MSRs are equivalent to the +* respective synthetic MSRs, so there's no need to override +* the apic accessors. The only exception is +* hv_apic_eoi_write, because it benefits from lazy EOI when +* available, but it works for both xapic and x2apic modes. +*/ apic_set_eoi_write (hv_apic_eoi_write); - apic->read = hv_apic_read; - apic->write = hv_apic_write; - apic->icr_write = hv_apic_icr_write; - apic->icr_read = hv_apic_icr_read; +if (!x2apic_enabled ()) { + apic->read = hv_apic_read; + apic->write = hv_apic_write; + apic->icr_write = hv_apic_icr_write; + apic->icr_read = hv_apic_icr_read; + } } }