Skip to content

Commit b11efea

Browse files
ayushr2gvisor-bot
authored andcommitted
nvproxy: Clean up struct field tags.
Before this change, there were 2 places in which the driver struct names were defined for nvproxy structs: 1. As struct field tags. The first field of structs had a tag `nvproxy:*`. This was kind of awkward. Such metadata is usually a struct comment. 2. In version.go while registering the struct with a name. Not all structs are defined in nvproxy (for example simple structs). In such cases, the driver struct name is directly assigned while registering struct info. This change gets rid of (1). Most of the struct tags were `nvproxy:"same"`. Now driverStructs() always infers the driver struct name using the nvproxy struct name itself. The few cases where the nvproxy tag was needed, because driver struct name was lower cased, were handled by defining driverStructWithName() which allows specifying a different name. Now all driver struct names definitions are in one place. Along the way, also made the following fixes: - For some reason, many structs defined in pkg/abi/nvgpu/frontend.go had camel-cased naming, while all other structs in pkg/abi/nvgpu/ctrl.go and pkg/abi/nvgpu/classes.go were named the same as their driver structs. The convention in the abi/* packages is to follow the kernel source naming. This is against Go sytle guide, but is more readable for gVisor purposes and has been a long accepted convention. This also makes the task of removing (1) easier. So renamed all such structs as per their driver names. - A lot of code in pkg/sentry/devices/nvproxy/version.go was still referring to driver struct info as "struct names", even though it was representing more than just struct names. It also contains the reflect.Type of the struct which is used to compare the nvproxy struct layout to the driver struct layout. PiperOrigin-RevId: 710648105
1 parent 768db86 commit b11efea

File tree

13 files changed

+567
-605
lines changed

13 files changed

+567
-605
lines changed

pkg/abi/nvgpu/classes.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ const (
9393
//
9494
// +marshal
9595
type NV2081_ALLOC_PARAMETERS struct {
96-
Reserved uint32 `nvproxy:"same"`
96+
Reserved uint32
9797
}
9898

9999
// NV0005_ALLOC_PARAMETERS is the alloc params type for NV01_EVENT* classes
100100
// from src/common/sdk/nvidia/inc/class/cl0005.h.
101101
//
102102
// +marshal
103103
type NV0005_ALLOC_PARAMETERS struct {
104-
HParentClient Handle `nvproxy:"same"`
104+
HParentClient Handle
105105
HSrcResource Handle
106106
HClass ClassID
107107
NotifyIndex uint32
@@ -118,7 +118,7 @@ const (
118118
//
119119
// +marshal
120120
type NV_MEMORY_VIRTUAL_ALLOCATION_PARAMS struct {
121-
Offset uint64 `nvproxy:"same"`
121+
Offset uint64
122122
Limit uint64
123123
HVASpace Handle
124124
Pad0 [4]byte
@@ -129,7 +129,7 @@ type NV_MEMORY_VIRTUAL_ALLOCATION_PARAMS struct {
129129
//
130130
// +marshal
131131
type NV0080_ALLOC_PARAMETERS struct {
132-
DeviceID uint32 `nvproxy:"same"`
132+
DeviceID uint32
133133
HClientShare Handle
134134
HTargetClient Handle
135135
HTargetDevice Handle
@@ -147,15 +147,15 @@ type NV0080_ALLOC_PARAMETERS struct {
147147
//
148148
// +marshal
149149
type NV2080_ALLOC_PARAMETERS struct {
150-
SubDeviceID uint32 `nvproxy:"same"`
150+
SubDeviceID uint32
151151
}
152152

153153
// NV_MEMORY_ALLOCATION_PARAMS is the alloc params type for various NV*_MEMORY*
154154
// allocation classes, from src/common/sdk/nvidia/inc/nvos.h.
155155
//
156156
// +marshal
157157
type NV_MEMORY_ALLOCATION_PARAMS struct {
158-
Owner uint32 `nvproxy:"same"`
158+
Owner uint32
159159
Type uint32
160160
Flags uint32
161161
Width uint32
@@ -185,16 +185,16 @@ type NV_MEMORY_ALLOCATION_PARAMS struct {
185185
//
186186
// +marshal
187187
type NV_MEMORY_ALLOCATION_PARAMS_V545 struct {
188-
NV_MEMORY_ALLOCATION_PARAMS `nvproxy:"NV_MEMORY_ALLOCATION_PARAMS"`
189-
NumaNode int32
190-
_ uint32
188+
NV_MEMORY_ALLOCATION_PARAMS
189+
NumaNode int32
190+
_ uint32
191191
}
192192

193193
// NV503B_BAR1_P2P_DMA_INFO from src/common/sdk/nvidia/inc/class/cl503b.h.
194194
//
195195
// +marshal
196196
type NV503B_BAR1_P2P_DMA_INFO struct {
197-
DmaAddress uint64 `nvproxy:"same"`
197+
DmaAddress uint64
198198
DmaSize uint64
199199
}
200200

@@ -203,7 +203,7 @@ type NV503B_BAR1_P2P_DMA_INFO struct {
203203
//
204204
// +marshal
205205
type NV503B_ALLOC_PARAMETERS struct {
206-
HSubDevice Handle `nvproxy:"same"`
206+
HSubDevice Handle
207207
HPeerSubDevice Handle
208208
SubDevicePeerIDMask uint32
209209
PeerSubDevicePeerIDMask uint32
@@ -221,15 +221,15 @@ type NV503B_ALLOC_PARAMETERS struct {
221221
//
222222
// +marshal
223223
type NV503C_ALLOC_PARAMETERS struct {
224-
Flags uint32 `nvproxy:"same"`
224+
Flags uint32
225225
}
226226

227227
// NV83DE_ALLOC_PARAMETERS is the alloc params type for GT200_DEBUGGER,
228228
// from src/common/sdk/nvidia/inc/class/cl83de.h.
229229
//
230230
// +marshal
231231
type NV83DE_ALLOC_PARAMETERS struct {
232-
HDebuggerClient_Obsolete Handle `nvproxy:"same"`
232+
HDebuggerClient_Obsolete Handle
233233
HAppClient Handle
234234
HClass3DObject Handle
235235
}
@@ -239,7 +239,7 @@ type NV83DE_ALLOC_PARAMETERS struct {
239239
//
240240
// +marshal
241241
type NV_CTXSHARE_ALLOCATION_PARAMETERS struct {
242-
HVASpace Handle `nvproxy:"same"`
242+
HVASpace Handle
243243
Flags uint32
244244
SubctxID uint32
245245
}
@@ -249,7 +249,7 @@ type NV_CTXSHARE_ALLOCATION_PARAMETERS struct {
249249
//
250250
// +marshal
251251
type NV_VASPACE_ALLOCATION_PARAMETERS struct {
252-
Index uint32 `nvproxy:"same"`
252+
Index uint32
253253
Flags uint32
254254
VASize uint64
255255
VAStartInternal uint64
@@ -264,7 +264,7 @@ type NV_VASPACE_ALLOCATION_PARAMETERS struct {
264264
//
265265
// +marshal
266266
type NV_CHANNEL_GROUP_ALLOCATION_PARAMETERS struct {
267-
HObjectError Handle `nvproxy:"same"`
267+
HObjectError Handle
268268
HObjectECCError Handle
269269
HVASpace Handle
270270
EngineType uint32
@@ -277,7 +277,7 @@ type NV_CHANNEL_GROUP_ALLOCATION_PARAMETERS struct {
277277
//
278278
// +marshal
279279
type NV_MEMORY_DESC_PARAMS struct {
280-
Base uint64 `nvproxy:"same"`
280+
Base uint64
281281
Size uint64
282282
AddressSpace uint32
283283
CacheAttrib uint32
@@ -289,7 +289,7 @@ type NV_MEMORY_DESC_PARAMS struct {
289289
//
290290
// +marshal
291291
type NV_CHANNEL_ALLOC_PARAMS struct {
292-
HObjectError Handle `nvproxy:"same"`
292+
HObjectError Handle
293293
HObjectBuffer Handle
294294
GPFIFOOffset uint64
295295
GPFIFOEntries uint32
@@ -323,7 +323,7 @@ type NV_CHANNEL_ALLOC_PARAMS struct {
323323
//
324324
// +marshal
325325
type NVB0B5_ALLOCATION_PARAMETERS struct {
326-
Version uint32 `nvproxy:"same"`
326+
Version uint32
327327
EngineType uint32
328328
}
329329

@@ -332,7 +332,7 @@ type NVB0B5_ALLOCATION_PARAMETERS struct {
332332
//
333333
// +marshal
334334
type NV_GR_ALLOCATION_PARAMETERS struct {
335-
Version uint32 `nvproxy:"same"`
335+
Version uint32
336336
Flags uint32
337337
Size uint32
338338
Caps uint32
@@ -343,7 +343,7 @@ type NV_GR_ALLOCATION_PARAMETERS struct {
343343
//
344344
// +marshal
345345
type NV_HOPPER_USERMODE_A_PARAMS struct {
346-
Bar1Mapping uint8 `nvproxy:"same"`
346+
Bar1Mapping uint8
347347
Priv uint8
348348
}
349349

@@ -352,7 +352,7 @@ type NV_HOPPER_USERMODE_A_PARAMS struct {
352352
//
353353
// +marshal
354354
type NV9072_ALLOCATION_PARAMETERS struct {
355-
LogicalHeadID uint32 `nvproxy:"same"`
355+
LogicalHeadID uint32
356356
DisplayMask uint32
357357
Caps uint32
358358
}
@@ -362,15 +362,15 @@ type NV9072_ALLOCATION_PARAMETERS struct {
362362
//
363363
// +marshal
364364
type NV00DE_ALLOC_PARAMETERS struct {
365-
Reserved uint32 `nvproxy:"same"`
365+
Reserved uint32
366366
}
367367

368368
// NV00DE_ALLOC_PARAMETERS_V545 is the updated version of
369369
// NV00DE_ALLOC_PARAMETERS since 545.23.06.
370370
//
371371
// +marshal
372372
type NV00DE_ALLOC_PARAMETERS_V545 struct {
373-
PolledDataMask uint64 `nvproxy:"NV00DE_ALLOC_PARAMETERS"`
373+
PolledDataMask uint64
374374
}
375375

376376
// +marshal
@@ -385,7 +385,7 @@ type nv00f8Map struct {
385385
//
386386
// +marshal
387387
type NV00F8_ALLOCATION_PARAMETERS struct {
388-
Alignment uint64 `nvproxy:"same"`
388+
Alignment uint64
389389
AllocSize uint64
390390
PageSize uint64
391391
AllocFlags uint32
@@ -412,7 +412,7 @@ type NV_EXPORT_MEM_PACKET struct {
412412
//
413413
// +marshal
414414
type NV00FD_ALLOCATION_PARAMETERS struct {
415-
Alignment uint64 `nvproxy:"same"`
415+
Alignment uint64
416416
AllocSize uint64
417417
PageSize uint32
418418
AllocFlags uint32
@@ -426,7 +426,7 @@ type NV00FD_ALLOCATION_PARAMETERS struct {
426426
//
427427
// +marshal
428428
type NV00FD_ALLOCATION_PARAMETERS_V545 struct {
429-
ExpPacket NV_EXPORT_MEM_PACKET `nvproxy:"NV00FD_ALLOCATION_PARAMETERS"`
429+
ExpPacket NV_EXPORT_MEM_PACKET
430430
Index uint16
431431
_ [6]byte
432432
NV00FD_ALLOCATION_PARAMETERS
@@ -437,5 +437,5 @@ type NV00FD_ALLOCATION_PARAMETERS_V545 struct {
437437
//
438438
// +marshal
439439
type NV_CONFIDENTIAL_COMPUTE_ALLOC_PARAMS struct {
440-
Handle Handle `nvproxy:"same"`
440+
Handle Handle
441441
}

pkg/abi/nvgpu/ctrl.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const (
8686
//
8787
// +marshal
8888
type NV0000_CTRL_GPU_GET_ID_INFO_PARAMS struct {
89-
GpuID uint32 `nvproxy:"same"`
89+
GpuID uint32
9090
GpuFlags uint32
9191
DeviceInstance uint32
9292
SubDeviceInstance uint32
@@ -120,7 +120,7 @@ const (
120120
//
121121
// +marshal
122122
type NV0000_CTRL_SYSTEM_GET_P2P_CAPS_PARAMS struct {
123-
GpuIDs [NV0000_CTRL_SYSTEM_MAX_ATTACHED_GPUS]uint32 `nvproxy:"same"`
123+
GpuIDs [NV0000_CTRL_SYSTEM_MAX_ATTACHED_GPUS]uint32
124124
GpuCount uint32
125125
P2PCaps uint32
126126
P2POptimalReadCEs uint32
@@ -135,8 +135,8 @@ type NV0000_CTRL_SYSTEM_GET_P2P_CAPS_PARAMS struct {
135135
//
136136
// +marshal
137137
type NV0000_CTRL_SYSTEM_GET_P2P_CAPS_PARAMS_V550 struct {
138-
NV0000_CTRL_SYSTEM_GET_P2P_CAPS_PARAMS `nvproxy:"NV0000_CTRL_SYSTEM_GET_P2P_CAPS_PARAMS"`
139-
BusEgmPeerIDs P64
138+
NV0000_CTRL_SYSTEM_GET_P2P_CAPS_PARAMS
139+
BusEgmPeerIDs P64
140140
}
141141

142142
// From src/common/sdk/nvidia/inc/ctrl/ctrl0000/ctrl0000unix.h:
@@ -149,7 +149,7 @@ const (
149149

150150
// +marshal
151151
type NV0000_CTRL_OS_UNIX_GET_EXPORT_OBJECT_INFO_PARAMS struct {
152-
FD int32 `nvproxy:"same"`
152+
FD int32
153153
DeviceInstance uint32
154154
MaxObjects uint16
155155
Metadata [NV0000_OS_UNIX_EXPORT_OBJECT_FD_BUFFER_SIZE]uint8
@@ -168,7 +168,7 @@ func (p *NV0000_CTRL_OS_UNIX_GET_EXPORT_OBJECT_INFO_PARAMS) SetFrontendFD(fd int
168168

169169
// +marshal
170170
type NV0000_CTRL_OS_UNIX_GET_EXPORT_OBJECT_INFO_PARAMS_V545 struct {
171-
FD int32 `nvproxy:"NV0000_CTRL_OS_UNIX_GET_EXPORT_OBJECT_INFO_PARAMS"`
171+
FD int32
172172
DeviceInstance uint32
173173
GpuInstanceID uint32
174174
MaxObjects uint16
@@ -194,7 +194,7 @@ type NV0000_CTRL_OS_UNIX_EXPORT_OBJECT struct {
194194

195195
// +marshal
196196
type NV0000_CTRL_OS_UNIX_EXPORT_OBJECT_TO_FD_PARAMS struct {
197-
Object NV0000_CTRL_OS_UNIX_EXPORT_OBJECT `nvproxy:"same"`
197+
Object NV0000_CTRL_OS_UNIX_EXPORT_OBJECT
198198
FD int32
199199
Flags uint32
200200
}
@@ -211,7 +211,7 @@ func (p *NV0000_CTRL_OS_UNIX_EXPORT_OBJECT_TO_FD_PARAMS) SetFrontendFD(fd int32)
211211

212212
// +marshal
213213
type NV0000_CTRL_OS_UNIX_IMPORT_OBJECT_FROM_FD_PARAMS struct {
214-
FD int32 `nvproxy:"same"`
214+
FD int32
215215
Object NV0000_CTRL_OS_UNIX_EXPORT_OBJECT
216216
}
217217

@@ -227,7 +227,7 @@ func (p *NV0000_CTRL_OS_UNIX_IMPORT_OBJECT_FROM_FD_PARAMS) SetFrontendFD(fd int3
227227

228228
// +marshal
229229
type NV0000_CTRL_SYSTEM_GET_BUILD_VERSION_PARAMS struct {
230-
SizeOfStrings uint32 `nvproxy:"same"`
230+
SizeOfStrings uint32
231231
Pad [4]byte
232232
PDriverVersionBuffer P64
233233
PVersionBuffer P64
@@ -262,7 +262,7 @@ const (
262262

263263
// +marshal
264264
type NV0080_CTRL_FIFO_GET_CHANNELLIST_PARAMS struct {
265-
NumChannels uint32 `nvproxy:"same"`
265+
NumChannels uint32
266266
Pad [4]byte
267267
PChannelHandleList P64
268268
PChannelList P64
@@ -309,7 +309,7 @@ type NV0080_CTRL_GET_CAPS_PARAMS struct {
309309

310310
// +marshal
311311
type NV0080_CTRL_GR_ROUTE_INFO struct {
312-
Flags uint32 `nvproxy:"same"`
312+
Flags uint32
313313
Pad [4]byte
314314
Route uint64
315315
}
@@ -377,7 +377,7 @@ const (
377377

378378
// +marshal
379379
type NV00FD_CTRL_ATTACH_GPU_PARAMS struct {
380-
HSubDevice Handle `nvproxy:"same"`
380+
HSubDevice Handle
381381
Flags uint32
382382
DevDescriptor uint64
383383
}
@@ -431,7 +431,7 @@ const (
431431

432432
// +marshal
433433
type NV2080_CTRL_FIFO_DISABLE_CHANNELS_PARAMS struct {
434-
BDisable uint8 `nvproxy:"same"`
434+
BDisable uint8
435435
Pad1 [3]byte
436436
NumChannels uint32
437437
BOnlyDisableScheduling uint8
@@ -495,8 +495,8 @@ const (
495495

496496
// +marshal
497497
type NV2080_CTRL_GR_GET_INFO_PARAMS struct {
498-
NvxxxCtrlXxxGetInfoParams `nvproxy:"same"`
499-
GRRouteInfo NV0080_CTRL_GR_ROUTE_INFO
498+
NvxxxCtrlXxxGetInfoParams
499+
GRRouteInfo NV0080_CTRL_GR_ROUTE_INFO
500500
}
501501

502502
// ListSize implements HasCtrlInfoList.ListSize.
@@ -555,7 +555,7 @@ const (
555555

556556
// +marshal
557557
type NV503C_CTRL_REGISTER_VA_SPACE_PARAMS struct {
558-
HVASpace Handle `nvproxy:"same"`
558+
HVASpace Handle
559559
Pad [4]byte
560560
VASpaceToken uint64
561561
}

0 commit comments

Comments
 (0)