Skip to contentSkip to conversation

Compile KVM support for x86_64 in i386.

PATCH New Glauber Costa 3 participants 8 messages Nov 5, 2008 – Nov 6, 2008

lore
Share & tools
lore
#0 lore raw

cover Compile KVM support for x86_64 in i386.

These two patches allow kvm to compile for x86_64 on a i386 host. This is actually the official config kvm-userspace uses. It breaks for me, so here's a fix.

The second patch is just a nitpick

#1 lore raw

PATCH 1/1 compile x86_64 on i386

This patch allows qemu-system-x86_64 to be compiled on a i386 host.

---
 configure |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)
configure +10 -7
index 067c3c5..65f0c74 100755
@@ -1447,13 +1447,16 @@ interp_prefix1=`echo "$interp_prefix" | sed "s/%M/$target_cpu/g"`
 echo "#define CONFIG_QEMU_PREFIX \"$interp_prefix1\"" >> $config_h
 gdb_xml_files=""
 
-# FIXME allow i386 to build on x86_64 and vice versa
-if test "$kvm" = "yes" -a "$target_cpu" != "$cpu" ; then
-  kvm="no"
-fi
-# Disable KVM for linux-user
-if test "$kvm" = "yes" -a "$target_softmmu" = "no" ; then
-  kvm="no"
+if test "$kvm" = "yes";
+then
+  # Disable KVM for linux-user
+  if test "$target_softmmu" = "no";
+  then
+     kvm="no"
+  elif test "$target_cpu" != "$cpu" && test ! "$cpu" = "i386" -a  "$target_cpu" = "x86_64" ;
+  then
+        kvm="no"
+  fi
 fi
 
 case "$target_cpu" in
Signature · 1 line
1.5.6.5
#2 lore raw

PATCH 1/1 correctly advertise presence of KVM support

We can fail in tests to enable kvm, for example, if we are compiling to a target different from our host platform. However, at that point, KVM support may have been already advertised to the user. This is very misleading.

So we first test it, and then advertise KVM support. To do that without spliting the summary strings around the whole configure, we move everything to the end, where nothing can change anymore

---
 configure |  102 ++++++++++++++++++++++++++++++------------------------------
 1 files changed, 51 insertions(+), 51 deletions(-)
configure +51 -51
index 65f0c74..8e11506 100755
@@ -1022,57 +1022,6 @@ else
   binsuffix="/bin"
 fi
 
-echo "Install prefix    $prefix"
-echo "BIOS directory    $prefix$datasuffix"
-echo "binary directory  $prefix$binsuffix"
-if test "$mingw32" = "no" ; then
-echo "Manual directory  $prefix$mansuffix"
-echo "ELF interp prefix $interp_prefix"
-fi
-echo "Source path       $source_path"
-echo "C compiler        $cc"
-echo "Host C compiler   $host_cc"
-echo "ARCH_CFLAGS       $ARCH_CFLAGS"
-echo "make              $make"
-echo "install           $install"
-echo "host CPU          $cpu"
-echo "host big endian   $bigendian"
-echo "target list       $target_list"
-echo "gprof enabled     $gprof"
-echo "sparse enabled    $sparse"
-echo "profiler          $profiler"
-echo "static build      $static"
-echo "-Werror enabled   $werror"
-if test "$darwin" = "yes" ; then
-    echo "Cocoa support     $cocoa"
-fi
-echo "SDL support       $sdl"
-if test "$sdl" != "no" ; then
-    echo "SDL static link   $sdl_static"
-fi
-echo "curses support    $curses"
-echo "mingw32 support   $mingw32"
-echo "Audio drivers     $audio_drv_list"
-echo "Extra audio cards $audio_card_list"
-echo "Mixer emulation   $mixemu"
-echo "VNC TLS support   $vnc_tls"
-if test "$vnc_tls" = "yes" ; then
-    echo "    TLS CFLAGS    $vnc_tls_cflags"
-    echo "    TLS LIBS      $vnc_tls_libs"
-fi
-if test -n "$sparc_cpu"; then
-    echo "Target Sparc Arch $sparc_cpu"
-fi
-echo "kqemu support     $kqemu"
-echo "brlapi support    $brlapi"
-echo "Documentation     $build_docs"
-[ ! -z "$uname_release" ] && \
-echo "uname -r          $uname_release"
-echo "NPTL support      $nptl"
-echo "vde support       $vde"
-echo "AIO support       $aio"
-echo "KVM support       $kvm"
-
 if test $sdl_too_old = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
 fi
@@ -1690,4 +1639,55 @@ if test "$source_path_used" = "yes" ; then
     done
 fi
 
+echo "Install prefix    $prefix"
+echo "BIOS directory    $prefix$datasuffix"
+echo "binary directory  $prefix$binsuffix"
+if test "$mingw32" = "no" ; then
+echo "Manual directory  $prefix$mansuffix"
+echo "ELF interp prefix $interp_prefix"
+fi
+echo "Source path       $source_path"
+echo "C compiler        $cc"
+echo "Host C compiler   $host_cc"
+echo "ARCH_CFLAGS       $ARCH_CFLAGS"
+echo "make              $make"
+echo "install           $install"
+echo "host CPU          $cpu"
+echo "host big endian   $bigendian"
+echo "target list       $target_list"
+echo "gprof enabled     $gprof"
+echo "sparse enabled    $sparse"
+echo "profiler          $profiler"
+echo "static build      $static"
+echo "-Werror enabled   $werror"
+if test "$darwin" = "yes" ; then
+    echo "Cocoa support     $cocoa"
+fi
+echo "SDL support       $sdl"
+if test "$sdl" != "no" ; then
+    echo "SDL static link   $sdl_static"
+fi
+echo "curses support    $curses"
+echo "mingw32 support   $mingw32"
+echo "Audio drivers     $audio_drv_list"
+echo "Extra audio cards $audio_card_list"
+echo "Mixer emulation   $mixemu"
+echo "VNC TLS support   $vnc_tls"
+if test "$vnc_tls" = "yes" ; then
+    echo "    TLS CFLAGS    $vnc_tls_cflags"
+    echo "    TLS LIBS      $vnc_tls_libs"
+fi
+if test -n "$sparc_cpu"; then
+    echo "Target Sparc Arch $sparc_cpu"
+fi
+echo "kqemu support     $kqemu"
+echo "brlapi support    $brlapi"
+echo "Documentation     $build_docs"
+[ ! -z "$uname_release" ] && \
+echo "uname -r          $uname_release"
+echo "NPTL support      $nptl"
+echo "vde support       $vde"
+echo "AIO support       $aio"
+echo "KVM support       $kvm"
+
 rm -f $TMPO $TMPC $TMPE $TMPS $TMPI
Signature · 1 line
1.5.6.5
#5 lore raw

Re: [Qemu-devel] [PATCH] compile x86_64 on i386

In reply to Glauber Costa
Quoted 2 lines · Glauber Costa

This patch allows qemu-system-x86_64 to be compiled on a i386 host.

For this to properly work, you need to fix the FIXMEs in target-i386/kvm.c that are around lm_capable_check. Basically, if you're on a 32-bit kernel, but a 64-bit capable processor, you need to mask long mode from the guest or it may try to use it.

Regards,

Anthony Liguori

Quoted 33 lines
---
 configure |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)
configure +10 -7
index 067c3c5..65f0c74 100755
@@ -1447,13 +1447,16 @@ interp_prefix1=`echo "$interp_prefix" | sed "s/%M/$target_cpu/g"`
 echo "#define CONFIG_QEMU_PREFIX \"$interp_prefix1\"" >> $config_h
 gdb_xml_files=""
 
-# FIXME allow i386 to build on x86_64 and vice versa
-if test "$kvm" = "yes" -a "$target_cpu" != "$cpu" ; then
-  kvm="no"
-fi
-# Disable KVM for linux-user
-if test "$kvm" = "yes" -a "$target_softmmu" = "no" ; then
-  kvm="no"
+if test "$kvm" = "yes";
+then
+  # Disable KVM for linux-user
+  if test "$target_softmmu" = "no";
+  then
+     kvm="no"
+  elif test "$target_cpu" != "$cpu" && test ! "$cpu" = "i386" -a  "$target_cpu" = "x86_64" ;
+  then
+        kvm="no"
+  fi
 fi
 
 case "$target_cpu" in
#6 lore raw

Re: [Qemu-devel] [PATCH] compile x86_64 on i386

Quoted 9 lines · Anthony Liguori
Quoted 3 lines · Glauber Costa

This patch allows qemu-system-x86_64 to be compiled on a i386 host.

For this to properly work, you need to fix the FIXMEs in target-i386/kvm.c that are around lm_capable_check. Basically, if you're on a 32-bit kernel, but a 64-bit capable processor, you need to mask long mode from the guest or it may try to use it.

Yes, but 32-bit kernels work fine (since they not even try) So they are orthogonal.

Quoted 41 lines

Regards,

Anthony Liguori

Quoted 33 lines
---
 configure |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)
configure +0 -0
index 067c3c5..65f0c74 100755
@@ -1447,13 +1447,16 @@ interp_prefix1=`echo "$interp_prefix" | sed

"s/%M/$target_cpu/g"`
echo "#define CONFIG_QEMU_PREFIX \"$interp_prefix1\"" >> $config_h gdb_xml_files=""
-# FIXME allow i386 to build on x86_64 and vice versa

configure +10 -6
-if test "$kvm" = "yes" -a "$target_cpu" != "$cpu" ; then
-  kvm="no"
-fi
-# Disable KVM for linux-user
-if test "$kvm" = "yes" -a "$target_softmmu" = "no" ; then
-  kvm="no"
+if test "$kvm" = "yes";
+then
+  # Disable KVM for linux-user
+  if test "$target_softmmu" = "no";
+  then
+     kvm="no"
+  elif test "$target_cpu" != "$cpu" && test ! "$cpu" = "i386" -a
 "$target_cpu" = "x86_64" ;
+  then
+        kvm="no"
+  fi
 fi
  case "$target_cpu" in
Signature · 5 lines
Glauber  Costa.
"Free as in Freedom"
http://glommer.net

"The less confident you are, the more serious you have to act."
#7 lore raw

Re: [Qemu-devel] [PATCH] compile x86_64 on i386

Quoted 7 lines · Glauber Costa
Quoted 5 lines · Anthony Liguori
Quoted 3 lines · Glauber Costa

This patch allows qemu-system-x86_64 to be compiled on a i386 host.

Quoted 9 lines
Quoted 5 lines

For this to properly work, you need to fix the FIXMEs in target-i386/kvm.c that are around lm_capable_check. Basically, if you're on a 32-bit kernel, but a 64-bit capable processor, you need to mask long mode from the guest or it may try to use it.

Yes, but 32-bit kernels work fine (since they not even try) So they are orthogonal.

Well, I don't buy your argument, but we have the same problem with qemu-system-i386 anyway so I guess your patch makes things no worse.

I've committed something slightly different that I hope will extend more easily. Thanks.

Regards,

Anthony Liguori

Quoted 46 lines
Quoted 42 lines

Regards,

Anthony Liguori

Quoted 34 lines
---
 configure |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)
configure +0 -0
index 067c3c5..65f0c74 100755
@@ -1447,13 +1447,16 @@ interp_prefix1=`echo "$interp_prefix" | sed

"s/%M/$target_cpu/g"`
echo "#define CONFIG_QEMU_PREFIX \"$interp_prefix1\"" >> $config_h gdb_xml_files=""
-# FIXME allow i386 to build on x86_64 and vice versa

configure +10 -6
-if test "$kvm" = "yes" -a "$target_cpu" != "$cpu" ; then
-  kvm="no"
-fi
-# Disable KVM for linux-user
-if test "$kvm" = "yes" -a "$target_softmmu" = "no" ; then
-  kvm="no"
+if test "$kvm" = "yes";
+then
+  # Disable KVM for linux-user
+  if test "$target_softmmu" = "no";
+  then
+     kvm="no"
+  elif test "$target_cpu" != "$cpu" && test ! "$cpu" = "i386" -a
 "$target_cpu" = "x86_64" ;
+  then
+        kvm="no"
+  fi
 fi
  case "$target_cpu" in
#3 lore raw

Re: [Qemu-devel] [PATCH] correctly advertise presence of KVM support

In reply to Glauber Costa
Quoted 9 lines · Glauber Costa

We can fail in tests to enable kvm, for example, if we are compiling to a target different from our host platform. However, at that point, KVM support may have been already advertised to the user. This is very misleading.

So we first test it, and then advertise KVM support. To do that without spliting the summary strings around the whole configure, we move everything to the end, where nothing can change anymore

This isn't quite correct. If you did something like:

configure --target-list='x86_64-softmmu cris-softmmu'

Then even though x86_64-softmmu may have KVM enabled, it's dumb luck whether or not you see KVM yes in the configure output depending on which target gets configured first.

I think we need something a bit more sophisticated like output for all of the targets with KVM enabled or something like that.

For instance, consider if you did configure --target-list='x86_64-softmmu i386-softmmu cris-softmmu'

Regards,

Anthony Liguori

Quoted 124 lines
---
 configure |  102 ++++++++++++++++++++++++++++++------------------------------
 1 files changed, 51 insertions(+), 51 deletions(-)
configure +51 -51
index 65f0c74..8e11506 100755
@@ -1022,57 +1022,6 @@ else
   binsuffix="/bin"
 fi
 
-echo "Install prefix    $prefix"
-echo "BIOS directory    $prefix$datasuffix"
-echo "binary directory  $prefix$binsuffix"
-if test "$mingw32" = "no" ; then
-echo "Manual directory  $prefix$mansuffix"
-echo "ELF interp prefix $interp_prefix"
-fi
-echo "Source path       $source_path"
-echo "C compiler        $cc"
-echo "Host C compiler   $host_cc"
-echo "ARCH_CFLAGS       $ARCH_CFLAGS"
-echo "make              $make"
-echo "install           $install"
-echo "host CPU          $cpu"
-echo "host big endian   $bigendian"
-echo "target list       $target_list"
-echo "gprof enabled     $gprof"
-echo "sparse enabled    $sparse"
-echo "profiler          $profiler"
-echo "static build      $static"
-echo "-Werror enabled   $werror"
-if test "$darwin" = "yes" ; then
-    echo "Cocoa support     $cocoa"
-fi
-echo "SDL support       $sdl"
-if test "$sdl" != "no" ; then
-    echo "SDL static link   $sdl_static"
-fi
-echo "curses support    $curses"
-echo "mingw32 support   $mingw32"
-echo "Audio drivers     $audio_drv_list"
-echo "Extra audio cards $audio_card_list"
-echo "Mixer emulation   $mixemu"
-echo "VNC TLS support   $vnc_tls"
-if test "$vnc_tls" = "yes" ; then
-    echo "    TLS CFLAGS    $vnc_tls_cflags"
-    echo "    TLS LIBS      $vnc_tls_libs"
-fi
-if test -n "$sparc_cpu"; then
-    echo "Target Sparc Arch $sparc_cpu"
-fi
-echo "kqemu support     $kqemu"
-echo "brlapi support    $brlapi"
-echo "Documentation     $build_docs"
-[ ! -z "$uname_release" ] && \
-echo "uname -r          $uname_release"
-echo "NPTL support      $nptl"
-echo "vde support       $vde"
-echo "AIO support       $aio"
-echo "KVM support       $kvm"
-
 if test $sdl_too_old = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
 fi
@@ -1690,4 +1639,55 @@ if test "$source_path_used" = "yes" ; then
     done
 fi
 
+echo "Install prefix    $prefix"
+echo "BIOS directory    $prefix$datasuffix"
+echo "binary directory  $prefix$binsuffix"
+if test "$mingw32" = "no" ; then
+echo "Manual directory  $prefix$mansuffix"
+echo "ELF interp prefix $interp_prefix"
+fi
+echo "Source path       $source_path"
+echo "C compiler        $cc"
+echo "Host C compiler   $host_cc"
+echo "ARCH_CFLAGS       $ARCH_CFLAGS"
+echo "make              $make"
+echo "install           $install"
+echo "host CPU          $cpu"
+echo "host big endian   $bigendian"
+echo "target list       $target_list"
+echo "gprof enabled     $gprof"
+echo "sparse enabled    $sparse"
+echo "profiler          $profiler"
+echo "static build      $static"
+echo "-Werror enabled   $werror"
+if test "$darwin" = "yes" ; then
+    echo "Cocoa support     $cocoa"
+fi
+echo "SDL support       $sdl"
+if test "$sdl" != "no" ; then
+    echo "SDL static link   $sdl_static"
+fi
+echo "curses support    $curses"
+echo "mingw32 support   $mingw32"
+echo "Audio drivers     $audio_drv_list"
+echo "Extra audio cards $audio_card_list"
+echo "Mixer emulation   $mixemu"
+echo "VNC TLS support   $vnc_tls"
+if test "$vnc_tls" = "yes" ; then
+    echo "    TLS CFLAGS    $vnc_tls_cflags"
+    echo "    TLS LIBS      $vnc_tls_libs"
+fi
+if test -n "$sparc_cpu"; then
+    echo "Target Sparc Arch $sparc_cpu"
+fi
+echo "kqemu support     $kqemu"
+echo "brlapi support    $brlapi"
+echo "Documentation     $build_docs"
+[ ! -z "$uname_release" ] && \
+echo "uname -r          $uname_release"
+echo "NPTL support      $nptl"
+echo "vde support       $vde"
+echo "AIO support       $aio"
+echo "KVM support       $kvm"
+
 rm -f $TMPO $TMPC $TMPE $TMPS $TMPI
#4 lore raw

Re: [Qemu-devel] [PATCH] correctly advertise presence of KVM support

Quoted 20 lines · Anthony Liguori
Quoted 10 lines · Glauber Costa

We can fail in tests to enable kvm, for example, if we are compiling to a target different from our host platform. However, at that point, KVM support may have been already advertised to the user. This is very misleading.

So we first test it, and then advertise KVM support. To do that without spliting the summary strings around the whole configure, we move everything to the end, where nothing can change anymore

This isn't quite correct. If you did something like:

configure --target-list='x86_64-softmmu cris-softmmu'

Then even though x86_64-softmmu may have KVM enabled, it's dumb luck whether
or not you see KVM yes in the configure output depending on which target
gets configured first.

Quoted 5 lines

I think we need something a bit more sophisticated like output for all of the targets with KVM enabled or something like that.

For instance, consider if you did configure --target-list='x86_64-softmmu i386-softmmu cris-softmmu'

I agree it's better as a general solution. I was just thinking short term. I'll rewrite it accordingly

Quoted 133 lines

Regards,

Anthony Liguori

Quoted 124 lines
---
 configure |  102
++++++++++++++++++++++++++++++------------------------------
 1 files changed, 51 insertions(+), 51 deletions(-)
configure +0 -50
index 65f0c74..8e11506 100755
@@ -1022,57 +1022,6 @@ else
  binsuffix="/bin"
 fi
 -echo "Install prefix    $prefix"
-echo "BIOS directory    $prefix$datasuffix"
-echo "binary directory  $prefix$binsuffix"
-if test "$mingw32" = "no" ; then
-echo "Manual directory  $prefix$mansuffix"
-echo "ELF interp prefix $interp_prefix"
-fi
-echo "Source path       $source_path"
-echo "C compiler        $cc"
-echo "Host C compiler   $host_cc"
-echo "ARCH_CFLAGS       $ARCH_CFLAGS"
-echo "make              $make"
-echo "install           $install"
-echo "host CPU          $cpu"
-echo "host big endian   $bigendian"
-echo "target list       $target_list"
-echo "gprof enabled     $gprof"
-echo "sparse enabled    $sparse"
-echo "profiler          $profiler"
-echo "static build      $static"
-echo "-Werror enabled   $werror"
-if test "$darwin" = "yes" ; then
-    echo "Cocoa support     $cocoa"
-fi
-echo "SDL support       $sdl"
-if test "$sdl" != "no" ; then
-    echo "SDL static link   $sdl_static"
-fi
-echo "curses support    $curses"
-echo "mingw32 support   $mingw32"
-echo "Audio drivers     $audio_drv_list"
-echo "Extra audio cards $audio_card_list"
-echo "Mixer emulation   $mixemu"
-echo "VNC TLS support   $vnc_tls"
-if test "$vnc_tls" = "yes" ; then
-    echo "    TLS CFLAGS    $vnc_tls_cflags"
-    echo "    TLS LIBS      $vnc_tls_libs"
-fi
-if test -n "$sparc_cpu"; then
-    echo "Target Sparc Arch $sparc_cpu"
-fi
-echo "kqemu support     $kqemu"
-echo "brlapi support    $brlapi"
-echo "Documentation     $build_docs"
-[ ! -z "$uname_release" ] && \
-echo "uname -r          $uname_release"
-echo "NPTL support      $nptl"
-echo "vde support       $vde"
-echo "AIO support       $aio"
-echo "KVM support       $kvm"
-
 if test $sdl_too_old = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL

support"
fi

configure +50 -0
@@ -1690,4 +1639,55 @@ if test "$source_path_used" = "yes" ; then
    done
 fi
 +echo "Install prefix    $prefix"
+echo "BIOS directory    $prefix$datasuffix"
+echo "binary directory  $prefix$binsuffix"
+if test "$mingw32" = "no" ; then
+echo "Manual directory  $prefix$mansuffix"
+echo "ELF interp prefix $interp_prefix"
+fi
+echo "Source path       $source_path"
+echo "C compiler        $cc"
+echo "Host C compiler   $host_cc"
+echo "ARCH_CFLAGS       $ARCH_CFLAGS"
+echo "make              $make"
+echo "install           $install"
+echo "host CPU          $cpu"
+echo "host big endian   $bigendian"
+echo "target list       $target_list"
+echo "gprof enabled     $gprof"
+echo "sparse enabled    $sparse"
+echo "profiler          $profiler"
+echo "static build      $static"
+echo "-Werror enabled   $werror"
+if test "$darwin" = "yes" ; then
+    echo "Cocoa support     $cocoa"
+fi
+echo "SDL support       $sdl"
+if test "$sdl" != "no" ; then
+    echo "SDL static link   $sdl_static"
+fi
+echo "curses support    $curses"
+echo "mingw32 support   $mingw32"
+echo "Audio drivers     $audio_drv_list"
+echo "Extra audio cards $audio_card_list"
+echo "Mixer emulation   $mixemu"
+echo "VNC TLS support   $vnc_tls"
+if test "$vnc_tls" = "yes" ; then
+    echo "    TLS CFLAGS    $vnc_tls_cflags"
+    echo "    TLS LIBS      $vnc_tls_libs"
+fi
+if test -n "$sparc_cpu"; then
+    echo "Target Sparc Arch $sparc_cpu"
+fi
+echo "kqemu support     $kqemu"
+echo "brlapi support    $brlapi"
+echo "Documentation     $build_docs"
+[ ! -z "$uname_release" ] && \
+echo "uname -r          $uname_release"
+echo "NPTL support      $nptl"
+echo "vde support       $vde"
+echo "AIO support       $aio"
+echo "KVM support       $kvm"
+
 rm -f $TMPO $TMPC $TMPE $TMPS $TMPI
Signature · 5 lines
Glauber  Costa.
"Free as in Freedom"
http://glommer.net

"The less confident you are, the more serious you have to act."