Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
virtcontainers: Don't create vfio devices in the guest
Browse files Browse the repository at this point in the history
vfio devices hotplugged in the VM are expected to be handled by the kernel
driver in the guest, hence the char vfio devices shouldn't appear in the
container under /dev/vfio/.

fixes #2539

Signed-off-by: Julio Montes <[email protected]>
  • Loading branch information
Julio Montes committed Mar 23, 2020
1 parent 078da1a commit 4d2574a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
15 changes: 15 additions & 0 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ const (
// KataLocalDevType creates a local directory inside the VM for sharing files between
// containers.
KataLocalDevType = "local"

// path to vfio devices
vfioPath = "/dev/vfio/"
)

var (
Expand Down Expand Up @@ -1067,6 +1070,18 @@ func (k *kataAgent) constraintGRPCSpec(grpcSpec *grpc.Spec, passSeccomp bool) {
}
}
grpcSpec.Linux.Namespaces = tmpNamespaces

// VFIO char device shouldn't not appear in the guest,
// the device driver should handle it and determinate its group.
var linuxDevices []grpc.LinuxDevice
for _, dev := range grpcSpec.Linux.Devices {
if dev.Type == "c" && strings.HasPrefix(dev.Path, vfioPath) {
k.Logger().WithField("vfio-dev", dev.Path).Debug("removing vfio device from grpcSpec")
continue
}
linuxDevices = append(linuxDevices, dev)
}
grpcSpec.Linux.Devices = linuxDevices
}

func (k *kataAgent) handleShm(grpcSpec *grpc.Spec, sandbox *Sandbox) {
Expand Down
16 changes: 15 additions & 1 deletion virtcontainers/kata_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"bufio"
"context"
"fmt"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"io/ioutil"
"net"
"os"
Expand All @@ -20,6 +19,8 @@ import (
"syscall"
"testing"

vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"

gpb "github.com/gogo/protobuf/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -611,6 +612,16 @@ func TestConstraintGRPCSpec(t *testing.T) {
Network: &pb.LinuxNetwork{},
},
CgroupsPath: "system.slice:foo:bar",
Devices: []pb.LinuxDevice{
{
Path: "/dev/vfio/1",
Type: "c",
},
{
Path: "/dev/vfio/2",
Type: "c",
},
},
},
Process: &pb.Process{
SelinuxLabel: "foo",
Expand Down Expand Up @@ -641,6 +652,9 @@ func TestConstraintGRPCSpec(t *testing.T) {

// check cgroup path
assert.Equal(expectedCgroupPath, g.Linux.CgroupsPath)

// check Linux devices
assert.Empty(g.Linux.Devices)
}

func TestHandleShm(t *testing.T) {
Expand Down
2 changes: 0 additions & 2 deletions virtcontainers/sandbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,6 @@ func TestContainerStateSetFstype(t *testing.T) {
assert.Equal(cImpl.state.Fstype, newFstype)
}

const vfioPath = "/dev/vfio/"

func TestSandboxAttachDevicesVFIO(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "")
assert.Nil(t, err)
Expand Down

0 comments on commit 4d2574a

Please sign in to comment.