[PATCH v3] drm/amdkfd: sparse: Fix warning in reading SDMA counters

Felix Kuehling felix.kuehling at amd.com
Tue Aug 18 18:35:17 UTC 2020


Am 2020-08-18 um 12:08 p.m. schrieb Mukul Joshi:
> Add __user annotation to fix related sparse warning while reading
> SDMA counters from userland.
> Also, rework the read SDMA counters function by removing redundant
> checks.
>
> Reported-by: kernel test robot <lkp at intel.com>
> Signed-off-by: Mukul Joshi <mukul.joshi at amd.com>

Reviewed-by: Felix Kuehling <Felix.Kuehling at amd.com>


> ---
>  .../drm/amd/amdkfd/kfd_device_queue_manager.c | 28 ++-----------------
>  .../drm/amd/amdkfd/kfd_device_queue_manager.h |  8 +++++-
>  drivers/gpu/drm/amd/amdkfd/kfd_process.c      |  6 ++--
>  3 files changed, 12 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
> index e0e60b0d0669..560adc57a050 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
> @@ -153,30 +153,6 @@ static void decrement_queue_count(struct device_queue_manager *dqm,
>  		dqm->active_cp_queue_count--;
>  }
>  
> -int read_sdma_queue_counter(uint64_t q_rptr, uint64_t *val)
> -{
> -	int ret;
> -	uint64_t tmp = 0;
> -
> -	if (!val)
> -		return -EINVAL;
> -	/*
> -	 * SDMA activity counter is stored at queue's RPTR + 0x8 location.
> -	 */
> -	if (!access_ok((const void __user *)(q_rptr +
> -					sizeof(uint64_t)), sizeof(uint64_t))) {
> -		pr_err("Can't access sdma queue activity counter\n");
> -		return -EFAULT;
> -	}
> -
> -	ret = get_user(tmp, (uint64_t *)(q_rptr + sizeof(uint64_t)));
> -	if (!ret) {
> -		*val = tmp;
> -	}
> -
> -	return ret;
> -}
> -
>  static int allocate_doorbell(struct qcm_process_device *qpd, struct queue *q)
>  {
>  	struct kfd_dev *dev = qpd->dqm->dev;
> @@ -552,7 +528,7 @@ static int destroy_queue_nocpsch(struct device_queue_manager *dqm,
>  	/* Get the SDMA queue stats */
>  	if ((q->properties.type == KFD_QUEUE_TYPE_SDMA) ||
>  	    (q->properties.type == KFD_QUEUE_TYPE_SDMA_XGMI)) {
> -		retval = read_sdma_queue_counter((uint64_t)q->properties.read_ptr,
> +		retval = read_sdma_queue_counter((uint64_t __user *)q->properties.read_ptr,
>  							&sdma_val);
>  		if (retval)
>  			pr_err("Failed to read SDMA queue counter for queue: %d\n",
> @@ -1473,7 +1449,7 @@ static int destroy_queue_cpsch(struct device_queue_manager *dqm,
>  	/* Get the SDMA queue stats */
>  	if ((q->properties.type == KFD_QUEUE_TYPE_SDMA) ||
>  	    (q->properties.type == KFD_QUEUE_TYPE_SDMA_XGMI)) {
> -		retval = read_sdma_queue_counter((uint64_t)q->properties.read_ptr,
> +		retval = read_sdma_queue_counter((uint64_t __user *)q->properties.read_ptr,
>  							&sdma_val);
>  		if (retval)
>  			pr_err("Failed to read SDMA queue counter for queue: %d\n",
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h
> index 49d8e324c636..16262e5d93f5 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h
> @@ -251,5 +251,11 @@ static inline void dqm_unlock(struct device_queue_manager *dqm)
>  	mutex_unlock(&dqm->lock_hidden);
>  }
>  
> -int read_sdma_queue_counter(uint64_t q_rptr, uint64_t *val);
> +static inline int read_sdma_queue_counter(uint64_t __user *q_rptr, uint64_t *val)
> +{
> +        /*
> +         * SDMA activity counter is stored at queue's RPTR + 0x8 location.
> +         */
> +	return get_user(*val, q_rptr + 1);
> +}
>  #endif /* KFD_DEVICE_QUEUE_MANAGER_H_ */
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> index 4480f905814c..ff7686250ae0 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> @@ -87,7 +87,7 @@ struct kfd_sdma_activity_handler_workarea {
>  };
>  
>  struct temp_sdma_queue_list {
> -	uint64_t rptr;
> +	uint64_t __user *rptr;
>  	uint64_t sdma_val;
>  	unsigned int queue_id;
>  	struct list_head list;
> @@ -159,7 +159,7 @@ static void kfd_sdma_activity_worker(struct work_struct *work)
>  		}
>  
>  		INIT_LIST_HEAD(&sdma_q->list);
> -		sdma_q->rptr = (uint64_t)q->properties.read_ptr;
> +		sdma_q->rptr = (uint64_t __user *)q->properties.read_ptr;
>  		sdma_q->queue_id = q->properties.queue_id;
>  		list_add_tail(&sdma_q->list, &sdma_q_list.list);
>  	}
> @@ -218,7 +218,7 @@ static void kfd_sdma_activity_worker(struct work_struct *work)
>  			continue;
>  
>  		list_for_each_entry_safe(sdma_q, next, &sdma_q_list.list, list) {
> -			if (((uint64_t)q->properties.read_ptr == sdma_q->rptr) &&
> +			if (((uint64_t __user *)q->properties.read_ptr == sdma_q->rptr) &&
>  			     (sdma_q->queue_id == q->properties.queue_id)) {
>  				list_del(&sdma_q->list);
>  				kfree(sdma_q);


More information about the amd-gfx mailing list