1
0
mirror of https://github.com/kata-containers/kata-containers.git synced 2025-09-18 15:28:10 +00:00

gpu: Reset cold or hot plug after overriding

If we override the cold, hot plug with an annotation
we need to reset the other plugging mechanism to NoPort
otherwise both will be enabled.

Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com>
This commit is contained in:
Zvonko Kaiser
2023-06-15 17:37:01 +00:00
parent fbacc09646
commit 72f2cb84e6
3 changed files with 11 additions and 3 deletions
src/runtime
pkg
device
drivers
oci
virtcontainers

@@ -71,8 +71,6 @@ func (device *VFIODevice) Attach(ctx context.Context, devReceiver api.DeviceRece
}
for _, vfio := range device.VfioDevs {
if vfio.IsPCIe {
//vfio.Rank = len(AllPCIeDevs)
//AllPCIeDevs[vfio.BDF] = true
busIndex := len(config.PCIeDevices[vfio.Port])
vfio.Bus = fmt.Sprintf("%s%d", config.PCIePortPrefixMapping[vfio.Port], busIndex)
config.PCIeDevices[vfio.Port][vfio.BDF] = true

@@ -592,11 +592,15 @@ func addHypervisorHotColdPlugVfioOverrides(ocispec specs.Spec, sbConfig *vc.Sand
if sbConfig.HypervisorConfig.HotPlugVFIO, err = addHypervisorPCIePortOverride(value); err != nil {
return err
}
// If hot-plug is specified disable cold-plug and vice versa
sbConfig.HypervisorConfig.ColdPlugVFIO = config.NoPort
}
if value, ok := ocispec.Annotations[vcAnnotations.ColdPlugVFIO]; ok {
if sbConfig.HypervisorConfig.ColdPlugVFIO, err = addHypervisorPCIePortOverride(value); err != nil {
return err
}
// If cold-plug is specified disable hot-plug and vice versa
sbConfig.HypervisorConfig.HotPlugVFIO = config.NoPort
}
return nil
}

@@ -65,6 +65,11 @@ const romFile = ""
// Default value is false.
const defaultDisableModern = false
// A deeper PCIe topology than 5 is already not advisable just for the sake
// of having enough buffer we limit ourselves to 10 and exit if we reach
// the root bus
const maxPCIeTopoDepth = 10
type qmpChannel struct {
qmp *govmmQemu.QMP
ctx context.Context
@@ -1771,6 +1776,7 @@ func (q *qemu) qomGetPciPath(qemuID string) (types.PciPath, error) {
}
slots = append(slots, devSlot)
// This only works for Q35 and Virt
r, _ := regexp.Compile(`^/machine/.*/pcie.0`)
var parentPath = qemuID
@@ -1778,7 +1784,7 @@ func (q *qemu) qomGetPciPath(qemuID string) (types.PciPath, error) {
// than 5 is already not advisable just for the sake of having enough
// buffer we limit ourselves to 10 and leave the loop early if we hit
// the root bus.
for i := 1; i <= 10; i++ {
for i := 1; i <= maxPCIeTopoDepth; i++ {
parenBusQOM, err := q.qmpMonitorCh.qmp.ExecQomGet(q.qmpMonitorCh.ctx, parentPath, "parent_bus")
if err != nil {
return types.PciPath{}, err