Re: [PATCH] kvm_para_available() should check hypervisor bit before accessing hypervisor cpuid leaf.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
> > 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.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux