All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@qumranet.com>
To: Izik Eidus <izike@qumranet.com>
Cc: kvm-devel <kvm-devel@lists.sourceforge.net>
Subject: Re: [PATCH RFC 2/2] Hardware task switching support
Date: Sun, 16 Mar 2008 16:18:21 +0200	[thread overview]
Message-ID: <47DD2C2D.4010407@qumranet.com> (raw)
In-Reply-To: <47D878B0.8090402@qumranet.com>

Izik Eidus wrote:
> >From 6a7207a0f3ee8af6ebafcec9d40a75b87f00a129 Mon Sep 17 00:00:00 2001
> From: Izik Eidus <izike@qumranet.com>
> Date: Thu, 13 Mar 2008 02:34:21 +0200
> Subject: [PATCH] KVM: hardware task switching support
>
> Signed-off-by: Izik Eidus <izike@qumranet.com>
> ---
>  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/

      reply	other threads:[~2008-03-16 14:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-13  0:43 [PATCH RFC 2/2] Hardware task switching support Izik Eidus
2008-03-16 14:18 ` Avi Kivity [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47DD2C2D.4010407@qumranet.com \
    --to=avi@qumranet.com \
    --cc=izike@qumranet.com \
    --cc=kvm-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.