qemu-kvm: wrong CPU capabilities shown in cpuid

Bug #1133236 reported by Roman Racine
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
linux (Ubuntu)
Incomplete
Undecided
Unassigned
qemu-kvm (Ubuntu)
Confirmed
High
Unassigned

Bug Description

I have installed the qemu-kvm packages from:
Description: Ubuntu 12.04.2 LTS
Release: 12.04

The installed versions are:
ii kvm 1:84+dfsg-0ubuntu16+1.0+noroms+0ubuntu14.7 dummy transitional package from kvm to qemu-kvm
ii qemu-kvm 1.0+noroms-0ubuntu14.7 Full virtualization on i386 and amd64 hardware

I'm running Ubuntu 12.04.2 LTS on the host machine as well as on the guest machine. I'm using the gcc package 4:4.6.3-1ubuntu5 for compiling the source code below.

If I compile this code using -O2 -march=native as options on the virtual guest machine, this results in a SIGILL:
#include <stdio.h>
#include <string.h>

int main(void) {
  char testchar[20] = "abcde";
  printf("%d\n",(int) strlen(testchar));
  return 0;
}

Debugging shows that the illegal instruction is:
andn %eax, %ecx, %eax

The basic problem is that the virtual CPU does not support the andn instruction. Nevertheless it says so. Executing this assembly code will tell that the CPU does support the andn instraction although in reality it doesn't:

        movl $7, %eax
        movl $0, %ecx
        cpuid

This means that code compiled with gcc -march=native potentially does not run as it should, as soon as gcc uses the andn instruction.

The CPU on the host system is:

processor : 0
vendor_id : AuthenticAMD
cpu family : 16
model : 9
model name : AMD Opteron(tm) Processor 6172
stepping : 1
microcode : 0x10000d9
cpu MHz : 800.000
cache size : 512 KB
physical id : 0
siblings : 12
core id : 0
cpu cores : 12
apicid : 16
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm 3dnowext 3dnow constant_tsc rep_good nopl nonstop_tsc extd_apicid amd_dcm pni monitor cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt nodeid_msr npt lbrv svm_lock nrip_save pausefilter
bogomips : 4200.11
TLB size : 1024 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 48 bits physical, 48 bits virtual
power management: ts ttp tm stc 100mhzsteps hwpstate

The CPU shown in the virtual machine is:
processor : 0
vendor_id : AuthenticAMD
cpu family : 6
model : 2
model name : QEMU Virtual CPU version 1.0
stepping : 3
microcode : 0x1000065
cpu MHz : 2100.000
cache size : 512 KB
fpu : yes
fpu_exception : yes
cpuid level : 4
wp : yes
flags : fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm nopl pni cx16 popcnt hypervisor lahf_lm svm abm sse4a
bogomips : 4200.00
TLB size : 1024 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:

Changed in qemu-kvm (Ubuntu):
importance: Undecided → High
Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Thanks for reporting this bug. Do you know if you can still reproduce this with either quantal or raring, or on an intel box with precise?

Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

(I'm assuming that abm is the bad cpu flag)

tags: added: amd
Changed in qemu-kvm (Ubuntu):
status: New → Incomplete
Revision history for this message
Roman Racine (roman-racine) wrote :

The host is a production machine, I cannot upgrade it to quantal or raring. I have however installed a VM with quantal (running on the same host system). I cannot reproduce the bug there using the same code but this might also be related to the newer compiler. I don't have any contemporary intel machines at hand unfortunately ...

Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Thanks - I have an amd laptop I'll try to reproduce on when it frees up.

Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Reproduced on amd with precise.

Changed in qemu-kvm (Ubuntu):
status: Incomplete → Confirmed
Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Even with the very latest upstream qemu (1.4.0+) on the precise kernel, I can reproduce this.

Revision history for this message
Brad Figg (brad-figg) wrote : Missing required logs.

This bug is missing log files that will aid in diagnosing the problem. From a terminal window please run:

apport-collect 1133236

and then change the status of the bug to 'Confirmed'.

If, due to the nature of the issue you have encountered, you are unable to run this command, please add a comment stating that fact and change the bug status to 'Confirmed'.

This change has been made by an automated script, maintained by the Ubuntu Kernel Team.

Changed in linux (Ubuntu):
status: New → Incomplete
tags: added: precise
Revision history for this message
Serge Hallyn (serge-hallyn) wrote : apport information

AlsaVersion: Advanced Linux Sound Architecture Driver Version 1.0.24.
AplayDevices: Error: [Errno 2] No such file or directory
ApportVersion: 2.0.1-0ubuntu17.1
Architecture: amd64
ArecordDevices: Error: [Errno 2] No such file or directory
AudioDevicesInUse: Error: command ['fuser', '-v', '/dev/snd/controlC1', '/dev/snd/hwC1D0', '/dev/snd/pcmC1D0c', '/dev/snd/pcmC1D0p', '/dev/snd/controlC0', '/dev/snd/hwC0D0', '/dev/snd/pcmC0D3p', '/dev/snd/by-path', '/dev/snd/controlC29', '/dev/snd/seq', '/dev/snd/timer'] failed with exit code 1:
CRDA: Error: [Errno 2] No such file or directory
Card0.Amixer.info: Error: [Errno 2] No such file or directory
Card0.Amixer.values: Error: [Errno 2] No such file or directory
Card1.Amixer.info: Error: [Errno 2] No such file or directory
Card1.Amixer.values: Error: [Errno 2] No such file or directory
Card29.Amixer.info: Error: [Errno 2] No such file or directory
Card29.Amixer.values: Error: [Errno 2] No such file or directory
DistroRelease: Ubuntu 12.04
HibernationDevice: RESUME=UUID=885c93f8-dca6-41ec-a282-4111b0ca243a
KvmCmdLine: Error: command ['ps', '-C', 'kvm', '-F'] failed with exit code 1: UID PID PPID C SZ RSS PSR STIME TTY TIME CMD
MachineType: LENOVO 062223U
MarkForUpload: True
Package: qemu-kvm 1.2.0+noroms-0ubuntu2.12.10.2
PackageArchitecture: amd64
ProcEnviron:
 LANGUAGE=en_US:
 TERM=screen
 PATH=(custom, no user)
 LANG=en_US.UTF-8
 SHELL=/bin/bash
ProcFB: 0 radeondrmfb
ProcKernelCmdLine: BOOT_IMAGE=/boot/vmlinuz-3.2.0-38-generic root=UUID=72e3072d-48ce-47bc-8be5-a41e7aa48393 ro quiet splash vt.handoff=7
ProcVersionSignature: Ubuntu 3.2.0-38.61-generic 3.2.37
RfKill: Error: [Errno 2] No such file or directory
StagingDrivers: rts_pstor
Tags: precise staging precise
Uname: Linux 3.2.0-38-generic x86_64
UnreportableReason: This is not an official Ubuntu package. Please remove any third party package and try again.
UpgradeStatus: No upgrade log present (probably fresh install)
UserGroups: adm cdrom dip kvm lpadmin plugdev sambashare sudo
dmi.bios.date: 11/15/2011
dmi.bios.vendor: LENOVO
dmi.bios.version: 8RET52WW (1.15 )
dmi.board.asset.tag: Not Available
dmi.board.name: 062223U
dmi.board.vendor: LENOVO
dmi.board.version: Not Available
dmi.chassis.asset.tag: No Asset Information
dmi.chassis.type: 10
dmi.chassis.vendor: LENOVO
dmi.chassis.version: Not Available
dmi.modalias: dmi:bvnLENOVO:bvr8RET52WW(1.15):bd11/15/2011:svnLENOVO:pn062223U:pvrThinkPadX130e:rvnLENOVO:rn062223U:rvrNotAvailable:cvnLENOVO:ct10:cvrNotAvailable:
dmi.product.name: 062223U
dmi.product.version: ThinkPad X130e
dmi.sys.vendor: LENOVO

tags: added: apport-collected staging
Revision history for this message
Serge Hallyn (serge-hallyn) wrote : AcpiTables.txt

apport information

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : AlsaDevices.txt

apport information

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : BootDmesg.txt

apport information

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : Card0.Codecs.codec.0.txt

apport information

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : Card1.Codecs.codec.0.txt

apport information

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : CurrentDmesg.txt

apport information

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : Dependencies.txt

apport information

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : IwConfig.txt

apport information

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : Lspci.txt

apport information

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : Lsusb.txt

apport information

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : PciMultimedia.txt

apport information

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : ProcCpuinfo.txt

apport information

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : ProcInterrupts.txt

apport information

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : ProcModules.txt

apport information

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : RelatedPackageVersions.txt

apport information

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : UdevDb.txt

apport information

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.