x2APIC emulation for HVM guest
This patch would enable Xen to handle x2APIC MSR accessing of HVM guest, which is faster(avoid decoding of MMIO accessing). The credit comes to Gleb Natapov who complete the work for KVM.
Have tested with 4 vcpus guest, with/without x2apic support.
tools/libxc/xc_cpufeature.h +1 -0
@@ -98,6 +98,7 @@#define X86_FEATURE_DCA (4*32+18)/* Direct Cache Access */ #define X86_FEATURE_SSE4_1 (4*32+19)/* Streaming SIMD Extensions 4.1 */ #define X86_FEATURE_SSE4_2 (4*32+20)/* Streaming SIMD Extensions 4.2 */ +#define X86_FEATURE_X2APIC (4*32+21)/* x2APIC */ #define X86_FEATURE_POPCNT (4*32+23)/* POPCNT instruction */ #define X86_FEATURE_AES (4*32+25)/* AES acceleration instructions */ #define X86_FEATURE_XSAVE (4*32+26)/* XSAVE/XRSTOR/XSETBV/XGETBV */
tools/libxc/xc_cpuid_x86.c +8 -2
@@ -169,12 +169,15 @@ const unsigned int *input, unsigned int *regs) { char brand[13]; -unsigned long pae; -int is_pae; +unsigned long pae, x2apic; +int is_pae, emul_x2apic;xc_get_hvm_param (xch, domid,HVM_PARAM_PAE_ENABLED , &pae); is_pae = !!pae; +xc_get_hvm_param (xch, domid,HVM_PARAM_EMUL_X2APIC , &x2apic); + emul_x2apic = !!x2apic; +switch ( input[0 ] ) {case 0x00000000 :
@@ -199,6 +202,9 @@ regs[2 ] |=bitmaskof (X86_FEATURE_HYPERVISOR ); +if (emul_x2apic) + regs[2 ] |=bitmaskof (X86_FEATURE_X2APIC ); + regs[3] &= (bitmaskof(X86_FEATURE_FPU) | bitmaskof(X86_FEATURE_VME) | bitmaskof(X86_FEATURE_DE) |
xen/arch/x86/hvm/hvm.c +11 -0
@@ -432,6 +432,7 @@hvm_init_guest_time (d); d->arch.hvm_domain.params[HVM_PARAM_HPET_ENABLED ] =1 ; + d->arch.hvm_domain.params[HVM_PARAM_EMUL_X2APIC ] =1 ;hvm_init_cacheattr_region_list (d);
@@ -2189,6 +2190,11 @@ *msr_content =vcpu_vlapic (v)->hw.apic_base_msr;break ; + case MSR_IA32_APICBASE_MSR ... MSR_IA32_APICBASE_MSR + 0x3ff: +if (hvm_x2apic_msr_read (v, msr, msr_content) ) + goto gp_fault; +break ; +case MSR_IA32_CR_PAT : *msr_content = v->arch.hvm_vcpu.pat_cr;break ;
@@ -2296,6 +2302,11 @@vlapic_msr_set (vcpu_vlapic (v), msr_content);break ; + case MSR_IA32_APICBASE_MSR ... MSR_IA32_APICBASE_MSR + 0x3ff: +if (hvm_x2apic_msr_write (v, msr, msr_content) ) + goto gp_fault; +break ; +case MSR_IA32_CR_PAT :if ( !pat_msr_set (&v->arch.hvm_vcpu.pat_cr, msr_content) ) goto gp_fault;
xen/arch/x86/hvm/vlapic.c +145 -57
279 lines not on this page · raw message
xen/include/asm-x86/hvm/hvm.h +3 -0
@@ -364,4 +364,7 @@ ? (u32)__d->arch.incarnation : (u32)(v)->arch.hvm_vcpu.msr_tsc_aux; \ }) +int hvm_x2apic_msr_read (struct vcpu *v,unsigned int msr,uint64_t *msr_content); +int hvm_x2apic_msr_write (struct vcpu *v,unsigned int msr,uint64_t msr_content); +#endif /* __ASM_X86_HVM_HVM_H__ */
xen/include/asm-x86/hvm/vlapic.h +2 -0
@@ -51,6 +51,8 @@#define vlapic_base_address (vlapic) \ ((vlapic)->hw.apic_base_msr & MSR_IA32_APICBASE_BASE) +#define vlapic_x2apic_mode (vlapic) \ + ((vlapic)->hw.apic_base_msr & MSR_IA32_APICBASE_EXTD)struct vlapic {struct hvm_hw_lapic hw;
xen/include/asm-x86/msr-index.h +1 -0
@@ -307,6 +307,7 @@#define MSR_IA32_APICBASE_EXTD (1<<10)#define MSR_IA32_APICBASE_ENABLE (1<<11)#define MSR_IA32_APICBASE_BASE (0xfffff<<12) +#define MSR_IA32_APICBASE_MSR 0x800#define MSR_IA32_UCODE_WRITE 0x00000079#define MSR_IA32_UCODE_REV 0x0000008b
xen/include/public/hvm/params.h +3 -1
@@ -124,6 +124,8 @@*/ #define HVM_PARAM_ACPI_IOPORTS_LOCATION 19 -#define HVM_NR_PARAMS 20 +#define HVM_PARAM_EMUL_X2APIC 20 + +#define HVM_NR_PARAMS 21#endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 3 lines · Sheng
This patch would enable Xen to handle x2APIC MSR accessing of HVM guest, which is faster(avoid decoding of MMIO accessing). The credit comes to Gleb Natapov who complete the work for KVM.
Compared to Gleb's patch, I think yours is missing support for directed EOI in the LAPIC emulation. Linux doesn't use it, but I think it's easy enough that it's better to do it early.
Paolo
Quoted 8 lines · On Thursday 02 December 2010 13:31:09 Paolo Bonzini wrote:
Quoted 3 lines · Sheng
This patch would enable Xen to handle x2APIC MSR accessing of HVM guest, which is faster(avoid decoding of MMIO accessing). The credit comes to Gleb Natapov who complete the work for KVM.
Compared to Gleb's patch, I think yours is missing support for directed EOI in the LAPIC emulation. Linux doesn't use it, but I think it's easy enough that it's better to do it early.
I think we can do it step by step. This patch is big enough. And also, directed EOI is indicated by one bit in APIC version register, so it won't affect us here.
I'd like to work the direct EOI patch out, but I am thinking about how to test it...
--
regards
Yang, Sheng
Quoted 2 lines
Paolo
Quoted 1 line · Sheng
I think we can do it step by step. This patch is big enough.
Yes, I agree it can go in as a separate patch.
Quoted 2 lines
I'd like to work the direct EOI patch out, but I am thinking about how to test it...
Maybe you can run Xen inside an HVM guest, forcing x2apic mode to be enabled? You do not need nested VMX if you only run PV guests in the guest hypervisor.
Paolo
Quoted 11 lines · On Thursday 02 December 2010 13:48:15 Paolo Bonzini wrote:
Quoted 1 line · Sheng
I think we can do it step by step. This patch is big enough.
Yes, I agree it can go in as a separate patch.
Quoted 2 lines
I'd like to work the direct EOI patch out, but I am thinking about how to test it...
Maybe you can run Xen inside an HVM guest, forcing x2apic mode to be enabled? You do not need nested VMX if you only run PV guests in the guest hypervisor.
I don't know how much work need to be done for this, and if it's worth to do for something was not be used in practice(if it would be used in practice, then it would be easy for us to test)...
Anyway I would prepare the code later.
--
regards
Yang, Sheng
Quoted 2 lines
Paolo
Quoted 9 lines · Sheng
Quoted 8 lines · On Thursday 02 December 2010 13:48:15 Paolo Bonzini wrote:
Quoted 1 line · Sheng
I think we can do it step by step. This patch is big enough.
Yes, I agree it can go in as a separate patch.
Quoted 2 lines
I'd like to work the direct EOI patch out, but I am thinking about how to test it...
Quoted 7 lines
Quoted 3 lines
Maybe you can run Xen inside an HVM guest, forcing x2apic mode to be enabled? You do not need nested VMX if you only run PV guests in the guest hypervisor.
I don't know how much work need to be done for this, and if it's worth to do for something was not be used in
practice(if it would be used in practice, then it would be easy for us to test)...
Maybe it's as easy as this:
xen/arch/x86/genapic/x2apic.c +2 -2
@@ -41,13 +41,13 @@ int x2apic_cmdline_disable(void)static int probe_x2apic_phys (void ) {return x2apic && x2apic_phys &&x2apic_is_available () && -iommu_supports_eim (); +1 ; }static int probe_x2apic_cluster (void ) {return x2apic && !x2apic_phys &&x2apic_is_available () && -iommu_supports_eim (); +1 ; }const struct genapic apic_x2apic_phys = {
The original Xen x2apic code was not conditional on iommu_supports_eim().
Paolo
Quoted 40 lines · On Thursday 02 December 2010 14:44:05 Paolo Bonzini wrote:
Quoted 9 lines · Sheng
Quoted 8 lines · On Thursday 02 December 2010 13:48:15 Paolo Bonzini wrote:
Quoted 1 line · Sheng
I think we can do it step by step. This patch is big enough.
Yes, I agree it can go in as a separate patch.
Quoted 2 lines
I'd like to work the direct EOI patch out, but I am thinking about how to test it...
Quoted 7 lines
Quoted 3 lines
Maybe you can run Xen inside an HVM guest, forcing x2apic mode to be enabled? You do not need nested VMX if you only run PV guests in the guest hypervisor.
I don't know how much work need to be done for this, and if it's worth to do for something was not be used in
practice(if it would be used in practice, then it would be easy for us to test)...Maybe it's as easy as this:
xen/arch/x86/genapic/x2apic.c +2
-2@@ -41,13 +41,13 @@ int x2apic_cmdline_disable(void)static int probe_x2apic_phys (void ) {return x2apic && x2apic_phys &&x2apic_is_available () && -iommu_supports_eim (); +1 ; }static int probe_x2apic_cluster (void ) {return x2apic && !x2apic_phys &&x2apic_is_available () && -iommu_supports_eim (); +1 ; }const struct genapic apic_x2apic_phys = {
Quoted 1 line
The original Xen x2apic code was not conditional on
iommu_supports_eim().
I didn't mean this part. I am just not sure if xen can run as HVM guest smoothly...
Would check that later.
--
regards
Yang, Sheng
Quoted 2 lines · Sheng
I didn't mean this part. I am just not sure if xen can run as HVM guest smoothly...
Yes, it does (or at least it did, and it definitely runs under KVM).
Paolo
Quoted 5 lines · Sheng
This patch would enable Xen to handle x2APIC MSR accessing of HVM guest, which is faster(avoid decoding of MMIO accessing). The credit comes to Gleb Natapov who complete the work for KVM.
Have tested with 4 vcpus guest, with/without x2apic support.
Keir?
--
regards
Yang, Sheng