From 27b878546fd148adb4cb214c14a7ade9b0d7b2c4 Mon Sep 17 00:00:00 2001 From: William Zhao Date: Thu, 3 Aug 2023 18:23:20 -0400 Subject: [PATCH] Set kernel arg PCI realloc on "cannot allocate memory" on VF creation When creating VFs via sysfs sriov_numvfs, there is a chance of getting the error "cannot allocate memory". This could occur when the BIOS is not providing enough MMIO space for VFs. A solution is to reallocate the MMIO space via "pci=realloc". Signed-off-by: William Zhao --- pkg/plugins/generic/generic_plugin.go | 5 +++++ pkg/utils/utils.go | 1 + 2 files changed, 6 insertions(+) diff --git a/pkg/plugins/generic/generic_plugin.go b/pkg/plugins/generic/generic_plugin.go index 5ed34fde3..8e0c5f82f 100644 --- a/pkg/plugins/generic/generic_plugin.go +++ b/pkg/plugins/generic/generic_plugin.go @@ -2,6 +2,7 @@ package generic import ( "bytes" + "errors" "os/exec" "reflect" "strconv" @@ -172,6 +173,10 @@ func (p *GenericPlugin) Apply() error { } if err := utils.SyncNodeState(p.DesireState, pfsToSkip); err != nil { + // Catch the "cannot allocate memory" error and try to use PCI realloc + if errors.Is(err, syscall.ENOMEM) { + p.addToDesiredKernelArgs(utils.KernelArgPciRealloc) + } return err } p.LastState = &sriovnetworkv1.SriovNetworkNodeState{} diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 635ca054b..a63c67587 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -42,6 +42,7 @@ const ( DeviceBF2 = "a2d6" DeviceBF3 = "a2dc" + KernelArgPciRealloc = "pci=realloc" KernelArgIntelIommu = "intel_iommu=on" KernelArgIommuPt = "iommu=pt" )