<?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>11277</bug_id>
          
          <creation_ts>2017-03-31 12:45:10 +0000</creation_ts>
          <short_desc>CI: enable the use of KVM for running selftests</short_desc>
          <delta_ts>2017-04-17 17:59:02 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>6</classification_id>
          <classification>Yocto Project Subprojects</classification>
          <product>IoT Reference OS Kit</product>
          <component>intel-iot-refkit-tools</component>
          <version>unspecified</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>2.3 M4</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Patrick Ohly">patrick.ohly</reporter>
          <assigned_to name="Olev Kartau">olev.kartau</assigned_to>
          <cc>mikko.ylinen</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>71961</commentid>
    <comment_count>0</comment_count>
    <who name="Patrick Ohly">patrick.ohly</who>
    <bug_when>2017-03-31 12:45:10 +0000</bug_when>
    <thetext>In https://github.com/intel/intel-iot-refkit/pull/97, QEMU_USE_KVM couldn&apos;t be set because the CI environment doesn&apos;t seem to have kvm enabled.

From http://www.yoctoproject.org/docs/latest/mega-manual/mega-manual.html

 For KVM to work, all the following conditions must be met:

    Your MACHINE must be either qemux86&quot; or &quot;qemux86-64&quot;.

    Your build host has to have the KVM modules installed, which are /dev/kvm.

    The build host /dev/kvm directory has to be both writable and readable.

Not having KVM makes qemu slower, in my experience by a factor of four or more.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72054</commentid>
    <comment_count>1</comment_count>
    <who name="Mikko Ylinen">mikko.ylinen</who>
    <bug_when>2017-04-04 06:01:39 +0000</bug_when>
    <thetext>(In reply to comment #0)

&gt; 
&gt;     Your MACHINE must be either qemux86&quot; or &quot;qemux86-64&quot;.

Do you know why&apos;s this a dependency?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72058</commentid>
    <comment_count>2</comment_count>
    <who name="Patrick Ohly">patrick.ohly</who>
    <bug_when>2017-04-04 06:44:38 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; (In reply to comment #0)
&gt; 
&gt; &gt; 
&gt; &gt;     Your MACHINE must be either qemux86&quot; or &quot;qemux86-64&quot;.
&gt; 
&gt; Do you know why&apos;s this a dependency?

I suspect the documentation is out-dated or over-simplifies the problem. Right now, those MACHINEs still work better under qemu (network configured correctly thanks to the ip boot parameter and some extra packages which apply that), but we recently also made it possible to run meta-intel MACHINEs.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72234</commentid>
    <comment_count>3</comment_count>
    <who name="Olev Kartau">olev.kartau</who>
    <bug_when>2017-04-10 18:30:02 +0000</bug_when>
    <thetext>title is confusing. &quot;enable the use of QEMU&quot; is already
satisfied as CI jobs have completed qemu sessions.
Inside text of Description however there is KVM mentioned.
KVM is one operating mode of QEMU.
So what is actually asked is &quot;enable KVM mode of QEMU&quot;?

Then  about KVM.
In current setup of pre- and post-build jobs,
these all run in docker.
Thats why it seems &quot;no kvm support&quot;, although the hosts have KVM support.
But it does not automatically propagate into docker session without
adding some set-up for this,
- we need to create device inside docker
- we need to run docker in --privileged mode

That&apos;s probably achievable, but then lets ask, is it necessary
to pile two levels of virtualization for this to work?
Can we run QEMU_KVM session in host, leaving docker out?

This thread starts to touch another topic which came out when we looked
how to run tests in parallel. And making tests running in parallel is harder
if the pos-tests are technically implemented as build steps inside docker.

From architecture POV, test steps should be independent from build steps,
with possibility to run them on some other worker node, in parallel.
But a post-test that runs in same docker session with builder,
is not detachable to be parallel.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72248</commentid>
    <comment_count>4</comment_count>
    <who name="Patrick Ohly">patrick.ohly</who>
    <bug_when>2017-04-10 20:23:11 +0000</bug_when>
    <thetext>(In reply to comment #3)
&gt; So what is actually asked is &quot;enable KVM mode of QEMU&quot;?

Yes.

&gt; Then  about KVM.
&gt; In current setup of pre- and post-build jobs,
&gt; these all run in docker.
&gt; Thats why it seems &quot;no kvm support&quot;, although the hosts have KVM support.
&gt; But it does not automatically propagate into docker session without
&gt; adding some set-up for this,
&gt; - we need to create device inside docker
&gt; - we need to run docker in --privileged mode
&gt; 
&gt; That&apos;s probably achievable, but then lets ask, is it necessary
&gt; to pile two levels of virtualization for this to work?

Selftests need the ability to invoke qemu. That&apos;s because they need to control how the virtual machine is configured, before booting it up.

&gt; Can we run QEMU_KVM session in host, leaving docker out?

No, that won&apos;t work for the selftests.

&gt; This thread starts to touch another topic which came out when we looked
&gt; how to run tests in parallel. And making tests running in parallel is harder
&gt; if the pos-tests are technically implemented as build steps inside docker.
&gt; 
&gt; From architecture POV, test steps should be independent from build steps,
&gt; with possibility to run them on some other worker node, in parallel.
&gt; But a post-test that runs in same docker session with builder,
&gt; is not detachable to be parallel.

True in theory, but in practice I expect the performance to be better when sharing the same build directory. That&apos;s because the post-selftest benefit from the existing build artifacts, which are exactly where the tests needs them. Doing it on another node and in another environment is both more complicated (need to share at least the sstate) and slower (need to rebuild directories and images from sstate).

Image testing is different because it has more-or-less well-defined input (but even there we have to hack around with non-upstreameable classes to make all required files available), whereas the selftest doesn&apos;t.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72283</commentid>
    <comment_count>5</comment_count>
    <who name="Olev Kartau">olev.kartau</who>
    <bug_when>2017-04-11 11:33:40 +0000</bug_when>
    <thetext>currently these steps are performed in CI builder, in docker session:
pre-build,build,store-images,post-build
I think it&apos;s good idea to open privileges as little as possible,
so can this work:
1. we run 3 steps in regular docker session, as present;
2. we add 2nd docker session in privileged mode, which can start qemu-kvm,
where we will start 4th step: selftests
Note that stopping of 1st docker session will lose runtime context of build session and keep everything which is in file system. Is this a problem?

If above plan is not doable, we have to run the one
docker session with wide privileges.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72284</commentid>
    <comment_count>6</comment_count>
    <who name="Patrick Ohly">patrick.ohly</who>
    <bug_when>2017-04-11 11:45:56 +0000</bug_when>
    <thetext>(In reply to comment #5)
&gt; currently these steps are performed in CI builder, in docker session:
&gt; pre-build,build,store-images,post-build
&gt; I think it&apos;s good idea to open privileges as little as possible,
&gt; so can this work:
&gt; 1. we run 3 steps in regular docker session, as present;
&gt; 2. we add 2nd docker session in privileged mode, which can start qemu-kvm,
&gt; where we will start 4th step: selftests
&gt; Note that stopping of 1st docker session will lose runtime context of build
&gt; session and keep everything which is in file system. Is this a problem?

Shouldn&apos;t be a problem. However, I wonder why this is so hard. I don&apos;t know what --privileged does, so let me ask: is this required? Normally, /dev/kvm is group-owned by kvm. When the user starting docker is in that group, what special privileges does docker need? It doesn&apos;t need to grant any additional privileges.

Granting the build job access to KVM doesn&apos;t worry me.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72285</commentid>
    <comment_count>7</comment_count>
    <who name="Olev Kartau">olev.kartau</who>
    <bug_when>2017-04-11 12:05:18 +0000</bug_when>
    <thetext>I may have been reading some older examples (about --privileged mode required).
Seems it is possible to pass rights to one device only (--device option).
I will try is this enough to get kvm mode going.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72385</commentid>
    <comment_count>8</comment_count>
    <who name="Olev Kartau">olev.kartau</who>
    <bug_when>2017-04-12 15:15:19 +0000</bug_when>
    <thetext>refkit PR#111 adds passing of /dev/kvm to docker session,
and I verified with qemu calling code added 
(which I temporarily borrowed from PR#94),
that -enable-kvm is supported.

In addition to that, builder hosts have /dev/kvm set as group+rw
and belong to jenkins group, i.e. the device is usable with
same credentials as are running the processes in docker session.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72540</commentid>
    <comment_count>9</comment_count>
    <who name="Olev Kartau">olev.kartau</who>
    <bug_when>2017-04-17 17:59:02 +0000</bug_when>
    <thetext>This was implemented in PR111, but that small commit was then also added to PR#97 which has now been merged, thus marking this as RESOLVED</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>