stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] drm/panthor: Replace sleep locks with spinlocks in fdinfo" failed to apply to 6.13-stable tree
@ 2025-04-09 10:37 gregkh
  2025-04-11 23:08 ` [PATCH 6.13.y] drm/panthor: Replace sleep locks with spinlocks in fdinfo path Adrián Larumbe
  0 siblings, 1 reply; 4+ messages in thread
From: gregkh @ 2025-04-09 10:37 UTC (permalink / raw)
  To: adrian.larumbe, boris.brezillon, liviu.dudau, steven.price; +Cc: stable


The patch below does not apply to the 6.13-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.13.y
git checkout FETCH_HEAD
git cherry-pick -x e379856b428acafb8ed689f31d65814da6447b2e
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2025040916-appraiser-chute-b24d@gregkh' --subject-prefix 'PATCH 6.13.y' HEAD^..

Possible dependencies:



thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From e379856b428acafb8ed689f31d65814da6447b2e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adri=C3=A1n=20Larumbe?= <adrian.larumbe@collabora.com>
Date: Mon, 3 Mar 2025 19:08:45 +0000
Subject: [PATCH] drm/panthor: Replace sleep locks with spinlocks in fdinfo
 path
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Commit 0590c94c3596 ("drm/panthor: Fix race condition when gathering fdinfo
group samples") introduced an xarray lock to deal with potential
use-after-free errors when accessing groups fdinfo figures. However, this
toggles the kernel's atomic context status, so the next nested mutex lock
will raise a warning when the kernel is compiled with mutex debug options:

CONFIG_DEBUG_RT_MUTEXES=y
CONFIG_DEBUG_MUTEXES=y

Replace Panthor's group fdinfo data mutex with a guarded spinlock.

Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
Fixes: 0590c94c3596 ("drm/panthor: Fix race condition when gathering fdinfo group samples")
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Signed-off-by: Steven Price <steven.price@arm.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250303190923.1639985-1-adrian.larumbe@collabora.com

diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index 1a276db095ff..4d31d1967716 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -9,6 +9,7 @@
 #include <drm/panthor_drm.h>
 
 #include <linux/build_bug.h>
+#include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
@@ -631,10 +632,10 @@ struct panthor_group {
 		struct panthor_gpu_usage data;
 
 		/**
-		 * @lock: Mutex to govern concurrent access from drm file's fdinfo callback
-		 * and job post-completion processing function
+		 * @fdinfo.lock: Spinlock to govern concurrent access from drm file's fdinfo
+		 * callback and job post-completion processing function
 		 */
-		struct mutex lock;
+		spinlock_t lock;
 
 		/** @fdinfo.kbo_sizes: Aggregate size of private kernel BO's held by the group. */
 		size_t kbo_sizes;
@@ -910,8 +911,6 @@ static void group_release_work(struct work_struct *work)
 						   release_work);
 	u32 i;
 
-	mutex_destroy(&group->fdinfo.lock);
-
 	for (i = 0; i < group->queue_count; i++)
 		group_free_queue(group, group->queues[i]);
 
@@ -2861,12 +2860,12 @@ static void update_fdinfo_stats(struct panthor_job *job)
 	struct panthor_job_profiling_data *slots = queue->profiling.slots->kmap;
 	struct panthor_job_profiling_data *data = &slots[job->profiling.slot];
 
-	mutex_lock(&group->fdinfo.lock);
-	if (job->profiling.mask & PANTHOR_DEVICE_PROFILING_CYCLES)
-		fdinfo->cycles += data->cycles.after - data->cycles.before;
-	if (job->profiling.mask & PANTHOR_DEVICE_PROFILING_TIMESTAMP)
-		fdinfo->time += data->time.after - data->time.before;
-	mutex_unlock(&group->fdinfo.lock);
+	scoped_guard(spinlock, &group->fdinfo.lock) {
+		if (job->profiling.mask & PANTHOR_DEVICE_PROFILING_CYCLES)
+			fdinfo->cycles += data->cycles.after - data->cycles.before;
+		if (job->profiling.mask & PANTHOR_DEVICE_PROFILING_TIMESTAMP)
+			fdinfo->time += data->time.after - data->time.before;
+	}
 }
 
 void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile)
@@ -2880,12 +2879,11 @@ void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile)
 
 	xa_lock(&gpool->xa);
 	xa_for_each(&gpool->xa, i, group) {
-		mutex_lock(&group->fdinfo.lock);
+		guard(spinlock)(&group->fdinfo.lock);
 		pfile->stats.cycles += group->fdinfo.data.cycles;
 		pfile->stats.time += group->fdinfo.data.time;
 		group->fdinfo.data.cycles = 0;
 		group->fdinfo.data.time = 0;
-		mutex_unlock(&group->fdinfo.lock);
 	}
 	xa_unlock(&gpool->xa);
 }
@@ -3537,7 +3535,7 @@ int panthor_group_create(struct panthor_file *pfile,
 	mutex_unlock(&sched->reset.lock);
 
 	add_group_kbo_sizes(group->ptdev, group);
-	mutex_init(&group->fdinfo.lock);
+	spin_lock_init(&group->fdinfo.lock);
 
 	return gid;
 


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 6.13.y] drm/panthor: Replace sleep locks with spinlocks in fdinfo path
  2025-04-09 10:37 FAILED: patch "[PATCH] drm/panthor: Replace sleep locks with spinlocks in fdinfo" failed to apply to 6.13-stable tree gregkh
@ 2025-04-11 23:08 ` Adrián Larumbe
  2025-04-13 16:46   ` Sasha Levin
  2025-04-17 14:20   ` Greg KH
  0 siblings, 2 replies; 4+ messages in thread
From: Adrián Larumbe @ 2025-04-11 23:08 UTC (permalink / raw)
  To: stable; +Cc: Adrián Larumbe, Liviu Dudau, Boris Brezillon, Steven Price

Commit 0590c94c3596 ("drm/panthor: Fix race condition when gathering fdinfo
group samples") introduced an xarray lock to deal with potential
use-after-free errors when accessing groups fdinfo figures. However, this
toggles the kernel's atomic context status, so the next nested mutex lock
will raise a warning when the kernel is compiled with mutex debug options:

CONFIG_DEBUG_RT_MUTEXES=y
CONFIG_DEBUG_MUTEXES=y

Replace Panthor's group fdinfo data mutex with a guarded spinlock.

Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
Fixes: 0590c94c3596 ("drm/panthor: Fix race condition when gathering fdinfo group samples")
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Signed-off-by: Steven Price <steven.price@arm.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250303190923.1639985-1-adrian.larumbe@collabora.com
(cherry picked from commit e379856b428acafb8ed689f31d65814da6447b2e)
---
 drivers/gpu/drm/panthor/panthor_sched.c | 28 ++++++++++++-------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index eb2c2ca375d7..52b5543acc19 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -9,6 +9,7 @@
 #include <drm/panthor_drm.h>
 
 #include <linux/build_bug.h>
+#include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
@@ -620,14 +621,14 @@ struct panthor_group {
 
 	/** @fdinfo: Per-file total cycle and timestamp values reference. */
 	struct {
-		/** @data: Total sampled values for jobs in queues from this group. */
+		/** @fdinfo.data: Total sampled values for jobs in queues from this group. */
 		struct panthor_gpu_usage data;
 
 		/**
-		 * @lock: Mutex to govern concurrent access from drm file's fdinfo callback
-		 * and job post-completion processing function
+		 * @fdinfo.lock: Spinlock to govern concurrent access from drm file's fdinfo
+		 * callback and job post-completion processing function
 		 */
-		struct mutex lock;
+		spinlock_t lock;
 	} fdinfo;
 
 	/** @state: Group state. */
@@ -900,8 +901,6 @@ static void group_release_work(struct work_struct *work)
 						   release_work);
 	u32 i;
 
-	mutex_destroy(&group->fdinfo.lock);
-
 	for (i = 0; i < group->queue_count; i++)
 		group_free_queue(group, group->queues[i]);
 
@@ -2845,12 +2844,12 @@ static void update_fdinfo_stats(struct panthor_job *job)
 	struct panthor_job_profiling_data *slots = queue->profiling.slots->kmap;
 	struct panthor_job_profiling_data *data = &slots[job->profiling.slot];
 
-	mutex_lock(&group->fdinfo.lock);
-	if (job->profiling.mask & PANTHOR_DEVICE_PROFILING_CYCLES)
-		fdinfo->cycles += data->cycles.after - data->cycles.before;
-	if (job->profiling.mask & PANTHOR_DEVICE_PROFILING_TIMESTAMP)
-		fdinfo->time += data->time.after - data->time.before;
-	mutex_unlock(&group->fdinfo.lock);
+	scoped_guard(spinlock, &group->fdinfo.lock) {
+		if (job->profiling.mask & PANTHOR_DEVICE_PROFILING_CYCLES)
+			fdinfo->cycles += data->cycles.after - data->cycles.before;
+		if (job->profiling.mask & PANTHOR_DEVICE_PROFILING_TIMESTAMP)
+			fdinfo->time += data->time.after - data->time.before;
+	}
 }
 
 void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile)
@@ -2864,12 +2863,11 @@ void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile)
 
 	xa_lock(&gpool->xa);
 	xa_for_each(&gpool->xa, i, group) {
-		mutex_lock(&group->fdinfo.lock);
+		guard(spinlock)(&group->fdinfo.lock);
 		pfile->stats.cycles += group->fdinfo.data.cycles;
 		pfile->stats.time += group->fdinfo.data.time;
 		group->fdinfo.data.cycles = 0;
 		group->fdinfo.data.time = 0;
-		mutex_unlock(&group->fdinfo.lock);
 	}
 	xa_unlock(&gpool->xa);
 }
@@ -3491,7 +3489,7 @@ int panthor_group_create(struct panthor_file *pfile,
 	}
 	mutex_unlock(&sched->reset.lock);
 
-	mutex_init(&group->fdinfo.lock);
+	spin_lock_init(&group->fdinfo.lock);
 
 	return gid;
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 6.13.y] drm/panthor: Replace sleep locks with spinlocks in fdinfo path
  2025-04-11 23:08 ` [PATCH 6.13.y] drm/panthor: Replace sleep locks with spinlocks in fdinfo path Adrián Larumbe
@ 2025-04-13 16:46   ` Sasha Levin
  2025-04-17 14:20   ` Greg KH
  1 sibling, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2025-04-13 16:46 UTC (permalink / raw)
  To: stable, adrian.larumbe; +Cc: Sasha Levin

[ Sasha's backport helper bot ]

Hi,

Summary of potential issues:
⚠️ Found matching upstream commit but patch is missing proper reference to it

Found matching upstream commit: e379856b428acafb8ed689f31d65814da6447b2e

Status in newer kernel trees:
6.14.y | Present (different SHA1: 446311aa801c)

Note: The patch differs from the upstream commit:
---
1:  e379856b428ac ! 1:  f19951b3eb02d drm/panthor: Replace sleep locks with spinlocks in fdinfo path
    @@ Commit message
         Reviewed-by: Steven Price <steven.price@arm.com>
         Signed-off-by: Steven Price <steven.price@arm.com>
         Link: https://patchwork.freedesktop.org/patch/msgid/20250303190923.1639985-1-adrian.larumbe@collabora.com
    +    (cherry picked from commit e379856b428acafb8ed689f31d65814da6447b2e)
     
      ## drivers/gpu/drm/panthor/panthor_sched.c ##
     @@
    @@ drivers/gpu/drm/panthor/panthor_sched.c
      #include <linux/delay.h>
      #include <linux/dma-mapping.h>
     @@ drivers/gpu/drm/panthor/panthor_sched.c: struct panthor_group {
    + 
    + 	/** @fdinfo: Per-file total cycle and timestamp values reference. */
    + 	struct {
    +-		/** @data: Total sampled values for jobs in queues from this group. */
    ++		/** @fdinfo.data: Total sampled values for jobs in queues from this group. */
      		struct panthor_gpu_usage data;
      
      		/**
    @@ drivers/gpu/drm/panthor/panthor_sched.c: struct panthor_group {
      		 */
     -		struct mutex lock;
     +		spinlock_t lock;
    + 	} fdinfo;
      
    - 		/** @fdinfo.kbo_sizes: Aggregate size of private kernel BO's held by the group. */
    - 		size_t kbo_sizes;
    + 	/** @state: Group state. */
     @@ drivers/gpu/drm/panthor/panthor_sched.c: static void group_release_work(struct work_struct *work)
      						   release_work);
      	u32 i;
    @@ drivers/gpu/drm/panthor/panthor_sched.c: void panthor_fdinfo_gather_group_sample
      	xa_unlock(&gpool->xa);
      }
     @@ drivers/gpu/drm/panthor/panthor_sched.c: int panthor_group_create(struct panthor_file *pfile,
    + 	}
      	mutex_unlock(&sched->reset.lock);
      
    - 	add_group_kbo_sizes(group->ptdev, group);
     -	mutex_init(&group->fdinfo.lock);
     +	spin_lock_init(&group->fdinfo.lock);
      
---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.13.y       |  Success    |  Success   |

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 6.13.y] drm/panthor: Replace sleep locks with spinlocks in fdinfo path
  2025-04-11 23:08 ` [PATCH 6.13.y] drm/panthor: Replace sleep locks with spinlocks in fdinfo path Adrián Larumbe
  2025-04-13 16:46   ` Sasha Levin
@ 2025-04-17 14:20   ` Greg KH
  1 sibling, 0 replies; 4+ messages in thread
From: Greg KH @ 2025-04-17 14:20 UTC (permalink / raw)
  To: Adrián Larumbe; +Cc: stable, Liviu Dudau, Boris Brezillon, Steven Price

On Sat, Apr 12, 2025 at 12:08:03AM +0100, Adrián Larumbe wrote:
> Commit 0590c94c3596 ("drm/panthor: Fix race condition when gathering fdinfo
> group samples") introduced an xarray lock to deal with potential
> use-after-free errors when accessing groups fdinfo figures. However, this
> toggles the kernel's atomic context status, so the next nested mutex lock
> will raise a warning when the kernel is compiled with mutex debug options:
> 
> CONFIG_DEBUG_RT_MUTEXES=y
> CONFIG_DEBUG_MUTEXES=y
> 
> Replace Panthor's group fdinfo data mutex with a guarded spinlock.
> 
> Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
> Fixes: 0590c94c3596 ("drm/panthor: Fix race condition when gathering fdinfo group samples")
> Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
> Reviewed-by: Steven Price <steven.price@arm.com>
> Signed-off-by: Steven Price <steven.price@arm.com>
> Link: https://patchwork.freedesktop.org/patch/msgid/20250303190923.1639985-1-adrian.larumbe@collabora.com
> (cherry picked from commit e379856b428acafb8ed689f31d65814da6447b2e)
> ---
>  drivers/gpu/drm/panthor/panthor_sched.c | 28 ++++++++++++-------------
>  1 file changed, 13 insertions(+), 15 deletions(-)

Does not apply at all, did something get corrupted?

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-04-17 14:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-09 10:37 FAILED: patch "[PATCH] drm/panthor: Replace sleep locks with spinlocks in fdinfo" failed to apply to 6.13-stable tree gregkh
2025-04-11 23:08 ` [PATCH 6.13.y] drm/panthor: Replace sleep locks with spinlocks in fdinfo path Adrián Larumbe
2025-04-13 16:46   ` Sasha Levin
2025-04-17 14:20   ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).