Skip to content

Commit 8fa2643

Browse files
committed
vtpm: Put vTPMs into container's cgroup
Put vTPMs into a container's cgroup to limits their CPU usage. Signed-off-by: Stefan Berger <[email protected]>
1 parent 1da1f00 commit 8fa2643

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

libcontainer/container_linux.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/opencontainers/runc/libcontainer/intelrdt"
2525
"github.com/opencontainers/runc/libcontainer/system"
2626
"github.com/opencontainers/runc/libcontainer/utils"
27+
"github.com/opencontainers/runc/libcontainer/vtpm/vtpm-helper"
2728
"github.com/opencontainers/runtime-spec/specs-go"
2829

2930
"github.com/checkpoint-restore/go-criu/v4"
@@ -391,6 +392,11 @@ func (c *linuxContainer) start(process *Process) error {
391392
return err
392393
}
393394
}
395+
if len(c.config.VTPMs) > 0 {
396+
if err := vtpmhelper.ApplyCGroupVTPMs(c.config.VTPMs, c.cgroupManager); err != nil {
397+
return err
398+
}
399+
}
394400
}
395401
return nil
396402
}

libcontainer/vtpm/vtpm-helper/vtpm_helper.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111
"syscall"
1212

13+
"github.com/opencontainers/runc/libcontainer/cgroups"
1314
"github.com/opencontainers/runc/libcontainer/configs"
1415
"github.com/opencontainers/runc/libcontainer/vtpm"
1516

@@ -153,3 +154,13 @@ func DestroyVTPMs(vtpms []*vtpm.VTPM) {
153154
vtpm.Stop(vtpm.CreatedStatepath)
154155
}
155156
}
157+
158+
// ApplyCGroupVTPMs puts all VTPMs into the given Cgroup manager's cgroup
159+
func ApplyCGroupVTPMs(vtpms []*vtpm.VTPM, cgroupManager cgroups.Manager) error {
160+
for _, vtpm := range vtpms {
161+
if err := cgroupManager.Apply(vtpm.Pid); err != nil {
162+
return fmt.Errorf("cGroupManager failed to apply vtpm with pid %d: %v", vtpm.Pid, err)
163+
}
164+
}
165+
return nil
166+
}

0 commit comments

Comments
 (0)