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

View File

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

View File

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

View File

@ -65,6 +65,11 @@ const romFile = ""
// Default value is false. // Default value is false.
const defaultDisableModern = 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 { type qmpChannel struct {
qmp *govmmQemu.QMP qmp *govmmQemu.QMP
ctx context.Context ctx context.Context
@ -1771,6 +1776,7 @@ func (q *qemu) qomGetPciPath(qemuID string) (types.PciPath, error) {
} }
slots = append(slots, devSlot) slots = append(slots, devSlot)
// This only works for Q35 and Virt
r, _ := regexp.Compile(`^/machine/.*/pcie.0`) r, _ := regexp.Compile(`^/machine/.*/pcie.0`)
var parentPath = qemuID 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 // 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 // buffer we limit ourselves to 10 and leave the loop early if we hit
// the root bus. // 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") parenBusQOM, err := q.qmpMonitorCh.qmp.ExecQomGet(q.qmpMonitorCh.ctx, parentPath, "parent_bus")
if err != nil { if err != nil {
return types.PciPath{}, err return types.PciPath{}, err