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 3/8] KVM: Adds ability to preempt an executing VCPU
Date: Mon, 14 May 2007 12:34:38 +0300 [thread overview]
Message-ID: <46482D2E.7040809@qumranet.com> (raw)
In-Reply-To: <20070509030325.23443.90129.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
Gregory Haskins wrote:
> The VCPU executes synchronously w.r.t. userspace today, and therefore
> interrupt injection is pretty straight forward. However, we will soon need
> to be able to inject interrupts asynchronous to the execution of the VCPU
> due to the introduction of SMP, paravirtualized drivers, and asynchronous
> hypercalls. This patch adds support to the interrupt mechanism to force
> a VCPU to VMEXIT when a new interrupt is pending.
>
>
Comments below are fairly minor, but worthwhile IMO.
> Signed-off-by: Gregory Haskins <ghaskins-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
> ---
>
> drivers/kvm/kvm.h | 2 ++
> drivers/kvm/kvm_main.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++-
> drivers/kvm/svm.c | 43 +++++++++++++++++++++++++++++++++++
> drivers/kvm/vmx.c | 43 +++++++++++++++++++++++++++++++++++
> 4 files changed, 146 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
> index 059f074..0f6cc32 100644
> --- a/drivers/kvm/kvm.h
> +++ b/drivers/kvm/kvm.h
> @@ -329,6 +329,8 @@ struct kvm_vcpu_irq {
> struct kvm_irqdevice dev;
> int pending;
> int deferred;
> + struct task_struct *task;
> + int guest_mode;
>
->guest_mode can be folded into ->task, by specifying that ->task !=
NULL is equivalent to ->guest_mode != 0. This will make the rest of the
code easier to read.
> };
>
> struct kvm_vcpu {
> diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
> index 199489b..a160638 100644
> --- a/drivers/kvm/kvm_main.c
> +++ b/drivers/kvm/kvm_main.c
> @@ -1868,6 +1868,9 @@ static int kvm_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
> kvm_arch_ops->decache_regs(vcpu);
> }
>
> + vcpu->irq.task = current;
> + smp_wmb();
> +
>
This is best moved where ->guest_mode is set.
> +/*
> * This function will be invoked whenever the vcpu->irq.dev raises its INTR
> * line
> */
> @@ -2318,10 +2335,50 @@ static void kvm_vcpu_intr(struct kvm_irqsink *this,
> {
> struct kvm_vcpu *vcpu = (struct kvm_vcpu*)this->private;
> unsigned long flags;
> + int direct_ipi = -1;
>
> spin_lock_irqsave(&vcpu->irq.lock, flags);
>
irqs are always enabled here, so spin_lock_irq() (and a corresponding
spin_unlock_irq) is sufficient.
> static void kvm_vcpu_irqsink_init(struct kvm_vcpu *vcpu)
> diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
> index 4c03881..91546ae 100644
> --- a/drivers/kvm/svm.c
> +++ b/drivers/kvm/svm.c
> @@ -1542,11 +1542,40 @@ static int svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
> u16 gs_selector;
> u16 ldt_selector;
> int r;
> + unsigned long irq_flags;
>
> 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.
> + *
> + * FIXME: Do we need to do anything additional to mask IPI/NMIs?
>
You can remove the FIXME.
> + */
> + local_irq_save(irq_flags);
>
Interrupts are always enabled here, so local_irq_disable() suffices.
> @@ -1688,6 +1717,13 @@ again:
> #endif
> : "cc", "memory" );
>
> + /*
> + * FIXME: We'd like to turn on interrupts ASAP, but is this so early
> + * that we will mess up the state of the CPU before we fully
> + * transition from guest to host?
> + */
>
You can remove the FIXME. Pre-patch enabled interrupts much earlier.
> + local_irq_restore(irq_flags);
> +
> if (vcpu->fpu_active) {
> fx_save(vcpu->guest_fx_image);
> fx_restore(vcpu->host_fx_image);
> @@ -1710,6 +1746,13 @@ again:
> reload_tss(vcpu);
>
> /*
> + * Signal that we have transitioned back to host mode
> + */
> + spin_lock_irqsave(&vcpu->irq.lock, irq_flags);
> + vcpu->irq.guest_mode = 0;
> + spin_unlock_irqrestore(&vcpu->irq.lock, irq_flags);
>
>> Don't you need to check interrupts here?
> No, we assume that host userspace won't sleep.
Right, I forgot again.
> (prof_on == KVM_PROFILING))
> diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
> index ca858cb..7b81fff 100644
> --- a/drivers/kvm/vmx.c
> +++ b/drivers/kvm/vmx.c
> @@ -1895,6 +1895,7 @@ static int vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
> u16 fs_sel, gs_sel, ldt_sel;
> int fs_gs_ldt_reload_needed;
> int r;
> + unsigned long irq_flags;
>
> preempted:
> /*
> @@ -1929,9 +1930,37 @@ preempted:
> if (vcpu->guest_debug.enabled)
> kvm_guest_debug_pre(vcpu);
>
> + /*
> + * 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.
> + *
> + * FIXME: Do we need to do anything additional to mask IPI/NMIs?
> + */
> + local_irq_save(irq_flags);
> +
>
Pretty much same comments apply here. One day we'll unify some of this
code.
[...]
--
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/
next prev parent reply other threads:[~2007-05-14 9:34 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-09 3:03 [PATCH 0/8] in-kernel APIC support "v1" Gregory Haskins
[not found] ` <20070509023731.23443.86578.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-09 3:03 ` [PATCH 1/8] KVM: Adds support for in-kernel mmio handlers Gregory Haskins
[not found] ` <20070509030315.23443.93779.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-09 9:51 ` [PATCH 1/8] KVM: Adds support for in-kernel mmiohandlers Dor Laor
2007-05-09 3:03 ` [PATCH 2/8] KVM: Add irqdevice object Gregory Haskins
[not found] ` <20070509030320.23443.51197.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-09 15:16 ` Dor Laor
[not found] ` <64F9B87B6B770947A9F8391472E032160BBA6157-yEcIvxbTEBqsx+V+t5oei8rau4O3wl8o3fe8/T/H7NteoWH0uzbU5w@public.gmane.org>
2007-05-09 18:04 ` Gregory Haskins
[not found] ` <4641D4D8.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-05-09 22:12 ` Dor Laor
[not found] ` <64F9B87B6B770947A9F8391472E032160BBA6471-yEcIvxbTEBqsx+V+t5oei8rau4O3wl8o3fe8/T/H7NteoWH0uzbU5w@public.gmane.org>
2007-05-09 22:47 ` Gregory Haskins
[not found] ` <4642170B.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-05-13 12:05 ` Avi Kivity
2007-05-09 3:03 ` [PATCH 3/8] KVM: Adds ability to preempt an executing VCPU Gregory Haskins
[not found] ` <20070509030325.23443.90129.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-14 9:34 ` Avi Kivity [this message]
[not found] ` <46482D2E.7040809-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-14 15:19 ` Gregory Haskins
[not found] ` <464845AD.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-05-14 15:45 ` Avi Kivity
[not found] ` <46488426.8090705-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-14 18:19 ` Gregory Haskins
[not found] ` <46486FD4.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-05-15 7:28 ` Avi Kivity
[not found] ` <46496125.5020909-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-15 11:56 ` Gregory Haskins
[not found] ` <4649679C.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-05-16 10:05 ` Avi Kivity
[not found] ` <464AD772.4050007-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-16 12:10 ` Gregory Haskins
[not found] ` <464ABC67.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-05-16 12:18 ` Avi Kivity
2007-05-09 3:03 ` [PATCH 4/8] KVM: Adds ability to signal userspace using a file-descriptor Gregory Haskins
2007-05-09 3:03 ` [PATCH 5/8] KVM: Add support for in-kernel LAPIC model Gregory Haskins
2007-05-09 3:03 ` [PATCH 6/8] KVM: Adds support for real NMI injection on VMX processors Gregory Haskins
[not found] ` <20070509030340.23443.84153.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-14 9:38 ` Avi Kivity
2007-05-09 3:03 ` [PATCH 7/8] KVM: Adds basic plumbing to support TPR shadow features Gregory Haskins
2007-05-09 3:03 ` [PATCH 8/8] KVM: Adds support for TPR shadowing under VMX processors Gregory Haskins
[not found] ` <20070509030350.23443.35387.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-14 11:09 ` Avi Kivity
[not found] ` <46484376.6090304-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-14 15:28 ` Gregory Haskins
2007-05-13 12:02 ` [PATCH 0/8] in-kernel APIC support "v1" Avi Kivity
[not found] ` <4646FE71.5080009-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-13 14:09 ` Gregory Haskins
[not found] ` <4646E3D1.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-05-13 15:45 ` Avi Kivity
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=46482D2E.7040809@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox