From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gleb Natapov Subject: Re: [PATCH] kvm_para_available() should check hypervisor bit before accessing hypervisor cpuid leaf. Date: Tue, 1 May 2012 09:52:17 +0300 Message-ID: <20120501065217.GB22191@redhat.com> References: <20120430114549.GA22191@redhat.com> <1335803832.2574.0.camel@offbook> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, avi@redhat.com, mtosatti@redhat.com, mst@redhat.com To: Davidlohr Bueso Return-path: Received: from mx1.redhat.com ([209.132.183.28]:20451 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751714Ab2EAGwV (ORCPT ); Tue, 1 May 2012 02:52:21 -0400 Content-Disposition: inline In-Reply-To: <1335803832.2574.0.camel@offbook> Sender: kvm-owner@vger.kernel.org List-ID: 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 > > 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.