[PATCH] drm/amdgpu: enable bo priority setting from user space

Michel Dänzer michel at daenzer.net
Thu Mar 7 09:55:20 UTC 2019


On 2019-03-07 10:15 a.m., Chunming Zhou wrote:
> Signed-off-by: Chunming Zhou <david1.zhou at amd.com>

Please provide corresponding UMD patches showing how this is to be used.


> @@ -229,6 +231,14 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
>  	if (args->in.domains & ~AMDGPU_GEM_DOMAIN_MASK)
>  		return -EINVAL;
>  
> +	/* check priority */
> +	if (args->in.priority == 0) {

Did you verify that this is 0 with old userspace compiled against struct
drm_amdgpu_gem_create_in without the priority field?


> +		/* default is normal */
> +		args->in.priority = TTM_BO_PRIORITY_NORMAL;
> +	} else if (args->in.priority > TTM_MAX_BO_PRIORITY) {
> +		args->in.priority = TTM_MAX_BO_PRIORITY;
> +		DRM_ERROR("priority specified from user space is over MAX priority\n");

This must be DRM_DEBUG, or buggy/malicious userspace can spam dmesg.


> @@ -252,6 +262,7 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
>  
>  	r = amdgpu_gem_object_create(adev, size, args->in.alignment,
>  				     (u32)(0xffffffff & args->in.domains),
> +				     args->in.priority - 1,
>  				     flags, ttm_bo_type_device, resv, &gobj);

It might be less confusing to subtract 1 after checking against
TTM_MAX_BO_PRIORITY instead of here. Still kind of confusing though. How
about this instead:

Make the priority field of struct drm_amdgpu_gem_create_in signed. In
amdgpu_gem_create_ioctl, clamp the priority to the supported range:

	args->in.priority += TTM_BO_PRIORITY_NORMAL;
	args->in.priority = max(args->in.priority, 0);
	args->in.priority = min(args->in.priority,
				TTM_BO_PRIORITY_NORMAL - 1);

This way userspace doesn't need to do a weird mapping of the priority
values (where 0 and 2 have the same meaning), and the range of supported
priorities could at least theoretically be extended without breaking
userspace.


> @@ -304,6 +315,7 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
>  
>  	/* create a gem object to contain this object in */
>  	r = amdgpu_gem_object_create(adev, args->size, 0, AMDGPU_GEM_DOMAIN_CPU,
> +				     TTM_BO_PRIORITY_NORMAL,
>  				     0, ttm_bo_type_device, NULL, &gobj);

Should the userptr ioctl also allow setting the priority?


> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index fd9c4beeaaa4..c85304e03021 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -494,8 +494,9 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
>  
>  	bo->tbo.bdev = &adev->mman.bdev;
>  	amdgpu_bo_placement_from_domain(bo, bp->domain);
> +	bo->tbo.priority = bp->priority;
>  	if (bp->type == ttm_bo_type_kernel)
> -		bo->tbo.priority = 1;
> +		bo->tbo.priority = TTM_BO_PRIORITY_VERYHIGH;

	if (bp->type == ttm_bo_type_kernel)
		bo->tbo.priority = TTM_BO_PRIORITY_VERYHIGH;
	else
		bo->tbo.priority = bp->priority;

would be clearer I think.


-- 
Earthling Michel Dänzer               |              https://www.amd.com
Libre software enthusiast             |             Mesa and X developer


More information about the amd-gfx mailing list