[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [ PATCH 1/2] xen: enable APIC-Register Virtualization


  • To: "xen-devel@xxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxx>
  • From: "Li, Jiongxi" <jiongxi.li@xxxxxxxxx>
  • Date: Fri, 31 Aug 2012 09:29:51 +0000
  • Accept-language: en-US
  • Delivery-date: Fri, 31 Aug 2012 09:30:10 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xen.org>
  • Thread-index: Ac2HWGKAUDDr53BWQZO2/Uq+OTcM5w==
  • Thread-topic: [ PATCH 1/2] xen: enable APIC-Register Virtualization

Add APIC register virtualization support
ãã- APIC read doesn't cause VM-Exit
ãã- APIC write becomes trap-like

Signed-off-by: Yang Zhang <yang.z.zhang@xxxxxxxxx>
Signed-off-by: Jiongxi Li <jiongxi.li@xxxxxxxxx>


diff -r 1126b3079bef xen/arch/x86/hvm/vlapic.c
--- a/xen/arch/x86/hvm/vlapic.cÂÂÂÂÂ Fri Aug 24 12:38:18 2012 +0100
+++ b/xen/arch/x86/hvm/vlapic.cÂÂ Thu Aug 30 22:38:26 2012 +0800
@@ -823,6 +823,16 @@ static int vlapic_write(struct vcpu *v, 
ÂÂÂÂÂreturn rc;
}

+int vlapic_apicv_write(struct vcpu *v, unsigned int offset)
+{
+ÂÂÂ uint32_t val = vlapic_get_reg(vcpu_vlapic(v), offset);
+
+ÂÂÂ ASSERT(cpu_has_vmx_apic_reg_virt);
+
+ÂÂÂ vlapic_reg_write(v, offset, val);
+ÂÂÂ return 0;
+}
+
int hvm_x2apic_msr_write(struct vcpu *v, unsigned int msr, uint64_t msr_content)
{
ÂÂÂÂ struct vlapic *vlapic = vcpu_vlapic(v);
diff -r 1126b3079bef xen/arch/x86/hvm/vmx/vmcs.c
--- a/xen/arch/x86/hvm/vmx/vmcs.cÂÂÂÂÂÂ Fri Aug 24 12:38:18 2012 +0100
+++ b/xen/arch/x86/hvm/vmx/vmcs.cÂÂÂ Thu Aug 30 22:38:26 2012 +0800
@@ -89,6 +89,7 @@ static void __init vmx_display_features(
ÂÂÂÂ P(cpu_has_vmx_vnmi, "Virtual NMI");
ÂÂÂÂ P(cpu_has_vmx_msr_bitmap, "MSR direct-access bitmap");
ÂÂÂÂ P(cpu_has_vmx_unrestricted_guest, "Unrestricted Guest");
+ÂÂÂ P(cpu_has_vmx_apic_reg_virt, "APIC Register Virtualization");
#undef P

ÂÂÂÂÂif ( !printed )
@@ -186,6 +187,14 @@ static int vmx_init_vmcs_config(void)
ÂÂÂÂÂÂÂÂ if ( opt_unrestricted_guest_enabled )
ÂÂÂÂÂÂÂÂÂÂÂÂ opt |= SECONDARY_EXEC_UNRESTRICTED_GUEST;

+ÂÂÂÂÂÂÂ /*
+ÂÂÂÂÂÂÂÂ * "APIC Register Virtualization"
+ÂÂÂÂÂÂÂÂ * can be set only when "use TPR shadow" is set
+ÂÂÂÂÂÂÂÂ */
+ÂÂÂÂÂÂÂ if ( _vmx_cpu_based_exec_control & CPU_BASED_TPR_SHADOW )
+ÂÂÂÂÂÂÂÂÂÂÂ opt |= SECONDARY_EXEC_APIC_REGISTER_VIRT;
+
+
ÂÂÂÂÂÂÂÂ _vmx_secondary_exec_control = adjust_vmx_controls(
ÂÂÂÂÂÂÂÂÂÂÂÂ "Secondary Exec Control", min, opt,
ÂÂÂÂÂÂÂÂÂÂÂÂ MSR_IA32_VMX_PROCBASED_CTLS2, &mismatch);
diff -r 1126b3079bef xen/arch/x86/hvm/vmx/vmx.c
--- a/xen/arch/x86/hvm/vmx/vmx.cÂÂÂÂÂÂÂÂ Fri Aug 24 12:38:18 2012 +0100
+++ b/xen/arch/x86/hvm/vmx/vmx.cÂÂÂÂÂ Thu Aug 30 22:38:26 2012 +0800
@@ -2273,6 +2273,14 @@ static void vmx_idtv_reinject(unsigned l
ÂÂÂÂ }
}

+static int vmx_handle_apic_write(void)
+{
+ÂÂÂ unsigned long exit_qualification = __vmread(EXIT_QUALIFICATION);
+ÂÂÂ unsigned int offset = exit_qualification & 0xfff;
+
+ÂÂÂ return vlapic_apicv_write(current, offset);
+}
+
void vmx_vmexit_handler(struct cpu_user_regs *regs)
{
ÂÂÂÂ unsigned int exit_reason, idtv_info, intr_info = 0, vector = 0;
@@ -2728,6 +2736,11 @@ void vmx_vmexit_handler(struct cpu_user_
ÂÂÂÂÂÂÂÂ break;
ÂÂÂÂ }

+ÂÂÂ case EXIT_REASON_APIC_WRITE:
+ÂÂÂÂÂÂÂ if ( vmx_handle_apic_write() )
+ÂÂÂÂÂÂÂÂÂÂÂ hvm_inject_hw_exception(TRAP_gp_fault, 0);
+ÂÂÂÂÂÂÂ break;
+
ÂÂÂÂ case EXIT_REASON_ACCESS_GDTR_OR_IDTR:
ÂÂÂÂ case EXIT_REASON_ACCESS_LDTR_OR_TR:
ÂÂÂÂ case EXIT_REASON_VMX_PREEMPTION_TIMER_EXPIRED:
diff -r 1126b3079bef xen/include/asm-x86/hvm/vlapic.h
--- a/xen/include/asm-x86/hvm/vlapic.h Fri Aug 24 12:38:18 2012 +0100
+++ b/xen/include/asm-x86/hvm/vlapic.hÂÂÂÂÂÂ Thu Aug 30 22:38:26 2012 +0800
@@ -103,6 +103,8 @@ void vlapic_EOI_set(struct vlapic *vlapi

Âint vlapic_ipi(struct vlapic *vlapic, uint32_t icr_low, uint32_t icr_high);

+int vlapic_apicv_write(struct vcpu *v, unsigned int offset);
+
struct vlapic *vlapic_lowest_prio(
ÂÂÂÂ struct domain *d, struct vlapic *source,
ÂÂÂÂ int short_hand, uint8_t dest, uint8_t dest_mode);
diff -r 1126b3079bef xen/include/asm-x86/hvm/vmx/vmcs.h
--- a/xen/include/asm-x86/hvm/vmx/vmcs.h Fri Aug 24 12:38:18 2012 +0100
+++ b/xen/include/asm-x86/hvm/vmx/vmcs.hÂÂÂÂÂÂÂ Thu Aug 30 22:38:26 2012 +0800
@@ -182,6 +182,7 @@ extern u32 vmx_vmentry_control;
#define SECONDARY_EXEC_ENABLE_VPIDÂÂÂÂÂÂÂÂÂÂÂÂÂ 0x00000020
#define SECONDARY_EXEC_WBINVD_EXITINGÂÂÂÂÂÂÂÂÂÂ 0x00000040
#define SECONDARY_EXEC_UNRESTRICTED_GUESTÂÂÂÂÂÂ 0x00000080
+#define SECONDARY_EXEC_APIC_REGISTER_VIRTÂÂÂÂÂÂ 0x00000100
#define SECONDARY_EXEC_PAUSE_LOOP_EXITINGÂÂÂÂÂÂ 0x00000400
#define SECONDARY_EXEC_ENABLE_INVPCIDÂÂÂÂÂÂÂÂÂÂ 0x00001000
extern u32 vmx_secondary_exec_control;
@@ -230,6 +231,8 @@ extern bool_t cpu_has_vmx_ins_outs_instr
ÂÂÂÂÂ SECONDARY_EXEC_UNRESTRICTED_GUEST)
#define cpu_has_vmx_ple \
ÂÂÂÂ (vmx_secondary_exec_control & SECONDARY_EXEC_PAUSE_LOOP_EXITING)
+#define cpu_has_vmx_apic_reg_virt \
+ÂÂÂ (vmx_secondary_exec_control & SECONDARY_EXEC_APIC_REGISTER_VIRT)

Â/* GUEST_INTERRUPTIBILITY_INFO flags. */
#define VMX_INTR_SHADOW_STIÂÂÂÂÂÂÂÂÂÂÂÂ 0x00000001
diff -r 1126b3079bef xen/include/asm-x86/hvm/vmx/vmx.h
--- a/xen/include/asm-x86/hvm/vmx/vmx.hÂÂÂ Fri Aug 24 12:38:18 2012 +0100
+++ b/xen/include/asm-x86/hvm/vmx/vmx.h Thu Aug 30 22:38:26 2012 +0800
@@ -129,6 +129,7 @@ void vmx_update_cpu_exec_control(struct 
Â#define EXIT_REASON_INVVPIDÂÂÂÂÂÂÂÂÂÂÂÂ 53
#define EXIT_REASON_WBINVDÂÂÂÂÂÂÂÂÂÂÂÂÂ 54
#define EXIT_REASON_XSETBVÂÂÂÂÂÂÂÂÂÂÂÂÂ 55
+#define EXIT_REASON_APIC_WRITEÂÂÂÂÂÂÂÂÂ 56
#define EXIT_REASON_INVPCIDÂÂÂÂÂÂÂÂÂÂÂÂ 58

Â/*

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.