From mboxrd@z Thu Jan 1 00:00:00 1970 From: Davidlohr Bueso Subject: Re: [PATCH] kvm_para_available() should check hypervisor bit before accessing hypervisor cpuid leaf. Date: Mon, 30 Apr 2012 18:37:12 +0200 Message-ID: <1335803832.2574.0.camel@offbook> References: <20120430114549.GA22191@redhat.com> Reply-To: dave@gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, avi@redhat.com, mtosatti@redhat.com, mst@redhat.com To: Gleb Natapov Return-path: Received: from caiajhbdcbbj.dreamhost.com ([208.97.132.119]:37665 "EHLO homiemail-a3.g.dreamhost.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755383Ab2D3QhQ (ORCPT ); Mon, 30 Apr 2012 12:37:16 -0400 In-Reply-To: <20120430114549.GA22191@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: 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? --- 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);