lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <51EE65F4.3000703@redhat.com>
Date:	Tue, 23 Jul 2013 13:16:04 +0200
From:	Paolo Bonzini <pbonzini@...hat.com>
To:	"H. Peter Anvin" <hpa@...or.com>
CC:	Jason Wang <jasowang@...hat.com>, tglx@...utronix.de,
	mingo@...hat.com, x86@...nel.org, gleb@...hat.com,
	kvm@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/4] x86: introduce hypervisor_cpuid_base()

Il 23/07/2013 12:04, H. Peter Anvin ha scritto:
> 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) && ...);

That's nicer, though strcmp is what the replaced code used to do in
patches 2 and 3.

Note that memcmp requires the caller to use "KVMKVMKVM\0\0" as the
signature (or alternatively hypervisor_cpuid_base can copy the argument
into another 12-byte local variable).

Paolo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ