Izik Eidus wrote: > >From 6a7207a0f3ee8af6ebafcec9d40a75b87f00a129 Mon 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 > > Signed-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.h > > diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c > index 4e1dd61..be78278 100644 > --- a/arch/x86/kvm/svm.c > +++ b/arch/x86/kvm/svm.c > @@ -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); >
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). > } > > static int cpuid_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) > diff --git a/arch/x86/kvm/tss_segment.h b/arch/x86/kvm/tss_segment.h > new file mode 100644 > index 0000000..622aa10 > --- /dev/null > +++ b/arch/x86/kvm/tss_segment.h > "tss" already has "segment" in it. call it just tss.h. > + > +/* allowed just for 8 bytes segments */ > +static int load_guest_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector, > + struct desc_struct *seg_desc) > +{ > + 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. > + > +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. > +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]; > + 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); > + 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. -- 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/ _______________________________________________ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel