diff --git a/pkg/abi/nvgpu/classes.go b/pkg/abi/nvgpu/classes.go index b0ebe93a7..6066deb96 100644 --- a/pkg/abi/nvgpu/classes.go +++ b/pkg/abi/nvgpu/classes.go @@ -42,6 +42,7 @@ const ( NV01_EVENT_OS_EVENT = 0x00000079 NV01_DEVICE_0 = 0x00000080 NV_MEMORY_FABRIC = 0x000000f8 + NV_MEMORY_MULTICAST_FABRIC = 0x000000fd NV20_SUBDEVICE_0 = 0x00002080 NV2081_BINAPI = 0x00002081 NV50_P2P = 0x0000503b @@ -333,6 +334,45 @@ type NV00F8_ALLOCATION_PARAMETERS struct { Map nv00f8Map } +// From src/common/sdk/nvidia/inc/class/cl00e0.h +const ( + NV_MEM_EXPORT_UUID_LEN = 16 +) + +// NV_EXPORT_MEM_PACKET is from +// src/common/sdk/nvidia/inc/class/cl00e0.h +// +// +marshal +type NV_EXPORT_MEM_PACKET struct { + UUID [NV_MEM_EXPORT_UUID_LEN]uint8 + Opaque [16]uint8 +} + +// NV00FD_ALLOCATION_PARAMETERS is the alloc param type for NV_MEMORY_MULTICAST_FABRIC +// from src/common/sdk/nvidia/inc/class/cl00fd.h +// +// +marshal +type NV00FD_ALLOCATION_PARAMETERS struct { + Alignment uint64 + AllocSize uint64 + PageSize uint32 + AllocFlags uint32 + NumGPUs uint32 + _ uint32 + POsEvent P64 +} + +// NV00FD_ALLOCATION_PARAMETERS_V545 is the updated version of +// NV00FD_ALLOCATION_PARAMETERS since 545.23.06. +// +// +marshal +type NV00FD_ALLOCATION_PARAMETERS_V545 struct { + ExpPacket NV_EXPORT_MEM_PACKET + Index uint16 + _ [6]byte + NV00FD_ALLOCATION_PARAMETERS +} + // NV_CONFIDENTIAL_COMPUTE_ALLOC_PARAMS is the alloc param type for // NV_CONFIDENTIAL_COMPUTE, from src/common/sdk/nvidia/inc/class/clcb33.h. // diff --git a/pkg/abi/nvgpu/ctrl.go b/pkg/abi/nvgpu/ctrl.go index c07432042..f3bcc5026 100644 --- a/pkg/abi/nvgpu/ctrl.go +++ b/pkg/abi/nvgpu/ctrl.go @@ -236,6 +236,21 @@ const ( NV0080_CTRL_CMD_PERF_CUDA_LIMIT_SET_CONTROL = 0x801909 ) +// From src/common/sdk/nvidia/inc/ctrl/ctrl00fd.h: +const ( + NV00FD_CTRL_CMD_GET_INFO = 0xfd0101 + NV00FD_CTRL_CMD_ATTACH_MEM = 0xfd0102 + NV00FD_CTRL_CMD_ATTACH_GPU = 0xfd0104 + NV00FD_CTRL_CMD_DETACH_MEM = 0xfd0105 +) + +// +marshal +type NV00FD_CTRL_ATTACH_GPU_PARAMS struct { + HSubDevice Handle + Flags uint32 + DevDescriptor uint64 +} + // From src/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080bus.h: const ( NV2080_CTRL_CMD_BUS_GET_PCI_INFO = 0x20801801 diff --git a/pkg/sentry/devices/nvproxy/frontend.go b/pkg/sentry/devices/nvproxy/frontend.go index 5eaa76182..4174e7333 100644 --- a/pkg/sentry/devices/nvproxy/frontend.go +++ b/pkg/sentry/devices/nvproxy/frontend.go @@ -564,6 +564,18 @@ func ctrlHasFrontendFD[Params any, PtrParams hasFrontendFDPtr[Params]](fi *front return n, nil } +func ctrlMemoryMulticastFabricAttachGPU(fi *frontendIoctlState, ioctlParams *nvgpu.NVOS54Parameters) (uintptr, error) { + var ctrlParams nvgpu.NV00FD_CTRL_ATTACH_GPU_PARAMS + if ctrlParams.SizeBytes() != int(ioctlParams.ParamsSize) { + return 0, linuxerr.EINVAL + } + if _, err := ctrlParams.CopyIn(fi.t, addrFromP64(ioctlParams.Params)); err != nil { + return 0, err + } + + return ctrlMemoryMulticastFabricAttachGPUInvoke(fi, ioctlParams, &ctrlParams) +} + func ctrlClientSystemGetBuildVersion(fi *frontendIoctlState, ioctlParams *nvgpu.NVOS54Parameters) (uintptr, error) { var ctrlParams nvgpu.NV0000_CTRL_SYSTEM_GET_BUILD_VERSION_PARAMS if ctrlParams.SizeBytes() != int(ioctlParams.ParamsSize) { diff --git a/pkg/sentry/devices/nvproxy/frontend_unsafe.go b/pkg/sentry/devices/nvproxy/frontend_unsafe.go index af6d330ac..3dfaf4834 100644 --- a/pkg/sentry/devices/nvproxy/frontend_unsafe.go +++ b/pkg/sentry/devices/nvproxy/frontend_unsafe.go @@ -47,6 +47,23 @@ func rmControlInvoke[Params any](fi *frontendIoctlState, ioctlParams *nvgpu.NVOS return n, nil } +func ctrlMemoryMulticastFabricAttachGPUInvoke(fi *frontendIoctlState, ioctlParams *nvgpu.NVOS54Parameters, ctrlParams *nvgpu.NV00FD_CTRL_ATTACH_GPU_PARAMS) (uintptr, error) { + origDevDescriptor := ctrlParams.DevDescriptor + devDescriptor, _ := fi.t.FDTable().Get(int32(origDevDescriptor)) + if devDescriptor == nil { + return 0, linuxerr.EINVAL + } + defer devDescriptor.DecRef(fi.ctx) + devDesc, ok := devDescriptor.Impl().(*frontendFD) + if !ok { + return 0, linuxerr.EINVAL + } + ctrlParams.DevDescriptor = uint64(devDesc.hostFD) + n, err := rmControlInvoke(fi, ioctlParams, ctrlParams) + ctrlParams.DevDescriptor = origDevDescriptor + return n, err +} + func ctrlClientSystemGetBuildVersionInvoke(fi *frontendIoctlState, ioctlParams *nvgpu.NVOS54Parameters, ctrlParams *nvgpu.NV0000_CTRL_SYSTEM_GET_BUILD_VERSION_PARAMS, driverVersionBuf, versionBuf, titleBuf *byte) (uintptr, error) { // *Buf arguments don't need runtime.KeepAlive() since our caller // ctrlClientSystemGetBuildVersion() copies them out, keeping them alive diff --git a/pkg/sentry/devices/nvproxy/version.go b/pkg/sentry/devices/nvproxy/version.go index 9c9d6935e..44ea77490 100644 --- a/pkg/sentry/devices/nvproxy/version.go +++ b/pkg/sentry/devices/nvproxy/version.go @@ -225,6 +225,9 @@ func Init() { 0x80028b: rmControlSimple, // unknown, paramsSize == 1 nvgpu.NV0080_CTRL_CMD_GPU_GET_CLASSLIST_V2: rmControlSimple, nvgpu.NV0080_CTRL_CMD_HOST_GET_CAPS_V2: rmControlSimple, + nvgpu.NV00FD_CTRL_CMD_GET_INFO: rmControlSimple, + nvgpu.NV00FD_CTRL_CMD_ATTACH_MEM: rmControlSimple, + nvgpu.NV00FD_CTRL_CMD_DETACH_MEM: rmControlSimple, nvgpu.NV2080_CTRL_CMD_BUS_GET_PCI_INFO: rmControlSimple, nvgpu.NV2080_CTRL_CMD_BUS_GET_PCI_BAR_INFO: rmControlSimple, nvgpu.NV2080_CTRL_CMD_BUS_GET_INFO_V2: rmControlSimple, @@ -290,46 +293,48 @@ func Init() { nvgpu.NV0000_CTRL_CMD_OS_UNIX_GET_EXPORT_OBJECT_INFO: ctrlHasFrontendFD[nvgpu.NV0000_CTRL_OS_UNIX_GET_EXPORT_OBJECT_INFO_PARAMS], nvgpu.NV0041_CTRL_CMD_GET_SURFACE_INFO: ctrlClientGetSurfaceInfo, nvgpu.NV0080_CTRL_CMD_FIFO_GET_CHANNELLIST: ctrlDevFIFOGetChannelList, + nvgpu.NV00FD_CTRL_CMD_ATTACH_GPU: ctrlMemoryMulticastFabricAttachGPU, nvgpu.NV0080_CTRL_CMD_GPU_GET_CLASSLIST: ctrlDevGpuGetClasslist, nvgpu.NV2080_CTRL_CMD_FIFO_DISABLE_CHANNELS: ctrlSubdevFIFODisableChannels, nvgpu.NV2080_CTRL_CMD_GR_GET_INFO: ctrlSubdevGRGetInfo, nvgpu.NV503C_CTRL_CMD_REGISTER_VA_SPACE: ctrlRegisterVASpace, }, allocationClass: map[nvgpu.ClassID]allocationClassHandler{ - nvgpu.NV01_ROOT: rmAllocRootClient, - nvgpu.NV01_ROOT_NON_PRIV: rmAllocRootClient, - nvgpu.NV01_MEMORY_SYSTEM: rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS], - nvgpu.NV01_MEMORY_LOCAL_USER: rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS], - nvgpu.NV01_ROOT_CLIENT: rmAllocRootClient, - nvgpu.NV01_EVENT_OS_EVENT: rmAllocEventOSEvent, - nvgpu.NV2081_BINAPI: rmAllocSimple[nvgpu.NV2081_ALLOC_PARAMETERS], - nvgpu.NV01_DEVICE_0: rmAllocSimple[nvgpu.NV0080_ALLOC_PARAMETERS], - nvgpu.NV_MEMORY_FABRIC: rmAllocSimple[nvgpu.NV00F8_ALLOCATION_PARAMETERS], - nvgpu.NV20_SUBDEVICE_0: rmAllocSimple[nvgpu.NV2080_ALLOC_PARAMETERS], - nvgpu.NV50_MEMORY_VIRTUAL: rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS], - nvgpu.NV50_P2P: rmAllocSimple[nvgpu.NV503B_ALLOC_PARAMETERS], - nvgpu.NV50_THIRD_PARTY_P2P: rmAllocSimple[nvgpu.NV503C_ALLOC_PARAMETERS], - nvgpu.GT200_DEBUGGER: rmAllocSMDebuggerSession, - nvgpu.FERMI_CONTEXT_SHARE_A: rmAllocContextShare, - nvgpu.FERMI_VASPACE_A: rmAllocSimple[nvgpu.NV_VASPACE_ALLOCATION_PARAMETERS], - nvgpu.KEPLER_CHANNEL_GROUP_A: rmAllocChannelGroup, - nvgpu.TURING_CHANNEL_GPFIFO_A: rmAllocChannel, - nvgpu.AMPERE_CHANNEL_GPFIFO_A: rmAllocChannel, - nvgpu.HOPPER_CHANNEL_GPFIFO_A: rmAllocChannel, - nvgpu.TURING_DMA_COPY_A: rmAllocSimple[nvgpu.NVB0B5_ALLOCATION_PARAMETERS], - nvgpu.AMPERE_DMA_COPY_A: rmAllocSimple[nvgpu.NVB0B5_ALLOCATION_PARAMETERS], - nvgpu.AMPERE_DMA_COPY_B: rmAllocSimple[nvgpu.NVB0B5_ALLOCATION_PARAMETERS], - nvgpu.HOPPER_DMA_COPY_A: rmAllocSimple[nvgpu.NVB0B5_ALLOCATION_PARAMETERS], - nvgpu.TURING_COMPUTE_A: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS], - nvgpu.AMPERE_COMPUTE_A: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS], - nvgpu.AMPERE_COMPUTE_B: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS], - nvgpu.ADA_COMPUTE_A: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS], - nvgpu.NV_CONFIDENTIAL_COMPUTE: rmAllocSimple[nvgpu.NV_CONFIDENTIAL_COMPUTE_ALLOC_PARAMS], - nvgpu.HOPPER_COMPUTE_A: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS], - nvgpu.HOPPER_USERMODE_A: rmAllocSimple[nvgpu.NV_HOPPER_USERMODE_A_PARAMS], - nvgpu.GF100_SUBDEVICE_MASTER: rmAllocNoParams, - nvgpu.TURING_USERMODE_A: rmAllocNoParams, - nvgpu.HOPPER_SEC2_WORK_LAUNCH_A: rmAllocNoParams, + nvgpu.NV01_ROOT: rmAllocRootClient, + nvgpu.NV01_ROOT_NON_PRIV: rmAllocRootClient, + nvgpu.NV01_MEMORY_SYSTEM: rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS], + nvgpu.NV01_MEMORY_LOCAL_USER: rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS], + nvgpu.NV01_ROOT_CLIENT: rmAllocRootClient, + nvgpu.NV01_EVENT_OS_EVENT: rmAllocEventOSEvent, + nvgpu.NV2081_BINAPI: rmAllocSimple[nvgpu.NV2081_ALLOC_PARAMETERS], + nvgpu.NV01_DEVICE_0: rmAllocSimple[nvgpu.NV0080_ALLOC_PARAMETERS], + nvgpu.NV_MEMORY_FABRIC: rmAllocSimple[nvgpu.NV00F8_ALLOCATION_PARAMETERS], + nvgpu.NV_MEMORY_MULTICAST_FABRIC: rmAllocSimple[nvgpu.NV00FD_ALLOCATION_PARAMETERS], + nvgpu.NV20_SUBDEVICE_0: rmAllocSimple[nvgpu.NV2080_ALLOC_PARAMETERS], + nvgpu.NV50_MEMORY_VIRTUAL: rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS], + nvgpu.NV50_P2P: rmAllocSimple[nvgpu.NV503B_ALLOC_PARAMETERS], + nvgpu.NV50_THIRD_PARTY_P2P: rmAllocSimple[nvgpu.NV503C_ALLOC_PARAMETERS], + nvgpu.GT200_DEBUGGER: rmAllocSMDebuggerSession, + nvgpu.FERMI_CONTEXT_SHARE_A: rmAllocContextShare, + nvgpu.FERMI_VASPACE_A: rmAllocSimple[nvgpu.NV_VASPACE_ALLOCATION_PARAMETERS], + nvgpu.KEPLER_CHANNEL_GROUP_A: rmAllocChannelGroup, + nvgpu.TURING_CHANNEL_GPFIFO_A: rmAllocChannel, + nvgpu.AMPERE_CHANNEL_GPFIFO_A: rmAllocChannel, + nvgpu.HOPPER_CHANNEL_GPFIFO_A: rmAllocChannel, + nvgpu.TURING_DMA_COPY_A: rmAllocSimple[nvgpu.NVB0B5_ALLOCATION_PARAMETERS], + nvgpu.AMPERE_DMA_COPY_A: rmAllocSimple[nvgpu.NVB0B5_ALLOCATION_PARAMETERS], + nvgpu.AMPERE_DMA_COPY_B: rmAllocSimple[nvgpu.NVB0B5_ALLOCATION_PARAMETERS], + nvgpu.HOPPER_DMA_COPY_A: rmAllocSimple[nvgpu.NVB0B5_ALLOCATION_PARAMETERS], + nvgpu.TURING_COMPUTE_A: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS], + nvgpu.AMPERE_COMPUTE_A: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS], + nvgpu.AMPERE_COMPUTE_B: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS], + nvgpu.ADA_COMPUTE_A: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS], + nvgpu.NV_CONFIDENTIAL_COMPUTE: rmAllocSimple[nvgpu.NV_CONFIDENTIAL_COMPUTE_ALLOC_PARAMS], + nvgpu.HOPPER_COMPUTE_A: rmAllocSimple[nvgpu.NV_GR_ALLOCATION_PARAMETERS], + nvgpu.HOPPER_USERMODE_A: rmAllocSimple[nvgpu.NV_HOPPER_USERMODE_A_PARAMS], + nvgpu.GF100_SUBDEVICE_MASTER: rmAllocNoParams, + nvgpu.TURING_USERMODE_A: rmAllocNoParams, + nvgpu.HOPPER_SEC2_WORK_LAUNCH_A: rmAllocNoParams, }, } } @@ -351,6 +356,7 @@ func Init() { v545_23_06 := func() *driverABI { abi := v535_113_01() abi.controlCmd[nvgpu.NV0000_CTRL_CMD_OS_UNIX_GET_EXPORT_OBJECT_INFO] = ctrlHasFrontendFD[nvgpu.NV0000_CTRL_OS_UNIX_GET_EXPORT_OBJECT_INFO_PARAMS_V545] + abi.allocationClass[nvgpu.NV_MEMORY_MULTICAST_FABRIC] = rmAllocSimple[nvgpu.NV00FD_ALLOCATION_PARAMETERS_V545] abi.allocationClass[nvgpu.NV01_MEMORY_SYSTEM] = rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS_V545] abi.allocationClass[nvgpu.NV01_MEMORY_LOCAL_USER] = rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS_V545] abi.allocationClass[nvgpu.NV50_MEMORY_VIRTUAL] = rmAllocSimple[nvgpu.NV_MEMORY_ALLOCATION_PARAMS_V545]