public inbox for kvm@vger.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] KVM-USER: Check kvm extensions at runtime
Date: Wed, 16 May 2007 14:47:39 +0300	[thread overview]
Message-ID: <464AEF5B.3010104@qumranet.com> (raw)
In-Reply-To: <20070515134018.12691.87290.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>

Gregory Haskins wrote:
> Newer userspace may run on an older kernel.  Therefore we need a way to 
> check the capabilities of the kernel so that we can downgrade userspace
> dynamically if necessary
>
> Signed-off-by: Gregory Haskins <ghaskins-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
> ---
>
>  qemu/qemu-kvm.c |   19 +++++++++++++++++++
>  user/kvmctl.c   |   14 ++++++++++++++
>  user/kvmctl.h   |    5 +++++
>  3 files changed, 38 insertions(+), 0 deletions(-)
>
> diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c
> index 59e79bf..6096f21 100644
> --- a/qemu/qemu-kvm.c
> +++ b/qemu/qemu-kvm.c
> @@ -697,6 +697,25 @@ int kvm_qemu_init()
>  int kvm_qemu_create_context(void)
>  {
>      int i;
> +    uint64_t ext;
> +
> +    if (kvm_check_extension(kvm_context, &ext) < 0) {
> +	kvm_qemu_destroy();
> +	return -1;
> +    }
> +
> +    if (!(ext & KVM_EXTENSION_LAPIC) && kvm_apic_level) {
> +	/*
> +	 * Opps... the kernel doesnt support apic-emulation even though
> +	 * the user wants it.  We must turn this off and warn the user
> +	 */
> +	kvm_apic_level = 0;
> +
> +	/* FIXME: We should log this officially */
> +	printf("WARNING: older kernel does not support apic " \
> +	       "emulation.  Falling back to userspace emulation.  Upgrade " \
> +	       "your kernel/modules\n");
> +    }
>   

The user may not be in a position to upgrade the kernel.  Think distro 
kernel and userspace.  A warning is a bit severe.

>  
>      if (kvm_create(kvm_context, phys_ram_size, kvm_apic_level,
>  		   (void**)&phys_ram_base) < 0) {
> diff --git a/user/kvmctl.c b/user/kvmctl.c
> index ea86426..fcabc1a 100644
> --- a/user/kvmctl.c
> +++ b/user/kvmctl.c
> @@ -889,3 +889,17 @@ int kvm_set_signal_mask(kvm_context_t kvm, int vcpu, const sigset_t *sigset)
>  	free(sigmask);
>  	return r;
>  }
> +
> +int kvm_check_extension(kvm_context_t kvm, uint64_t *ext)
> +{
> +	*ext = 0;
> +
> +	int r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_APIC_MSG);
> +	if (r < 0)
> +		return r;
>   

-errno for new code, please.

> +
> +	if (r)
> +		*ext |= KVM_EXTENSION_LAPIC;
> +
> +	return 0;
> +}
>   

How about a struct with a field per extension instead of bitmasks?

-- 
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-16 11:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-15 13:40 [PATCH] KVM-USER: Check kvm extensions at runtime Gregory Haskins
     [not found] ` <20070515134018.12691.87290.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-16 11:47   ` Avi Kivity [this message]
     [not found]     ` <464AEF5B.3010104-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-16 12:31       ` Gregory Haskins
     [not found]         ` <464AC145.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-05-16 14:36           ` 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=464AEF5B.3010104@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