Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/v3d: Size the kperfmon_ids array at runtime

Instead of statically reserving pessimistic space for the kperfmon_ids
array, make the userspace extension code allocate the exactly required
amount of space.

Apart from saving some memory at runtime, this also removes the need for
the V3D_MAX_PERFMONS macro whose removal will benefit further driver
cleanup.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Reviewed-by: Maíra Canal <mcanal@igalia.com>
Signed-off-by: Maíra Canal <mcanal@igalia.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240711135340.84617-8-tursulin@igalia.com

authored by

Tvrtko Ursulin and committed by
Maíra Canal
c9d6630f 4bd75a81

+15 -12
+1 -5
drivers/gpu/drm/v3d/v3d_drv.h
··· 351 351 struct drm_syncobj *syncobj; 352 352 }; 353 353 354 - /* Number of perfmons required to handle all supported performance counters */ 355 - #define V3D_MAX_PERFMONS DIV_ROUND_UP(V3D_MAX_COUNTERS, \ 356 - DRM_V3D_MAX_PERF_COUNTERS) 357 - 358 354 struct v3d_performance_query { 359 355 /* Performance monitor IDs for this query */ 360 - u32 kperfmon_ids[V3D_MAX_PERFMONS]; 356 + u32 *kperfmon_ids; 361 357 362 358 /* Syncobj that indicates the query availability */ 363 359 struct drm_syncobj *syncobj;
+3 -1
drivers/gpu/drm/v3d/v3d_sched.c
··· 94 94 if (query_info->queries) { 95 95 unsigned int i; 96 96 97 - for (i = 0; i < count; i++) 97 + for (i = 0; i < count; i++) { 98 98 drm_syncobj_put(query_info->queries[i].syncobj); 99 + kvfree(query_info->queries[i].kperfmon_ids); 100 + } 99 101 100 102 kvfree(query_info->queries); 101 103 }
+11 -6
drivers/gpu/drm/v3d/v3d_submit.c
··· 671 671 goto error; 672 672 } 673 673 674 + query->kperfmon_ids = 675 + kvmalloc_array(nperfmons, 676 + sizeof(struct v3d_performance_query *), 677 + GFP_KERNEL); 678 + if (!query->kperfmon_ids) { 679 + err = -ENOMEM; 680 + goto error; 681 + } 682 + 674 683 ids_pointer = u64_to_user_ptr(ids); 675 684 676 685 for (j = 0; j < nperfmons; j++) { 677 686 if (get_user(id, ids_pointer++)) { 687 + kvfree(query->kperfmon_ids); 678 688 err = -EFAULT; 679 689 goto error; 680 690 } ··· 694 684 695 685 query->syncobj = drm_syncobj_find(file_priv, sync); 696 686 if (!query->syncobj) { 687 + kvfree(query->kperfmon_ids); 697 688 err = -ENOENT; 698 689 goto error; 699 690 } ··· 727 716 728 717 if (copy_from_user(&reset, ext, sizeof(reset))) 729 718 return -EFAULT; 730 - 731 - if (reset.nperfmons > V3D_MAX_PERFMONS) 732 - return -EINVAL; 733 719 734 720 job->job_type = V3D_CPU_JOB_TYPE_RESET_PERFORMANCE_QUERY; 735 721 ··· 773 765 return -EFAULT; 774 766 775 767 if (copy.pad) 776 - return -EINVAL; 777 - 778 - if (copy.nperfmons > V3D_MAX_PERFMONS) 779 768 return -EINVAL; 780 769 781 770 job->job_type = V3D_CPU_JOB_TYPE_COPY_PERFORMANCE_QUERY;