Skip to content

Commit

Permalink
vtpm: Put vTPMs into container's cgroup
Browse files Browse the repository at this point in the history
Put vTPMs into a container's cgroup to limits their CPU usage.

Signed-off-by: Stefan Berger <[email protected]>
  • Loading branch information
stefanberger committed Jul 6, 2020
1 parent 209338c commit d34a3bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/opencontainers/runc/libcontainer/intelrdt"
"github.com/opencontainers/runc/libcontainer/system"
"github.com/opencontainers/runc/libcontainer/utils"
"github.com/opencontainers/runc/libcontainer/vtpm/vtpm-helper"
"github.com/opencontainers/runtime-spec/specs-go"

"github.com/checkpoint-restore/go-criu/v4"
Expand Down Expand Up @@ -391,6 +392,11 @@ func (c *linuxContainer) start(process *Process) error {
return err
}
}
if len(c.config.VTPMs) > 0 {
if err := vtpmhelper.ApplyCGroupVTPMs(c.config.VTPMs, c.cgroupManager); err != nil {
return err
}
}
}
return nil
}
Expand Down
11 changes: 11 additions & 0 deletions libcontainer/vtpm/vtpm-helper/vtpm_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"syscall"

"github.com/opencontainers/runc/libcontainer/cgroups"
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/opencontainers/runc/libcontainer/vtpm"

Expand Down Expand Up @@ -153,3 +154,13 @@ func DestroyVTPMs(vtpms []*vtpm.VTPM) {
vtpm.Stop(vtpm.CreatedStatepath)
}
}

// ApplyCGroupVTPMs puts all VTPMs into the given Cgroup manager's cgroup
func ApplyCGroupVTPMs(vtpms []*vtpm.VTPM, cgroupManager cgroups.Manager) error {
for _, vtpm := range vtpms {
if err := cgroupManager.Apply(vtpm.Pid); err != nil {
return fmt.Errorf("cGroupManager failed to apply vtpm with pid %d: %v", vtpm.Pid, err)
}
}
return nil
}

0 comments on commit d34a3bb

Please sign in to comment.