public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@qumranet.com>
To: Bernhard Kaindl <bk@suse.de>
Cc: kvm-devel@lists.sourceforge.net
Subject: Re: [PATCH] Fix host_cpuid() in qemu/qemu-kvm-x86.c
Date: Thu, 21 Feb 2008 10:46:43 +0200	[thread overview]
Message-ID: <47BD3A73.7040704@qumranet.com> (raw)
In-Reply-To: <alpine.LNX.1.00.0802201656290.10030@jbgna.fhfr.qr>

Bernhard Kaindl wrote:
> Hi,
>
> I found that on kvm-61 the cpuid in the guest was reported incorrectly
> when qemu-kvm was compiled with gcc-4.1 or 4.3.
>
> This resulted in linux-64bit not booting, complaining that it is not
> running on a 64-bit machine.
>
> Symptom: Unexpected behaviour after the assembly snippet.
>
> Solution: New assembly which is simpler and leaves optimizations to gcc,
> resulting in much shorter and maintainable code.
>
> Comments are welcome,
>   

There were two reasons for the obfuscated code: first, qemu-kvm.c used 
to be compiled with ebx assigned to a global register, which can't be 
clobbered, and second not to cause excessive register pressure on i386.  
The first reason is gone, but can you test the second by compiling on i386?

> Bernhard
>
> PS: Thanks a lot to Alex Graf for the fix.
>
> --- qemu/qemu-kvm-x86.c
> +++ qemu/qemu-kvm-x86.c
> @@ -428,35 +428,7 @@ static void host_cpuid(uint32_t function
>      uint32_t vec[4];
>  
>      vec[0] = function;
> -    asm volatile (
> -#ifdef __x86_64__
> -	 "sub $128, %%rsp \n\t"  /* skip red zone */
> -         "push %0;  push %%rsi \n\t"
> -	 "push %%rax; push %%rbx; push %%rcx; push %%rdx \n\t"
> -	 "mov 8*5(%%rsp), %%rsi \n\t"
> -	 "mov (%%rsi), %%eax \n\t"
> -	 "cpuid \n\t"
> -	 "mov %%eax, (%%rsi) \n\t"
> -	 "mov %%ebx, 4(%%rsi) \n\t"
> -	 "mov %%ecx, 8(%%rsi) \n\t"
> -	 "mov %%edx, 12(%%rsi) \n\t"
> -	 "pop %%rdx; pop %%rcx; pop %%rbx; pop %%rax \n\t"
> -	 "pop %%rsi; pop %0 \n\t"
> -	 "add $128, %%rsp"
> -#else
> -         "push %0;  push %%esi \n\t"
> -	 "push %%eax; push %%ebx; push %%ecx; push %%edx \n\t"
> -	 "mov 4*5(%%esp), %%esi \n\t"
> -	 "mov (%%esi), %%eax \n\t"
> -	 "cpuid \n\t"
> -	 "mov %%eax, (%%esi) \n\t"
> -	 "mov %%ebx, 4(%%esi) \n\t"
> -	 "mov %%ecx, 8(%%esi) \n\t"
> -	 "mov %%edx, 12(%%esi) \n\t"
> -	 "pop %%edx; pop %%ecx; pop %%ebx; pop %%eax \n\t"
> -	 "pop %%esi; pop %0 \n\t"
> -#endif
> -	 : : "rm"(vec) : "memory");
> +    asm volatile("cpuid" : "+a" (vec[0]), "=b" (vec[1]),"=c" (vec[2]), "=d" (vec[3]));
>      if (eax)
>  	*eax = vec[0];
>      if (ebx)
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> kvm-devel mailing list
> kvm-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/kvm-devel
>   


-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

  reply	other threads:[~2008-02-21  8:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-20 15:57 [PATCH] Fix host_cpuid() in qemu/qemu-kvm-x86.c Bernhard Kaindl
2008-02-21  8:46 ` Avi Kivity [this message]
2008-02-21  9:14   ` Alexander Graf
2008-02-21 10:34     ` Alexander Graf
2008-02-21 10:52       ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47BD3A73.7040704@qumranet.com \
    --to=avi@qumranet.com \
    --cc=bk@suse.de \
    --cc=kvm-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox