From mboxrd@z Thu Jan 1 00:00:00 1970 From: "H. Peter Anvin" Subject: Re: [PATCH 1/4] x86: introduce hypervisor_cpuid_base() Date: Tue, 23 Jul 2013 03:04:44 -0700 Message-ID: <51EE553C.40305@zytor.com> References: <1374572465-15278-1-git-send-email-jasowang@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: tglx@linutronix.de, mingo@redhat.com, x86@kernel.org, gleb@redhat.com, pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org To: Jason Wang Return-path: In-Reply-To: <1374572465-15278-1-git-send-email-jasowang@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On 07/23/2013 02:41 AM, Jason Wang wrote: > > +static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves) > +{ > + uint32_t base, eax, ebx, ecx, edx; > + char signature[13]; > + > + for (base = 0x40000000; base < 0x40010000; base += 0x100) { > + cpuid(base, &eax, &ebx, &ecx, &edx); > + *(uint32_t *)(signature + 0) = ebx; > + *(uint32_t *)(signature + 4) = ecx; > + *(uint32_t *)(signature + 8) = edx; > + signature[12] = 0; > + > + if (!strcmp(sig, signature) && > + (leaves == 0 || ((eax - base) >= leaves))) > + return base; > + } > + > + return 0; > +} > + Hmm... how about: uint32_t sign[3]; cpuid(base, &eax, &sign[0], &sign[1], &sign[2]); if (!memcmp(sig, sign, 12) && ...); -hpa