public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Davidlohr Bueso <dave@gnu.org>
Cc: kvm@vger.kernel.org, avi@redhat.com, mtosatti@redhat.com, mst@redhat.com
Subject: Re: [PATCH] kvm_para_available() should check hypervisor bit before accessing hypervisor cpuid leaf.
Date: Tue, 1 May 2012 09:52:17 +0300	[thread overview]
Message-ID: <20120501065217.GB22191@redhat.com> (raw)
In-Reply-To: <1335803832.2574.0.camel@offbook>

On Mon, Apr 30, 2012 at 06:37:12PM +0200, Davidlohr Bueso wrote:
> On Mon, 2012-04-30 at 14:45 +0300, Gleb Natapov wrote:
> > This couid range does not exist on real HW and Intel spec says that
> > "Information returned for highest basic information leaf" will be
> > returned. Not very well defined. 
> > 
> > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> > diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h
> > index 99c4bbe..a7a7a94 100644
> > --- a/arch/x86/include/asm/kvm_para.h
> > +++ b/arch/x86/include/asm/kvm_para.h
> > @@ -178,14 +178,16 @@ static inline int kvm_para_available(void)
> >  	unsigned int eax, ebx, ecx, edx;
> >  	char signature[13];
> >  
> > -	cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
> > -	memcpy(signature + 0, &ebx, 4);
> > -	memcpy(signature + 4, &ecx, 4);
> > -	memcpy(signature + 8, &edx, 4);
> > -	signature[12] = 0;
> > -
> > -	if (strcmp(signature, "KVMKVMKVM") == 0)
> > -		return 1;
> > +	if (cpu_has_hypervisor) {
> > +		cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
> > +		memcpy(signature + 0, &ebx, 4);
> > +		memcpy(signature + 4, &ecx, 4);
> > +		memcpy(signature + 8, &edx, 4);
> > +		signature[12] = 0;
> > +
> > +		if (strcmp(signature, "KVMKVMKVM") == 0)
> > +			return 1;
> > +	}
> >  
> >  	return 0;
> >  }
> 
> Wouldn't this be better?
> 
If I thought it would I would have wrote it like that :) I prefer less exit
points from a function if possible.

> --- a/arch/x86/include/asm/kvm_para.h
> +++ b/arch/x86/include/asm/kvm_para.h
> @@ -170,6 +170,9 @@ static inline int kvm_para_available(void)
>         unsigned int eax, ebx, ecx, edx;
>         char signature[13];
>  
> +       if (!cpu_has_hypervisor)
> +               return 0;
> +
>         cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
>         memcpy(signature + 0, &ebx, 4);
>         memcpy(signature + 4, &ecx, 4);
> 

--
			Gleb.

  reply	other threads:[~2012-05-01  6:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-30 11:45 [PATCH] kvm_para_available() should check hypervisor bit before accessing hypervisor cpuid leaf Gleb Natapov
2012-04-30 16:37 ` Davidlohr Bueso
2012-05-01  6:52   ` Gleb Natapov [this message]
2012-05-01 12:50 ` Avi Kivity
2012-05-01 12:55   ` Gleb Natapov
2012-05-01 12:59     ` Avi Kivity
2012-05-02 12:09       ` Gleb Natapov
2012-05-06 12:55         ` Avi Kivity
2012-05-06 13:00 ` 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=20120501065217.GB22191@redhat.com \
    --to=gleb@redhat.com \
    --cc=avi@redhat.com \
    --cc=dave@gnu.org \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    /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