mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 12:44:39 +00:00
gpu: Check for VFIO port assignments
Bailing out early if the port is wrong, allowed port settings are no-port, root-port, switch-port Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com>
This commit is contained in:
parent
138ada049c
commit
13d7f39c71
@ -20,6 +20,7 @@ import (
|
|||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
hv "github.com/kata-containers/kata-containers/src/runtime/pkg/hypervisors"
|
||||||
ktu "github.com/kata-containers/kata-containers/src/runtime/pkg/katatestutils"
|
ktu "github.com/kata-containers/kata-containers/src/runtime/pkg/katatestutils"
|
||||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
||||||
vcAnnotations "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations"
|
vcAnnotations "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations"
|
||||||
@ -308,6 +309,7 @@ func TestCreateContainerConfigFail(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createAllRuntimeConfigFiles(dir, hypervisor string) (config string, err error) {
|
func createAllRuntimeConfigFiles(dir, hypervisor string) (config string, err error) {
|
||||||
|
var coldPlugVFIO hv.PCIePort
|
||||||
if dir == "" {
|
if dir == "" {
|
||||||
return "", fmt.Errorf("BUG: need directory")
|
return "", fmt.Errorf("BUG: need directory")
|
||||||
}
|
}
|
||||||
@ -332,6 +334,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config string, err err
|
|||||||
disableNewNetNs := false
|
disableNewNetNs := false
|
||||||
sharedFS := "virtio-9p"
|
sharedFS := "virtio-9p"
|
||||||
virtioFSdaemon := path.Join(dir, "virtiofsd")
|
virtioFSdaemon := path.Join(dir, "virtiofsd")
|
||||||
|
coldPlugVFIO = hv.RootPort
|
||||||
|
|
||||||
configFileOptions := ktu.RuntimeConfigOptions{
|
configFileOptions := ktu.RuntimeConfigOptions{
|
||||||
Hypervisor: "qemu",
|
Hypervisor: "qemu",
|
||||||
@ -350,6 +353,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config string, err err
|
|||||||
DisableNewNetNs: disableNewNetNs,
|
DisableNewNetNs: disableNewNetNs,
|
||||||
SharedFS: sharedFS,
|
SharedFS: sharedFS,
|
||||||
VirtioFSDaemon: virtioFSdaemon,
|
VirtioFSDaemon: virtioFSdaemon,
|
||||||
|
ColdPlugVFIO: coldPlugVFIO,
|
||||||
}
|
}
|
||||||
|
|
||||||
runtimeConfigFileData := ktu.MakeRuntimeConfigFileData(configFileOptions)
|
runtimeConfigFileData := ktu.MakeRuntimeConfigFileData(configFileOptions)
|
||||||
|
@ -48,10 +48,12 @@ func (p PCIePort) String() string {
|
|||||||
return "root-port"
|
return "root-port"
|
||||||
case SwitchPort:
|
case SwitchPort:
|
||||||
return "switch-port"
|
return "switch-port"
|
||||||
|
case BridgePort:
|
||||||
|
return "bridge-port"
|
||||||
case NoPort:
|
case NoPort:
|
||||||
return "no-port"
|
return "no-port"
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("unknown PCIePort: %s", string(p))
|
return fmt.Sprintf("<unknown PCIePort: %s>", string(p))
|
||||||
}
|
}
|
||||||
|
|
||||||
type HypervisorState struct {
|
type HypervisorState struct {
|
||||||
|
@ -9,6 +9,10 @@
|
|||||||
|
|
||||||
package katautils
|
package katautils
|
||||||
|
|
||||||
|
import (
|
||||||
|
hv "github.com/kata-containers/kata-containers/src/runtime/pkg/hypervisors"
|
||||||
|
)
|
||||||
|
|
||||||
// name is the name of the runtime
|
// name is the name of the runtime
|
||||||
var NAME = "@RUNTIME_NAME@"
|
var NAME = "@RUNTIME_NAME@"
|
||||||
|
|
||||||
@ -104,4 +108,4 @@ const defaultVMCacheEndpoint string = "/var/run/kata-containers/cache.sock"
|
|||||||
// Default config file used by stateless systems.
|
// Default config file used by stateless systems.
|
||||||
var defaultRuntimeConfiguration = "@CONFIG_PATH@"
|
var defaultRuntimeConfiguration = "@CONFIG_PATH@"
|
||||||
|
|
||||||
const defaultColdPlugVFIO = "no-port"
|
const defaultColdPlugVFIO = hv.NoPort
|
||||||
|
@ -287,6 +287,13 @@ func (h hypervisor) firmware() (string, error) {
|
|||||||
return ResolvePath(p)
|
return ResolvePath(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h hypervisor) coldPlugVFIO() hv.PCIePort {
|
||||||
|
if h.ColdPlugVFIO == "" {
|
||||||
|
return defaultColdPlugVFIO
|
||||||
|
}
|
||||||
|
return h.ColdPlugVFIO
|
||||||
|
}
|
||||||
|
|
||||||
func (h hypervisor) firmwareVolume() (string, error) {
|
func (h hypervisor) firmwareVolume() (string, error) {
|
||||||
p := h.FirmwareVolume
|
p := h.FirmwareVolume
|
||||||
|
|
||||||
@ -856,7 +863,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
|
|||||||
Msize9p: h.msize9p(),
|
Msize9p: h.msize9p(),
|
||||||
DisableImageNvdimm: h.DisableImageNvdimm,
|
DisableImageNvdimm: h.DisableImageNvdimm,
|
||||||
HotplugVFIOOnRootBus: h.HotplugVFIOOnRootBus,
|
HotplugVFIOOnRootBus: h.HotplugVFIOOnRootBus,
|
||||||
ColdPlugVFIO: h.ColdPlugVFIO,
|
ColdPlugVFIO: h.coldPlugVFIO(),
|
||||||
PCIeRootPort: h.PCIeRootPort,
|
PCIeRootPort: h.PCIeRootPort,
|
||||||
DisableVhostNet: h.DisableVhostNet,
|
DisableVhostNet: h.DisableVhostNet,
|
||||||
EnableVhostUserStore: h.EnableVhostUserStore,
|
EnableVhostUserStore: h.EnableVhostUserStore,
|
||||||
@ -1051,7 +1058,7 @@ func newClhHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
|
|||||||
EnableIOThreads: h.EnableIOThreads,
|
EnableIOThreads: h.EnableIOThreads,
|
||||||
Msize9p: h.msize9p(),
|
Msize9p: h.msize9p(),
|
||||||
HotplugVFIOOnRootBus: h.HotplugVFIOOnRootBus,
|
HotplugVFIOOnRootBus: h.HotplugVFIOOnRootBus,
|
||||||
ColdPlugVFIO: h.ColdPlugVFIO,
|
ColdPlugVFIO: h.coldPlugVFIO(),
|
||||||
PCIeRootPort: h.PCIeRootPort,
|
PCIeRootPort: h.PCIeRootPort,
|
||||||
DisableVhostNet: true,
|
DisableVhostNet: true,
|
||||||
GuestHookPath: h.guestHookPath(),
|
GuestHookPath: h.guestHookPath(),
|
||||||
@ -1655,9 +1662,32 @@ func checkConfig(config oci.RuntimeConfig) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
coldPlugVFIO := config.HypervisorConfig.ColdPlugVFIO
|
||||||
|
machineType := config.HypervisorConfig.HypervisorMachineType
|
||||||
|
if err := checkPCIeConfig(coldPlugVFIO, machineType); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkPCIeConfig ensures the PCIe configuration is valid.
|
||||||
|
// Only allow one of the following settings for cold-plug:
|
||||||
|
// no-port, root-port, switch-port
|
||||||
|
func checkPCIeConfig(vfioPort hv.PCIePort, machineType string) error {
|
||||||
|
// Currently only QEMU q35 supports advanced PCIe topologies
|
||||||
|
// firecracker, dragonball do not have right now any PCIe support
|
||||||
|
if machineType != "q35" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if vfioPort == hv.NoPort || vfioPort == hv.RootPort || vfioPort == hv.SwitchPort {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("invalid vfio_port=%s setting, allowed values %s, %s, %s",
|
||||||
|
vfioPort, hv.NoPort, hv.RootPort, hv.SwitchPort)
|
||||||
|
}
|
||||||
|
|
||||||
// checkNetNsConfig performs sanity checks on disable_new_netns config.
|
// checkNetNsConfig performs sanity checks on disable_new_netns config.
|
||||||
// Because it is an expert option and conflicts with some other common configs.
|
// Because it is an expert option and conflicts with some other common configs.
|
||||||
func checkNetNsConfig(config oci.RuntimeConfig) error {
|
func checkNetNsConfig(config oci.RuntimeConfig) error {
|
||||||
|
@ -623,7 +623,7 @@ func newSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor
|
|||||||
|
|
||||||
// If we have a confidential guest we need to cold-plug the PCIe VFIO devices
|
// If we have a confidential guest we need to cold-plug the PCIe VFIO devices
|
||||||
// until we have TDISP/IDE PCIe support.
|
// until we have TDISP/IDE PCIe support.
|
||||||
coldPlugVFIO := (sandboxConfig.HypervisorConfig.ColdPlugVFIO == hv.RootPort)
|
coldPlugVFIO := (sandboxConfig.HypervisorConfig.ColdPlugVFIO != hv.NoPort)
|
||||||
var devs []config.DeviceInfo
|
var devs []config.DeviceInfo
|
||||||
for cnt, containers := range sandboxConfig.Containers {
|
for cnt, containers := range sandboxConfig.Containers {
|
||||||
for dev, device := range containers.DeviceInfos {
|
for dev, device := range containers.DeviceInfos {
|
||||||
|
Loading…
Reference in New Issue
Block a user