Hardware task switching support
RFC PATCH 2/2 Hardware task switching support
Quoted 1 line
From
6a7207a0f3ee8af6ebafcec9d40a75b87f00a129Mon Sep 17 00:00:00 2001
From: Izik Eidus <[email protected]>
Date: Thu, 13 Mar 2008 02:34:21 +0200
Subject: [PATCH] KVM: hardware task switching support
--- arch/x86/kvm/svm.c | 11 +- arch/x86/kvm/tss_segment.h | 59 +++++++ arch/x86/kvm/vmx.c | 15 ++ arch/x86/kvm/x86.c | 385 ++++++++++++++++++++++++++++++++++++++++++++ include/asm-x86/kvm_host.h | 2 + 5 files changed, 469 insertions(+), 3 deletions(-) create mode 100644 arch/x86/kvm/tss_segment.h
arch/x86/kvm/svm.c +8 -3
@@ -1121,9 +1121,14 @@ static int invalid_op_interception(struct vcpu_svm *svm,static int task_switch_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run) { -pr_unimpl (&svm->vcpu,"%s: task switch is unsupported\n" , __func__); - kvm_run->exit_reason =KVM_EXIT_UNKNOWN ; -return 0 ; +u16 tss_selector; + + tss_selector = (u16 )svm->vmcb->control.exit_info_1; +if (svm->vmcb->control.exit_info_2 & ((unsigned long )1 <<36 )) +return kvm_task_switch (&svm->vcpu, tss_selector,1 ); +if (svm->vmcb->control.exit_info_2 & ((unsigned long )1 <<38 )) +return kvm_task_switch (&svm->vcpu, tss_selector,2 ); +return kvm_task_switch (&svm->vcpu, tss_selector,0 ); }static int cpuid_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run)
arch/x86/kvm/tss_segment.h new file +59 -0
59 lines not on this page · raw message
arch/x86/kvm/vmx.c +15 -0
@@ -2246,6 +2246,20 @@ static int handle_apic_access(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)return 1 ; } +static int handle_task_switch (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run) +{ +unsigned long exit_qualification; +u16 tss_selector; +int reason; + + exit_qualification =vmcs_readl (EXIT_QUALIFICATION ); + + reason = (u32 )exit_qualification >>30 ; + tss_selector = (u16 )exit_qualification; + +return kvm_task_switch (vcpu, tss_selector, reason); +} +/* * The exit handlers return 1 if the exit was handled fully and guest execution * may resume. Otherwise they set the kvm_run parameter to indicate what needs
@@ -2268,6 +2282,7 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu, [EXIT_REASON_TPR_BELOW_THRESHOLD] = handle_tpr_below_threshold, [EXIT_REASON_APIC_ACCESS] = handle_apic_access, [EXIT_REASON_WBINVD] = handle_wbinvd, + [EXIT_REASON_TASK_SWITCH] = handle_task_switch, }; static const int kvm_vmx_max_exit_handlers =
arch/x86/kvm/x86.c +385 -0
397 lines not on this page · raw message
include/asm-x86/kvm_host.h +2 -0
@@ -472,6 +472,8 @@ int emulator_get_dr(struct x86_emulate_ctxt *ctxt, int dr,int emulator_set_dr (struct x86_emulate_ctxt *ctxt,int dr,unsigned long value); +int kvm_task_switch (struct kvm_vcpu *vcpu,u16 tss_selector,int reason); +void kvm_set_cr0 (struct kvm_vcpu *vcpu,unsigned long cr0);void kvm_set_cr3 (struct kvm_vcpu *vcpu,unsigned long cr0);void kvm_set_cr4 (struct kvm_vcpu *vcpu,unsigned long cr0);
Signature · 6 lines
1.5.3.6 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Quoted 25 lines · Izik Eidus
Quoted 1 line
From
6a7207a0f3ee8af6ebafcec9d40a75b87f00a129Mon Sep 17 00:00:00 2001From: Izik Eidus <[email protected]>
Date: Thu, 13 Mar 2008 02:34:21 +0200
Subject: [PATCH] KVM: hardware task switching supportSigned-off-by Izik Eidus <[email protected]>--- arch/x86/kvm/svm.c | 11 +- arch/x86/kvm/tss_segment.h | 59 +++++++ arch/x86/kvm/vmx.c | 15 ++ arch/x86/kvm/x86.c | 385 ++++++++++++++++++++++++++++++++++++++++++++ include/asm-x86/kvm_host.h | 2 + 5 files changed, 469 insertions(+), 3 deletions(-) create mode 100644 arch/x86/kvm/tss_segment.harch/x86/kvm/svm.c +0
-2@@ -1121,9 +1121,14 @@ static int invalid_op_interception(struct vcpu_svm *svm,static int task_switch_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run) { -pr_unimpl (&svm->vcpu,"%s: task switch is unsupported\n" , __func__); - kvm_run->exit_reason =KVM_EXIT_UNKNOWN ;
arch/x86/kvm/svm.c static int invalid_op_interception(struct vcpu_svm *svm, · line 1132
Quoted 10 lines
arch/x86/kvm/svm.c +8
-1-return 0 ; +u16 tss_selector; + + tss_selector = (u16 )svm->vmcb->control.exit_info_1; +if (svm->vmcb->control.exit_info_2 & ((unsigned long )1 <<36 )) +return kvm_task_switch (&svm->vcpu, tss_selector,1 ); +if (svm->vmcb->control.exit_info_2 & ((unsigned long )1 <<38 )) +return kvm_task_switch (&svm->vcpu, tss_selector,2 ); +return kvm_task_switch (&svm->vcpu, tss_selector,0 );
space after if. Change the magic numbers (36, 38, 0, 1, 2) inuo constants in svm.h and kvm_host.h. (unsigned long)1 << 36 will break on i386 (needs 1ULL << 36).
arch/x86/kvm/tss_segment.h
Quoted 9 lines
arch/x86/kvm/svm.c +0
-0}static int
cpuid_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)arch/x86/kvm/tss_segment.h new file +0
-0
"tss" already has "segment" in it. call it just tss.h.
Quoted 5 lines
arch/x86/kvm/tss_segment.h new file +4
-0+ +/* allowed just for 8 bytes segments */ +static int load_guest_segment_descriptor (struct kvm_vcpu *vcpu,u16 selector, +struct desc_struct *seg_desc)
arch/x86/kvm/tss_segment.h
Quoted 10 lines
arch/x86/kvm/tss_segment.h new file +10
-0+{ +struct descriptor_table gdt_ldt; +u16 index = selector >>3 ; + +if (selector &1 <<2 ) + kvm_x86_ops->get_ldt (vcpu, &gdt_ldt); +else + kvm_x86_ops->get_gdt (vcpu, &gdt_ldt); +if (gdt_ldt.limit < index *8 +7 ) +return 1 ;
This part can be in a helper function shared with load_ and save_guest_segment_descriptor. Maybe rename to read_ and write_ to avoid confusion.
arch/x86/kvm/tss_segment.h
Quoted 11 lines
arch/x86/kvm/tss_segment.h new file +10
-0+ +static int load_tss_segment32 (struct kvm_vcpu *vcpu, +struct desc_struct *seg_desc, +struct tss_segment_32 *tss) +{ +u32 base_addr; + + base_addr = seg_desc->base0; + base_addr |= (seg_desc->base1 <<16 ); + base_addr |= (seg_desc->base2 <<24 );
A helper, again.
Quoted 10 lines
arch/x86/kvm/tss_segment.h new file +9
-0+static void save_state_to_tss32 (struct kvm_vcpu *vcpu, +struct tss_segment_32 *tss) +{ +struct kvm_segment kvm_seg; + + tss->cr3 = vcpu->arch.cr3; + tss->eip = vcpu->arch.rip; + tss->eflags = kvm_x86_ops->get_rflags (vcpu); + tss->eax = vcpu->arch.regs[VCPU_REGS_RAX ];
arch/x86/kvm/tss_segment.h
Quoted 10 lines
arch/x86/kvm/tss_segment.h new file +10
-0+ tss->ecx = vcpu->arch.regs[VCPU_REGS_RCX ]; + tss->edx = vcpu->arch.regs[VCPU_REGS_RDX ]; + tss->ebx = vcpu->arch.regs[VCPU_REGS_RBX ]; + tss->esp = vcpu->arch.regs[VCPU_REGS_RSP ]; + tss->ebp = vcpu->arch.regs[VCPU_REGS_RBP ]; + tss->esi = vcpu->arch.regs[VCPU_REGS_RSI ]; + tss->edi = vcpu->arch.regs[VCPU_REGS_RDI ]; + +get_segment (vcpu, &kvm_seg,VCPU_SREG_ES ); + tss->es = kvm_seg.selector;
tss->es = get_segment_selector(vcpu, VCPU_SREG_ES);
arch/x86/kvm/tss_segment.h
Quoted 13 lines
arch/x86/kvm/tss_segment.h new file +12
-0+load_guest_segment_descriptor (vcpu, tss->ldt_selector, + &seg_desc); +seg_desct_to_kvm_desct (&seg_desc, tss->ldt_selector, + &kvm_seg); +set_segment (vcpu, &kvm_seg,VCPU_SREG_LDTR ); + +load_guest_segment_descriptor (vcpu, tss->es, &seg_desc); +seg_desct_to_kvm_desct (&seg_desc, tss->es, &kvm_seg); + kvm_seg.type |=1 ; +if (!kvm_seg.s) + kvm_seg.unusable =1 ; +set_segment (vcpu, &kvm_seg,VCPU_SREG_ES );
Wrap these into a helper.
Signature · 7 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/