All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Alexander Graf <agraf@suse.de>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] Activate Virtualization On Demand
Date: Tue, 17 Mar 2009 14:04:38 +0200	[thread overview]
Message-ID: <49BF91D6.7000008@redhat.com> (raw)
In-Reply-To: <1237279648-7839-1-git-send-email-agraf@suse.de>

Alexander Graf wrote:
> X86 CPUs need to have some magic happening to enable the virtualization
> extensions on them. This magic can result in unpleasant results for
> users, like blocking other VMMs from working (vmx) or using invalid TLB
> entries (svm).
>
> Currently KVM activates virtualization when the respective kernel module
> is loaded. This blocks us from autoloading KVM modules without breaking
> other VMMs.
>
> To circumvent this problem at least a bit, this patch introduces on
> demand activation of virtualization. This means, that instead
> virtualization is enabled on creation of the first virtual machine
> and disabled on destruction of the last one.
>
> So using this, KVM can be easily autoloaded, while keeping other
> hypervisors usable.
>   

> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 68b217e..7c40743 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -65,6 +65,8 @@ DEFINE_SPINLOCK(kvm_lock);
>  LIST_HEAD(vm_list);
>  
>  static cpumask_var_t cpus_hardware_enabled;
> +static int kvm_usage_count = 0;
> +static DEFINE_SPINLOCK(kvm_usage_lock);
>   

Please use kvm_lock for this.

>  
> @@ -2327,14 +2341,40 @@ static struct miscdevice kvm_dev = {
>  	&kvm_chardev_ops,
>  };
>  
> -static void hardware_enable(void *junk)
> +static void hardware_enable(void *_r)
>  {
>  	int cpu = raw_smp_processor_id();
> +	int r;
> +
> +	/* If enabling a previous CPU failed already, let's not continue */
> +	if (_r && *((int*)_r))
> +		return;
>   
>  
>  	if (cpumask_test_cpu(cpu, cpus_hardware_enabled))
>  		return;
> +	r = kvm_arch_hardware_enable(NULL);
> +	if (_r)
> +		*((int*)_r) = r;
>   

Racy.  If one cpu succeeds and another fails, the successful one could 
overwrite the failing one's result.

While the race will never happen (start two VMMs simultaneously) it will 
cause an endless stream of complaints.  Let's use an atomic_t 
incremented on each failure.

Oh, and it can be global since we're inside a lock, so some of the 
changes to add a return value become unnecessary.

>  
> +static void hardware_disable_all(void)
> +{
> +	if (!kvm_usage_count)
> +		return;
>   

Can this happen?

> +
> +	spin_lock(&kvm_usage_lock);
> +	kvm_usage_count--;
> +	if (!kvm_usage_count)
> +		on_each_cpu(hardware_disable, NULL, 1);
> +	spin_unlock(&kvm_usage_lock);
> +}
> +
>   

Please make sure cpu hotplug/hotunplug (and this suspend/resume) still work.

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


  reply	other threads:[~2009-03-17 12:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-17  8:47 [PATCH] Activate Virtualization On Demand Alexander Graf
2009-03-17 12:04 ` Avi Kivity [this message]
2009-03-17 15:48   ` Alexander Graf
2009-03-18  6:43     ` Avi Kivity
  -- strict thread matches above, loose matches on Subject: below --
2009-09-09 14:18 Alexander Graf
2009-09-14  5:05 ` Avi Kivity
2009-09-14 13:23 ` Marcelo Tosatti
2009-09-14 15:52   ` Alexander Graf
2009-09-14 16:14     ` Marcelo Tosatti
2009-09-14 16:25       ` Alexander Graf
2009-09-14 16:46         ` Marcelo Tosatti
2009-09-14 16:54           ` Alexander Graf
2009-09-15  9:37 Alexander Graf

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=49BF91D6.7000008@redhat.com \
    --to=avi@redhat.com \
    --cc=agraf@suse.de \
    --cc=kvm@vger.kernel.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.