Skip to content

Commit

Permalink
Add NV0000_CTRL_CMD_OS_UNIX_EXPORT_OBJECT_TO_FD to nvproxy.
Browse files Browse the repository at this point in the history
Updates #10413

PiperOrigin-RevId: 632277477
  • Loading branch information
ayushr2 authored and gvisor-bot committed May 9, 2024
1 parent e515601 commit e9b3218
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/abi/nvgpu/ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ const (
NV0000_CTRL_CMD_SYSTEM_GET_FEATURES = 0x1f0
)

// From src/common/sdk/nvidia/inc/ctrl/ctrl0000/ctrl0000unix.h:
const (
NV0000_CTRL_CMD_OS_UNIX_EXPORT_OBJECT_TO_FD = 0x3d05
)

// +marshal
type NV0000_CTRL_OS_UNIX_EXPORT_OBJECT struct {
Type uint32 // enum NV0000_CTRL_OS_UNIX_EXPORT_OBJECT_TYPE
// These fields are inside union `data`, in struct `rmObject`.
HDevice Handle
HParent Handle
HObject Handle
}

// +marshal
type NV0000_CTRL_OS_UNIX_EXPORT_OBJECT_TO_FD_PARAMS struct {
Object NV0000_CTRL_OS_UNIX_EXPORT_OBJECT
FD int32
Flags uint32
}

// +marshal
type NV0000_CTRL_SYSTEM_GET_BUILD_VERSION_PARAMS struct {
SizeOfStrings uint32
Expand Down
31 changes: 31 additions & 0 deletions pkg/sentry/devices/nvproxy/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,37 @@ func ctrlCmdFailWithStatus(fi *frontendIoctlState, ioctlParams *nvgpu.NVOS54Para
return err
}

func ctrlExportObjectToFD(fi *frontendIoctlState, ioctlParams *nvgpu.NVOS54Parameters) (uintptr, error) {
var ctrlParams nvgpu.NV0000_CTRL_OS_UNIX_EXPORT_OBJECT_TO_FD_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
}
ctlFileGeneric, _ := fi.t.FDTable().Get(ctrlParams.FD)
if ctlFileGeneric == nil {
return 0, linuxerr.EINVAL
}
defer ctlFileGeneric.DecRef(fi.ctx)
ctlFile, ok := ctlFileGeneric.Impl().(*frontendFD)
if !ok {
return 0, linuxerr.EINVAL
}

origFD := ctrlParams.FD
ctrlParams.FD = ctlFile.hostFD
n, err := rmControlInvoke(fi, ioctlParams, &ctrlParams)
ctrlParams.FD = origFD
if err != nil {
return n, err
}
if _, err := ctrlParams.CopyOut(fi.t, addrFromP64(ioctlParams.Params)); err != nil {
return n, err
}
return n, nil
}

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) {
Expand Down
1 change: 1 addition & 0 deletions pkg/sentry/devices/nvproxy/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func Init() {
nvgpu.NVA06F_CTRL_CMD_GPFIFO_SCHEDULE: rmControlSimple,
nvgpu.NVC56F_CTRL_CMD_GET_KMB: rmControlSimple,
nvgpu.NV0000_CTRL_CMD_SYSTEM_GET_BUILD_VERSION: ctrlClientSystemGetBuildVersion,
nvgpu.NV0000_CTRL_CMD_OS_UNIX_EXPORT_OBJECT_TO_FD: ctrlExportObjectToFD,
nvgpu.NV0080_CTRL_CMD_FIFO_GET_CHANNELLIST: ctrlDevFIFOGetChannelList,
nvgpu.NV0080_CTRL_CMD_GPU_GET_CLASSLIST: ctrlDevGpuGetClasslist,
nvgpu.NV2080_CTRL_CMD_FIFO_DISABLE_CHANNELS: ctrlSubdevFIFODisableChannels,
Expand Down

0 comments on commit e9b3218

Please sign in to comment.