Skip to content

Commit 219be47

Browse files
Prike Liangalexdeucher
authored andcommitted
drm/amdgpu: validate userq input args
This will help on validating the userq input args, and rejecting for the invalid userq request at the IOCTLs first place. Signed-off-by: Prike Liang <Prike.Liang@amd.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 0561324 commit 219be47

File tree

2 files changed

+56
-32
lines changed

2 files changed

+56
-32
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -404,27 +404,10 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
404404
(args->in.flags & AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_MASK) >>
405405
AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_SHIFT;
406406

407-
/* Usermode queues are only supported for GFX IP as of now */
408-
if (args->in.ip_type != AMDGPU_HW_IP_GFX &&
409-
args->in.ip_type != AMDGPU_HW_IP_DMA &&
410-
args->in.ip_type != AMDGPU_HW_IP_COMPUTE) {
411-
drm_file_err(uq_mgr->file, "Usermode queue doesn't support IP type %u\n",
412-
args->in.ip_type);
413-
return -EINVAL;
414-
}
415-
416407
r = amdgpu_userq_priority_permit(filp, priority);
417408
if (r)
418409
return r;
419410

420-
if ((args->in.flags & AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE) &&
421-
(args->in.ip_type != AMDGPU_HW_IP_GFX) &&
422-
(args->in.ip_type != AMDGPU_HW_IP_COMPUTE) &&
423-
!amdgpu_is_tmz(adev)) {
424-
drm_file_err(uq_mgr->file, "Secure only supported on GFX/Compute queues\n");
425-
return -EINVAL;
426-
}
427-
428411
r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
429412
if (r < 0) {
430413
drm_file_err(uq_mgr->file, "pm_runtime_get_sync() failed for userqueue create\n");
@@ -543,22 +526,45 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
543526
return r;
544527
}
545528

546-
int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
547-
struct drm_file *filp)
529+
static int amdgpu_userq_input_args_validate(struct drm_device *dev,
530+
union drm_amdgpu_userq *args,
531+
struct drm_file *filp)
548532
{
549-
union drm_amdgpu_userq *args = data;
550-
int r;
533+
struct amdgpu_device *adev = drm_to_adev(dev);
551534

552535
switch (args->in.op) {
553536
case AMDGPU_USERQ_OP_CREATE:
554537
if (args->in.flags & ~(AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_MASK |
555538
AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE))
556539
return -EINVAL;
557-
r = amdgpu_userq_create(filp, args);
558-
if (r)
559-
drm_file_err(filp, "Failed to create usermode queue\n");
560-
break;
540+
/* Usermode queues are only supported for GFX IP as of now */
541+
if (args->in.ip_type != AMDGPU_HW_IP_GFX &&
542+
args->in.ip_type != AMDGPU_HW_IP_DMA &&
543+
args->in.ip_type != AMDGPU_HW_IP_COMPUTE) {
544+
drm_file_err(filp, "Usermode queue doesn't support IP type %u\n",
545+
args->in.ip_type);
546+
return -EINVAL;
547+
}
548+
549+
if ((args->in.flags & AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE) &&
550+
(args->in.ip_type != AMDGPU_HW_IP_GFX) &&
551+
(args->in.ip_type != AMDGPU_HW_IP_COMPUTE) &&
552+
!amdgpu_is_tmz(adev)) {
553+
drm_file_err(filp, "Secure only supported on GFX/Compute queues\n");
554+
return -EINVAL;
555+
}
561556

557+
if (args->in.queue_va == AMDGPU_BO_INVALID_OFFSET ||
558+
args->in.queue_va == 0 ||
559+
args->in.queue_size == 0) {
560+
drm_file_err(filp, "invalidate userq queue va or size\n");
561+
return -EINVAL;
562+
}
563+
if (!args->in.wptr_va || !args->in.rptr_va) {
564+
drm_file_err(filp, "invalidate userq queue rptr or wptr\n");
565+
return -EINVAL;
566+
}
567+
break;
562568
case AMDGPU_USERQ_OP_FREE:
563569
if (args->in.ip_type ||
564570
args->in.doorbell_handle ||
@@ -571,6 +577,31 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
571577
args->in.mqd ||
572578
args->in.mqd_size)
573579
return -EINVAL;
580+
break;
581+
default:
582+
return -EINVAL;
583+
}
584+
585+
return 0;
586+
}
587+
588+
int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
589+
struct drm_file *filp)
590+
{
591+
union drm_amdgpu_userq *args = data;
592+
int r;
593+
594+
if (amdgpu_userq_input_args_validate(dev, args, filp) < 0)
595+
return -EINVAL;
596+
597+
switch (args->in.op) {
598+
case AMDGPU_USERQ_OP_CREATE:
599+
r = amdgpu_userq_create(filp, args);
600+
if (r)
601+
drm_file_err(filp, "Failed to create usermode queue\n");
602+
break;
603+
604+
case AMDGPU_USERQ_OP_FREE:
574605
r = amdgpu_userq_destroy(filp, args->in.queue_id);
575606
if (r)
576607
drm_file_err(filp, "Failed to destroy usermode queue\n");

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,6 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
263263
return -ENOMEM;
264264
}
265265

266-
if (!mqd_user->wptr_va || !mqd_user->rptr_va ||
267-
!mqd_user->queue_va || mqd_user->queue_size == 0) {
268-
DRM_ERROR("Invalid MQD parameters for userqueue\n");
269-
r = -EINVAL;
270-
goto free_props;
271-
}
272-
273266
r = amdgpu_userq_create_object(uq_mgr, &queue->mqd, mqd_hw_default->mqd_size);
274267
if (r) {
275268
DRM_ERROR("Failed to create MQD object for userqueue\n");

0 commit comments

Comments
 (0)