All of lore.kernel.org
 help / color / mirror / Atom feed
* Using KVM from a process inside a Docker container
@ 2017-12-01 19:44 Mike Spreitzer
  2017-12-01 20:04 ` Sean Christopherson
       [not found] ` <OF37FA08E6.3309AFBF-ON002581E9.006EB91B@LocalDomain>
  0 siblings, 2 replies; 4+ messages in thread
From: Mike Spreitzer @ 2017-12-01 19:44 UTC (permalink / raw)
  To: kvm

I am trying to do this, giving the container as few exceptional abilities 
as possible.  How can I accomplish this?

I know I could simply make the container "privileged", and that would 
work.  But I am trying to give less than that to the container.

Could I get what I need by giving the container some Linux "capabilities"? 
 If so, which ones?

It looks like the process inside the container needs to see a char-special 
file at "/dev/kvm".  So I tried making one, with `mknod /dev/kvm c 10 232` 
inside the container (matching the major and minor I found outside the 
container).  Here is what I saw from inside the container after that 
`mknod`:

# ls -l /dev/kvm
crw-rw---- 1 root 121 10, 232 Nov 27 01:31 /dev/kvm

But I still got these complaints when QEMU inside the container tried to 
use KVM:

Could not access KVM kernel module: Operation not permitted
failed to initialize KVM: Operation not permitted

I also tried bind-mounting the host's /dev/kvm to /dev/kvm inside the 
container.  But that also led to the two same complaints.  I also tried 
bind-mounting the host's /dev to /hostdev inside the container and then 
symlinking /hostdev/kvm to /dev/kvm inside the container, but that also 
produced the same two complaints.  What does it take to get an adequate 
/dev/kvm inside the container?  Is it just a matter of the right Linux 
capabilities, or is it something else?  I am running QEMU as root inside 
the container.

I am using Docker 1.12 and QEMU 2.6 on Ubuntu 16.10 (I know that's 
outdated).

Thanks,
Mike

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Using KVM from a process inside a Docker container
  2017-12-01 19:44 Using KVM from a process inside a Docker container Mike Spreitzer
@ 2017-12-01 20:04 ` Sean Christopherson
       [not found] ` <OF37FA08E6.3309AFBF-ON002581E9.006EB91B@LocalDomain>
  1 sibling, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2017-12-01 20:04 UTC (permalink / raw)
  To: Mike Spreitzer, kvm

On Fri, 2017-12-01 at 14:44 -0500, Mike Spreitzer wrote:
> I am trying to do this, giving the container as few exceptional abilities 
> as possible.  How can I accomplish this?
> 
> I know I could simply make the container "privileged", and that would 
> work.  But I am trying to give less than that to the container.
> 
> Could I get what I need by giving the container some Linux "capabilities"? 
>  If so, which ones?
> 
> It looks like the process inside the container needs to see a char-special 
> file at "/dev/kvm".  So I tried making one, with `mknod /dev/kvm c 10 232` 
> inside the container (matching the major and minor I found outside the 
> container).  Here is what I saw from inside the container after that 
> `mknod`:
> 
> # ls -l /dev/kvm
> crw-rw---- 1 root 121 10, 232 Nov 27 01:31 /dev/kvm
> 
> But I still got these complaints when QEMU inside the container tried to 
> use KVM:
> 
> Could not access KVM kernel module: Operation not permitted
> failed to initialize KVM: Operation not permitted
> 
> I also tried bind-mounting the host's /dev/kvm to /dev/kvm inside the 
> container.  But that also led to the two same complaints.  I also tried 
> bind-mounting the host's /dev to /hostdev inside the container and then 
> symlinking /hostdev/kvm to /dev/kvm inside the container, but that also 
> produced the same two complaints.  What does it take to get an adequate 
> /dev/kvm inside the container?  Is it just a matter of the right Linux 
> capabilities, or is it something else?  I am running QEMU as root inside 
> the container.
> 
> I am using Docker 1.12 and QEMU 2.6 on Ubuntu 16.10 (I know that's 
> outdated).
> 
> Thanks,
> Mike
> 

Try --device, e.g. 'docker run --device=/dev/kvm ...'.  I haven't used it
for KVM specifically, but have successfully used it to expose other IOCTL
char devices to an otherwise unprivileged container.

https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Using KVM from a process inside a Docker container
       [not found] ` <OF37FA08E6.3309AFBF-ON002581E9.006EB91B@LocalDomain>
@ 2017-12-03 22:01   ` Mike Spreitzer
  2017-12-04 13:16     ` Mike Rapoport
  0 siblings, 1 reply; 4+ messages in thread
From: Mike Spreitzer @ 2017-12-03 22:01 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: kvm

> From: Sean Christopherson <sean.j.christopherson@intel.com>
...

> On Fri, 2017-12-01 at 14:44 -0500, Mike Spreitzer wrote:
> > I am trying to do this, giving the container as few exceptional 
abilities 
> > as possible.  How can I accomplish this?
> > 
...

> Try --device, e.g. 'docker run --device=/dev/kvm ...'.  I haven't used 
it
> for KVM specifically, but have successfully used it to expose other 
IOCTL
> char devices to an otherwise unprivileged container.

That worked!

Thanks,
Mike

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Using KVM from a process inside a Docker container
  2017-12-03 22:01   ` Mike Spreitzer
@ 2017-12-04 13:16     ` Mike Rapoport
  0 siblings, 0 replies; 4+ messages in thread
From: Mike Rapoport @ 2017-12-04 13:16 UTC (permalink / raw)
  To: Mike Spreitzer; +Cc: Sean Christopherson, kvm

On Sun, Dec 03, 2017 at 05:01:02PM -0500, Mike Spreitzer wrote:
> > From: Sean Christopherson <sean.j.christopherson@intel.com>
> ...
> 
> > On Fri, 2017-12-01 at 14:44 -0500, Mike Spreitzer wrote:
> > > I am trying to do this, giving the container as few exceptional 
> abilities 
> > > as possible.  How can I accomplish this?
> > > 
> ...
> 
> > Try --device, e.g. 'docker run --device=/dev/kvm ...'.  I haven't used 
> it
> > for KVM specifically, but have successfully used it to expose other 
> IOCTL
> > char devices to an otherwise unprivileged container.
 
You might also want to add /dev/vhost* to speedup the guest I/O.

> That worked!
> 
> Thanks,
> Mike
> 
> 

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-12-04 13:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-01 19:44 Using KVM from a process inside a Docker container Mike Spreitzer
2017-12-01 20:04 ` Sean Christopherson
     [not found] ` <OF37FA08E6.3309AFBF-ON002581E9.006EB91B@LocalDomain>
2017-12-03 22:01   ` Mike Spreitzer
2017-12-04 13:16     ` Mike Rapoport

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.