Skip to content

Commit d3d19f1

Browse files
committed
nvproxy: implement missing NV_MEMORY_MULTICAST_FABRIC, NV00FD_*
1 parent 2d9b51e commit d3d19f1

File tree

5 files changed

+126
-34
lines changed

5 files changed

+126
-34
lines changed

pkg/abi/nvgpu/classes.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const (
4242
NV01_EVENT_OS_EVENT = 0x00000079
4343
NV01_DEVICE_0 = 0x00000080
4444
NV_MEMORY_FABRIC = 0x000000f8
45+
NV_MEMORY_MULTICAST_FABRIC = 0x000000fd
4546
NV20_SUBDEVICE_0 = 0x00002080
4647
NV2081_BINAPI = 0x00002081
4748
NV50_P2P = 0x0000503b
@@ -333,6 +334,46 @@ type NV00F8_ALLOCATION_PARAMETERS struct {
333334
Map nv00f8Map
334335
}
335336

337+
// From src/common/sdk/nvidia/inc/class/cl00e0.h
338+
const (
339+
NV_MEM_EXPORT_UUID_LEN = 16
340+
)
341+
342+
// NV_EXPORT_MEM_PACKET is from
343+
// src/common/sdk/nvidia/inc/class/cl00e0.h
344+
//
345+
// +marshal
346+
type NV_EXPORT_MEM_PACKET struct {
347+
UUID [NV_MEM_EXPORT_UUID_LEN]uint8
348+
Opaque [16]uint8
349+
}
350+
351+
// NV00FD_ALLOCATION_PARAMETERS is the alloc param type for NV_MEMORY_MULTICAST_FABRIC
352+
// from src/common/sdk/nvidia/inc/class/cl00fd.h
353+
//
354+
// +marshal
355+
type NV00FD_ALLOCATION_PARAMETERS struct {
356+
Alignment uint64
357+
AllocSize uint64
358+
PageSize uint32
359+
AllocFlags uint32
360+
NumGPUs uint32
361+
_ uint32
362+
POsEvent P64
363+
}
364+
365+
// NV00FD_ALLOCATION_PARAMETERS_V545 is the updated version of
366+
// NV00FD_ALLOCATION_PARAMETERS since 545.23.06.
367+
//
368+
// +marshal
369+
type NV00FD_ALLOCATION_PARAMETERS_V545 struct {
370+
ExpPacket NV_EXPORT_MEM_PACKET
371+
Index uint16
372+
_ [6]byte
373+
NV00FD_ALLOCATION_PARAMETERS
374+
}
375+
376+
336377
// NV_CONFIDENTIAL_COMPUTE_ALLOC_PARAMS is the alloc param type for
337378
// NV_CONFIDENTIAL_COMPUTE, from src/common/sdk/nvidia/inc/class/clcb33.h.
338379
//

pkg/abi/nvgpu/ctrl.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,22 @@ const (
236236
NV0080_CTRL_CMD_PERF_CUDA_LIMIT_SET_CONTROL = 0x801909
237237
)
238238

239+
// From src/common/sdk/nvidia/inc/ctrl/ctrl00fd.h:
240+
const (
241+
NV00FD_CTRL_CMD_GET_INFO = 0xfd0101
242+
NV00FD_CTRL_CMD_ATTACH_MEM = 0xfd0102
243+
NV00FD_CTRL_CMD_ATTACH_GPU = 0xfd0104
244+
NV00FD_CTRL_CMD_DETACH_MEM = 0xfd0105
245+
)
246+
247+
// +marshal
248+
type NV00FD_CTRL_ATTACH_GPU_PARAMS struct {
249+
HSubDevice Handle
250+
Flags uint32
251+
DevDescriptor uint64
252+
}
253+
254+
239255
// From src/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080bus.h:
240256
const (
241257
NV2080_CTRL_CMD_BUS_GET_PCI_INFO = 0x20801801

pkg/sentry/devices/nvproxy/frontend.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,18 @@ func ctrlHasFrontendFD[Params any, PtrParams hasFrontendFDPtr[Params]](fi *front
564564
return n, nil
565565
}
566566

567+
func ctrlMemoryMulticastFabricAttachGPU(fi *frontendIoctlState, ioctlParams *nvgpu.NVOS54Parameters) (uintptr, error) {
568+
var ctrlParams nvgpu.NV00FD_CTRL_ATTACH_GPU_PARAMS
569+
if ctrlParams.SizeBytes() != int(ioctlParams.ParamsSize) {
570+
return 0, linuxerr.EINVAL
571+
}
572+
if _, err := ctrlParams.CopyIn(fi.t, addrFromP64(ioctlParams.Params)); err != nil {
573+
return 0, err
574+
}
575+
576+
return ctrlMemoryMulticastFabricAttachGPUInvoke(fi, ioctlParams, &ctrlParams)
577+
}
578+
567579
func ctrlClientSystemGetBuildVersion(fi *frontendIoctlState, ioctlParams *nvgpu.NVOS54Parameters) (uintptr, error) {
568580
var ctrlParams nvgpu.NV0000_CTRL_SYSTEM_GET_BUILD_VERSION_PARAMS
569581
if ctrlParams.SizeBytes() != int(ioctlParams.ParamsSize) {

pkg/sentry/devices/nvproxy/frontend_unsafe.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ func rmControlInvoke[Params any](fi *frontendIoctlState, ioctlParams *nvgpu.NVOS
4747
return n, nil
4848
}
4949

50+
func ctrlMemoryMulticastFabricAttachGPUInvoke(fi *frontendIoctlState, ioctlParams *nvgpu.NVOS54Parameters, ctrlParams *nvgpu.NV00FD_CTRL_ATTACH_GPU_PARAMS) (uintptr, error) {
51+
origDevDescriptor := ctrlParams.DevDescriptor
52+
devDescriptor, _ := fi.t.FDTable().Get(int32(origDevDescriptor))
53+
if devDescriptor == nil {
54+
return 0, linuxerr.EINVAL
55+
}
56+
defer devDescriptor.DecRef(fi.ctx)
57+
devDesc, ok := devDescriptor.Impl().(*frontendFD)
58+
if !ok {
59+
return 0, linuxerr.EINVAL
60+
}
61+
ctrlParams.DevDescriptor = uint64(devDesc.hostFD)
62+
n, err := rmControlInvoke(fi, ioctlParams, ctrlParams)
63+
ctrlParams.DevDescriptor = origDevDescriptor
64+
return n, err
65+
}
66+
5067
func ctrlClientSystemGetBuildVersionInvoke(fi *frontendIoctlState, ioctlParams *nvgpu.NVOS54Parameters, ctrlParams *nvgpu.NV0000_CTRL_SYSTEM_GET_BUILD_VERSION_PARAMS, driverVersionBuf, versionBuf, titleBuf *byte) (uintptr, error) {
5168
// *Buf arguments don't need runtime.KeepAlive() since our caller
5269
// ctrlClientSystemGetBuildVersion() copies them out, keeping them alive

pkg/sentry/devices/nvproxy/version.go

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ func Init() {
225225
0x80028b: rmControlSimple, // unknown, paramsSize == 1
226226
nvgpu.NV0080_CTRL_CMD_GPU_GET_CLASSLIST_V2: rmControlSimple,
227227
nvgpu.NV0080_CTRL_CMD_HOST_GET_CAPS_V2: rmControlSimple,
228+
nvgpu.NV00FD_CTRL_CMD_GET_INFO: rmControlSimple,
229+
nvgpu.NV00FD_CTRL_CMD_ATTACH_MEM: rmControlSimple,
230+
nvgpu.NV00FD_CTRL_CMD_DETACH_MEM: rmControlSimple,
228231
nvgpu.NV2080_CTRL_CMD_BUS_GET_PCI_INFO: rmControlSimple,
229232
nvgpu.NV2080_CTRL_CMD_BUS_GET_PCI_BAR_INFO: rmControlSimple,
230233
nvgpu.NV2080_CTRL_CMD_BUS_GET_INFO_V2: rmControlSimple,
@@ -288,46 +291,48 @@ func Init() {
288291
nvgpu.NV0000_CTRL_CMD_OS_UNIX_GET_EXPORT_OBJECT_INFO: ctrlHasFrontendFD[nvgpu.NV0000_CTRL_OS_UNIX_GET_EXPORT_OBJECT_INFO_PARAMS],
289292
nvgpu.NV0041_CTRL_CMD_GET_SURFACE_INFO: ctrlClientGetSurfaceInfo,
290293
nvgpu.NV0080_CTRL_CMD_FIFO_GET_CHANNELLIST: ctrlDevFIFOGetChannelList,
294+
nvgpu.NV00FD_CTRL_CMD_ATTACH_GPU: ctrlMemoryMulticastFabricAttachGPU,
291295
nvgpu.NV0080_CTRL_CMD_GPU_GET_CLASSLIST: ctrlDevGpuGetClasslist,
292296
nvgpu.NV2080_CTRL_CMD_FIFO_DISABLE_CHANNELS: ctrlSubdevFIFODisableChannels,
293297
nvgpu.NV2080_CTRL_CMD_GR_GET_INFO: ctrlSubdevGRGetInfo,
294298
nvgpu.NV503C_CTRL_CMD_REGISTER_VA_SPACE: ctrlRegisterVASpace,
295299
},
296300
allocationClass: map[nvgpu.ClassID]allocationClassHandler{
297-
nvgpu.NV01_ROOT: rmAllocRootClient,
298-
nvgpu.NV01_ROOT_NON_PRIV: rmAllocRootClient,
299-
nvgpu.NV01_MEMORY_SYSTEM: rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS],
300-
nvgpu.NV01_MEMORY_LOCAL_USER: rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS],
301-
nvgpu.NV01_ROOT_CLIENT: rmAllocRootClient,
302-
nvgpu.NV01_EVENT_OS_EVENT: rmAllocEventOSEvent,
303-
nvgpu.NV2081_BINAPI: rmAllocSimple[nvgpu.NV2081_ALLOC_PARAMETERS],
304-
nvgpu.NV01_DEVICE_0: rmAllocSimple[nvgpu.NV0080_ALLOC_PARAMETERS],
305-
nvgpu.NV_MEMORY_FABRIC: rmAllocSimple[nvgpu.NV00F8_ALLOCATION_PARAMETERS],
306-
nvgpu.NV20_SUBDEVICE_0: rmAllocSimple[nvgpu.NV2080_ALLOC_PARAMETERS],
307-
nvgpu.NV50_MEMORY_VIRTUAL: rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS],
308-
nvgpu.NV50_P2P: rmAllocSimple[nvgpu.NV503B_ALLOC_PARAMETERS],
309-
nvgpu.NV50_THIRD_PARTY_P2P: rmAllocSimple[nvgpu.NV503C_ALLOC_PARAMETERS],
310-
nvgpu.GT200_DEBUGGER: rmAllocSMDebuggerSession,
311-
nvgpu.FERMI_CONTEXT_SHARE_A: rmAllocContextShare,
312-
nvgpu.FERMI_VASPACE_A: rmAllocSimple[nvgpu.NV_VASPACE_ALLOCATION_PARAMETERS],
313-
nvgpu.KEPLER_CHANNEL_GROUP_A: rmAllocChannelGroup,
314-
nvgpu.TURING_CHANNEL_GPFIFO_A: rmAllocChannel,
315-
nvgpu.AMPERE_CHANNEL_GPFIFO_A: rmAllocChannel,
316-
nvgpu.HOPPER_CHANNEL_GPFIFO_A: rmAllocChannel,
317-
nvgpu.TURING_DMA_COPY_A: rmAllocSimple[nvgpu.NVB0B5_ALLOCATION_PARAMETERS],
318-
nvgpu.AMPERE_DMA_COPY_A: rmAllocSimple[nvgpu.NVB0B5_ALLOCATION_PARAMETERS],
319-
nvgpu.AMPERE_DMA_COPY_B: rmAllocSimple[nvgpu.NVB0B5_ALLOCATION_PARAMETERS],
320-
nvgpu.HOPPER_DMA_COPY_A: rmAllocSimple[nvgpu.NVB0B5_ALLOCATION_PARAMETERS],
321-
nvgpu.TURING_COMPUTE_A: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS],
322-
nvgpu.AMPERE_COMPUTE_A: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS],
323-
nvgpu.AMPERE_COMPUTE_B: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS],
324-
nvgpu.ADA_COMPUTE_A: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS],
325-
nvgpu.NV_CONFIDENTIAL_COMPUTE: rmAllocSimple[nvgpu.NV_CONFIDENTIAL_COMPUTE_ALLOC_PARAMS],
326-
nvgpu.HOPPER_COMPUTE_A: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS],
327-
nvgpu.HOPPER_USERMODE_A: rmAllocSimple[nvgpu.NV_HOPPER_USERMODE_A_PARAMS],
328-
nvgpu.GF100_SUBDEVICE_MASTER: rmAllocNoParams,
329-
nvgpu.TURING_USERMODE_A: rmAllocNoParams,
330-
nvgpu.HOPPER_SEC2_WORK_LAUNCH_A: rmAllocNoParams,
301+
nvgpu.NV01_ROOT: rmAllocRootClient,
302+
nvgpu.NV01_ROOT_NON_PRIV: rmAllocRootClient,
303+
nvgpu.NV01_MEMORY_SYSTEM: rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS],
304+
nvgpu.NV01_MEMORY_LOCAL_USER: rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS],
305+
nvgpu.NV01_ROOT_CLIENT: rmAllocRootClient,
306+
nvgpu.NV01_EVENT_OS_EVENT: rmAllocEventOSEvent,
307+
nvgpu.NV2081_BINAPI: rmAllocSimple[nvgpu.NV2081_ALLOC_PARAMETERS],
308+
nvgpu.NV01_DEVICE_0: rmAllocSimple[nvgpu.NV0080_ALLOC_PARAMETERS],
309+
nvgpu.NV_MEMORY_FABRIC: rmAllocSimple[nvgpu.NV00F8_ALLOCATION_PARAMETERS],
310+
nvgpu.NV_MEMORY_MULTICAST_FABRIC: rmAllocSimple[nvgpu.NV00FD_ALLOCATION_PARAMETERS],
311+
nvgpu.NV20_SUBDEVICE_0: rmAllocSimple[nvgpu.NV2080_ALLOC_PARAMETERS],
312+
nvgpu.NV50_MEMORY_VIRTUAL: rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS],
313+
nvgpu.NV50_P2P: rmAllocSimple[nvgpu.NV503B_ALLOC_PARAMETERS],
314+
nvgpu.NV50_THIRD_PARTY_P2P: rmAllocSimple[nvgpu.NV503C_ALLOC_PARAMETERS],
315+
nvgpu.GT200_DEBUGGER: rmAllocSMDebuggerSession,
316+
nvgpu.FERMI_CONTEXT_SHARE_A: rmAllocContextShare,
317+
nvgpu.FERMI_VASPACE_A: rmAllocSimple[nvgpu.NV_VASPACE_ALLOCATION_PARAMETERS],
318+
nvgpu.KEPLER_CHANNEL_GROUP_A: rmAllocChannelGroup,
319+
nvgpu.TURING_CHANNEL_GPFIFO_A: rmAllocChannel,
320+
nvgpu.AMPERE_CHANNEL_GPFIFO_A: rmAllocChannel,
321+
nvgpu.HOPPER_CHANNEL_GPFIFO_A: rmAllocChannel,
322+
nvgpu.TURING_DMA_COPY_A: rmAllocSimple[nvgpu.NVB0B5_ALLOCATION_PARAMETERS],
323+
nvgpu.AMPERE_DMA_COPY_A: rmAllocSimple[nvgpu.NVB0B5_ALLOCATION_PARAMETERS],
324+
nvgpu.AMPERE_DMA_COPY_B: rmAllocSimple[nvgpu.NVB0B5_ALLOCATION_PARAMETERS],
325+
nvgpu.HOPPER_DMA_COPY_A: rmAllocSimple[nvgpu.NVB0B5_ALLOCATION_PARAMETERS],
326+
nvgpu.TURING_COMPUTE_A: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS],
327+
nvgpu.AMPERE_COMPUTE_A: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS],
328+
nvgpu.AMPERE_COMPUTE_B: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS],
329+
nvgpu.ADA_COMPUTE_A: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS],
330+
nvgpu.NV_CONFIDENTIAL_COMPUTE: rmAllocSimple[nvgpu.NV_CONFIDENTIAL_COMPUTE_ALLOC_PARAMS],
331+
nvgpu.HOPPER_COMPUTE_A: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS],
332+
nvgpu.HOPPER_USERMODE_A: rmAllocSimple[nvgpu.NV_HOPPER_USERMODE_A_PARAMS],
333+
nvgpu.GF100_SUBDEVICE_MASTER: rmAllocNoParams,
334+
nvgpu.TURING_USERMODE_A: rmAllocNoParams,
335+
nvgpu.HOPPER_SEC2_WORK_LAUNCH_A: rmAllocNoParams,
331336
},
332337
}
333338
}
@@ -349,6 +354,7 @@ func Init() {
349354
v545_23_06 := func() *driverABI {
350355
abi := v535_113_01()
351356
abi.controlCmd[nvgpu.NV0000_CTRL_CMD_OS_UNIX_GET_EXPORT_OBJECT_INFO] = ctrlHasFrontendFD[nvgpu.NV0000_CTRL_OS_UNIX_GET_EXPORT_OBJECT_INFO_PARAMS_V545]
357+
abi.allocationClass[nvgpu.NV_MEMORY_MULTICAST_FABRIC] = rmAllocSimple[nvgpu.NV00FD_ALLOCATION_PARAMETERS_V545]
352358
abi.allocationClass[nvgpu.NV01_MEMORY_SYSTEM] = rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS_V545]
353359
abi.allocationClass[nvgpu.NV01_MEMORY_LOCAL_USER] = rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS_V545]
354360
abi.allocationClass[nvgpu.NV50_MEMORY_VIRTUAL] = rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS_V545]

0 commit comments

Comments
 (0)