drm/amdkfd: sparse: Fix warning in reading SDMA counters
Subsystems (3)
PATCH v2 1/1 drm/amdkfd: sparse: Fix warning in reading SDMA counters
Add __user annotation to fix related sparse warning while reading SDMA counters from userland.
--- drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +3 -6
@@ -157,19 +157,16 @@ int read_sdma_queue_counter(uint64_t q_rptr, uint64_t *val) {int ret;uint64_t tmp =0 ; +uint64_t __user *sdma_usage_cntr;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 ; - } + sdma_usage_cntr = (uint64_t __user *)q_rptr +1 ; - ret =get_user (tmp, (uint64_t *)(q_rptr +sizeof (uint64_t ))); + ret =get_user (tmp, sdma_usage_cntr);if (!ret) { *val = tmp; }
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Felix Kuehling
maintainerSorry, more bike-shedding.
Am 2020-08-17 um 7:58 p.m. schrieb Mukul Joshi:
Quoted 14 lines
Add
__userannotation to fix related sparse warning while reading SDMA counters from userland.Reported-by kernel test robot <[email protected]>Signed-off-by Mukul Joshi <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +0
-0
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c int read_sdma_queue_counter(uint64_t q_rptr, uint64_t *val) · line 163
Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1
-0@@ -157,19 +157,16 @@ int read_sdma_queue_counter(uint64_t q_rptr, uint64_t *val) {int ret;uint64_t tmp =0 ; +uint64_t __user *sdma_usage_cntr;if (!val)return -EINVAL ;
Maybe this check isn't needed. Both callers pass in pointers to local variables. If a caller gets that wrong, how likely are they going to handle the error code correctly?
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c int read_sdma_queue_counter(uint64_t q_rptr, uint64_t *val) · line 169
Quoted 12 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +2
-6/* * 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 ; - } + sdma_usage_cntr = (uint64_t __user *)q_rptr +1 ; - ret =get_user (tmp, (uint64_t *)(q_rptr +sizeof (uint64_t ))); + ret =get_user (tmp, sdma_usage_cntr);
Maybe you don't need sdma_usage_cntr. Just inline the pointer arithmetic. And I'm not sure why you need tmp either. Is it in case the read gets only one dword and fails on the second one? The callers will ignore the value, if you return an error, so I don't think it matters. So this whole function would become very simple:
return get_user(*val, (uint64_t __user *)q_rptr + 1);
Now it could probably be a static inline function in a kfd_device_queue_manager.h.
If that is the only use of q_rptr in the function, why not make the parameter type uint64_t __user *, so you don't even need the type cast in here? You can also change the type in struct temp_sdma_queue_list to match.
While you're at it, you could also change the types of read_ptr and write_ptr in struct queue_properties, because uint32_t * is really not the correct type. It's a pointer to the wrong size and the wrong address space. Though that change may have a few more ripple effects.
Regards,
Felix
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c int read_sdma_queue_counter(uint64_t q_rptr, uint64_t *val) · line 172
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +0
-0if (!ret) { *val = tmp; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx