@@ -95,6 +95,30 @@ func unlockCNIExecution(lock *flock.Flock) {
9595 _ = lock .Unlock ()
9696}
9797
98+ func handleVfioPciDetection (netConf * localtypes.NetConf ) error {
99+ if netConf .DeviceID == "" {
100+ return fmt .Errorf ("device ID is required for VFIO PCI detection" )
101+ }
102+
103+ isVfioPci , err := utils .IsVfioPciDevice (netConf .DeviceID )
104+ if err != nil {
105+ return fmt .Errorf ("failed to check vfio-pci driver binding for device %s: %v" , netConf .DeviceID , err )
106+ }
107+
108+ // If vfioPciMode is explicitly set to true, validate the device is actually bound to vfio-pci
109+ if netConf .VfioPciMode {
110+ if ! isVfioPci {
111+ return fmt .Errorf ("vfioPciMode is enabled but device %s is not bound to vfio-pci driver" , netConf .DeviceID )
112+ }
113+ } else {
114+ // Auto-detect: if device is bound to vfio-pci, enable vfioPciMode
115+ if isVfioPci {
116+ netConf .VfioPciMode = true
117+ }
118+ }
119+ return nil
120+ }
121+
98122// Get network config, updated with GUID, device info and network namespace.
99123func getNetConfNetns (args * skel.CmdArgs ) (* localtypes.NetConf , ns.NetNS , error ) {
100124 netConf , err := config .LoadConf (args .StdinData )
@@ -116,13 +140,18 @@ func getNetConfNetns(args *skel.CmdArgs) (*localtypes.NetConf, ns.NetNS, error)
116140 "infiniband SRIOV-CNI failed, Unexpected error. GUID must be provided by ib-kubernetes" )
117141 }
118142
119- if netConf .RdmaIso {
143+ if netConf .RdmaIsolation {
120144 err = utils .EnsureRdmaSystemMode ()
121145 if err != nil {
122146 return nil , nil , err
123147 }
124148 }
125149
150+ // Handle vfio-pci detection
151+ if err := handleVfioPciDetection (netConf ); err != nil {
152+ return nil , nil , err
153+ }
154+
126155 err = config .LoadDeviceInfo (netConf )
127156 if err != nil {
128157 return nil , nil , fmt .Errorf ("failed to get device specific information. %v" , err )
@@ -135,18 +164,23 @@ func getNetConfNetns(args *skel.CmdArgs) (*localtypes.NetConf, ns.NetNS, error)
135164 return netConf , netns , nil
136165}
137166
138- // Applies VF config and performs VF setup. if RdmaIso is configured, moves RDMA device into namespace
167+ // Applies VF config and performs VF setup. if RdmaIsolation is configured, moves RDMA device into namespace
139168func doVFConfig (sm localtypes.Manager , netConf * localtypes.NetConf , netns ns.NetNS , args * skel.CmdArgs ) (retErr error ) {
140169 err := sm .ApplyVFConfig (netConf )
141170 if err != nil {
142171 return fmt .Errorf ("infiniBand SRI-OV CNI failed to configure VF %q" , err )
143172 }
144173
174+ // VFIO devices don't have network interfaces, skip SetupVF
175+ if netConf .VfioPciMode {
176+ return nil
177+ }
178+
145179 // Note(adrianc): We do this here as ApplyVFCOnfig is rebinding the VF, causing the RDMA device to be recreated.
146180 // We do this here due to some un-intuitive kernel behavior (which i hope will change), moving an RDMA device
147181 // to namespace causes all of its associated ULP devices (IPoIB) to be recreated in the default namespace,
148182 // hence SetupVF needs to occur after moving RDMA device to namespace
149- if netConf .RdmaIso {
183+ if netConf .RdmaIsolation {
150184 var rdmaDev string
151185 rdmaDev , err = utils .MoveRdmaDevToNsPci (netConf .DeviceID , netns )
152186 if err != nil {
@@ -244,7 +278,7 @@ func cmdAdd(args *skel.CmdArgs) (retErr error) {
244278 if nsErr == nil {
245279 _ = sm .ReleaseVF (netConf , args .IfName , args .ContainerID , netns )
246280 }
247- if netConf .RdmaIso {
281+ if netConf .RdmaIsolation {
248282 _ = utils .MoveRdmaDevFromNs (netConf .RdmaNetState .ContainerRdmaDevName , netns )
249283 }
250284 }
@@ -256,7 +290,8 @@ func cmdAdd(args *skel.CmdArgs) (retErr error) {
256290 Sandbox : netns .Path (),
257291 }}
258292
259- if netConf .IPAM .Type != "" {
293+ // VFIO devices don't have network interfaces, skip IPAM configuration
294+ if netConf .IPAM .Type != "" && ! netConf .VfioPciMode {
260295 var newResult * current.Result
261296 newResult , err = runIPAMPlugin (args .StdinData , netConf )
262297 if err != nil {
@@ -294,6 +329,17 @@ func cmdAdd(args *skel.CmdArgs) (retErr error) {
294329 return types .PrintResult (result , netConf .CNIVersion )
295330}
296331
332+ func handleIPAMCleanup (netConf * localtypes.NetConf , stdinData []byte ) error {
333+ // VFIO devices don't use IPAM
334+ if netConf .VfioPciMode {
335+ return nil
336+ }
337+ if netConf .IPAM .Type == ipamDHCP {
338+ return fmt .Errorf ("ipam type dhcp is not supported" )
339+ }
340+ return ipam .ExecDel (netConf .IPAM .Type , stdinData )
341+ }
342+
297343func cmdDel (args * skel.CmdArgs ) (retErr error ) {
298344 // https://github.com/kubernetes/kubernetes/pull/35240
299345 if args .Netns == "" {
@@ -320,10 +366,7 @@ func cmdDel(args *skel.CmdArgs) (retErr error) {
320366 sm := sriov .NewSriovManager ()
321367
322368 if netConf .IPAM .Type != "" {
323- if netConf .IPAM .Type == ipamDHCP {
324- return fmt .Errorf ("ipam type dhcp is not supported" )
325- }
326- err = ipam .ExecDel (netConf .IPAM .Type , args .StdinData )
369+ err = handleIPAMCleanup (netConf , args .StdinData )
327370 if err != nil {
328371 return err
329372 }
@@ -352,9 +395,12 @@ func cmdDel(args *skel.CmdArgs) (retErr error) {
352395 }
353396 defer unlockCNIExecution (lock )
354397
355- err = sm .ReleaseVF (netConf , args .IfName , args .ContainerID , netns )
356- if err != nil {
357- return err
398+ // VFIO devices don't have network interfaces to release
399+ if ! netConf .VfioPciMode {
400+ err = sm .ReleaseVF (netConf , args .IfName , args .ContainerID , netns )
401+ if err != nil {
402+ return err
403+ }
358404 }
359405
360406 // Move RDMA device to default namespace
@@ -364,7 +410,7 @@ func cmdDel(args *skel.CmdArgs) (retErr error) {
364410 // 1. netedv cleanup during ReleaseVF.
365411 // 2. rdma dev netns cleanup as ResetVFConfig will rebind the VF.
366412 // Doing anything would have yielded the same results however ResetVFConfig will eventually not trigger VF rebind.
367- if netConf .RdmaIso {
413+ if netConf .RdmaIsolation {
368414 err = utils .MoveRdmaDevFromNs (netConf .RdmaNetState .ContainerRdmaDevName , netns )
369415 if err != nil {
370416 return fmt .Errorf (
0 commit comments