v3d: Perfmon cleanup
Subsystems (4)
v2 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.
Tvrtko Ursulin (12):
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: Align data types of internal and uapi counts drm/v3d: Add some local variables in queries/extensions drm/v3d: Prefer get_user for scalar types
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 | 285 ++++++++++-------- 6 files changed, 281 insertions(+), 195 deletions(-)
Signature · 1 line
2.44.0
PATCH v2 1/12 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
Re: [PATCH 01/12] drm/v3d: Prevent out of bounds access in performance query extensions
Quoted 11 lines · Tvrtko Ursulin
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.
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+
On this one I forgot to carry over from v1:
Regards,
Tvrtko
Quoted 28 lines
--- 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,
Re: [PATCH 01/12] drm/v3d: Prevent out of bounds access in performance query extensions
In reply to Tvrtko UrsulinQuoted 7 lines · Tvrtko Ursulin
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.
Signed-off-by Tvrtko Ursulin <[email protected]>
Best Regards,
- Maíra
Quoted 32 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 | 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,
PATCH v2 2/12 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 | 36 ++++++++++++++++++++++---------- 3 files changed, 43 insertions(+), 17 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 *qinfo, +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 *qinfo, +unsigned int count) +{ +if (qinfo->queries) { +unsigned int i; + +for (i =0 ; i < count; i++) +drm_syncobj_put (qinfo->queries[i].syncobj); + +kvfree (qinfo->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 +25 -11
@@ -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; +int err;if (!job) {DRM_DEBUG ("CPU job extension was attached to a GPU job.\n" );
@@ -484,15 +485,15 @@ v3d_get_cpu_timestamp_query_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);
@@ -500,6 +501,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 (qinfo, i); +return err; } static int
@@ -509,6 +514,7 @@ v3d_get_cpu_reset_timestamp_params(struct drm_file *file_priv, {u32 __user *syncs;struct drm_v3d_reset_timestamp_query reset; +int err;if (!job) {DRM_DEBUG ("CPU job extension was attached to a GPU job.\n" );
@@ -539,8 +545,8 @@ 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))) { -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 +554,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 (qinfo, i); +return err; }/* Get data for the copy timestamp query results job submission. */
@@ -558,7 +568,7 @@ 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; +int i, err;if (!job) {DRM_DEBUG ("CPU job extension was attached to a GPU job.\n" );
@@ -591,15 +601,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 +623,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 (qinfo, i); +return err; } static int
Signature · 1 line
2.44.0
Maíra Canal
maintainerRe: [PATCH 02/12] 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]>
This patch looks fine to me apart from two nits and a compilation issue.
Quoted 15 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 | 36 ++++++++++++++++++++++---------- 3 files changed, 43 insertions(+), 17 deletions(-)drivers/gpu/drm/v3d/v3d_drv.h +0
-0
drivers/gpu/drm/v3d/v3d_drv.h void v3d_mmu_insert_ptes(struct v3d_bo *bo); · line 567
Quoted 5 lines
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 *qinfo, +unsigned int count);
My two nits:
I believe we never used this __ pattern in V3D and I'm not sure how comfortable I am to introduce it now. I know it is pretty common in drivers like i915, but I wonder how much semantics we would miss to remove it.
Also, any chance we could use query_info instead of qinfo? This suggestion applies to all patches in the series that uses qinfo.
Quoted 75 lines
drivers/gpu/drm/v3d/v3d_drv.h +0
-0void 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 *qinfo, +unsigned int count) +{ +if (qinfo->queries) { +unsigned int i; + +for (i =0 ; i < count; i++) +drm_syncobj_put (qinfo->queries[i].syncobj); + +kvfree (qinfo->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 +5
-4@@ -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; +int err;if (!job) {DRM_DEBUG ("CPU job extension was attached to a GPU job.\n" );@@ -484,15 +485,15 @@ v3d_get_cpu_timestamp_query_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);
drivers/gpu/drm/v3d/v3d_submit.c v3d_get_cpu_timestamp_query_params(struct drm_file *file_priv, · line 506
Quoted 6 lines
drivers/gpu/drm/v3d/v3d_submit.c +3
-0@@ -500,6 +501,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 (qinfo, i);
I don't see where qinfo is declared in this function.
Quoted 24 lines
drivers/gpu/drm/v3d/v3d_submit.c +4
-2+return err; } static int@@ -509,6 +514,7 @@ v3d_get_cpu_reset_timestamp_params(struct drm_file *file_priv, {u32 __user *syncs;struct drm_v3d_reset_timestamp_query reset; +int err;if (!job) {DRM_DEBUG ("CPU job extension was attached to a GPU job.\n" );@@ -539,8 +545,8 @@ 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))) { -kvfree (job->timestamp_query.queries); -return -EFAULT ; + err = -EFAULT ; + goto error; } job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync);
drivers/gpu/drm/v3d/v3d_submit.c v3d_get_cpu_reset_timestamp_params(struct drm_file *file_priv, · line 559
Quoted 6 lines
drivers/gpu/drm/v3d/v3d_submit.c +3
-0@@ -548,6 +554,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 (qinfo, i);
Same here.
Quoted 34 lines
drivers/gpu/drm/v3d/v3d_submit.c +6
-5+return err; }/* Get data for the copy timestamp query results job submission. */ @@ -558,7 +568,7 @@ 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; +int i, err;if (!job) {DRM_DEBUG ("CPU job extension was attached to a GPU job.\n" );@@ -591,15 +601,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);
drivers/gpu/drm/v3d/v3d_submit.c v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv, · line 628
Quoted 6 lines
drivers/gpu/drm/v3d/v3d_submit.c +3
-0@@ -613,6 +623,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 (qinfo, i);
Same here.
Best Regards,
- Maíra
Quoted 4 lines
drivers/gpu/drm/v3d/v3d_submit.c +1
-0+return err; } static int
PATCH v2 3/12 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 | 40 +++++++++++++++++++++----------- 3 files changed, 44 insertions(+), 20 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 *qinfo,unsigned int count); +void __v3d_performance_query_info_free (struct v3d_performance_query_info *qinfo, +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 *qinfo, } } +void +__v3d_performance_query_info_free (struct v3d_performance_query_info *qinfo, +unsigned int count) +{ +if (qinfo->queries) { +unsigned int i; + +for (i =0 ; i < count; i++) +drm_syncobj_put (qinfo->queries[i].syncobj); + +kvfree (qinfo->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 +26 -14
@@ -637,6 +637,7 @@ 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; +int err;if (!job) {DRM_DEBUG ("CPU job extension was attached to a GPU job.\n" );
@@ -672,32 +673,36 @@ v3d_get_cpu_reset_performance_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 < 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 (qinfo, i); +return err; } static int
@@ -708,6 +713,7 @@ 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; +int err;if (!job) {DRM_DEBUG ("CPU job extension was attached to a GPU job.\n" );
@@ -746,27 +752,29 @@ 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++) {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;
@@ -779,6 +787,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 (qinfo, i); +return err; }/* Whenever userspace sets ioctl extensions, v3d_get_extensions parses data
Signature · 1 line
2.44.0
Maíra Canal
maintainerRe: [PATCH 03/12] drm/v3d: Fix potential memory leak in the performance extension
Quoted 10 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"
Missing ) at the end of Fixes.
Quoted 14 lines
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 | 40 +++++++++++++++++++++----------- 3 files changed, 44 insertions(+), 20 deletions(-)drivers/gpu/drm/v3d/v3d_drv.h +0
-0
drivers/gpu/drm/v3d/v3d_drv.h void v3d_mmu_remove_ptes(struct v3d_bo *bo); · line 569
Quoted 5 lines
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 *qinfo,unsigned int count); +void __v3d_performance_query_info_free (struct v3d_performance_query_info *qinfo, +unsigned int count);
Same nits from the previous patch.
Quoted 86 lines
drivers/gpu/drm/v3d/v3d_drv.h +0
-0void 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 *qinfo, } } +void +__v3d_performance_query_info_free (struct v3d_performance_query_info *qinfo, +unsigned int count) +{ +if (qinfo->queries) { +unsigned int i; + +for (i =0 ; i < count; i++) +drm_syncobj_put (qinfo->queries[i].syncobj); + +kvfree (qinfo->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 +7
-8@@ -637,6 +637,7 @@ 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; +int err;if (!job) {DRM_DEBUG ("CPU job extension was attached to a GPU job.\n" );@@ -672,32 +673,36 @@ v3d_get_cpu_reset_performance_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 < 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;
drivers/gpu/drm/v3d/v3d_submit.c v3d_get_cpu_reset_performance_params(struct drm_file *file_priv, · line 703
Quoted 10 lines
drivers/gpu/drm/v3d/v3d_submit.c +4
-0} + + 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 (qinfo, i);
I miss the declaration of qinfo.
Quoted 13 lines
drivers/gpu/drm/v3d/v3d_submit.c +2
-0+return err; } static int@@ -708,6 +713,7 @@ 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; +int err;if (!job) {DRM_DEBUG ("CPU job extension was attached to a GPU job.\n" );
drivers/gpu/drm/v3d/v3d_submit.c v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv, · line 759
Quoted 10 lines
drivers/gpu/drm/v3d/v3d_submit.c +2
-2@@ -746,27 +752,29 @@ 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);
I believe this line should be deleted as it is introduced later in this patch.
Quoted 26 lines
drivers/gpu/drm/v3d/v3d_submit.c +6
-4if (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++) {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 792
Quoted 6 lines
drivers/gpu/drm/v3d/v3d_submit.c +3
-0@@ -779,6 +787,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 (qinfo, i);
Missing declaration of qinfo.
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
PATCH v2 4/12 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 successfuly 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
@@ -497,6 +497,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;
@@ -550,6 +554,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;
@@ -613,6 +621,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
Maíra Canal
maintainerRe: [PATCH 04/12] drm/v3d: Validate passed in drm syncobj handles in the timestamp extension
Quoted 6 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
I believe you mean "Fix it by checking if the handle..."
Also s/successfuly/successfully
Quoted 16 lines
extension by jumping into the existing unwind.
Signed-off-by Tvrtko Ursulin <[email protected]>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 +0
-0
drivers/gpu/drm/v3d/v3d_submit.c v3d_get_cpu_timestamp_query_params(struct drm_file *file_priv, · line 501
Quoted 5 lines
drivers/gpu/drm/v3d/v3d_submit.c +2
-0@@ -497,6 +497,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 ;
I'm not sure if err should be -ENOENT or -EINVAL, but based on other drivers, I believe it should be -EINVAL.
Best Regards,
- Maíra
Quoted 27 lines
drivers/gpu/drm/v3d/v3d_submit.c +10
-0+ goto error; + } } job->timestamp_query.count = timestamp.count;@@ -550,6 +554,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;@@ -613,6 +621,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;
Re: [PATCH 04/12] drm/v3d: Validate passed in drm syncobj handles in the timestamp extension
Quoted 11 lines · Maíra Canal
Quoted 6 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
I believe you mean "Fix it by checking if the handle..."
Also s/successfuly/successfully
Oops, thank you!
Quoted 12 lines
Quoted 12 lines
extension by jumping into the existing unwind.
Signed-off-by Tvrtko Ursulin <[email protected]>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(+)
Quoted 12 lines
drivers/gpu/drm/v3d/v3d_submit.c v3d_get_cpu_timestamp_query_params(struct · line 501
Quoted 10 lines
drivers/gpu/drm/v3d/v3d_submit.c +2
-0@@ -497,6 +497,10 @@ v3d_get_cpu_timestamp_query_params(structdrm_file *file_priv, } job->timestamp_query.queries[i].syncobj = drm_syncobj_find(file_priv, sync); + if (!job->timestamp_query.queries[i].syncobj) { + err = -ENOENT;I'm not sure if err should be
-ENOENTor-EINVAL, but based on other drivers, I believe it should be-EINVAL.
After a quick grep I am inclined to think ENOENT is correct. DRM core uses that, and drivers seem generally confused (split between ENOENT and EINVAL). With one even going for ENODEV!
Regards,
Tvrtko
Quoted 24 lines
Quoted 24 lines
drivers/gpu/drm/v3d/v3d_submit.c +10
-0+ goto error; + } } job->timestamp_query.count = timestamp.count;@@ -550,6 +554,10 @@ v3d_get_cpu_reset_timestamp_params(structdrm_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;@@ -613,6 +621,10 @@ v3d_get_cpu_copy_query_results_params(structdrm_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 v2 5/12 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
@@ -706,6 +706,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;
@@ -787,6 +791,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
Maíra Canal
maintainerRe: [PATCH 05/12] drm/v3d: Validate passed in drm syncobj handles in the performance extension
Quoted 22 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.
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_submit.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/gpu/drm/v3d/v3d_submit.c +0
-0
drivers/gpu/drm/v3d/v3d_submit.c v3d_get_cpu_reset_performance_params(struct drm_file *file_priv, · line 710
Quoted 5 lines
drivers/gpu/drm/v3d/v3d_submit.c +2
-0@@ -706,6 +706,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 ;
Same from previous patch.
Best Regards,
- Maíra
Quoted 16 lines
drivers/gpu/drm/v3d/v3d_submit.c +6
-0+ goto error; + } } job->performance_query.count = reset.count; job->performance_query.nperfmons = reset.nperfmons;@@ -787,6 +791,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 v2 6/12 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.
--- drivers/gpu/drm/v3d/v3d_submit.c | 148 +++++++++++++------------------ 1 file changed, 64 insertions(+), 84 deletions(-)
drivers/gpu/drm/v3d/v3d_submit.c +64 -84
@@ -641,13 +641,63 @@ v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv,return err; } +static int +copy_query_info (struct v3d_performance_query_info *qinfo, +unsigned int count, +unsigned int nperfmons, +u32 __user *syncs, +u64 __user *kperfmon_ids, +struct drm_file *fpriv) +{ +unsigned int i, j; +int err; + +for (i =0 ; i < count; i++) { +struct v3d_performance_query *query = &qinfo->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 (fpriv, sync); +if (!query->syncobj) { + err = -ENOENT ; + goto error; + } + } + +return 0 ; + +error: +__v3d_performance_query_info_free (qinfo, 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;int err;
@@ -675,50 +725,17 @@ 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 =copy_query_info (qinfo, reset.count, reset.nperfmons, +u64_to_user_ptr (reset.syncs), +u64_to_user_ptr (reset.kperfmon_ids), + file_priv); +if (err) +return err; -for (int 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 (int 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 (qinfo, i); -return err; } static int
@@ -726,8 +743,6 @@ 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;int err;
@@ -758,44 +773,13 @@ 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 =copy_query_info (qinfo, 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; - } - - job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); - -if (copy_from_user (&ids, kperfmon_ids++,sizeof (ids))) { - err = -EFAULT ; - goto error; - } - - ids_pointer =u64_to_user_ptr (ids); - -for (int 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;
@@ -807,10 +791,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 (qinfo, i); -return err; }/* Whenever userspace sets ioctl extensions, v3d_get_extensions parses data
Signature · 1 line
2.44.0
Maíra Canal
maintainerRe: [PATCH 06/12] drm/v3d: Move part of copying of reset/copy performance extension to a helper
Quoted 15 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.
Signed-off-by Tvrtko Ursulin <[email protected]>--- drivers/gpu/drm/v3d/v3d_submit.c | 148 +++++++++++++------------------ 1 file changed, 64 insertions(+), 84 deletions(-)drivers/gpu/drm/v3d/v3d_submit.c +0
-0
drivers/gpu/drm/v3d/v3d_submit.c v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv, · line 644
Quoted 4 lines
drivers/gpu/drm/v3d/v3d_submit.c +1
-0@@ -641,13 +641,63 @@ v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv,return err; } +static int
Could you prefix the name of this function with v3d_?
drivers/gpu/drm/v3d/v3d_submit.c v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv, · line 650
Quoted 6 lines
drivers/gpu/drm/v3d/v3d_submit.c +6
-0+copy_query_info(struct v3d_performance_query_info *qinfo, + unsigned int count, + unsigned int nperfmons, + u32 __user *syncs, + u64 __user *kperfmon_ids, + struct drm_file *fpriv)
Nit: s/fpriv/file_priv
drivers/gpu/drm/v3d/v3d_submit.c v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv, · line 661
Quoted 11 lines
drivers/gpu/drm/v3d/v3d_submit.c +11
-0+{ +unsigned int i, j; +int err; + +for (i =0 ; i < count; i++) { +struct v3d_performance_query *query = &qinfo->queries[i]; +u32 __user *ids_pointer; +u32 sync, id; +u64 ids; + +if (get_user (sync, syncs++)) {
Could you mention on the commit message that now you are using get_user()?
Quoted 45 lines
drivers/gpu/drm/v3d/v3d_submit.c +34
-2+ 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 (fpriv, sync); +if (!query->syncobj) { + err = -ENOENT ; + goto error; + } + } + +return 0 ; + +error: +__v3d_performance_query_info_free (qinfo, 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;int err;
drivers/gpu/drm/v3d/v3d_submit.c v3d_get_cpu_reset_performance_params(struct drm_file *file_priv, · line 731
Quoted 9 lines
drivers/gpu/drm/v3d/v3d_submit.c +4
-2@@ -675,50 +725,17 @@ 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 =copy_query_info (qinfo, reset.count, reset.nperfmons, +u64_to_user_ptr (reset.syncs), +u64_to_user_ptr (reset.kperfmon_ids), + file_priv);
I'm missing where qinfo is being declared.
Quoted 57 lines
drivers/gpu/drm/v3d/v3d_submit.c +2
-39+if (err) +return err; -for (int 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 (int 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 (qinfo, i); -return err; } static int@@ -726,8 +743,6 @@ 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;int err;
drivers/gpu/drm/v3d/v3d_submit.c v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv, · line 779
Quoted 9 lines
drivers/gpu/drm/v3d/v3d_submit.c +4
-2@@ -758,44 +773,13 @@ 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 =copy_query_info (qinfo, copy.count, copy.nperfmons, +u64_to_user_ptr (copy.syncs), +u64_to_user_ptr (copy.kperfmon_ids), + file_priv);
Same here.
Best Regards,
- Maíra
Quoted 52 lines
drivers/gpu/drm/v3d/v3d_submit.c +2
-39+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; - } - - job->performance_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); - -if (copy_from_user (&ids, kperfmon_ids++,sizeof (ids))) { - err = -EFAULT ; - goto error; - } - - ids_pointer =u64_to_user_ptr (ids); - -for (int 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;@@ -807,10 +791,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 (qinfo, i); -return err; }/* Whenever userspace sets ioctl extensions, v3d_get_extensions parses data
PATCH v2 7/12 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 *qinfo,if (qinfo->queries) {unsigned int i; -for (i =0 ; i < count; i++) +for (i =0 ; i < count; i++) {drm_syncobj_put (qinfo->queries[i].syncobj); +kvfree (qinfo->queries[i].kperfmon_ids); + }kvfree (qinfo->queries); }
drivers/gpu/drm/v3d/v3d_submit.c +11 -6
@@ -668,10 +668,20 @@ copy_query_info(struct v3d_performance_query_info *qinfo, 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; }
@@ -681,6 +691,7 @@ copy_query_info(struct v3d_performance_query_info *qinfo, query->syncobj =drm_syncobj_find (fpriv, sync);if (!query->syncobj) { +kvfree (query->kperfmon_ids); err = -ENOENT ; goto error; }
@@ -714,9 +725,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,
@@ -762,9 +770,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/12] 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 *qinfo,if (qinfo->queries) {unsigned int i; -for (i =0 ; i < count; i++) +for (i =0 ; i < count; i++) {drm_syncobj_put (qinfo->queries[i].syncobj); +kvfree (qinfo->queries[i].kperfmon_ids); + }kvfree (qinfo->queries); }drivers/gpu/drm/v3d/v3d_submit.c +11
-6@@ -668,10 +668,20 @@ copy_query_info(struct v3d_performance_query_info *qinfo, 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; }@@ -681,6 +691,7 @@ copy_query_info(struct v3d_performance_query_info *qinfo, query->syncobj =drm_syncobj_find (fpriv, sync);if (!query->syncobj) { +kvfree (query->kperfmon_ids); err = -ENOENT ; goto error; }@@ -714,9 +725,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,@@ -762,9 +770,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 v2 8/12 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
PATCH v2 9/12 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 792d16b5375d ("drm/v3d: Move perfmon init completely into own unit").
References: 792d16b5375d ("drm/v3d: Move perfmon init completely into own unit")
--- 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/12] 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
792d16b5375d("drm/v3d: Move perfmon init completely into own unit").
I believe you mean:
9c3951ec27b9 ("drm/v3d: Fix perfmon build error/warning")
Currently, it is reference the current patch.
Apart from this fix, this is
Best Regards,
- Maíra
Quoted 159 lines
Signed-off-by Tvrtko Ursulin <[email protected]>References:
792d16b5375d("drm/v3d: Move perfmon init completely into own unit")--- 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
Re: [PATCH 09/12] drm/v3d: Move perfmon init completely into own unit
Quoted 7 lines · Maíra Canal
Quoted 6 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.
Quoted 8 lines
Quoted 2 lines
This improves on the temporary fix quickly delivered in
792d16b5375d("drm/v3d: Move perfmon init completely into own unit").I believe you mean:
9c3951ec27b9("drm/v3d: Fix perfmon build error/warning")Currently, it is reference the current patch.
Well that was a hillarious mistake, well spotted!
Regards,
Tvrtko
Quoted 160 lines
Apart from this fix, this is
Reviewed-by Maíra Canal <[email protected]>Best Regards,
- MaíraQuoted 153 lines
Signed-off-by Tvrtko Ursulin <[email protected]>References:
792d16b5375d("drm/v3d: Move perfmon init completely into own unit")
---
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 +0
-0@@ -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);drivers/gpu/drm/v3d/v3d_drv.c +0
-0@@ -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 +0
-1@@ -104,10 +104,7 @@ struct v3d_dev { int ver; bool single_irq_line; - /* Different revisions of V3D have different total number ofperformance
- * counters
- */
- unsigned intmax_counters;
+ structv3d_perfmon_infoperfmon_info;
void__iomem*hub_regs;
void__iomem*core_regs[3];drivers/gpu/drm/v3d/v3d_drv.h +1
-0@@ -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 +6
-4@@ -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 */
drivers/gpu/drm/v3d/v3d_performance_counters.h +5
-1-#define V3D_MAX_COUNTERS (93) + /* + * Array of counters valid for the platform. + */ + const struct v3d_perf_counter_desc *counters; +};#endif
PATCH v2 10/12 drm/v3d: Align data types of internal and uapi counts
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
In the timestamp and performance extensions userspace type for counts is u32 so lets use unsigned in the kernel too.
--- drivers/gpu/drm/v3d/v3d_submit.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/v3d/v3d_submit.c +6 -3
@@ -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; +unsigned int i;int err;if (!job) {
@@ -481,7 +482,7 @@ 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))) {
@@ -518,6 +519,7 @@ 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) {
@@ -543,7 +545,7 @@ 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;
@@ -576,7 +578,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, err; +unsigned int i; +int err;if (!job) {DRM_DEBUG ("CPU job extension was attached to a GPU job.\n" );
Signature · 1 line
2.44.0
Re: [PATCH 10/12] drm/v3d: Align data types of internal and uapi counts
Quoted 23 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
In the timestamp and performance extensions userspace type for counts is u32 so lets use unsigned in the kernel too.
Signed-off-by Tvrtko Ursulin <[email protected]>--- drivers/gpu/drm/v3d/v3d_submit.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/gpu/drm/v3d/v3d_submit.c +1
-0@@ -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; +unsigned int i;int err;if (!job) {
drivers/gpu/drm/v3d/v3d_submit.c v3d_get_cpu_timestamp_query_params(struct drm_file *file_priv, · line 485
Quoted 5 lines
drivers/gpu/drm/v3d/v3d_submit.c +1
-1@@ -481,7 +482,7 @@ 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++) {
Can't we just replace this line for
for (u32 i = 0; i < timestamp.count; i++) {
or
for (unsigned int i = 0; i < timestamp.count; i++) {?
Well, anyway, just a minor nit, this is:
Best Regards,
- Maíra
Quoted 30 lines
drivers/gpu/drm/v3d/v3d_submit.c +4
-2u32 offset, sync;if (copy_from_user (&offset, offsets++,sizeof (offset))) {@@ -518,6 +519,7 @@ 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) {@@ -543,7 +545,7 @@ 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;@@ -576,7 +578,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, err; +unsigned int i; +int err;if (!job) {DRM_DEBUG ("CPU job extension was attached to a GPU job.\n" );
PATCH v2 11/12 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 | 79 +++++++++++++++++--------------- 1 file changed, 42 insertions(+), 37 deletions(-)
drivers/gpu/drm/v3d/v3d_submit.c +42 -37
@@ -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 *qinfo = &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) + qinfo->queries =kvmalloc_array (timestamp.count, +sizeof (struct v3d_timestamp_query ), +GFP_KERNEL ); +if (!qinfo->queries)return -ENOMEM ; offsets =u64_to_user_ptr (timestamp.offsets);
@@ -490,20 +491,20 @@ v3d_get_cpu_timestamp_query_params(struct drm_file *file_priv, goto error; } - job->timestamp_query.queries[i].offset = offset; + qinfo->queries[i].offset = offset;if (copy_from_user (&sync, syncs++,sizeof (sync))) { err = -EFAULT ; goto error; } - job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); -if (!job->timestamp_query.queries[i].syncobj) { + qinfo->queries[i].syncobj =drm_syncobj_find (file_priv, sync); +if (!qinfo->queries[i].syncobj) { err = -ENOENT ; goto error; } } - job->timestamp_query.count = timestamp.count; + qinfo->count = timestamp.count;return 0 ;
@@ -519,6 +520,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 *qinfo = &job->timestamp_query;unsigned int i;int err;
@@ -537,10 +539,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) + qinfo->queries =kvmalloc_array (reset.count, +sizeof (struct v3d_timestamp_query ), +GFP_KERNEL ); +if (!qinfo->queries)return -ENOMEM ; syncs =u64_to_user_ptr (reset.syncs);
@@ -548,20 +550,20 @@ 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; + qinfo->queries[i].offset = reset.offset +8 * i;if (copy_from_user (&sync, syncs++,sizeof (sync))) { err = -EFAULT ; goto error; } - job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); -if (!job->timestamp_query.queries[i].syncobj) { + qinfo->queries[i].syncobj =drm_syncobj_find (file_priv, sync); +if (!qinfo->queries[i].syncobj) { err = -ENOENT ; goto error; } } - job->timestamp_query.count = reset.count; + qinfo->count = reset.count;return 0 ;
@@ -578,6 +580,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 *qinfo = &job->timestamp_query;unsigned int i;int err;
@@ -599,10 +602,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) + qinfo->queries =kvmalloc_array (copy.count, +sizeof (struct v3d_timestamp_query ), +GFP_KERNEL ); +if (!qinfo->queries)return -ENOMEM ; offsets =u64_to_user_ptr (copy.offsets);
@@ -616,20 +619,20 @@ v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv, goto error; } - job->timestamp_query.queries[i].offset = offset; + qinfo->queries[i].offset = offset;if (copy_from_user (&sync, syncs++,sizeof (sync))) { err = -EFAULT ; goto error; } - job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); -if (!job->timestamp_query.queries[i].syncobj) { + qinfo->queries[i].syncobj =drm_syncobj_find (file_priv, sync); +if (!qinfo->queries[i].syncobj) { err = -ENOENT ; goto error; } } - job->timestamp_query.count = copy.count; + qinfo->count = copy.count; job->copy.do_64bit = copy.do_64bit; job->copy.do_partial = copy.do_partial;
@@ -712,6 +715,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 *qinfo = &job->performance_query;struct drm_v3d_reset_performance_query reset;int err;
@@ -730,10 +734,10 @@ 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) + qinfo->queries =kvmalloc_array (reset.count, +sizeof (struct v3d_performance_query ), +GFP_KERNEL ); +if (!qinfo->queries)return -ENOMEM ; err = copy_query_info(qinfo, reset.count, reset.nperfmons,
@@ -743,8 +747,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; + qinfo->count = reset.count; + qinfo->nperfmons = reset.nperfmons;return 0 ; }
@@ -754,6 +758,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 *qinfo = &job->performance_query;struct drm_v3d_copy_performance_query copy;int err;
@@ -775,10 +780,10 @@ 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) + qinfo->queries =kvmalloc_array (copy.count, +sizeof (struct v3d_performance_query ), +GFP_KERNEL ); +if (!qinfo->queries)return -ENOMEM ; err = copy_query_info(qinfo, copy.count, copy.nperfmons,
@@ -788,9 +793,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; + qinfo->count = copy.count; + qinfo->nperfmons = copy.nperfmons; + qinfo->ncounters = copy.ncounters; job->copy.do_64bit = copy.do_64bit; job->copy.do_partial = copy.do_partial;
Signature · 1 line
2.44.0
Re: [PATCH 11/12] drm/v3d: Add some local variables in queries/extensions
Quoted 6 lines · Tvrtko Ursulin
From: 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.
Signed-off-by Tvrtko Ursulin <[email protected]>
I'd prefer query_info, but anyway:
Best Regards,
- Maíra
Quoted 222 lines
--- drivers/gpu/drm/v3d/v3d_submit.c | 79 +++++++++++++++++--------------- 1 file changed, 42 insertions(+), 37 deletions(-)drivers/gpu/drm/v3d/v3d_submit.c +42
-37@@ -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 *qinfo = &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) + qinfo->queries =kvmalloc_array (timestamp.count, +sizeof (struct v3d_timestamp_query ), +GFP_KERNEL ); +if (!qinfo->queries)return -ENOMEM ; offsets =u64_to_user_ptr (timestamp.offsets);@@ -490,20 +491,20 @@ v3d_get_cpu_timestamp_query_params(struct drm_file *file_priv, goto error; } - job->timestamp_query.queries[i].offset = offset; + qinfo->queries[i].offset = offset;if (copy_from_user (&sync, syncs++,sizeof (sync))) { err = -EFAULT ; goto error; } - job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); -if (!job->timestamp_query.queries[i].syncobj) { + qinfo->queries[i].syncobj =drm_syncobj_find (file_priv, sync); +if (!qinfo->queries[i].syncobj) { err = -ENOENT ; goto error; } } - job->timestamp_query.count = timestamp.count; + qinfo->count = timestamp.count;return 0 ;@@ -519,6 +520,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 *qinfo = &job->timestamp_query;unsigned int i;int err;@@ -537,10 +539,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) + qinfo->queries =kvmalloc_array (reset.count, +sizeof (struct v3d_timestamp_query ), +GFP_KERNEL ); +if (!qinfo->queries)return -ENOMEM ; syncs =u64_to_user_ptr (reset.syncs);@@ -548,20 +550,20 @@ 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; + qinfo->queries[i].offset = reset.offset +8 * i;if (copy_from_user (&sync, syncs++,sizeof (sync))) { err = -EFAULT ; goto error; } - job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); -if (!job->timestamp_query.queries[i].syncobj) { + qinfo->queries[i].syncobj =drm_syncobj_find (file_priv, sync); +if (!qinfo->queries[i].syncobj) { err = -ENOENT ; goto error; } } - job->timestamp_query.count = reset.count; + qinfo->count = reset.count;return 0 ;@@ -578,6 +580,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 *qinfo = &job->timestamp_query;unsigned int i;int err;@@ -599,10 +602,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) + qinfo->queries =kvmalloc_array (copy.count, +sizeof (struct v3d_timestamp_query ), +GFP_KERNEL ); +if (!qinfo->queries)return -ENOMEM ; offsets =u64_to_user_ptr (copy.offsets);@@ -616,20 +619,20 @@ v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv, goto error; } - job->timestamp_query.queries[i].offset = offset; + qinfo->queries[i].offset = offset;if (copy_from_user (&sync, syncs++,sizeof (sync))) { err = -EFAULT ; goto error; } - job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); -if (!job->timestamp_query.queries[i].syncobj) { + qinfo->queries[i].syncobj =drm_syncobj_find (file_priv, sync); +if (!qinfo->queries[i].syncobj) { err = -ENOENT ; goto error; } } - job->timestamp_query.count = copy.count; + qinfo->count = copy.count; job->copy.do_64bit = copy.do_64bit; job->copy.do_partial = copy.do_partial;@@ -712,6 +715,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 *qinfo = &job->performance_query;struct drm_v3d_reset_performance_query reset;int err;@@ -730,10 +734,10 @@ 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) + qinfo->queries =kvmalloc_array (reset.count, +sizeof (struct v3d_performance_query ), +GFP_KERNEL ); +if (!qinfo->queries)return -ENOMEM ; err = copy_query_info(qinfo, reset.count, reset.nperfmons,@@ -743,8 +747,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; + qinfo->count = reset.count; + qinfo->nperfmons = reset.nperfmons;return 0 ; }@@ -754,6 +758,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 *qinfo = &job->performance_query;struct drm_v3d_copy_performance_query copy;int err;@@ -775,10 +780,10 @@ 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) + qinfo->queries =kvmalloc_array (copy.count, +sizeof (struct v3d_performance_query ), +GFP_KERNEL ); +if (!qinfo->queries)return -ENOMEM ; err = copy_query_info(qinfo, copy.count, copy.nperfmons,@@ -788,9 +793,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; + qinfo->count = copy.count; + qinfo->nperfmons = copy.nperfmons; + qinfo->ncounters = copy.ncounters; job->copy.do_64bit = copy.do_64bit; job->copy.do_partial = copy.do_partial;
Re: [PATCH 11/12] drm/v3d: Add some local variables in queries/extensions
Quoted 9 lines · Maíra Canal
Quoted 6 lines · Tvrtko Ursulin
From: 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.
Signed-off-by Tvrtko Ursulin <[email protected]>I'd prefer
query_info, but anyway:
Yeah it does look nicer - done throughout the series.
I also bumped this patch to be last in the series since I don't "believe" in it that much any more. We probably should drop it.
Regards,
Tvrtko
Quoted 207 lines
Reviewed-by Maíra Canal <[email protected]>Best Regards,
- MaíraQuoted 202 lines
---
drivers/gpu/drm/v3d/v3d_submit.c| 79 +++++++++++++++++---------------1 file changed, 42 insertions(+), 37 deletions(-)drivers/gpu/drm/v3d/v3d_submit.c +42
-37@@ -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 *qinfo = &job->timestamp_query; unsigned int i; int err;@@ -473,10 +474,10 @@ v3d_get_cpu_timestamp_query_params(structdrm_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) + qinfo->queries = kvmalloc_array(timestamp.count, + sizeof(struct v3d_timestamp_query), + GFP_KERNEL); + if (!qinfo->queries) return -ENOMEM; offsets = u64_to_user_ptr(timestamp.offsets);@@ -490,20 +491,20 @@ v3d_get_cpu_timestamp_query_params(structdrm_file *file_priv, goto error; } - job->timestamp_query.queries[i].offset = offset; + qinfo->queries[i].offset = offset; if (copy_from_user(&sync, syncs++, sizeof(sync))) { err = -EFAULT; goto error; } - job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); - if (!job->timestamp_query.queries[i].syncobj) { + qinfo->queries[i].syncobj = drm_syncobj_find(file_priv, sync); + if (!qinfo->queries[i].syncobj) { err = -ENOENT; goto error; } } - job->timestamp_query.count = timestamp.count; + qinfo->count = timestamp.count; return 0;@@ -519,6 +520,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 *qinfo = &job->timestamp_query; unsigned int i; int err;@@ -537,10 +539,10 @@ v3d_get_cpu_reset_timestamp_params(structdrm_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) + qinfo->queries = kvmalloc_array(reset.count, + sizeof(struct v3d_timestamp_query), + GFP_KERNEL); + if (!qinfo->queries) return -ENOMEM; syncs = u64_to_user_ptr(reset.syncs);@@ -548,20 +550,20 @@ 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; + qinfo->queries[i].offset = reset.offset + 8 * i; if (copy_from_user(&sync, syncs++, sizeof(sync))) { err = -EFAULT; goto error; } - job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); - if (!job->timestamp_query.queries[i].syncobj) { + qinfo->queries[i].syncobj = drm_syncobj_find(file_priv, sync); + if (!qinfo->queries[i].syncobj) { err = -ENOENT; goto error; } } - job->timestamp_query.count = reset.count; + qinfo->count = reset.count; return 0;@@ -578,6 +580,7 @@ v3d_get_cpu_copy_query_results_params(structdrm_file *file_priv, { u32 __user *offsets, *syncs; struct drm_v3d_copy_timestamp_query copy; + struct v3d_timestamp_query_info *qinfo = &job->timestamp_query; unsigned int i; int err;@@ -599,10 +602,10 @@ v3d_get_cpu_copy_query_results_params(structdrm_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) + qinfo->queries = kvmalloc_array(copy.count, + sizeof(struct v3d_timestamp_query), + GFP_KERNEL); + if (!qinfo->queries) return -ENOMEM; offsets = u64_to_user_ptr(copy.offsets);@@ -616,20 +619,20 @@ v3d_get_cpu_copy_query_results_params(structdrm_file *file_priv, goto error; } - job->timestamp_query.queries[i].offset = offset; + qinfo->queries[i].offset = offset; if (copy_from_user(&sync, syncs++, sizeof(sync))) { err = -EFAULT; goto error; } - job->timestamp_query.queries[i].syncobj =drm_syncobj_find (file_priv, sync); - if (!job->timestamp_query.queries[i].syncobj) { + qinfo->queries[i].syncobj = drm_syncobj_find(file_priv, sync); + if (!qinfo->queries[i].syncobj) { err = -ENOENT; goto error; } } - job->timestamp_query.count = copy.count; + qinfo->count = copy.count; job->copy.do_64bit = copy.do_64bit; job->copy.do_partial = copy.do_partial;@@ -712,6 +715,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 *qinfo = &job->performance_query; struct drm_v3d_reset_performance_query reset; int err;@@ -730,10 +734,10 @@ v3d_get_cpu_reset_performance_params(structdrm_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) + qinfo->queries = kvmalloc_array(reset.count, + sizeof(struct v3d_performance_query), + GFP_KERNEL); + if (!qinfo->queries) return -ENOMEM; err = copy_query_info(qinfo, reset.count, reset.nperfmons,@@ -743,8 +747,8 @@ v3d_get_cpu_reset_performance_params(structdrm_file *file_priv, if (err) return err; - job->performance_query.count = reset.count; - job->performance_query.nperfmons = reset.nperfmons; + qinfo->count = reset.count; + qinfo->nperfmons = reset.nperfmons; return 0; }@@ -754,6 +758,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 *qinfo = &job->performance_query; struct drm_v3d_copy_performance_query copy; int err;@@ -775,10 +780,10 @@ v3d_get_cpu_copy_performance_query_params(structdrm_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) + qinfo->queries = kvmalloc_array(copy.count, + sizeof(struct v3d_performance_query), + GFP_KERNEL); + if (!qinfo->queries) return -ENOMEM; err = copy_query_info(qinfo, copy.count, copy.nperfmons,@@ -788,9 +793,9 @@ v3d_get_cpu_copy_performance_query_params(structdrm_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; + qinfo->count = copy.count; + qinfo->nperfmons = copy.nperfmons; + qinfo->ncounters = copy.ncounters; job->copy.do_64bit = copy.do_64bit; job->copy.do_partial = copy.do_partial;
PATCH v2 12/12 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
@@ -486,14 +486,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; } qinfo->queries[i].offset = offset; -if (copy_from_user (&sync, syncs++,sizeof (sync))) { +if (get_user (sync, syncs++)) { err = -EFAULT ; goto error; }
@@ -552,7 +552,7 @@ v3d_get_cpu_reset_timestamp_params(struct drm_file *file_priv, qinfo->queries[i].offset = reset.offset +8 * i; -if (copy_from_user (&sync, syncs++,sizeof (sync))) { +if (get_user (sync, syncs++)) { err = -EFAULT ; goto error; }
@@ -614,14 +614,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; } qinfo->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
Re: [PATCH 12/12] drm/v3d: Prefer get_user for scalar types
Quoted 5 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
It makes it just a tiny bit more obvious what is going on.
Signed-off-by Tvrtko Ursulin <[email protected]>
Best Regards,
- Maíra
Quoted 51 lines
--- drivers/gpu/drm/v3d/v3d_submit.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/gpu/drm/v3d/v3d_submit.c +5
-5@@ -486,14 +486,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; } qinfo->queries[i].offset = offset; -if (copy_from_user (&sync, syncs++,sizeof (sync))) { +if (get_user (sync, syncs++)) { err = -EFAULT ; goto error; }@@ -552,7 +552,7 @@ v3d_get_cpu_reset_timestamp_params(struct drm_file *file_priv, qinfo->queries[i].offset = reset.offset +8 * i; -if (copy_from_user (&sync, syncs++,sizeof (sync))) { +if (get_user (sync, syncs++)) { err = -EFAULT ; goto error; }@@ -614,14 +614,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; } qinfo->queries[i].offset = offset; -if (copy_from_user (&sync, syncs++,sizeof (sync))) { +if (get_user (sync, syncs++)) { err = -EFAULT ; goto error; }