All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
To: Gregory Haskins <ghaskins-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: [PATCH 4/9] KVM: Adds ability to preempt an executing VCPU
Date: Sun, 27 May 2007 14:16:22 +0300	[thread overview]
Message-ID: <46596886.5040909@qumranet.com> (raw)
In-Reply-To: <20070524132305.11321.61433.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>

Gregory Haskins wrote:
>  static void kvm_vcpu_irqsink_init(struct kvm_vcpu *vcpu)
> diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
> index a9d917a..c79bfc0 100644
> --- a/drivers/kvm/svm.c
> +++ b/drivers/kvm/svm.c
> @@ -1544,9 +1544,43 @@ static int svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
>  	int r;
>  
>  again:
> +	/*
> +	 * We disable interrupts until the next VMEXIT to eliminate a race
> +	 * condition for delivery of virtual interrutps.  Note that this is
> +	 * probably not as bad as it sounds, as interrupts will still invoke
> +	 * a VMEXIT once transitioned to GUEST mode (and thus exit this lock
> +	 * scope) even if they are disabled.
> +	 */
> +	local_irq_disable();
> +
>  	spin_lock(&vcpu->irq.lock);
>  
>  	/*
> +	 * If there are any signals pending (virtual interrupt related or
> +	 * otherwise), don't even bother trying to enter guest mode...
> +	 */
> +	if (signal_pending(current)) {
> +		kvm_run->exit_reason = KVM_EXIT_INTR;
> +		spin_unlock(&vcpu->irq.lock);
> +		local_irq_enable();
> +		r = -EINTR;
> +		/*
> +		 * FIXME: We probably want to move this whole lock-block below
> +		 * the host->guest state loading so we don't restore when
> +		 * the system was never saved to begin with
> +		 */
> +		goto out;
> +	}
> +
> +	/*
> +	 * There are optimizations we can make when signaling interrupts
> +	 * if we know the VCPU is in GUEST mode, so record the guest's
> +	 * CPU to both serve as an indicator of vcpu state and a target
> +	 * for our interrupts
> +	 */
> +	vcpu->irq.guest_cpu = task_cpu(current);
> +
> +	/*
>  	 * We must inject interrupts (if any) while the irq_lock
>  	 * is held
>  	 */
> @@ -1688,6 +1722,15 @@ again:
>  #endif
>  		: "cc", "memory" );
>  
> +	/*
> +	 * Signal that we have transitioned back to host mode
> +	 */
> +	spin_lock(&vcpu->irq.lock);
> +	vcpu->irq.guest_cpu = -1;
> +	spin_unlock(&vcpu->irq.lock);
>   

One issue right here. spin_lock() may touch per-cpu data (for 
debugging), but %gs has not been restored yet.  Moving the block after 
host state restore still has problems, though.

> +
> +	local_irq_enable();
> +
>  	if (vcpu->fpu_active) {
>  		fx_save(vcpu->guest_fx_image);
>  		fx_restore(vcpu->host_fx_image);
> @@ -1734,20 +1777,23 @@ again:
>  	if (r > 0) {
>  		if (signal_pending(current)) {
>  			++vcpu->stat.signal_exits;
> -			post_kvm_run_save(vcpu, kvm_run);
>  			kvm_run->exit_reason = KVM_EXIT_INTR;
> -			return -EINTR;
> +			r = -EINTR;
> +			goto out;
>  		}
>  
>  		if (dm_request_for_irq_injection(vcpu, kvm_run)) {
>  			++vcpu->stat.request_irq_exits;
>  			post_kvm_run_save(vcpu, kvm_run);
>  			kvm_run->exit_reason = KVM_EXIT_INTR;
> -			return -EINTR;
> +			r = -EINTR;
> +			goto out;
>  		}
>  		kvm_resched(vcpu);
>  		goto again;
>  	}
> +
> + out:
>  	post_kvm_run_save(vcpu, kvm_run);
>  	return r;
>  }
>   

-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

  parent reply	other threads:[~2007-05-27 11:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-24 13:22 [PATCH 0/9] in-kernel APIC v8 (kernel side) Gregory Haskins
     [not found] ` <20070524131917.11321.17746.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-24 13:22   ` [PATCH 1/9] KVM: Adds support for in-kernel mmio handlers Gregory Haskins
2007-05-24 13:22   ` [PATCH 2/9] KVM: VMX - fix interrupt checking on light-exit Gregory Haskins
2007-05-24 13:23   ` [PATCH 3/9] KVM: Add irqdevice object Gregory Haskins
2007-05-24 13:23   ` [PATCH 4/9] KVM: Adds ability to preempt an executing VCPU Gregory Haskins
     [not found]     ` <20070524132305.11321.61433.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-27 11:16       ` Avi Kivity [this message]
2007-05-24 13:23   ` [PATCH 5/9] KVM: Add support for in-kernel LAPIC model Gregory Haskins
2007-05-24 13:23   ` [PATCH 6/9] KVM: Adds support for real NMI injection on VMX processors Gregory Haskins
2007-05-24 13:23   ` [PATCH 7/9] KVM: Adds basic plumbing to support TPR shadow features Gregory Haskins
2007-05-24 13:23   ` [PATCH 8/9] KVM: Add statistics from interrupt subsystem Gregory Haskins
2007-05-24 13:23   ` [PATCH 9/9] KVM: Adds support for halting in the kernel Gregory Haskins
2007-05-24 14:50   ` [PATCH 0/9] in-kernel APIC v8 (kernel side) Avi Kivity
     [not found]     ` <4655A63E.7000505-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-24 14:58       ` Avi Kivity
     [not found]         ` <4655A80C.4000606-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-24 15:02           ` Gregory Haskins
     [not found]             ` <4655709E.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-05-24 15:06               ` Avi Kivity
     [not found]                 ` <4655AA0C.9040108-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-24 15:12                   ` Gregory Haskins
  -- strict thread matches above, loose matches on Subject: below --
2007-05-31 18:08 [PATCH 0/9] in-kernel APIC v9 " Gregory Haskins
     [not found] ` <20070531180005.1810.23884.stgit-5CR4LY5GPkvLDviKLk5550HKjMygAv58XqFh9Ls21Oc@public.gmane.org>
2007-05-31 18:09   ` [PATCH 4/9] KVM: Adds ability to preempt an executing VCPU Gregory Haskins
2007-05-18 21:50 [PATCH 0/9] in-kernel APIC v6 (kernel side) Gregory Haskins
     [not found] ` <20070518214737.30990.39272.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-18 21:51   ` [PATCH 4/9] KVM: Adds ability to preempt an executing VCPU Gregory Haskins
2007-05-15 14:57 [PATCH 0/9] in-kernel APIC v5 (kernel side) Gregory Haskins
     [not found] ` <20070515145404.15609.61552.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-15 14:57   ` [PATCH 4/9] KVM: Adds ability to preempt an executing VCPU Gregory Haskins
2007-05-15  3:15 [PATCH 0/9] in-kernel APIC v4 (kernel side) Gregory Haskins
     [not found] ` <20070515031217.9382.44999.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-15  3:15   ` [PATCH 4/9] KVM: Adds ability to preempt an executing VCPU Gregory Haskins
2007-05-09 15:18 [PATCH 0/9] in-kernel APIC v2 Gregory Haskins
     [not found] ` <20070509151238.8673.4818.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-09 15:19   ` [PATCH 4/9] KVM: Adds ability to preempt an executing VCPU Gregory Haskins

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=46596886.5040909@qumranet.com \
    --to=avi-atkuwr5tajbwk0htik3j/w@public.gmane.org \
    --cc=ghaskins-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /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.