drm/amdkfd: sparse: Fix warning in reading SDMA counters

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@intel.com>
Signed-off-by: Mukul Joshi <mukul.joshi@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
Mukul Joshi 2020-08-18 14:51:41 -04:00 committed by Alex Deucher
parent 37d0474542
commit 818b032433
3 changed files with 12 additions and 30 deletions

View File

@ -153,30 +153,6 @@ static void decrement_queue_count(struct device_queue_manager *dqm,
dqm->active_cp_queue_count--; 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) static int allocate_doorbell(struct qcm_process_device *qpd, struct queue *q)
{ {
struct kfd_dev *dev = qpd->dqm->dev; 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 */ /* Get the SDMA queue stats */
if ((q->properties.type == KFD_QUEUE_TYPE_SDMA) || if ((q->properties.type == KFD_QUEUE_TYPE_SDMA) ||
(q->properties.type == KFD_QUEUE_TYPE_SDMA_XGMI)) { (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); &sdma_val);
if (retval) if (retval)
pr_err("Failed to read SDMA queue counter for queue: %d\n", 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 */ /* Get the SDMA queue stats */
if ((q->properties.type == KFD_QUEUE_TYPE_SDMA) || if ((q->properties.type == KFD_QUEUE_TYPE_SDMA) ||
(q->properties.type == KFD_QUEUE_TYPE_SDMA_XGMI)) { (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); &sdma_val);
if (retval) if (retval)
pr_err("Failed to read SDMA queue counter for queue: %d\n", pr_err("Failed to read SDMA queue counter for queue: %d\n",

View File

@ -251,5 +251,11 @@ static inline void dqm_unlock(struct device_queue_manager *dqm)
mutex_unlock(&dqm->lock_hidden); 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_ */ #endif /* KFD_DEVICE_QUEUE_MANAGER_H_ */

View File

@ -87,7 +87,7 @@ struct kfd_sdma_activity_handler_workarea {
}; };
struct temp_sdma_queue_list { struct temp_sdma_queue_list {
uint64_t rptr; uint64_t __user *rptr;
uint64_t sdma_val; uint64_t sdma_val;
unsigned int queue_id; unsigned int queue_id;
struct list_head list; struct list_head list;
@ -159,7 +159,7 @@ static void kfd_sdma_activity_worker(struct work_struct *work)
} }
INIT_LIST_HEAD(&sdma_q->list); 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; sdma_q->queue_id = q->properties.queue_id;
list_add_tail(&sdma_q->list, &sdma_q_list.list); 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; continue;
list_for_each_entry_safe(sdma_q, next, &sdma_q_list.list, list) { 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)) { (sdma_q->queue_id == q->properties.queue_id)) {
list_del(&sdma_q->list); list_del(&sdma_q->list);
kfree(sdma_q); kfree(sdma_q);