<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>599</bug_id>
          
          <creation_ts>2010-12-15 06:47:44 +0000</creation_ts>
          <short_desc>[poky] qemu running with KVM needs root permission</short_desc>
          <delta_ts>2011-01-07 17:26:47 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>Meta-yocto</product>
          <component>meta-yocto</component>
          <version>1.0</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>VERIFIED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>High</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>1.0 M2</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jiajun Xu">jiajun.xu</reporter>
          <assigned_to name="Edwin Zhai">edwin.zhai</assigned_to>
          <cc>edwin.zhai</cc>
    
    <cc>kevin.tian</cc>
    
    <cc>kunwei.tian</cc>
    
    <cc>poky.bs.watcher</cc>
    
    <cc>poky.watcher</cc>
    
    <cc>richard.purdie</cc>
    
    <cc>sgw</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          <cf_verified>Program Management</cf_verified>
          <cf_docchange>---</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>11184</commentid>
    <comment_count>0</comment_count>
    <who name="Jiajun Xu">jiajun.xu</who>
    <bug_when>2010-12-15 06:47:44 +0000</bug_when>
    <thetext>Testing Env:    
Poky gitinfo: 3a78838d4f1db75d06b5d3df042638f34cf328f5

After KVM feature is enabled in poky, now qemu can run with KVM enabled. But it needs root permission currently. Pls. check following log:

#########
jxu49@vt-nhm4:~/osel/poky-m2/build$ poky-qemu qemux86 kvm images/qemux86/bzImage-2.6.37+git0+ee0a10ab687b29c4d22d47e5b28bc8b3ebb7a8d9_0+87aacc373557f8849dde8618fbe1f7f8f2af6038-r14-qemux86-20101211200958.bin images/qemux86/poky-image-
poky-image-minimal-qemux86-20101211235049.rootfs.ext3  poky-image-sato-qemux86-20101211224433.rootfs.ext3     poky-image-sdk-qemux86-20101211220547.rootfs.ext3
jxu49@vt-nhm4:~/osel/poky-m2/build$ poky-qemu qemux86 kvm images/qemux86/bzImage-2.6.37+git0+ee0a10ab687b29c4d22d47e5b28bc8b3ebb7a8d9_0+87aacc373557f8849dde8618fbe1f7f8f2af6038-
r14-qemux86-20101211200958.bin images/qemux86/poky-image-sato-qemux86-20101211224433.rootfs.ext3

Continuing with the following parameters:
KERNEL: [images/qemux86/bzImage-2.6.37+git0+ee0a10ab687b29c4d22d47e5b28bc8b3ebb7a8d9_0+87aacc373557f8849dde8618fbe1f7f8f2af6038-r14-qemux86-20101211200958.bin]
ROOTFS: [images/qemux86/poky-image-sato-qemux86-20101211224433.rootfs.ext3]
FSTYPE: [ext3]
Acquiring lockfile for tap0...
Setting up tap interface under sudo
[sudo] password for jxu49:
Acquiring lockfile for tap1...
Warning: distccd not present, no distcc support loaded.
Running qemu...
/home/jxu49/osel/poky-m2/build/tmp/sysroots/i686-linux/usr/bin/qemu -kernel images/qemux86/bzImage-2.6.37+git0+ee0a10ab687b29c4d22d47e5b28bc8b3ebb7a8d9_0+87aacc373557f8849dde8618fbe1f7f8f2af6038-r14-qemux86-20101211200958.bin -net nic,vlan=0 -net tap,vlan=0,ifname=tap1,script=no,downscript=no -hda images/qemux86/poky-image-sato-qemux86-20101211224433.rootfs.ext3 -show-cursor -usb -usbdevice wacom-tablet -vga vmware -enable-gl -k en-us -no-reboot --append &quot;vga=0 root=/dev/hda mem=128M ip=192.168.7.4::192.168.7.3:255.255.255.0 &quot;
Enabling opengl
Could not access KVM kernel module: Permission denied
failed to initialize KVM
Set &apos;tap1&apos; nonpersistent
Releasing lockfile of preconfigured tap device &apos;tap1&apos;
###########</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11229</commentid>
    <comment_count>1</comment_count>
    <who name="Edwin Zhai">edwin.zhai</who>
    <bug_when>2010-12-17 01:11:02 +0000</bug_when>
    <thetext>ubuntu required root privilege to access kvm module for security reason. One fix is to use &quot;sudo&quot; to run qemu. Another one is change the ownership of &quot;/dev/kvm&quot;, which is more reasonable.

Other distribution like RH and Debian seems has something similar, so step 1~3 are probably not needed.

Jiajun,
Can you have a try on following steps? I&apos;ll make documents for those in our wiki

1. As root to insert all modules
# modprobe kvm-intel

2. Add a new group named &quot;kvm&quot;, and add current user to it
$sudo addgroup --system kvm
$sudo adduser $USER kvm

3. Change the ownership and mod
$ sudo chown root:kvm /dev/kvm
$ sudo chmod 0660 /dev/kvm 

The output of &quot;ls -l /dev/kvm&quot; should be like this:
crw-rw----+ 1 root kvm 10, 232 2010-07-02 09:27 /dev/kvm

4. to make it works, need logout then login with current user, now you can access kvm module as non-root user.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11244</commentid>
    <comment_count>2</comment_count>
    <who name="Edwin Zhai">edwin.zhai</who>
    <bug_when>2010-12-20 05:10:39 +0000</bug_when>
    <thetext>I have created a howto @
https://oldwiki.pokylinux.org/wiki2/index.php/How_to_enable_KVM_for_Poky_qemu

I have no edit right on the public wiki. Once I get it, I can move it to public wiki.

Jiajun,
It works on my part. Can you have a try with the ownership changing part. If it works, I can mark it as fix.

Thanks,</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11263</commentid>
    <comment_count>3</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2010-12-21 06:39:01 +0000</bug_when>
    <thetext>Edwin:

Firstly, can we detect whether we have permission to access the kvm device and only use it if we have permission? If we don&apos;t have permission can we print a warning to the user about how to enable the speedup?

Secondly, you can get edit permissions on the wiki by creating an account and confirming your email address.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11266</commentid>
    <comment_count>4</comment_count>
    <who name="Edwin Zhai">edwin.zhai</who>
    <bug_when>2010-12-21 17:15:16 +0000</bug_when>
    <thetext>(In reply to comment #3)
&gt; Edwin:
&gt; 
&gt; Firstly, can we detect whether we have permission to access the kvm device and
&gt; only use it if we have permission? If we don&apos;t have permission can we print a
&gt; warning to the user about how to enable the speedup?

This was also what Ke suggested and I&apos;m doing. The issue here is I have no idea of how to open the &quot;/dev/kvm&quot; with rw mode in bash to check if we have the right. I don&apos;t want to write a C program using &quot;open&quot; system call, or check the ownership and rw permission of &quot;/dev/kvm&quot; against current user in a complicated way.

&gt; 
&gt; Secondly, you can get edit permissions on the wiki by creating an account and
&gt; confirming your email address.

Done.
Thanks</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11267</commentid>
    <comment_count>5</comment_count>
    <who name="Edwin Zhai">edwin.zhai</who>
    <bug_when>2010-12-21 17:29:57 +0000</bug_when>
    <thetext>Move bkm to https://wiki.yoctoproject.org/wiki/How_to_enable_KVM_for_Poky_qemu</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11268</commentid>
    <comment_count>6</comment_count>
    <who name="Kevin Tian">kevin.tian</who>
    <bug_when>2010-12-21 17:38:28 +0000</bug_when>
    <thetext>(In reply to comment #4)
&gt; (In reply to comment #3)
&gt; &gt; Edwin:
&gt; &gt; 
&gt; &gt; Firstly, can we detect whether we have permission to access the kvm device and
&gt; &gt; only use it if we have permission? If we don&apos;t have permission can we print a
&gt; &gt; warning to the user about how to enable the speedup?
&gt; This was also what Ke suggested and I&apos;m doing. The issue here is I have no idea
&gt; of how to open the &quot;/dev/kvm&quot; with rw mode in bash to check if we have the
&gt; right. I don&apos;t want to write a C program using &quot;open&quot; system call, or check the
&gt; ownership and rw permission of &quot;/dev/kvm&quot; against current user in a complicated
&gt; way.

how about using &quot;9&lt;&gt;/dev/kvm&quot;?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11315</commentid>
    <comment_count>7</comment_count>
    <who name="Edwin Zhai">edwin.zhai</who>
    <bug_when>2010-12-26 21:23:05 +0000</bug_when>
    <thetext>got fixed in poky/master @ 983bd9a77e4afdb2890245653f39d6c6d093a655</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11321</commentid>
    <comment_count>8</comment_count>
    <who name="Jiajun Xu">jiajun.xu</who>
    <bug_when>2010-12-27 07:17:25 +0000</bug_when>
    <thetext>Kunwei,
Could you help to verify the bug by following Edwin&apos;s BKM, https://wiki.yoctoproject.org/wiki/How_to_enable_KVM_for_Poky_qemu?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11364</commentid>
    <comment_count>9</comment_count>
    <who name="Kunwei Tian">kunwei.tian</who>
    <bug_when>2010-12-30 21:45:34 +0000</bug_when>
    <thetext>According to Edwin&apos;s methods，this problem was resolved.So verified it as fixed.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>