v3d: Perfmon cleanup
Subsystems (4)
v3 cover v3d: Perfmon cleanup
From: Tvrtko Ursulin <[email protected]>
When we had to quickly deal with a tree build issue via merging 792d16b5375d ("drm/v3d: Move perfmon init completely into own unit"), we promised to follow up with a nicer solution.
As in the process of eliminating the hardcoded defines we have discovered a few issues in handling of corner cases and userspace input validation, the fix has turned into a larger series, but hopefully the end result is a justifiable cleanup.
v2:
* Re-order the patches so fixes come first while last three are optional cleanups.
v3:
* Fixed a bunch of rebase errors I made when re-ordering patches from v1 to v2.
* Dropped the double underscore from __v3d_timestamp_query_info_free.
* Added v3d prefix to v3d_copy_query_info.
* Renamed qinfo to query_info.
* Fixed some spelling errors and bad patch references.
* Added mention to get_user to one commit message.
* Dropped one patch from the series which became redundant due other re-ordering.
* Re-ordered last two patches with the view of dropping the last.
Tvrtko Ursulin (11):
drm/v3d: Prevent out of bounds access in performance query extensions drm/v3d: Fix potential memory leak in the timestamp extension drm/v3d: Fix potential memory leak in the performance extension drm/v3d: Validate passed in drm syncobj handles in the timestamp
extension
drm/v3d: Validate passed in drm syncobj handles in the performance
extension
drm/v3d: Move part of copying of reset/copy performance extension to a
helper
drm/v3d: Size the kperfmon_ids array at runtime
drm/v3d: Do not use intermediate storage when copying performance
query results
drm/v3d: Move perfmon init completely into own unit drm/v3d: Prefer get_user for scalar types
drm/v3d: Add some local variables in queries/extensions
drivers/gpu/drm/v3d/v3d_drv.c | 9 +- drivers/gpu/drm/v3d/v3d_drv.h | 16 +- drivers/gpu/drm/v3d/v3d_perfmon.c | 44 +-- .../gpu/drm/v3d/v3d_performance_counters.h | 16 +- drivers/gpu/drm/v3d/v3d_sched.c | 106 ++++--- drivers/gpu/drm/v3d/v3d_submit.c | 294 +++++++++++------- 6 files changed, 290 insertions(+), 195 deletions(-)
Signature · 1 line
2.44.0
PATCH v3 1/11 drm/v3d: Prevent out of bounds access in performance query extensions
From: Tvrtko Ursulin <[email protected]>
Check that the number of perfmons userspace is passing in the copy and reset extensions is not greater than the internal kernel storage where the ids will be copied into.
--- drivers/gpu/drm/v3d/v3d_submit.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/v3d/v3d_submit.c +6 -0
@@ -637,6 +637,9 @@ v3d_get_cpu_reset_performance_params(struct drm_file *file_priv,if (copy_from_user (&reset, ext,sizeof (reset)))return -EFAULT ; +if (reset.nperfmons >V3D_MAX_PERFMONS ) +return -EINVAL ; + job->job_type =V3D_CPU_JOB_TYPE_RESET_PERFORMANCE_QUERY ; job->performance_query.queries = kvmalloc_array(reset.count,
@@ -708,6 +711,9 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv,if (copy.pad)return -EINVAL ; +if (copy.nperfmons >V3D_MAX_PERFMONS ) +return -EINVAL ; + job->job_type =V3D_CPU_JOB_TYPE_COPY_PERFORMANCE_QUERY ; job->performance_query.queries = kvmalloc_array(copy.count,
Signature · 1 line
2.44.0
PATCH v3 2/11 drm/v3d: Fix potential memory leak in the timestamp extension
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
If fetching of userspace memory fails during the main loop, all drm sync objs looked up until that point will be leaked because of the missing drm_syncobj_put.
Fix it by exporting and using a common cleanup helper.
--- drivers/gpu/drm/v3d/v3d_drv.h | 2 ++ drivers/gpu/drm/v3d/v3d_sched.c | 22 +++++++++++----- drivers/gpu/drm/v3d/v3d_submit.c | 43 ++++++++++++++++++++++---------- 3 files changed, 48 insertions(+), 19 deletions(-)
drivers/gpu/drm/v3d/v3d_drv.h +2 -0
@@ -563,6 +563,8 @@ void v3d_mmu_insert_ptes(struct v3d_bo *bo);void v3d_mmu_remove_ptes (struct v3d_bo *bo);/* v3d_sched.c */ +void v3d_timestamp_query_info_free (struct v3d_timestamp_query_info *query_info, +unsigned int count);void v3d_job_update_stats (struct v3d_job *job,enum v3d_queue queue);int v3d_sched_init (struct v3d_dev *v3d);void v3d_sched_fini (struct v3d_dev *v3d);
drivers/gpu/drm/v3d/v3d_sched.c +16 -6
@@ -73,18 +73,28 @@ v3d_sched_job_free(struct drm_sched_job *sched_job)v3d_job_cleanup (job); } +void +v3d_timestamp_query_info_free (struct v3d_timestamp_query_info *query_info, +unsigned int count) +{ +if (query_info->queries) { +unsigned int i; + +for (i =0 ; i < count; i++) +drm_syncobj_put (query_info->queries[i].syncobj); + +kvfree (query_info->queries); + } +} +static void v3d_cpu_job_free (struct drm_sched_job *sched_job) {struct v3d_cpu_job *job =to_cpu_job (sched_job); -struct v3d_timestamp_query_info *timestamp_query = &job->timestamp_query;struct v3d_performance_query_info *performance_query = &job->performance_query; -if (timestamp_query->queries) { -for (int i =0 ; i < timestamp_query->count; i++) -drm_syncobj_put (timestamp_query->queries[i].syncobj); -kvfree (timestamp_query->queries); - } +v3d_timestamp_query_info_free (&job->timestamp_query, + job->timestamp_query.count);if (performance_query->queries) {for (int i =0 ; i < performance_query->count; i++)
drivers/gpu/drm/v3d/v3d_submit.c +30 -13
115 lines not on this page · raw message
Signature · 1 line
2.44.0
Re: [PATCH 02/11] drm/v3d: Fix potential memory leak in the timestamp extension
Quoted 9 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
If fetching of userspace memory fails during the main loop, all drm sync objs looked up until that point will be leaked because of the missing
drm_syncobj_put.Fix it by exporting and using a common cleanup helper.
Signed-off-by Tvrtko Ursulin <[email protected]>
Best Regards,
- Maíra
Quoted 190 lines
Fixes 9ba0ff3e083f ("drm/v3d: Create a CPU job extension for the timestamp query job")Cc Maíra Canal <[email protected]>Cc Iago Toral Quiroga <[email protected]>Cc <[email protected]> # v6.8+--- drivers/gpu/drm/v3d/v3d_drv.h | 2 ++ drivers/gpu/drm/v3d/v3d_sched.c | 22 +++++++++++----- drivers/gpu/drm/v3d/v3d_submit.c | 43 ++++++++++++++++++++++---------- 3 files changed, 48 insertions(+), 19 deletions(-)drivers/gpu/drm/v3d/v3d_drv.h +2
-0@@ -563,6 +563,8 @@ void v3d_mmu_insert_ptes(struct v3d_bo *bo);void v3d_mmu_remove_ptes (struct v3d_bo *bo);/* v3d_sched.c */ +void v3d_timestamp_query_info_free (struct v3d_timestamp_query_info *query_info, +unsigned int count);void v3d_job_update_stats (struct v3d_job *job,enum v3d_queue queue);int v3d_sched_init (struct v3d_dev *v3d);void v3d_sched_fini (struct v3d_dev *v3d);drivers/gpu/drm/v3d/v3d_sched.c +16
-6@@ -73,18 +73,28 @@ v3d_sched_job_free(struct drm_sched_job *sched_job)v3d_job_cleanup (job); } +void +v3d_timestamp_query_info_free (struct v3d_timestamp_query_info *query_info, +unsigned int count) +{ +if (query_info->queries) { +unsigned int i; + +for (i =0 ; i < count; i++) +drm_syncobj_put (query_info->queries[i].syncobj); + +kvfree (query_info->queries); + } +} +static void v3d_cpu_job_free (struct drm_sched_job *sched_job) {struct v3d_cpu_job *job =to_cpu_job (sched_job); -struct v3d_timestamp_query_info *timestamp_query = &job->timestamp_query;struct v3d_performance_query_info *performance_query = &job->performance_query; -if (timestamp_query->queries) { -for (int i =0 ; i < timestamp_query->count; i++) -drm_syncobj_put (timestamp_query->queries[i].syncobj); -kvfree (timestamp_query->queries); - } +v3d_timestamp_query_info_free (&job->timestamp_query, + job->timestamp_query.count);if (performance_query->queries) {for (int i =0 ; i < performance_query->count; i++)drivers/gpu/drm/v3d/v3d_submit.c +30
-13@@ -452,6 +452,8 @@ v3d_get_cpu_timestamp_query_params(struct drm_file *file_priv, {u32 __user *offsets, *syncs;struct drm_v3d_timestamp_query timestamp; +unsigned int i; +int err;if (!job) {DRM_DEBUG ("CPU job extension was attached to a GPU job.\n" );@@ -480,19 +482,19 @@ v3d_get_cpu_timestamp_query_params(struct drm_file *file_priv, offsets =u64_to_user_ptr (timestamp.offsets); syncs =u64_to_user_ptr (timestamp.syncs); -for (int i =0 ; i < timestamp.count; i++) { +for (i =0 ; i < timestamp.count; i++) {u32 offset, sync;if (copy_from_user (&offset, offsets++,sizeof (offset))) { -kvfree (job->timestamp_query.queries); -return -EFAULT ; + err = -EFAULT ; + goto error; } job->timestamp_query.queries[i].offset = offset;if (copy_from_user (&sync, syncs++,sizeof (sync))) { -kvfree (job->timestamp_query.queries); -return -EFAULT ; + err = -EFAULT ; + goto error; } job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync);@@ -500,6 +502,10 @@ v3d_get_cpu_timestamp_query_params(struct drm_file *file_priv, job->timestamp_query.count = timestamp.count;return 0 ; + +error: +v3d_timestamp_query_info_free (&job->timestamp_query, i); +return err; } static int@@ -509,6 +515,8 @@ v3d_get_cpu_reset_timestamp_params(struct drm_file *file_priv, {u32 __user *syncs;struct drm_v3d_reset_timestamp_query reset; +unsigned int i; +int err;if (!job) {DRM_DEBUG ("CPU job extension was attached to a GPU job.\n" );@@ -533,14 +541,14 @@ v3d_get_cpu_reset_timestamp_params(struct drm_file *file_priv, syncs =u64_to_user_ptr (reset.syncs); -for (int i =0 ; i < reset.count; i++) { +for (i =0 ; i < reset.count; i++) {u32 sync; job->timestamp_query.queries[i].offset = reset.offset +8 * i;if (copy_from_user (&sync, syncs++,sizeof (sync))) { -kvfree (job->timestamp_query.queries); -return -EFAULT ; + err = -EFAULT ; + goto error; } job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync);@@ -548,6 +556,10 @@ v3d_get_cpu_reset_timestamp_params(struct drm_file *file_priv, job->timestamp_query.count = reset.count;return 0 ; + +error: +v3d_timestamp_query_info_free (&job->timestamp_query, i); +return err; }/* Get data for the copy timestamp query results job submission. */ @@ -558,7 +570,8 @@ v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv, {u32 __user *offsets, *syncs;struct drm_v3d_copy_timestamp_query copy; -int i; +unsigned int i; +int err;if (!job) {DRM_DEBUG ("CPU job extension was attached to a GPU job.\n" );@@ -591,15 +604,15 @@ v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv,u32 offset, sync;if (copy_from_user (&offset, offsets++,sizeof (offset))) { -kvfree (job->timestamp_query.queries); -return -EFAULT ; + err = -EFAULT ; + goto error; } job->timestamp_query.queries[i].offset = offset;if (copy_from_user (&sync, syncs++,sizeof (sync))) { -kvfree (job->timestamp_query.queries); -return -EFAULT ; + err = -EFAULT ; + goto error; } job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync);@@ -613,6 +626,10 @@ v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv, job->copy.stride = copy.stride;return 0 ; + +error: +v3d_timestamp_query_info_free (&job->timestamp_query, i); +return err; } static int
PATCH v3 3/11 drm/v3d: Fix potential memory leak in the performance extension
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
If fetching of userspace memory fails during the main loop, all drm sync objs looked up until that point will be leaked because of the missing drm_syncobj_put.
Fix it by exporting and using a common cleanup helper.
--- drivers/gpu/drm/v3d/v3d_drv.h | 2 ++ drivers/gpu/drm/v3d/v3d_sched.c | 22 ++++++++++---- drivers/gpu/drm/v3d/v3d_submit.c | 50 ++++++++++++++++++++------------ 3 files changed, 49 insertions(+), 25 deletions(-)
drivers/gpu/drm/v3d/v3d_drv.h +2 -0
@@ -565,6 +565,8 @@ void v3d_mmu_remove_ptes(struct v3d_bo *bo);/* v3d_sched.c */ void v3d_timestamp_query_info_free (struct v3d_timestamp_query_info *query_info,unsigned int count); +void v3d_performance_query_info_free (struct v3d_performance_query_info *query_info, +unsigned int count);void v3d_job_update_stats (struct v3d_job *job,enum v3d_queue queue);int v3d_sched_init (struct v3d_dev *v3d);void v3d_sched_fini (struct v3d_dev *v3d);
drivers/gpu/drm/v3d/v3d_sched.c +16 -6
@@ -87,20 +87,30 @@ v3d_timestamp_query_info_free(struct v3d_timestamp_query_info *query_info, } } +void +v3d_performance_query_info_free (struct v3d_performance_query_info *query_info, +unsigned int count) +{ +if (query_info->queries) { +unsigned int i; + +for (i =0 ; i < count; i++) +drm_syncobj_put (query_info->queries[i].syncobj); + +kvfree (query_info->queries); + } +} +static void v3d_cpu_job_free (struct drm_sched_job *sched_job) {struct v3d_cpu_job *job =to_cpu_job (sched_job); -struct v3d_performance_query_info *performance_query = &job->performance_query;v3d_timestamp_query_info_free (&job->timestamp_query, job->timestamp_query.count); -if (performance_query->queries) { -for (int i =0 ; i < performance_query->count; i++) -drm_syncobj_put (performance_query->queries[i].syncobj); -kvfree (performance_query->queries); - } +v3d_performance_query_info_free (&job->performance_query, + job->performance_query.count);v3d_job_cleanup (&job->base); }
drivers/gpu/drm/v3d/v3d_submit.c +31 -19
115 lines not on this page · raw message
Signature · 1 line
2.44.0
Maíra Canal
maintainerRe: [PATCH 03/11] drm/v3d: Fix potential memory leak in the performance extension
Quoted 187 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
If fetching of userspace memory fails during the main loop, all drm sync objs looked up until that point will be leaked because of the missing
drm_syncobj_put.Fix it by exporting and using a common cleanup helper.
Signed-off-by Tvrtko Ursulin <[email protected]>Fixes bae7cb5d6800 ("drm/v3d: Create a CPU job extension for the reset performance query job")Cc Maíra Canal <[email protected]>Cc Iago Toral Quiroga <[email protected]>Cc <[email protected]> # v6.8+--- drivers/gpu/drm/v3d/v3d_drv.h | 2 ++ drivers/gpu/drm/v3d/v3d_sched.c | 22 ++++++++++---- drivers/gpu/drm/v3d/v3d_submit.c | 50 ++++++++++++++++++++------------ 3 files changed, 49 insertions(+), 25 deletions(-)drivers/gpu/drm/v3d/v3d_drv.h +2
-0@@ -565,6 +565,8 @@ void v3d_mmu_remove_ptes(struct v3d_bo *bo);/* v3d_sched.c */ void v3d_timestamp_query_info_free (struct v3d_timestamp_query_info *query_info,unsigned int count); +void v3d_performance_query_info_free (struct v3d_performance_query_info *query_info, +unsigned int count);void v3d_job_update_stats (struct v3d_job *job,enum v3d_queue queue);int v3d_sched_init (struct v3d_dev *v3d);void v3d_sched_fini (struct v3d_dev *v3d);drivers/gpu/drm/v3d/v3d_sched.c +16
-6@@ -87,20 +87,30 @@ v3d_timestamp_query_info_free(struct v3d_timestamp_query_info *query_info, } } +void +v3d_performance_query_info_free (struct v3d_performance_query_info *query_info, +unsigned int count) +{ +if (query_info->queries) { +unsigned int i; + +for (i =0 ; i < count; i++) +drm_syncobj_put (query_info->queries[i].syncobj); + +kvfree (query_info->queries); + } +} +static void v3d_cpu_job_free (struct drm_sched_job *sched_job) {struct v3d_cpu_job *job =to_cpu_job (sched_job); -struct v3d_performance_query_info *performance_query = &job->performance_query;v3d_timestamp_query_info_free (&job->timestamp_query, job->timestamp_query.count); -if (performance_query->queries) { -for (int i =0 ; i < performance_query->count; i++) -drm_syncobj_put (performance_query->queries[i].syncobj); -kvfree (performance_query->queries); - } +v3d_performance_query_info_free (&job->performance_query, + job->performance_query.count);v3d_job_cleanup (&job->base); }drivers/gpu/drm/v3d/v3d_submit.c +27
-19@@ -640,6 +640,8 @@ v3d_get_cpu_reset_performance_params(struct drm_file *file_priv,u32 __user *syncs;u64 __user *kperfmon_ids;struct drm_v3d_reset_performance_query reset; +unsigned int i, j; +int err;if (!job) {DRM_DEBUG ("CPU job extension was attached to a GPU job.\n" );@@ -668,39 +670,43 @@ v3d_get_cpu_reset_performance_params(struct drm_file *file_priv, syncs =u64_to_user_ptr (reset.syncs); kperfmon_ids =u64_to_user_ptr (reset.kperfmon_ids); -for (int i =0 ; i < reset.count; i++) { +for (i =0 ; i < reset.count; i++) {u32 sync;u64 ids;u32 __user *ids_pointer;u32 id;if (copy_from_user (&sync, syncs++,sizeof (sync))) { -kvfree (job->performance_query.queries); -return -EFAULT ; + err = -EFAULT ; + goto error; } - job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); -if (copy_from_user (&ids, kperfmon_ids++,sizeof (ids))) { -kvfree (job->performance_query.queries); -return -EFAULT ; + err = -EFAULT ; + goto error; } ids_pointer =u64_to_user_ptr (ids); -for (int j =0 ; j < reset.nperfmons; j++) { +for (j =0 ; j < reset.nperfmons; j++) {if (copy_from_user (&id, ids_pointer++,sizeof (id))) { -kvfree (job->performance_query.queries); -return -EFAULT ; + err = -EFAULT ; + goto error; } job->performance_query.queries[i].kperfmon_ids[j] = id; } + + job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); } job->performance_query.count = reset.count; job->performance_query.nperfmons = reset.nperfmons;return 0 ; + +error: +v3d_performance_query_info_free (&job->performance_query, i); +return err; } static int@@ -711,6 +717,8 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv,u32 __user *syncs;u64 __user *kperfmon_ids;struct drm_v3d_copy_performance_query copy; +unsigned int i, j; +int err;if (!job) {DRM_DEBUG ("CPU job extension was attached to a GPU job.\n" );@@ -749,27 +757,27 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv,u32 id;if (copy_from_user (&sync, syncs++,sizeof (sync))) { -kvfree (job->performance_query.queries); -return -EFAULT ; + err = -EFAULT ; + goto error; } - job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); -if (copy_from_user (&ids, kperfmon_ids++,sizeof (ids))) { -kvfree (job->performance_query.queries); -return -EFAULT ; + err = -EFAULT ; + goto error; } ids_pointer =u64_to_user_ptr (ids); -for (int j =0 ; j < copy.nperfmons; j++) { +for (j =0 ; j < copy.nperfmons; j++) {if (copy_from_user (&id, ids_pointer++,sizeof (id))) { -kvfree (job->performance_query.queries); -return -EFAULT ; + err = -EFAULT ; + goto error; } job->performance_query.queries[i].kperfmon_ids[j] = id; } + + job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); } job->performance_query.count = copy.count; job->performance_query.nperfmons = copy.nperfmons;
drivers/gpu/drm/v3d/v3d_submit.c v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv, · line 795
Quoted 6 lines
drivers/gpu/drm/v3d/v3d_submit.c +3
-0@@ -782,6 +790,10 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv, job->copy.stride = copy.stride;return 0 ; + +error: +v3d_performance_query_info_free (&job->performance_query, i);
I'm seeing this compiling warning from this patch:
drivers/gpu/drm/v3d/v3d_submit.c:860:59: warning: variable 'i' is uninitialized when used here [-Wuninitialized]
860 |v3d_performance_query_info_free(&job->performance_query, i);
| ^drivers/gpu/drm/v3d/v3d_submit.c:781:16: note: initialize the variable 'i' to silence this warning
781 | unsigned int i, j;
| ^
| = 01 warning generated.
I believe that we are currently defining int i twice.
Best Regards,
- Maíra
Quoted 4 lines
drivers/gpu/drm/v3d/v3d_submit.c +1
-0+return err; }/* Whenever userspace sets ioctl extensions, v3d_get_extensions parses data
Re: [PATCH 03/11] drm/v3d: Fix potential memory leak in the performance extension
Quoted 199 lines · Maíra Canal
Quoted 180 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
If fetching of userspace memory fails during the main loop, all drm sync objs looked up until that point will be leaked because of the missing
drm_syncobj_put.Fix it by exporting and using a common cleanup helper.
Signed-off-by Tvrtko Ursulin <[email protected]>Fixes bae7cb5d6800 ("drm/v3d: Create a CPU job extension for the reset performance query job")Cc Maíra Canal <[email protected]>Cc Iago Toral Quiroga <[email protected]>Cc <[email protected]> # v6.8+---
drivers/gpu/drm/v3d/v3d_drv.h | 2 ++ drivers/gpu/drm/v3d/v3d_sched.c | 22 ++++++++++----drivers/gpu/drm/v3d/v3d_submit.c| 50 ++++++++++++++++++++------------3 files changed, 49 insertions(+), 25 deletions(-)drivers/gpu/drm/v3d/v3d_drv.h +2
-0@@ -565,6 +565,8 @@ void v3d_mmu_remove_ptes(struct v3d_bo *bo); /* v3d_sched.c */ void v3d_timestamp_query_info_free(struct v3d_timestamp_query_info *query_info, unsigned int count); +void v3d_performance_query_info_free (struct v3d_performance_query_info *query_info, + unsigned int count); void v3d_job_update_stats(struct v3d_job *job, enum v3d_queue queue); int v3d_sched_init(struct v3d_dev *v3d);void
v3d_sched_fini(struct v3d_dev *v3d);drivers/gpu/drm/v3d/v3d_sched.c +14
-0@@ -87,20 +87,30 @@ v3d_timestamp_query_info_free(structv3d_timestamp_query_info *query_info, } } +void +v3d_performance_query_info_free(struct v3d_performance_query_info *query_info, + unsigned int count) +{ + if (query_info->queries) { + unsigned int i; + + for (i = 0; i < count; i++) + drm_syncobj_put(query_info->queries[i].syncobj); + + kvfree(query_info->queries); + } +} +static void
v3d_cpu_job_free(struct drm_sched_job *sched_job)
{
structv3d_cpu_job*job =to_cpu_job(sched_job);
- structv3d_performance_query_info*performance_query=&job->performance_query;v3d_timestamp_query_info_free(&job->timestamp_query, job->timestamp_query.count);
- if (performance_query->queries) {
- for (int i = 0; i <performance_query->count; i++) -drm_syncobj_put(performance_query->queries[i].syncobj); -kvfree(performance_query->queries);
- }
+v3d_performance_query_info_free(&job->performance_query, + job->performance_query.count);v3d_job_cleanup(&job->base);
}drivers/gpu/drm/v3d/v3d_submit.c +16
-10@@ -640,6 +640,8 @@ v3d_get_cpu_reset_performance_params(structdrm_file *file_priv, u32 __user *syncs; u64 __user *kperfmon_ids; struct drm_v3d_reset_performance_query reset; + unsigned int i, j; + int err; if (!job) { DRM_DEBUG("CPU job extension was attached to a GPU job.\n");@@ -668,39 +670,43 @@ v3d_get_cpu_reset_performance_params(structdrm_file *file_priv, syncs = u64_to_user_ptr(reset.syncs); kperfmon_ids = u64_to_user_ptr(reset.kperfmon_ids); - for (int i = 0; i < reset.count; i++) { + for (i = 0; i < reset.count; i++) { u32 sync; u64 ids; u32 __user *ids_pointer; u32 id; if (copy_from_user(&sync, syncs++, sizeof(sync))) { - kvfree(job->performance_query.queries); - return -EFAULT; + err = -EFAULT; + goto error; } - job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); - if (copy_from_user(&ids, kperfmon_ids++, sizeof(ids))) { - kvfree(job->performance_query.queries); - return -EFAULT; + err = -EFAULT; + goto error; } ids_pointer = u64_to_user_ptr(ids); - for (int j = 0; j < reset.nperfmons; j++) { + for (j = 0; j < reset.nperfmons; j++) { if (copy_from_user(&id, ids_pointer++, sizeof(id))) { - kvfree(job->performance_query.queries); - return -EFAULT; + err = -EFAULT; + goto error; } job->performance_query.queries[i].kperfmon_ids[j] = id; } + + job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); } job->performance_query.count = reset.count; job->performance_query.nperfmons = reset.nperfmons; return 0; + +error: + v3d_performance_query_info_free(&job->performance_query, i); + return err; }static int
drivers/gpu/drm/v3d/v3d_submit.c +11
-9@@ -711,6 +717,8 @@ v3d_get_cpu_copy_performance_query_params(structdrm_file *file_priv, u32 __user *syncs; u64 __user *kperfmon_ids; struct drm_v3d_copy_performance_query copy; + unsigned int i, j; + int err; if (!job) { DRM_DEBUG("CPU job extension was attached to a GPU job.\n");@@ -749,27 +757,27 @@ v3d_get_cpu_copy_performance_query_params(structdrm_file *file_priv, u32 id; if (copy_from_user(&sync, syncs++, sizeof(sync))) { - kvfree(job->performance_query.queries); - return -EFAULT; + err = -EFAULT; + goto error; } - job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); - if (copy_from_user(&ids, kperfmon_ids++, sizeof(ids))) { - kvfree(job->performance_query.queries); - return -EFAULT; + err = -EFAULT; + goto error; } ids_pointer = u64_to_user_ptr(ids); - for (int j = 0; j < copy.nperfmons; j++) { + for (j = 0; j < copy.nperfmons; j++) { if (copy_from_user(&id, ids_pointer++, sizeof(id))) { - kvfree(job->performance_query.queries); - return -EFAULT; + err = -EFAULT; + goto error; } job->performance_query.queries[i].kperfmon_ids[j] = id; } + + job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); } job->performance_query.count = copy.count; job->performance_query.nperfmons = copy.nperfmons;drivers/gpu/drm/v3d/v3d_submit.c v3d_get_cpu_copy_performance_query_params(struct · line 795
Quoted 6 lines
drivers/gpu/drm/v3d/v3d_submit.c +3
-0@@ -782,6 +790,10 @@ v3d_get_cpu_copy_performance_query_params(structdrm_file *file_priv, job->copy.stride = copy.stride; return 0; + +error: + v3d_performance_query_info_free(&job->performance_query, i);I'm seeing this compiling warning from this patch:
drivers/gpu/drm/v3d/v3d_submit.c:860:59: warning: variable 'i' is uninitialized when used here [-Wuninitialized]
860 |v3d_performance_query_info_free(&job->performance_query, i);
| ^drivers/gpu/drm/v3d/v3d_submit.c:781:16: note: initialize the variable 'i' to silence this warning
781 | unsigned int i, j;
| ^
| = 0
1 warning generated.
Quoted 1 line
I believe that we are currently defining int i twice.
Yep.. more re-ordering/rebasing fails on my end. Fixed locally.
Regards,
Tvrtko
PATCH v3 4/11 drm/v3d: Validate passed in drm syncobj handles in the timestamp extension
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
If userspace provides an unknown or invalid handle anywhere in the handle array the rest of the driver will not handle that well.
Fix it by checking handle was looked up successfully or otherwise fail the extension by jumping into the existing unwind.
--- drivers/gpu/drm/v3d/v3d_submit.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/gpu/drm/v3d/v3d_submit.c +12 -0
@@ -498,6 +498,10 @@ v3d_get_cpu_timestamp_query_params(struct drm_file *file_priv, } job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); +if (!job->timestamp_query.queries[i].syncobj) { + err = -ENOENT ; + goto error; + } } job->timestamp_query.count = timestamp.count;
@@ -552,6 +556,10 @@ v3d_get_cpu_reset_timestamp_params(struct drm_file *file_priv, } job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); +if (!job->timestamp_query.queries[i].syncobj) { + err = -ENOENT ; + goto error; + } } job->timestamp_query.count = reset.count;
@@ -616,6 +624,10 @@ v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv, } job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); +if (!job->timestamp_query.queries[i].syncobj) { + err = -ENOENT ; + goto error; + } } job->timestamp_query.count = copy.count;
Signature · 1 line
2.44.0
Re: [PATCH 04/11] drm/v3d: Validate passed in drm syncobj handles in the timestamp extension
Quoted 7 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
If userspace provides an unknown or invalid handle anywhere in the handle array the rest of the driver will not handle that well.
Fix it by checking handle was looked up successfully or otherwise fail the extension by jumping into the existing unwind.
I'm not a English-native speaker, but again I need to say that it feels to me that it is something missing in this sentence.
I suggested "Fix it by checking if the handle..."
Quoted 2 lines
Signed-off-by Tvrtko Ursulin <[email protected]>
Best Regards,
- Maíra
Quoted 45 lines
Fixes 9ba0ff3e083f ("drm/v3d: Create a CPU job extension for the timestamp query job")Cc Maíra Canal <[email protected]>Cc Iago Toral Quiroga <[email protected]>Cc <[email protected]> # v6.8+--- drivers/gpu/drm/v3d/v3d_submit.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/gpu/drm/v3d/v3d_submit.c +12
-0@@ -498,6 +498,10 @@ v3d_get_cpu_timestamp_query_params(struct drm_file *file_priv, } job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); +if (!job->timestamp_query.queries[i].syncobj) { + err = -ENOENT ; + goto error; + } } job->timestamp_query.count = timestamp.count;@@ -552,6 +556,10 @@ v3d_get_cpu_reset_timestamp_params(struct drm_file *file_priv, } job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); +if (!job->timestamp_query.queries[i].syncobj) { + err = -ENOENT ; + goto error; + } } job->timestamp_query.count = reset.count;@@ -616,6 +624,10 @@ v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv, } job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); +if (!job->timestamp_query.queries[i].syncobj) { + err = -ENOENT ; + goto error; + } } job->timestamp_query.count = copy.count;
PATCH v3 5/11 drm/v3d: Validate passed in drm syncobj handles in the performance extension
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
If userspace provides an unknown or invalid handle anywhere in the handle array the rest of the driver will not handle that well.
Fix it by checking handle was looked up successfuly or otherwise fail the extension by jumping into the existing unwind.
--- drivers/gpu/drm/v3d/v3d_submit.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/v3d/v3d_submit.c +8 -0
@@ -710,6 +710,10 @@ v3d_get_cpu_reset_performance_params(struct drm_file *file_priv, } job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); +if (!job->performance_query.queries[i].syncobj) { + err = -ENOENT ; + goto error; + } } job->performance_query.count = reset.count; job->performance_query.nperfmons = reset.nperfmons;
@@ -790,6 +794,10 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv, } job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); +if (!job->performance_query.queries[i].syncobj) { + err = -ENOENT ; + goto error; + } } job->performance_query.count = copy.count; job->performance_query.nperfmons = copy.nperfmons;
Signature · 1 line
2.44.0
Re: [PATCH 05/11] drm/v3d: Validate passed in drm syncobj handles in the performance extension
Quoted 7 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
If userspace provides an unknown or invalid handle anywhere in the handle array the rest of the driver will not handle that well.
Fix it by checking handle was looked up successfuly or otherwise fail the extension by jumping into the existing unwind.
I'm not a English-native speaker, but again I need to say that it feels to me that it is something missing in this sentence.
I suggested "Fix it by checking if the handle..."
Also, s/successfuly/successfully
Quoted 2 lines
Signed-off-by Tvrtko Ursulin <[email protected]>
Best Regards,
- Maíra
Quoted 34 lines
Fixes bae7cb5d6800 ("drm/v3d: Create a CPU job extension for the reset performance query job"Cc Maíra Canal <[email protected]>Cc Iago Toral Quiroga <[email protected]>Cc <[email protected]> # v6.8+--- drivers/gpu/drm/v3d/v3d_submit.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/gpu/drm/v3d/v3d_submit.c +8
-0@@ -710,6 +710,10 @@ v3d_get_cpu_reset_performance_params(struct drm_file *file_priv, } job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); +if (!job->performance_query.queries[i].syncobj) { + err = -ENOENT ; + goto error; + } } job->performance_query.count = reset.count; job->performance_query.nperfmons = reset.nperfmons;@@ -790,6 +794,10 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv, } job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); +if (!job->performance_query.queries[i].syncobj) { + err = -ENOENT ; + goto error; + } } job->performance_query.count = copy.count; job->performance_query.nperfmons = copy.nperfmons;
PATCH v3 6/11 drm/v3d: Move part of copying of reset/copy performance extension to a helper
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
The loop which looks up the syncobj and copies the kperfmon ids is identical so lets move it to a helper.
The only change is replacing copy_from_user with get_user when copying a scalar.
--- drivers/gpu/drm/v3d/v3d_submit.c | 152 ++++++++++++++----------------- 1 file changed, 68 insertions(+), 84 deletions(-)
drivers/gpu/drm/v3d/v3d_submit.c +68 -84
@@ -644,15 +644,64 @@ v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv,return err; } +static int +v3d_copy_query_info (struct v3d_performance_query_info *query_info, +unsigned int count, +unsigned int nperfmons, +u32 __user *syncs, +u64 __user *kperfmon_ids, +struct drm_file *file_priv) +{ +unsigned int i, j; +int err; + +for (i =0 ; i < count; i++) { +struct v3d_performance_query *query = &query_info->queries[i]; +u32 __user *ids_pointer; +u32 sync, id; +u64 ids; + +if (get_user (sync, syncs++)) { + err = -EFAULT ; + goto error; + } + +if (get_user (ids, kperfmon_ids++)) { + err = -EFAULT ; + goto error; + } + + ids_pointer =u64_to_user_ptr (ids); + +for (j =0 ; j < nperfmons; j++) { +if (get_user (id, ids_pointer++)) { + err = -EFAULT ; + goto error; + } + + query->kperfmon_ids[j] = id; + } + + query->syncobj =drm_syncobj_find (file_priv, sync); +if (!query->syncobj) { + err = -ENOENT ; + goto error; + } + } + +return 0 ; + +error: +v3d_performance_query_info_free (query_info, i); +return err; +} +static int v3d_get_cpu_reset_performance_params (struct drm_file *file_priv,struct drm_v3d_extension __user *ext,struct v3d_cpu_job *job) { -u32 __user *syncs; -u64 __user *kperfmon_ids;struct drm_v3d_reset_performance_query reset; -unsigned int i, j;int err;if (!job) {
@@ -679,50 +728,19 @@ v3d_get_cpu_reset_performance_params(struct drm_file *file_priv,if (!job->performance_query.queries)return -ENOMEM ; - syncs =u64_to_user_ptr (reset.syncs); - kperfmon_ids =u64_to_user_ptr (reset.kperfmon_ids); + err =v3d_copy_query_info (&job->performance_query, + reset.count, + reset.nperfmons, +u64_to_user_ptr (reset.syncs), +u64_to_user_ptr (reset.kperfmon_ids), + file_priv); +if (err) +return err; -for (i =0 ; i < reset.count; i++) { -u32 sync; -u64 ids; -u32 __user *ids_pointer; -u32 id; - -if (copy_from_user (&sync, syncs++,sizeof (sync))) { - err = -EFAULT ; - goto error; - } - -if (copy_from_user (&ids, kperfmon_ids++,sizeof (ids))) { - err = -EFAULT ; - goto error; - } - - ids_pointer =u64_to_user_ptr (ids); - -for (j =0 ; j < reset.nperfmons; j++) { -if (copy_from_user (&id, ids_pointer++,sizeof (id))) { - err = -EFAULT ; - goto error; - } - - job->performance_query.queries[i].kperfmon_ids[j] = id; - } - - job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); -if (!job->performance_query.queries[i].syncobj) { - err = -ENOENT ; - goto error; - } - } job->performance_query.count = reset.count; job->performance_query.nperfmons = reset.nperfmons;return 0 ; - -error: -v3d_performance_query_info_free (&job->performance_query, i); -return err; } static int
@@ -730,10 +748,7 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv,struct drm_v3d_extension __user *ext, struct v3d_cpu_job *job) { - u32 __user *syncs; -u64 __user *kperfmon_ids; struct drm_v3d_copy_performance_query copy; -unsigned int i, j;int err;if (!job) {
@@ -763,42 +778,15 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv,if (!job->performance_query.queries)return -ENOMEM ; - syncs =u64_to_user_ptr (copy.syncs); - kperfmon_ids =u64_to_user_ptr (copy.kperfmon_ids); + err =v3d_copy_query_info (&job->performance_query, + copy.count, + copy.nperfmons, +u64_to_user_ptr (copy.syncs), +u64_to_user_ptr (copy.kperfmon_ids), + file_priv); +if (err) +return err; -for (int i =0 ; i < copy.count; i++) { -u32 sync; -u64 ids; -u32 __user *ids_pointer; -u32 id; - -if (copy_from_user (&sync, syncs++,sizeof (sync))) { - err = -EFAULT ; - goto error; - } - -if (copy_from_user (&ids, kperfmon_ids++,sizeof (ids))) { - err = -EFAULT ; - goto error; - } - - ids_pointer =u64_to_user_ptr (ids); - -for (j =0 ; j < copy.nperfmons; j++) { -if (copy_from_user (&id, ids_pointer++,sizeof (id))) { - err = -EFAULT ; - goto error; - } - - job->performance_query.queries[i].kperfmon_ids[j] = id; - } - - job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); -if (!job->performance_query.queries[i].syncobj) { - err = -ENOENT ; - goto error; - } - } job->performance_query.count = copy.count; job->performance_query.nperfmons = copy.nperfmons; job->performance_query.ncounters = copy.ncounters;
@@ -810,10 +798,6 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv, job->copy.stride = copy.stride;return 0 ; - -error: -v3d_performance_query_info_free (&job->performance_query, i); -return err; }/* Whenever userspace sets ioctl extensions, v3d_get_extensions parses data
Signature · 1 line
2.44.0
Re: [PATCH 06/11] drm/v3d: Move part of copying of reset/copy performance extension to a helper
Quoted 9 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
The loop which looks up the syncobj and copies the kperfmon ids is identical so lets move it to a helper.
The only change is replacing
copy_from_userwithget_userwhen copying a scalar.Signed-off-by Tvrtko Ursulin <[email protected]>
Best Regards,
- Maíra
Quoted 208 lines
--- drivers/gpu/drm/v3d/v3d_submit.c | 152 ++++++++++++++----------------- 1 file changed, 68 insertions(+), 84 deletions(-)drivers/gpu/drm/v3d/v3d_submit.c +68
-84@@ -644,15 +644,64 @@ v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv,return err; } +static int +v3d_copy_query_info (struct v3d_performance_query_info *query_info, +unsigned int count, +unsigned int nperfmons, +u32 __user *syncs, +u64 __user *kperfmon_ids, +struct drm_file *file_priv) +{ +unsigned int i, j; +int err; + +for (i =0 ; i < count; i++) { +struct v3d_performance_query *query = &query_info->queries[i]; +u32 __user *ids_pointer; +u32 sync, id; +u64 ids; + +if (get_user (sync, syncs++)) { + err = -EFAULT ; + goto error; + } + +if (get_user (ids, kperfmon_ids++)) { + err = -EFAULT ; + goto error; + } + + ids_pointer =u64_to_user_ptr (ids); + +for (j =0 ; j < nperfmons; j++) { +if (get_user (id, ids_pointer++)) { + err = -EFAULT ; + goto error; + } + + query->kperfmon_ids[j] = id; + } + + query->syncobj =drm_syncobj_find (file_priv, sync); +if (!query->syncobj) { + err = -ENOENT ; + goto error; + } + } + +return 0 ; + +error: +v3d_performance_query_info_free (query_info, i); +return err; +} +static int v3d_get_cpu_reset_performance_params (struct drm_file *file_priv,struct drm_v3d_extension __user *ext,struct v3d_cpu_job *job) { -u32 __user *syncs; -u64 __user *kperfmon_ids;struct drm_v3d_reset_performance_query reset; -unsigned int i, j;int err;if (!job) {@@ -679,50 +728,19 @@ v3d_get_cpu_reset_performance_params(struct drm_file *file_priv,if (!job->performance_query.queries)return -ENOMEM ; - syncs =u64_to_user_ptr (reset.syncs); - kperfmon_ids =u64_to_user_ptr (reset.kperfmon_ids); + err =v3d_copy_query_info (&job->performance_query, + reset.count, + reset.nperfmons, +u64_to_user_ptr (reset.syncs), +u64_to_user_ptr (reset.kperfmon_ids), + file_priv); +if (err) +return err; -for (i =0 ; i < reset.count; i++) { -u32 sync; -u64 ids; -u32 __user *ids_pointer; -u32 id; - -if (copy_from_user (&sync, syncs++,sizeof (sync))) { - err = -EFAULT ; - goto error; - } - -if (copy_from_user (&ids, kperfmon_ids++,sizeof (ids))) { - err = -EFAULT ; - goto error; - } - - ids_pointer =u64_to_user_ptr (ids); - -for (j =0 ; j < reset.nperfmons; j++) { -if (copy_from_user (&id, ids_pointer++,sizeof (id))) { - err = -EFAULT ; - goto error; - } - - job->performance_query.queries[i].kperfmon_ids[j] = id; - } - - job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); -if (!job->performance_query.queries[i].syncobj) { - err = -ENOENT ; - goto error; - } - } job->performance_query.count = reset.count; job->performance_query.nperfmons = reset.nperfmons;return 0 ; - -error: -v3d_performance_query_info_free (&job->performance_query, i); -return err; } static int@@ -730,10 +748,7 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv,struct drm_v3d_extension __user *ext, struct v3d_cpu_job *job) { - u32 __user *syncs; -u64 __user *kperfmon_ids; struct drm_v3d_copy_performance_query copy; -unsigned int i, j;int err;if (!job) {@@ -763,42 +778,15 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv,if (!job->performance_query.queries)return -ENOMEM ; - syncs =u64_to_user_ptr (copy.syncs); - kperfmon_ids =u64_to_user_ptr (copy.kperfmon_ids); + err =v3d_copy_query_info (&job->performance_query, + copy.count, + copy.nperfmons, +u64_to_user_ptr (copy.syncs), +u64_to_user_ptr (copy.kperfmon_ids), + file_priv); +if (err) +return err; -for (int i =0 ; i < copy.count; i++) { -u32 sync; -u64 ids; -u32 __user *ids_pointer; -u32 id; - -if (copy_from_user (&sync, syncs++,sizeof (sync))) { - err = -EFAULT ; - goto error; - } - -if (copy_from_user (&ids, kperfmon_ids++,sizeof (ids))) { - err = -EFAULT ; - goto error; - } - - ids_pointer =u64_to_user_ptr (ids); - -for (j =0 ; j < copy.nperfmons; j++) { -if (copy_from_user (&id, ids_pointer++,sizeof (id))) { - err = -EFAULT ; - goto error; - } - - job->performance_query.queries[i].kperfmon_ids[j] = id; - } - - job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); -if (!job->performance_query.queries[i].syncobj) { - err = -ENOENT ; - goto error; - } - } job->performance_query.count = copy.count; job->performance_query.nperfmons = copy.nperfmons; job->performance_query.ncounters = copy.ncounters;@@ -810,10 +798,6 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv, job->copy.stride = copy.stride;return 0 ; - -error: -v3d_performance_query_info_free (&job->performance_query, i); -return err; }/* Whenever userspace sets ioctl extensions, v3d_get_extensions parses data
PATCH v3 7/11 drm/v3d: Size the kperfmon_ids array at runtime
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
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.
--- drivers/gpu/drm/v3d/v3d_drv.h | 6 +----- drivers/gpu/drm/v3d/v3d_sched.c | 4 +++- drivers/gpu/drm/v3d/v3d_submit.c | 17 +++++++++++------ 3 files changed, 15 insertions(+), 12 deletions(-)
drivers/gpu/drm/v3d/v3d_drv.h +1 -5
@@ -351,13 +351,9 @@ struct v3d_timestamp_query {struct drm_syncobj *syncobj; }; -/* Number of perfmons required to handle all supported performance counters */ -#define V3D_MAX_PERFMONS DIV_ROUND_UP(V3D_MAX_COUNTERS, \ - DRM_V3D_MAX_PERF_COUNTERS) -struct v3d_performance_query {/* Performance monitor IDs for this query */ -u32 kperfmon_ids[V3D_MAX_PERFMONS ]; +u32 *kperfmon_ids;/* Syncobj that indicates the query availability */ struct drm_syncobj *syncobj;
drivers/gpu/drm/v3d/v3d_sched.c +3 -1
@@ -94,8 +94,10 @@ v3d_performance_query_info_free(struct v3d_performance_query_info *query_info,if (query_info->queries) {unsigned int i; -for (i =0 ; i < count; i++) +for (i =0 ; i < count; i++) {drm_syncobj_put (query_info->queries[i].syncobj); +kvfree (query_info->queries[i].kperfmon_ids); + }kvfree (query_info->queries); }
drivers/gpu/drm/v3d/v3d_submit.c +11 -6
@@ -671,10 +671,20 @@ v3d_copy_query_info(struct v3d_performance_query_info *query_info, goto error; } + query->kperfmon_ids = +kvmalloc_array (nperfmons, +sizeof (struct v3d_performance_query *), +GFP_KERNEL ); +if (!query->kperfmon_ids) { + err = -ENOMEM ; + goto error; + } + ids_pointer =u64_to_user_ptr (ids);for (j =0 ; j < nperfmons; j++) {if (get_user (id, ids_pointer++)) { +kvfree (query->kperfmon_ids); err = -EFAULT ; goto error; }
@@ -684,6 +694,7 @@ v3d_copy_query_info(struct v3d_performance_query_info *query_info, query->syncobj =drm_syncobj_find (file_priv, sync);if (!query->syncobj) { +kvfree (query->kperfmon_ids); err = -ENOENT ; goto error; }
@@ -717,9 +728,6 @@ v3d_get_cpu_reset_performance_params(struct drm_file *file_priv,if (copy_from_user (&reset, ext,sizeof (reset)))return -EFAULT ; -if (reset.nperfmons >V3D_MAX_PERFMONS ) -return -EINVAL ; - job->job_type =V3D_CPU_JOB_TYPE_RESET_PERFORMANCE_QUERY ; job->performance_query.queries = kvmalloc_array(reset.count,
@@ -767,9 +775,6 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv,if (copy.pad)return -EINVAL ; -if (copy.nperfmons >V3D_MAX_PERFMONS ) -return -EINVAL ; - job->job_type =V3D_CPU_JOB_TYPE_COPY_PERFORMANCE_QUERY ; job->performance_query.queries = kvmalloc_array(copy.count,
Signature · 1 line
2.44.0
Re: [PATCH 07/11] drm/v3d: Size the kperfmon_ids array at runtime
Quoted 11 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
Instead of statically reserving pessimistic space for the
kperfmon_idsarray, 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_PERFMONSmacro whose removal will benefit further driver cleanup.Signed-off-by Tvrtko Ursulin <[email protected]>
Best Regards,
- Maíra
Quoted 94 lines
--- drivers/gpu/drm/v3d/v3d_drv.h | 6 +----- drivers/gpu/drm/v3d/v3d_sched.c | 4 +++- drivers/gpu/drm/v3d/v3d_submit.c | 17 +++++++++++------ 3 files changed, 15 insertions(+), 12 deletions(-)drivers/gpu/drm/v3d/v3d_drv.h +1
-5@@ -351,13 +351,9 @@ struct v3d_timestamp_query {struct drm_syncobj *syncobj; }; -/* Number of perfmons required to handle all supported performance counters */ -#define V3D_MAX_PERFMONS DIV_ROUND_UP(V3D_MAX_COUNTERS, \ - DRM_V3D_MAX_PERF_COUNTERS) -struct v3d_performance_query {/* Performance monitor IDs for this query */ -u32 kperfmon_ids[V3D_MAX_PERFMONS ]; +u32 *kperfmon_ids;/* Syncobj that indicates the query availability */ struct drm_syncobj *syncobj;drivers/gpu/drm/v3d/v3d_sched.c +3
-1@@ -94,8 +94,10 @@ v3d_performance_query_info_free(struct v3d_performance_query_info *query_info,if (query_info->queries) {unsigned int i; -for (i =0 ; i < count; i++) +for (i =0 ; i < count; i++) {drm_syncobj_put (query_info->queries[i].syncobj); +kvfree (query_info->queries[i].kperfmon_ids); + }kvfree (query_info->queries); }drivers/gpu/drm/v3d/v3d_submit.c +11
-6@@ -671,10 +671,20 @@ v3d_copy_query_info(struct v3d_performance_query_info *query_info, goto error; } + query->kperfmon_ids = +kvmalloc_array (nperfmons, +sizeof (struct v3d_performance_query *), +GFP_KERNEL ); +if (!query->kperfmon_ids) { + err = -ENOMEM ; + goto error; + } + ids_pointer =u64_to_user_ptr (ids);for (j =0 ; j < nperfmons; j++) {if (get_user (id, ids_pointer++)) { +kvfree (query->kperfmon_ids); err = -EFAULT ; goto error; }@@ -684,6 +694,7 @@ v3d_copy_query_info(struct v3d_performance_query_info *query_info, query->syncobj =drm_syncobj_find (file_priv, sync);if (!query->syncobj) { +kvfree (query->kperfmon_ids); err = -ENOENT ; goto error; }@@ -717,9 +728,6 @@ v3d_get_cpu_reset_performance_params(struct drm_file *file_priv,if (copy_from_user (&reset, ext,sizeof (reset)))return -EFAULT ; -if (reset.nperfmons >V3D_MAX_PERFMONS ) -return -EINVAL ; - job->job_type =V3D_CPU_JOB_TYPE_RESET_PERFORMANCE_QUERY ; job->performance_query.queries = kvmalloc_array(reset.count,@@ -767,9 +775,6 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv,if (copy.pad)return -EINVAL ; -if (copy.nperfmons >V3D_MAX_PERFMONS ) -return -EINVAL ; - job->job_type =V3D_CPU_JOB_TYPE_COPY_PERFORMANCE_QUERY ; job->performance_query.queries = kvmalloc_array(copy.count,
PATCH v3 8/11 drm/v3d: Do not use intermediate storage when copying performance query results
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Removing the intermediate buffer removes the last use of the V3D_MAX_COUNTERS define, which will enable further driver cleanup.
While at it pull the 32 vs 64 bit copying decision outside the loop in order to reduce the number of conditional instructions.
--- drivers/gpu/drm/v3d/v3d_sched.c | 60 ++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 23 deletions(-)
drivers/gpu/drm/v3d/v3d_sched.c +37 -23
@@ -421,18 +421,23 @@ v3d_reset_timestamp_queries(struct v3d_cpu_job *job)v3d_put_bo_vaddr (bo); } +static void write_to_buffer_32 (u32 *dst,unsigned int idx,u32 value) +{ + dst[idx] = value; +} + +static void write_to_buffer_64 (u64 *dst,unsigned int idx,u64 value) +{ + dst[idx] = value; +} +static void -write_to_buffer (void *dst,u32 idx,bool do_64bit,u64 value) +write_to_buffer (void *dst,unsigned int idx,bool do_64bit,u64 value) { -if (do_64bit) { -u64 *dst64 = (u64 *)dst; - - dst64[idx] = value; - }else { -u32 *dst32 = (u32 *)dst; - - dst32[idx] = (u32 )value; - } +if (do_64bit) +write_to_buffer_64 (dst, idx, value); +else +write_to_buffer_32 (dst, idx, value); } static void
@@ -505,18 +510,23 @@ v3d_reset_performance_queries(struct v3d_cpu_job *job) }static void -v3d_write_performance_query_result (struct v3d_cpu_job *job,void *data,u32 query) +v3d_write_performance_query_result (struct v3d_cpu_job *job,void *data, +unsigned int query) { -struct v3d_performance_query_info *performance_query = &job->performance_query; -struct v3d_copy_query_results_info *copy = &job->copy; +struct v3d_performance_query_info *performance_query = + &job->performance_query;struct v3d_file_priv *v3d_priv = job->base.file->driver_priv;struct v3d_dev *v3d = job->base.v3d; -struct v3d_perfmon *perfmon; -u64 counter_values[V3D_MAX_COUNTERS ]; +unsigned int i, j, offset; -for (int i =0 ; i < performance_query->nperfmons; i++) { - perfmon =v3d_perfmon_find (v3d_priv, - performance_query->queries[query].kperfmon_ids[i]); +for (i =0 , offset =0 ; + i < performance_query->nperfmons; + i++, offset +=DRM_V3D_MAX_PERF_COUNTERS ) { +struct v3d_performance_query *q = + &performance_query->queries[query]; +struct v3d_perfmon *perfmon; + + perfmon =v3d_perfmon_find (v3d_priv, q->kperfmon_ids[i]);if (!perfmon) {DRM_DEBUG ("Failed to find perfmon." );continue ;
@@ -524,14 +534,18 @@ v3d_write_performance_query_result(struct v3d_cpu_job *job, void *data, u32 querv3d_perfmon_stop (v3d, perfmon, true); -memcpy (&counter_values[i *DRM_V3D_MAX_PERF_COUNTERS ], perfmon->values, - perfmon->ncounters *sizeof (u64)); +if (job->copy.do_64bit) { +for (j =0 ; j < perfmon->ncounters; j++) +write_to_buffer_64 (data, offset + j, + perfmon->values[j]); + }else { +for (j =0 ; j < perfmon->ncounters; j++) +write_to_buffer_32 (data, offset + j, + perfmon->values[j]); + }v3d_perfmon_put (perfmon); } - -for (int i =0 ; i < performance_query->ncounters; i++) -write_to_buffer (data, i, copy->do_64bit, counter_values[i]); } static void
Signature · 1 line
2.44.0
Re: [PATCH 08/11] drm/v3d: Do not use intermediate storage when copying performance query results
Quoted 9 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
Removing the intermediate buffer removes the last use of the
V3D_MAX_COUNTERSdefine, which will enable further driver cleanup.While at it pull the 32 vs 64 bit copying decision outside the loop in order to reduce the number of conditional instructions.
Signed-off-by Tvrtko Ursulin <[email protected]>
After addressing Iago's comment, you can add my
Best Regards,
- Maíra
Quoted 98 lines
--- drivers/gpu/drm/v3d/v3d_sched.c | 60 ++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 23 deletions(-)drivers/gpu/drm/v3d/v3d_sched.c +37
-23@@ -421,18 +421,23 @@ v3d_reset_timestamp_queries(struct v3d_cpu_job *job)v3d_put_bo_vaddr (bo); } +static void write_to_buffer_32 (u32 *dst,unsigned int idx,u32 value) +{ + dst[idx] = value; +} + +static void write_to_buffer_64 (u64 *dst,unsigned int idx,u64 value) +{ + dst[idx] = value; +} +static void -write_to_buffer (void *dst,u32 idx,bool do_64bit,u64 value) +write_to_buffer (void *dst,unsigned int idx,bool do_64bit,u64 value) { -if (do_64bit) { -u64 *dst64 = (u64 *)dst; - - dst64[idx] = value; - }else { -u32 *dst32 = (u32 *)dst; - - dst32[idx] = (u32 )value; - } +if (do_64bit) +write_to_buffer_64 (dst, idx, value); +else +write_to_buffer_32 (dst, idx, value); } static void@@ -505,18 +510,23 @@ v3d_reset_performance_queries(struct v3d_cpu_job *job) }static void -v3d_write_performance_query_result (struct v3d_cpu_job *job,void *data,u32 query) +v3d_write_performance_query_result (struct v3d_cpu_job *job,void *data, +unsigned int query) { -struct v3d_performance_query_info *performance_query = &job->performance_query; -struct v3d_copy_query_results_info *copy = &job->copy; +struct v3d_performance_query_info *performance_query = + &job->performance_query;struct v3d_file_priv *v3d_priv = job->base.file->driver_priv;struct v3d_dev *v3d = job->base.v3d; -struct v3d_perfmon *perfmon; -u64 counter_values[V3D_MAX_COUNTERS ]; +unsigned int i, j, offset; -for (int i =0 ; i < performance_query->nperfmons; i++) { - perfmon =v3d_perfmon_find (v3d_priv, - performance_query->queries[query].kperfmon_ids[i]); +for (i =0 , offset =0 ; + i < performance_query->nperfmons; + i++, offset +=DRM_V3D_MAX_PERF_COUNTERS ) { +struct v3d_performance_query *q = + &performance_query->queries[query]; +struct v3d_perfmon *perfmon; + + perfmon =v3d_perfmon_find (v3d_priv, q->kperfmon_ids[i]);if (!perfmon) {DRM_DEBUG ("Failed to find perfmon." );continue ;@@ -524,14 +534,18 @@ v3d_write_performance_query_result(struct v3d_cpu_job *job, void *data, u32 querv3d_perfmon_stop (v3d, perfmon, true); -memcpy (&counter_values[i *DRM_V3D_MAX_PERF_COUNTERS ], perfmon->values, - perfmon->ncounters *sizeof (u64)); +if (job->copy.do_64bit) { +for (j =0 ; j < perfmon->ncounters; j++) +write_to_buffer_64 (data, offset + j, + perfmon->values[j]); + }else { +for (j =0 ; j < perfmon->ncounters; j++) +write_to_buffer_32 (data, offset + j, + perfmon->values[j]); + }v3d_perfmon_put (perfmon); } - -for (int i =0 ; i < performance_query->ncounters; i++) -write_to_buffer (data, i, copy->do_64bit, counter_values[i]); } static void
PATCH v3 9/11 drm/v3d: Move perfmon init completely into own unit
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Now that the build time dependencies on various array sizes have been removed, we can move the perfmon init completely into its own compilation unit and remove the hardcoded defines.
This improves on the temporary fix quickly delivered in 9c3951ec27b9 ("drm/v3d: Fix perfmon build error/warning").
References: 9c3951ec27b9 ("drm/v3d: Fix perfmon build error/warning")
--- drivers/gpu/drm/v3d/v3d_drv.c | 9 +--- drivers/gpu/drm/v3d/v3d_drv.h | 6 +-- drivers/gpu/drm/v3d/v3d_perfmon.c | 44 +++++++++++-------- .../gpu/drm/v3d/v3d_performance_counters.h | 16 ++++--- 4 files changed, 40 insertions(+), 35 deletions(-)
drivers/gpu/drm/v3d/v3d_drv.c +2 -7
@@ -95,7 +95,7 @@ static int v3d_get_param_ioctl(struct drm_device *dev, void *data, args->value =1 ;return 0 ;case DRM_V3D_PARAM_MAX_PERF_COUNTERS : - args->value = v3d->max_counters; + args->value = v3d->perfmon_info.max_counters;return 0 ;default :DRM_DEBUG ("Unknown parameter %d\n" , args->param);
@@ -298,12 +298,7 @@ static int v3d_platform_drm_probe(struct platform_device *pdev) v3d->cores =V3D_GET_FIELD (ident1,V3D_HUB_IDENT1_NCORES );WARN_ON (v3d->cores >1 );/* multicore not yet implemented */ -if (v3d->ver >=71 ) - v3d->max_counters =V3D_V71_NUM_PERFCOUNTERS ; -else if (v3d->ver >=42 ) - v3d->max_counters =V3D_V42_NUM_PERFCOUNTERS ; -else - v3d->max_counters =0 ; +v3d_perfmon_init (v3d); v3d->reset =devm_reset_control_get_exclusive (dev,NULL );if (IS_ERR (v3d->reset)) {
drivers/gpu/drm/v3d/v3d_drv.h +2 -4
@@ -104,10 +104,7 @@ struct v3d_dev {int ver;bool single_irq_line; -/* Different revisions of V3D have different total number of performance -* counters -*/ -unsigned int max_counters; +struct v3d_perfmon_info perfmon_info;void __iomem *hub_regs;void __iomem *core_regs[3 ];
@@ -568,6 +565,7 @@ int v3d_sched_init(struct v3d_dev *v3d);void v3d_sched_fini (struct v3d_dev *v3d);/* v3d_perfmon.c */ +void v3d_perfmon_init (struct v3d_dev *v3d);void v3d_perfmon_get (struct v3d_perfmon *perfmon);void v3d_perfmon_put (struct v3d_perfmon *perfmon);void v3d_perfmon_start (struct v3d_dev *v3d,struct v3d_perfmon *perfmon);
drivers/gpu/drm/v3d/v3d_perfmon.c +25 -19
64 lines not on this page · raw message
drivers/gpu/drm/v3d/v3d_performance_counters.h +11 -5
@@ -19,11 +19,17 @@ struct v3d_perf_counter_desc { char description[256]; }; +struct v3d_perfmon_info { +/* +* Different revisions of V3D have different total number of +* performance counters. +*/ +unsigned int max_counters; -#define V3D_V42_NUM_PERFCOUNTERS (87) -#define V3D_V71_NUM_PERFCOUNTERS (93) - -/* Maximum number of performance counters supported by any version of V3D */ -#define V3D_MAX_COUNTERS (93) +/* +* Array of counters valid for the platform. +*/ +const struct v3d_perf_counter_desc *counters; +};#endif
Signature · 1 line
2.44.0
Re: [PATCH 09/11] drm/v3d: Move perfmon init completely into own unit
Quoted 8 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
Now that the build time dependencies on various array sizes have been removed, we can move the perfmon init completely into its own compilation unit and remove the hardcoded defines.
This improves on the temporary fix quickly delivered in
9c3951ec27b9("drm/v3d: Fix perfmon build error/warning").
Just to please checkpatch, can you write "...delivered in commit 9c3951ec27b9 ("drm/v3d: Fix perfmon build error/warning")."
You can send the next version with my R-b:
Best Regards,
- Maíra
Quoted 159 lines
Signed-off-by Tvrtko Ursulin <[email protected]>References:
9c3951ec27b9("drm/v3d: Fix perfmon build error/warning")--- drivers/gpu/drm/v3d/v3d_drv.c | 9 +--- drivers/gpu/drm/v3d/v3d_drv.h | 6 +-- drivers/gpu/drm/v3d/v3d_perfmon.c | 44 +++++++++++-------- .../gpu/drm/v3d/v3d_performance_counters.h | 16 ++++--- 4 files changed, 40 insertions(+), 35 deletions(-)drivers/gpu/drm/v3d/v3d_drv.c +2
-7@@ -95,7 +95,7 @@ static int v3d_get_param_ioctl(struct drm_device *dev, void *data, args->value =1 ;return 0 ;case DRM_V3D_PARAM_MAX_PERF_COUNTERS : - args->value = v3d->max_counters; + args->value = v3d->perfmon_info.max_counters;return 0 ;default :DRM_DEBUG ("Unknown parameter %d\n" , args->param);@@ -298,12 +298,7 @@ static int v3d_platform_drm_probe(struct platform_device *pdev) v3d->cores =V3D_GET_FIELD (ident1,V3D_HUB_IDENT1_NCORES );WARN_ON (v3d->cores >1 );/* multicore not yet implemented */ -if (v3d->ver >=71 ) - v3d->max_counters =V3D_V71_NUM_PERFCOUNTERS ; -else if (v3d->ver >=42 ) - v3d->max_counters =V3D_V42_NUM_PERFCOUNTERS ; -else - v3d->max_counters =0 ; +v3d_perfmon_init (v3d); v3d->reset =devm_reset_control_get_exclusive (dev,NULL );if (IS_ERR (v3d->reset)) {drivers/gpu/drm/v3d/v3d_drv.h +2
-4@@ -104,10 +104,7 @@ struct v3d_dev {int ver;bool single_irq_line; -/* Different revisions of V3D have different total number of performance -* counters -*/ -unsigned int max_counters; +struct v3d_perfmon_info perfmon_info;void __iomem *hub_regs;void __iomem *core_regs[3 ];@@ -568,6 +565,7 @@ int v3d_sched_init(struct v3d_dev *v3d);void v3d_sched_fini (struct v3d_dev *v3d);/* v3d_perfmon.c */ +void v3d_perfmon_init (struct v3d_dev *v3d);void v3d_perfmon_get (struct v3d_perfmon *perfmon);void v3d_perfmon_put (struct v3d_perfmon *perfmon);void v3d_perfmon_start (struct v3d_dev *v3d,struct v3d_perfmon *perfmon);drivers/gpu/drm/v3d/v3d_perfmon.c +25
-19@@ -195,6 +195,23 @@ static const struct v3d_perf_counter_desc v3d_v71_performance_counters[] = { {"QPU", "QPU-stalls-other", "[QPU] Stalled qcycles waiting for any other reason (vary/W/Z)"}, }; +void v3d_perfmon_init (struct v3d_dev *v3d) +{ +const struct v3d_perf_counter_desc *counters =NULL ; +unsigned int max =0 ; + +if (v3d->ver >=71 ) { + counters = v3d_v71_performance_counters; + max =ARRAY_SIZE (v3d_v71_performance_counters); + }else if (v3d->ver >=42 ) { + counters = v3d_v42_performance_counters; + max =ARRAY_SIZE (v3d_v42_performance_counters); + } + + v3d->perfmon_info.max_counters = max; + v3d->perfmon_info.counters = counters; +} +void v3d_perfmon_get (struct v3d_perfmon *perfmon) {if (perfmon)@@ -321,7 +338,7 @@ int v3d_perfmon_create_ioctl(struct drm_device *dev, void *data,/* Make sure all counters are valid. */ for (i =0 ; i < req->ncounters; i++) { -if (req->counters[i] >= v3d->max_counters) +if (req->counters[i] >= v3d->perfmon_info.max_counters)return -EINVAL ; }@@ -416,26 +433,15 @@ int v3d_perfmon_get_counter_ioctl(struct drm_device *dev, void *data,return -EINVAL ; } -/* Make sure that the counter ID is valid */ -if (req->counter >= v3d->max_counters) -return -EINVAL ; - -BUILD_BUG_ON (ARRAY_SIZE (v3d_v42_performance_counters) != -V3D_V42_NUM_PERFCOUNTERS ); -BUILD_BUG_ON (ARRAY_SIZE (v3d_v71_performance_counters) != -V3D_V71_NUM_PERFCOUNTERS ); -BUILD_BUG_ON (V3D_MAX_COUNTERS <V3D_V42_NUM_PERFCOUNTERS ); -BUILD_BUG_ON (V3D_MAX_COUNTERS <V3D_V71_NUM_PERFCOUNTERS ); -BUILD_BUG_ON ((V3D_MAX_COUNTERS !=V3D_V42_NUM_PERFCOUNTERS ) && - (V3D_MAX_COUNTERS !=V3D_V71_NUM_PERFCOUNTERS )); - -if (v3d->ver >=71 ) - counter = &v3d_v71_performance_counters[req->counter]; -else if (v3d->ver >=42 ) - counter = &v3d_v42_performance_counters[req->counter]; -else +if (!v3d->perfmon_info.max_counters)return -EOPNOTSUPP ; +/* Make sure that the counter ID is valid */ +if (req->counter >= v3d->perfmon_info.max_counters) +return -EINVAL ; + + counter = &v3d->perfmon_info.counters[req->counter]; +strscpy (req->name, counter->name,sizeof (req->name));strscpy (req->category, counter->category,sizeof (req->category));strscpy (req->description, counter->description,sizeof (req->description));drivers/gpu/drm/v3d/v3d_performance_counters.h +11
-5@@ -19,11 +19,17 @@ struct v3d_perf_counter_desc { char description[256]; }; +struct v3d_perfmon_info { +/* +* Different revisions of V3D have different total number of +* performance counters. +*/ +unsigned int max_counters; -#define V3D_V42_NUM_PERFCOUNTERS (87) -#define V3D_V71_NUM_PERFCOUNTERS (93) - -/* Maximum number of performance counters supported by any version of V3D */ -#define V3D_MAX_COUNTERS (93) +/* +* Array of counters valid for the platform. +*/ +const struct v3d_perf_counter_desc *counters; +};#endif
PATCH v3 10/11 drm/v3d: Prefer get_user for scalar types
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
It makes it just a tiny bit more obvious what is going on.
--- drivers/gpu/drm/v3d/v3d_submit.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/v3d/v3d_submit.c +5 -5
@@ -485,14 +485,14 @@ v3d_get_cpu_timestamp_query_params(struct drm_file *file_priv,for (i =0 ; i < timestamp.count; i++) {u32 offset, sync; -if (copy_from_user (&offset, offsets++,sizeof (offset))) { +if (get_user (offset, offsets++)) { err = -EFAULT ; goto error; } job->timestamp_query.queries[i].offset = offset; -if (copy_from_user (&sync, syncs++,sizeof (sync))) { +if (get_user (sync, syncs++)) { err = -EFAULT ; goto error; }
@@ -550,7 +550,7 @@ v3d_get_cpu_reset_timestamp_params(struct drm_file *file_priv, job->timestamp_query.queries[i].offset = reset.offset +8 * i; -if (copy_from_user (&sync, syncs++,sizeof (sync))) { +if (get_user (sync, syncs++)) { err = -EFAULT ; goto error; }
@@ -611,14 +611,14 @@ v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv,for (i =0 ; i < copy.count; i++) {u32 offset, sync; -if (copy_from_user (&offset, offsets++,sizeof (offset))) { +if (get_user (offset, offsets++)) { err = -EFAULT ; goto error; } job->timestamp_query.queries[i].offset = offset; -if (copy_from_user (&sync, syncs++,sizeof (sync))) { +if (get_user (sync, syncs++)) { err = -EFAULT ; goto error; }
Signature · 1 line
2.44.0
PATCH v3 11/11 drm/v3d: Add some local variables in queries/extensions
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Add some local variables to make the code a bit less verbose, with the main benefit being pulling some lines to under 80 columns wide.
--- drivers/gpu/drm/v3d/v3d_submit.c | 88 ++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 39 deletions(-)
drivers/gpu/drm/v3d/v3d_submit.c +49 -39
@@ -452,6 +452,7 @@ v3d_get_cpu_timestamp_query_params(struct drm_file *file_priv, {u32 __user *offsets, *syncs;struct drm_v3d_timestamp_query timestamp; +struct v3d_timestamp_query_info *query_info = &job->timestamp_query;unsigned int i;int err;
@@ -473,10 +474,10 @@ v3d_get_cpu_timestamp_query_params(struct drm_file *file_priv, job->job_type =V3D_CPU_JOB_TYPE_TIMESTAMP_QUERY ; - job->timestamp_query.queries =kvmalloc_array (timestamp.count, -sizeof (struct v3d_timestamp_query ), -GFP_KERNEL ); -if (!job->timestamp_query.queries) + query_info->queries =kvmalloc_array (timestamp.count, +sizeof (struct v3d_timestamp_query ), +GFP_KERNEL ); +if (!query_info->queries)return -ENOMEM ; offsets =u64_to_user_ptr (timestamp.offsets);
@@ -490,20 +491,21 @@ v3d_get_cpu_timestamp_query_params(struct drm_file *file_priv, goto error; } - job->timestamp_query.queries[i].offset = offset; + query_info->queries[i].offset = offset;if (get_user (sync, syncs++)) { err = -EFAULT ; goto error; } - job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); -if (!job->timestamp_query.queries[i].syncobj) { + query_info->queries[i].syncobj =drm_syncobj_find (file_priv, + sync); +if (!query_info->queries[i].syncobj) { err = -ENOENT ; goto error; } } - job->timestamp_query.count = timestamp.count; + query_info->count = timestamp.count;return 0 ;
@@ -519,6 +521,7 @@ v3d_get_cpu_reset_timestamp_params(struct drm_file *file_priv, {u32 __user *syncs;struct drm_v3d_reset_timestamp_query reset; +struct v3d_timestamp_query_info *query_info = &job->timestamp_query;unsigned int i;int err;
@@ -537,10 +540,10 @@ v3d_get_cpu_reset_timestamp_params(struct drm_file *file_priv, job->job_type =V3D_CPU_JOB_TYPE_RESET_TIMESTAMP_QUERY ; - job->timestamp_query.queries =kvmalloc_array (reset.count, -sizeof (struct v3d_timestamp_query ), -GFP_KERNEL ); -if (!job->timestamp_query.queries) + query_info->queries =kvmalloc_array (reset.count, +sizeof (struct v3d_timestamp_query ), +GFP_KERNEL ); +if (!query_info->queries)return -ENOMEM ; syncs =u64_to_user_ptr (reset.syncs);
@@ -548,20 +551,21 @@ v3d_get_cpu_reset_timestamp_params(struct drm_file *file_priv,for (i =0 ; i < reset.count; i++) {u32 sync; - job->timestamp_query.queries[i].offset = reset.offset +8 * i; + query_info->queries[i].offset = reset.offset +8 * i;if (get_user (sync, syncs++)) { err = -EFAULT ; goto error; } - job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); -if (!job->timestamp_query.queries[i].syncobj) { + query_info->queries[i].syncobj =drm_syncobj_find (file_priv, + sync); +if (!query_info->queries[i].syncobj) { err = -ENOENT ; goto error; } } - job->timestamp_query.count = reset.count; + query_info->count = reset.count;return 0 ;
@@ -578,6 +582,7 @@ v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv, {u32 __user *offsets, *syncs;struct drm_v3d_copy_timestamp_query copy; +struct v3d_timestamp_query_info *query_info = &job->timestamp_query;unsigned int i;int err;
@@ -599,10 +604,10 @@ v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv, job->job_type =V3D_CPU_JOB_TYPE_COPY_TIMESTAMP_QUERY ; - job->timestamp_query.queries =kvmalloc_array (copy.count, -sizeof (struct v3d_timestamp_query ), -GFP_KERNEL ); -if (!job->timestamp_query.queries) + query_info->queries =kvmalloc_array (copy.count, +sizeof (struct v3d_timestamp_query ), +GFP_KERNEL ); +if (!query_info->queries)return -ENOMEM ; offsets =u64_to_user_ptr (copy.offsets);
@@ -616,20 +621,21 @@ v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv, goto error; } - job->timestamp_query.queries[i].offset = offset; + query_info->queries[i].offset = offset;if (get_user (sync, syncs++)) { err = -EFAULT ; goto error; } - job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); -if (!job->timestamp_query.queries[i].syncobj) { + query_info->queries[i].syncobj =drm_syncobj_find (file_priv, + sync); +if (!query_info->queries[i].syncobj) { err = -ENOENT ; goto error; } } - job->timestamp_query.count = copy.count; + query_info->count = copy.count; job->copy.do_64bit = copy.do_64bit; job->copy.do_partial = copy.do_partial;
@@ -712,6 +718,7 @@ v3d_get_cpu_reset_performance_params(struct drm_file *file_priv,struct drm_v3d_extension __user *ext, struct v3d_cpu_job *job) { + struct v3d_performance_query_info *query_info = &job->performance_query;struct drm_v3d_reset_performance_query reset;int err;
@@ -730,13 +737,14 @@ v3d_get_cpu_reset_performance_params(struct drm_file *file_priv, job->job_type =V3D_CPU_JOB_TYPE_RESET_PERFORMANCE_QUERY ; - job->performance_query.queries =kvmalloc_array (reset.count, -sizeof (struct v3d_performance_query ), -GFP_KERNEL ); -if (!job->performance_query.queries) + query_info->queries = +kvmalloc_array (reset.count, +sizeof (struct v3d_performance_query ), +GFP_KERNEL ); +if (!query_info->queries)return -ENOMEM ; - err = v3d_copy_query_info(&job->performance_query, + err = v3d_copy_query_info(query_info, reset.count, reset.nperfmons, u64_to_user_ptr(reset.syncs),
@@ -745,8 +753,8 @@ v3d_get_cpu_reset_performance_params(struct drm_file *file_priv,if (err)return err; - job->performance_query.count = reset.count; - job->performance_query.nperfmons = reset.nperfmons; + query_info->count = reset.count; + query_info->nperfmons = reset.nperfmons;return 0 ; }
@@ -756,6 +764,7 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv,struct drm_v3d_extension __user *ext, struct v3d_cpu_job *job) { + struct v3d_performance_query_info *query_info = &job->performance_query;struct drm_v3d_copy_performance_query copy;int err;
@@ -777,13 +786,14 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv, job->job_type =V3D_CPU_JOB_TYPE_COPY_PERFORMANCE_QUERY ; - job->performance_query.queries =kvmalloc_array (copy.count, -sizeof (struct v3d_performance_query ), -GFP_KERNEL ); -if (!job->performance_query.queries) + query_info->queries = +kvmalloc_array (copy.count, +sizeof (struct v3d_performance_query ), +GFP_KERNEL ); +if (!query_info->queries)return -ENOMEM ; - err = v3d_copy_query_info(&job->performance_query, + err = v3d_copy_query_info(query_info, copy.count, copy.nperfmons, u64_to_user_ptr(copy.syncs),
@@ -792,9 +802,9 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv,if (err)return err; - job->performance_query.count = copy.count; - job->performance_query.nperfmons = copy.nperfmons; - job->performance_query.ncounters = copy.ncounters; + query_info->count = copy.count; + query_info->nperfmons = copy.nperfmons; + query_info->ncounters = copy.ncounters; job->copy.do_64bit = copy.do_64bit; job->copy.do_partial = copy.do_partial;
Signature · 1 line
2.44.0