Skip to content

Commit 738e1d9

Browse files
ayushr2gvisor-bot
authored andcommitted
nvproxy: Add HasStatus.SetStatus and provide failWithStatus() util functions.
This creates a more centralized way for nvproxy to return errors to the the user mode driver via the NvStatus field in ioctl structs. As opposed to failing the ioctl with mysterious EINVALs. Also updated the following structs to NOT implement HasStatus interface: - IoctlRegisterFD - RMAPIVersion - IoctlSysParams These don't have a Status field so it is misleading for them to implement HasStatus. Created frontendIoctlSimpleNoStatus() and frontendIoctlInvokeNoStatus() for such structs to use. PiperOrigin-RevId: 738959856
1 parent c16d3fd commit 738e1d9

File tree

8 files changed

+347
-84
lines changed

8 files changed

+347
-84
lines changed

pkg/abi/nvgpu/frontend.go

Lines changed: 97 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,6 @@ type IoctlRegisterFD struct {
6666
CtlFD int32
6767
}
6868

69-
// GetStatus implements HasStatus.GetStatus.
70-
func (p *IoctlRegisterFD) GetStatus() uint32 {
71-
// nv_ioctl_register_fd_t doesn't have a NvStatus field. Any failures are
72-
// returned from src/nvidia/arch/nvalloc/unix/src/escape.c:nvidia_ioctl()'s
73-
// NV_ESC_REGISTER_FD case to kernel-open/nvidia/nv.c:nvidia_ioctl()'s
74-
// default case, which converts it to an ioctl(2) syscall error.
75-
return NV_OK
76-
}
77-
7869
// IoctlAllocOSEvent is the parameter type for NV_ESC_ALLOC_OS_EVENT.
7970
//
8071
// +marshal
@@ -100,6 +91,11 @@ func (p *IoctlAllocOSEvent) GetStatus() uint32 {
10091
return p.Status
10192
}
10293

94+
// SetStatus implements HasStatus.SetStatus.
95+
func (p *IoctlAllocOSEvent) SetStatus(status uint32) {
96+
p.Status = status
97+
}
98+
10399
// IoctlFreeOSEvent is the parameter type for NV_ESC_FREE_OS_EVENT.
104100
//
105101
// +marshal
@@ -125,6 +121,11 @@ func (p *IoctlFreeOSEvent) GetStatus() uint32 {
125121
return p.Status
126122
}
127123

124+
// SetStatus implements HasStatus.SetStatus.
125+
func (p *IoctlFreeOSEvent) SetStatus(status uint32) {
126+
p.Status = status
127+
}
128+
128129
// RMAPIVersion is the parameter type for NV_ESC_CHECK_VERSION_STR.
129130
//
130131
// +marshal
@@ -134,29 +135,13 @@ type RMAPIVersion struct {
134135
VersionString [64]byte
135136
}
136137

137-
// GetStatus implements HasStatus.GetStatus.
138-
func (p *RMAPIVersion) GetStatus() uint32 {
139-
// nv_ioctl_rm_api_version_t doesn't have a NvStatus field. The driver
140-
// translates the rmStatus to an ioctl(2) failure. See
141-
// kernel-open/nvidia/nv.c:nvidia_ioctl() => case NV_ESC_CHECK_VERSION_STR.
142-
return NV_OK
143-
}
144-
145138
// IoctlSysParams is the parameter type for NV_ESC_SYS_PARAMS.
146139
//
147140
// +marshal
148141
type IoctlSysParams struct {
149142
MemblockSize uint64
150143
}
151144

152-
// GetStatus implements HasStatus.GetStatus.
153-
func (p *IoctlSysParams) GetStatus() uint32 {
154-
// nv_ioctl_sys_params_t doesn't have a NvStatus field. The driver fails the
155-
// ioctl(2) syscall in case of any failure. See
156-
// kernel-open/nvidia/nv.c:nvidia_ioctl() => case NV_ESC_SYS_PARAMS.
157-
return NV_OK
158-
}
159-
160145
// IoctlWaitOpenComplete is the parameter type for NV_ESC_WAIT_OPEN_COMPLETE.
161146
//
162147
// +marshal
@@ -170,6 +155,11 @@ func (p *IoctlWaitOpenComplete) GetStatus() uint32 {
170155
return p.AdapterStatus
171156
}
172157

158+
// SetStatus implements HasStatus.SetStatus.
159+
func (p *IoctlWaitOpenComplete) SetStatus(status uint32) {
160+
p.AdapterStatus = status
161+
}
162+
173163
// IoctlNVOS02ParametersWithFD is the parameter type for NV_ESC_RM_ALLOC_MEMORY.
174164
//
175165
// +marshal
@@ -184,6 +174,11 @@ func (p *IoctlNVOS02ParametersWithFD) GetStatus() uint32 {
184174
return p.Params.Status
185175
}
186176

177+
// SetStatus implements HasStatus.SetStatus.
178+
func (p *IoctlNVOS02ParametersWithFD) SetStatus(status uint32) {
179+
p.Params.Status = status
180+
}
181+
187182
// +marshal
188183
type NVOS02_PARAMETERS struct {
189184
HRoot Handle
@@ -224,6 +219,11 @@ func (p *NVOS00_PARAMETERS) GetStatus() uint32 {
224219
return p.Status
225220
}
226221

222+
// SetStatus implements HasStatus.SetStatus.
223+
func (p *NVOS00_PARAMETERS) SetStatus(status uint32) {
224+
p.Status = status
225+
}
226+
227227
// RmAllocParamType should be implemented by all possible parameter types for
228228
// NV_ESC_RM_ALLOC.
229229
type RmAllocParamType interface {
@@ -308,11 +308,16 @@ func (n *NVOS21_PARAMETERS) ToOS64() NVOS64_PARAMETERS {
308308
}
309309
}
310310

311-
// GetStatus implements RmAllocParamType.GetStatus.
311+
// GetStatus implements HasStatus.GetStatus.
312312
func (n *NVOS21_PARAMETERS) GetStatus() uint32 {
313313
return n.Status
314314
}
315315

316+
// SetStatus implements HasStatus.SetStatus.
317+
func (n *NVOS21_PARAMETERS) SetStatus(status uint32) {
318+
n.Status = status
319+
}
320+
316321
// NVOS55_PARAMETERS is the parameter type for NV_ESC_RM_DUP_OBJECT.
317322
//
318323
// +marshal
@@ -331,6 +336,11 @@ func (n *NVOS55_PARAMETERS) GetStatus() uint32 {
331336
return n.Status
332337
}
333338

339+
// SetStatus implements HasStatus.SetStatus.
340+
func (n *NVOS55_PARAMETERS) SetStatus(status uint32) {
341+
n.Status = status
342+
}
343+
334344
// NVOS57_PARAMETERS is the parameter type for NV_ESC_RM_SHARE.
335345
//
336346
// +marshal
@@ -346,6 +356,11 @@ func (n *NVOS57_PARAMETERS) GetStatus() uint32 {
346356
return n.Status
347357
}
348358

359+
// SetStatus implements HasStatus.SetStatus.
360+
func (n *NVOS57_PARAMETERS) SetStatus(status uint32) {
361+
n.Status = status
362+
}
363+
349364
// NVOS30_PARAMETERS is the parameter type for NV_ESC_RM_IDLE_CHANNELS.
350365
//
351366
// +marshal
@@ -370,6 +385,11 @@ func (n *NVOS30_PARAMETERS) GetStatus() uint32 {
370385
return n.Status
371386
}
372387

388+
// SetStatus implements HasStatus.SetStatus.
389+
func (n *NVOS30_PARAMETERS) SetStatus(status uint32) {
390+
n.Status = status
391+
}
392+
373393
// NVOS32_PARAMETERS is the parameter type for NV_ESC_RM_VID_HEAP_CONTROL.
374394
//
375395
// +marshal
@@ -391,6 +411,11 @@ func (n *NVOS32_PARAMETERS) GetStatus() uint32 {
391411
return n.Status
392412
}
393413

414+
// SetStatus implements HasStatus.SetStatus.
415+
func (n *NVOS32_PARAMETERS) SetStatus(status uint32) {
416+
n.Status = status
417+
}
418+
394419
// Possible values for NVOS32Parameters.Function:
395420
const (
396421
NVOS32_FUNCTION_ALLOC_SIZE = 2
@@ -457,6 +482,11 @@ func (p *IoctlNVOS33ParametersWithFD) GetStatus() uint32 {
457482
return p.Params.Status
458483
}
459484

485+
// SetStatus implements HasStatus.SetStatus.
486+
func (p *IoctlNVOS33ParametersWithFD) SetStatus(status uint32) {
487+
p.Params.Status = status
488+
}
489+
460490
// +marshal
461491
type NVOS33_PARAMETERS struct {
462492
HClient Handle
@@ -500,6 +530,11 @@ func (n *NVOS34_PARAMETERS) GetStatus() uint32 {
500530
return n.Status
501531
}
502532

533+
// SetStatus implements HasStatus.SetStatus.
534+
func (n *NVOS34_PARAMETERS) SetStatus(status uint32) {
535+
n.Status = status
536+
}
537+
503538
// NVOS39_PARAMETERS is the parameter type for NV_ESC_RM_ALLOC_CONTEXT_DMA2.
504539
//
505540
// +marshal
@@ -523,6 +558,11 @@ func (n *NVOS39_PARAMETERS) GetStatus() uint32 {
523558
return n.Status
524559
}
525560

561+
// SetStatus implements HasStatus.SetStatus.
562+
func (n *NVOS39_PARAMETERS) SetStatus(status uint32) {
563+
n.Status = status
564+
}
565+
526566
// NVOS46_PARAMETERS is the parameter type for NV_ESC_RM_MAP_MEMORY_DMA.
527567
//
528568
// +marshal
@@ -545,6 +585,11 @@ func (n *NVOS46_PARAMETERS) GetStatus() uint32 {
545585
return n.Status
546586
}
547587

588+
// SetStatus implements HasStatus.SetStatus.
589+
func (n *NVOS46_PARAMETERS) SetStatus(status uint32) {
590+
n.Status = status
591+
}
592+
548593
// NVOS47_PARAMETERS is the parameter type for NV_ESC_RM_UNMAP_MEMORY_DMA.
549594
//
550595
// +marshal
@@ -565,6 +610,11 @@ func (n *NVOS47_PARAMETERS) GetStatus() uint32 {
565610
return n.Status
566611
}
567612

613+
// SetStatus implements HasStatus.SetStatus.
614+
func (n *NVOS47_PARAMETERS) SetStatus(status uint32) {
615+
n.Status = status
616+
}
617+
568618
// NVOS47_PARAMETERS_V550 is the updated version of NVOS47_PARAMETERS since
569619
// 550.54.04.
570620
//
@@ -587,6 +637,11 @@ func (n *NVOS47_PARAMETERS_V550) GetStatus() uint32 {
587637
return n.Status
588638
}
589639

640+
// SetStatus implements HasStatus.SetStatus.
641+
func (n *NVOS47_PARAMETERS_V550) SetStatus(status uint32) {
642+
n.Status = status
643+
}
644+
590645
// NVOS54_PARAMETERS is the parameter type for NV_ESC_RM_CONTROL.
591646
//
592647
// +marshal
@@ -605,6 +660,11 @@ func (n *NVOS54_PARAMETERS) GetStatus() uint32 {
605660
return n.Status
606661
}
607662

663+
// SetStatus implements HasStatus.SetStatus.
664+
func (n *NVOS54_PARAMETERS) SetStatus(status uint32) {
665+
n.Status = status
666+
}
667+
608668
// NVOS56_PARAMETERS is the parameter type for NV_ESC_RM_UPDATE_DEVICE_MAPPING_INFO.
609669
//
610670
// +marshal
@@ -624,6 +684,11 @@ func (n *NVOS56_PARAMETERS) GetStatus() uint32 {
624684
return n.Status
625685
}
626686

687+
// SetStatus implements HasStatus.SetStatus.
688+
func (n *NVOS56_PARAMETERS) SetStatus(status uint32) {
689+
n.Status = status
690+
}
691+
627692
// NVOS64_PARAMETERS is one possible parameter type for NV_ESC_RM_ALLOC.
628693
//
629694
// +marshal
@@ -668,11 +733,16 @@ func (n *NVOS64_PARAMETERS) FromOS64(other NVOS64_PARAMETERS) { *n = other }
668733
// ToOS64 implements RmAllocParamType.ToOS64.
669734
func (n *NVOS64_PARAMETERS) ToOS64() NVOS64_PARAMETERS { return *n }
670735

671-
// GetStatus implements RmAllocParamType.GetStatus.
736+
// GetStatus implements HasStatus.GetStatus.
672737
func (n *NVOS64_PARAMETERS) GetStatus() uint32 {
673738
return n.Status
674739
}
675740

741+
// SetStatus implements HasStatus.SetStatus.
742+
func (n *NVOS64_PARAMETERS) SetStatus(status uint32) {
743+
n.Status = status
744+
}
745+
676746
// HasFrontendFD is a type constraint for parameter structs containing a
677747
// frontend FD field. This is necessary because, as of this writing (Go 1.20),
678748
// there is no way to enable field access using a Go type constraint.

pkg/abi/nvgpu/nvgpu.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,5 @@ type NvUUID [16]uint8
8888
// HasStatus is an interface for parameter structs that have a Status field.
8989
type HasStatus interface {
9090
GetStatus() uint32
91+
SetStatus(status uint32)
9192
}

0 commit comments

Comments
 (0)