netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] drm/nouveau: Don't set signaled fences' error codes
@ 2025-04-15 12:18 Philipp Stanner
  2025-04-15 12:19 ` [PATCH v2 1/2] drm/nouveau: Fix WARN_ON in nouveau_fence_context_kill() Philipp Stanner
  2025-04-15 12:19 ` [PATCH v2 2/2] drm/nouveau: nouveau_fence: Standardize list iterations Philipp Stanner
  0 siblings, 2 replies; 6+ messages in thread
From: Philipp Stanner @ 2025-04-15 12:18 UTC (permalink / raw)
  To: Lyude Paul, Danilo Krummrich, David Airlie, Simona Vetter,
	Sabrina Dubroca, Sumit Semwal, Christian König
  Cc: dri-devel, nouveau, linux-kernel, netdev, linux-media,
	linaro-mm-sig, Philipp Stanner

Changes in v2:
  - Only fix the issue by checking for a fence being signaled in
    nouveau_fence_context_kill(), before setting the fence's error.
    (Christian, Danilo)
  - Drop cleanup patches. Instead, idiomaticize for-each-loops.

Was called "Fix & improve nouveau_fence_done()" before.

I've tested this with KASAN & kmemleak.

P.

Philipp Stanner (2):
  drm/nouveau: Fix WARN_ON in nouveau_fence_context_kill()
  drm/nouveau: nouveau_fence: Standardize list iterations

 drivers/gpu/drm/nouveau/nouveau_fence.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

-- 
2.48.1


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

* [PATCH v2 1/2] drm/nouveau: Fix WARN_ON in nouveau_fence_context_kill()
  2025-04-15 12:18 [PATCH v2 0/2] drm/nouveau: Don't set signaled fences' error codes Philipp Stanner
@ 2025-04-15 12:19 ` Philipp Stanner
  2025-04-23 15:54   ` Danilo Krummrich
  2025-04-15 12:19 ` [PATCH v2 2/2] drm/nouveau: nouveau_fence: Standardize list iterations Philipp Stanner
  1 sibling, 1 reply; 6+ messages in thread
From: Philipp Stanner @ 2025-04-15 12:19 UTC (permalink / raw)
  To: Lyude Paul, Danilo Krummrich, David Airlie, Simona Vetter,
	Sabrina Dubroca, Sumit Semwal, Christian König
  Cc: dri-devel, nouveau, linux-kernel, netdev, linux-media,
	linaro-mm-sig, Philipp Stanner, stable

Nouveau is mostly designed in a way that it's expected that fences only
ever get signaled through nouveau_fence_signal(). However, in at least
one other place, nouveau_fence_done(), can signal fences, too. If that
happens (race) a signaled fence remains in the pending list for a while,
until it gets removed by nouveau_fence_update().

Should nouveau_fence_context_kill() run in the meantime, this would be
a bug because the function would attempt to set an error code on an
already signaled fence.

Have nouveau_fence_context_kill() check for a fence being signaled.

Cc: <stable@vger.kernel.org> # v5.10+
Fixes: ea13e5abf807 ("drm/nouveau: signal pending fences when channel has been killed")
Suggested-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
 drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
index 7622587f149e..6ded8c2b6d3b 100644
--- a/drivers/gpu/drm/nouveau/nouveau_fence.c
+++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
@@ -90,7 +90,7 @@ nouveau_fence_context_kill(struct nouveau_fence_chan *fctx, int error)
 	while (!list_empty(&fctx->pending)) {
 		fence = list_entry(fctx->pending.next, typeof(*fence), head);
 
-		if (error)
+		if (error && !dma_fence_is_signaled_locked(&fence->base))
 			dma_fence_set_error(&fence->base, error);
 
 		if (nouveau_fence_signal(fence))
-- 
2.48.1


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

* [PATCH v2 2/2] drm/nouveau: nouveau_fence: Standardize list iterations
  2025-04-15 12:18 [PATCH v2 0/2] drm/nouveau: Don't set signaled fences' error codes Philipp Stanner
  2025-04-15 12:19 ` [PATCH v2 1/2] drm/nouveau: Fix WARN_ON in nouveau_fence_context_kill() Philipp Stanner
@ 2025-04-15 12:19 ` Philipp Stanner
  2025-04-15 12:28   ` Christian König
  2025-04-23 15:26   ` Danilo Krummrich
  1 sibling, 2 replies; 6+ messages in thread
From: Philipp Stanner @ 2025-04-15 12:19 UTC (permalink / raw)
  To: Lyude Paul, Danilo Krummrich, David Airlie, Simona Vetter,
	Sabrina Dubroca, Sumit Semwal, Christian König
  Cc: dri-devel, nouveau, linux-kernel, netdev, linux-media,
	linaro-mm-sig, Philipp Stanner

nouveau_fence.c iterates over lists in a non-canonical way. Since the
operations done are just basic for-each-loops, they should be written in
the standard form.

Use for_each_safe() instead of the custom loop iterations.

Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
 drivers/gpu/drm/nouveau/nouveau_fence.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
index 6ded8c2b6d3b..60d961b43488 100644
--- a/drivers/gpu/drm/nouveau/nouveau_fence.c
+++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
@@ -84,11 +84,12 @@ void
 nouveau_fence_context_kill(struct nouveau_fence_chan *fctx, int error)
 {
 	struct nouveau_fence *fence;
+	struct list_head *pos, *tmp;
 	unsigned long flags;
 
 	spin_lock_irqsave(&fctx->lock, flags);
-	while (!list_empty(&fctx->pending)) {
-		fence = list_entry(fctx->pending.next, typeof(*fence), head);
+	list_for_each_safe(pos, tmp, &fctx->pending) {
+		fence = list_entry(pos, struct nouveau_fence, head);
 
 		if (error && !dma_fence_is_signaled_locked(&fence->base))
 			dma_fence_set_error(&fence->base, error);
@@ -131,11 +132,12 @@ static int
 nouveau_fence_update(struct nouveau_channel *chan, struct nouveau_fence_chan *fctx)
 {
 	struct nouveau_fence *fence;
+	struct list_head *pos, *tmp;
 	int drop = 0;
 	u32 seq = fctx->read(chan);
 
-	while (!list_empty(&fctx->pending)) {
-		fence = list_entry(fctx->pending.next, typeof(*fence), head);
+	list_for_each_safe(pos, tmp, &fctx->pending) {
+		fence = list_entry(pos, struct nouveau_fence, head);
 
 		if ((int)(seq - fence->base.seqno) < 0)
 			break;
-- 
2.48.1


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

* Re: [PATCH v2 2/2] drm/nouveau: nouveau_fence: Standardize list iterations
  2025-04-15 12:19 ` [PATCH v2 2/2] drm/nouveau: nouveau_fence: Standardize list iterations Philipp Stanner
@ 2025-04-15 12:28   ` Christian König
  2025-04-23 15:26   ` Danilo Krummrich
  1 sibling, 0 replies; 6+ messages in thread
From: Christian König @ 2025-04-15 12:28 UTC (permalink / raw)
  To: Philipp Stanner, Lyude Paul, Danilo Krummrich, David Airlie,
	Simona Vetter, Sabrina Dubroca, Sumit Semwal
  Cc: dri-devel, nouveau, linux-kernel, netdev, linux-media,
	linaro-mm-sig

Am 15.04.25 um 14:19 schrieb Philipp Stanner:
> nouveau_fence.c iterates over lists in a non-canonical way. Since the
> operations done are just basic for-each-loops, they should be written in
> the standard form.
>
> Use for_each_safe() instead of the custom loop iterations.
>
> Signed-off-by: Philipp Stanner <phasta@kernel.org>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>  drivers/gpu/drm/nouveau/nouveau_fence.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
> index 6ded8c2b6d3b..60d961b43488 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
> @@ -84,11 +84,12 @@ void
>  nouveau_fence_context_kill(struct nouveau_fence_chan *fctx, int error)
>  {
>  	struct nouveau_fence *fence;
> +	struct list_head *pos, *tmp;
>  	unsigned long flags;
>  
>  	spin_lock_irqsave(&fctx->lock, flags);
> -	while (!list_empty(&fctx->pending)) {
> -		fence = list_entry(fctx->pending.next, typeof(*fence), head);
> +	list_for_each_safe(pos, tmp, &fctx->pending) {
> +		fence = list_entry(pos, struct nouveau_fence, head);
>  
>  		if (error && !dma_fence_is_signaled_locked(&fence->base))
>  			dma_fence_set_error(&fence->base, error);
> @@ -131,11 +132,12 @@ static int
>  nouveau_fence_update(struct nouveau_channel *chan, struct nouveau_fence_chan *fctx)
>  {
>  	struct nouveau_fence *fence;
> +	struct list_head *pos, *tmp;
>  	int drop = 0;
>  	u32 seq = fctx->read(chan);
>  
> -	while (!list_empty(&fctx->pending)) {
> -		fence = list_entry(fctx->pending.next, typeof(*fence), head);
> +	list_for_each_safe(pos, tmp, &fctx->pending) {
> +		fence = list_entry(pos, struct nouveau_fence, head);
>  
>  		if ((int)(seq - fence->base.seqno) < 0)
>  			break;


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

* Re: [PATCH v2 2/2] drm/nouveau: nouveau_fence: Standardize list iterations
  2025-04-15 12:19 ` [PATCH v2 2/2] drm/nouveau: nouveau_fence: Standardize list iterations Philipp Stanner
  2025-04-15 12:28   ` Christian König
@ 2025-04-23 15:26   ` Danilo Krummrich
  1 sibling, 0 replies; 6+ messages in thread
From: Danilo Krummrich @ 2025-04-23 15:26 UTC (permalink / raw)
  To: Philipp Stanner
  Cc: Lyude Paul, David Airlie, Simona Vetter, Sabrina Dubroca,
	Sumit Semwal, Christian König, dri-devel, nouveau,
	linux-kernel, netdev, linux-media, linaro-mm-sig

On Tue, Apr 15, 2025 at 02:19:01PM +0200, Philipp Stanner wrote:
> nouveau_fence.c iterates over lists in a non-canonical way. Since the
> operations done are just basic for-each-loops, they should be written in
> the standard form.
> 
> Use for_each_safe() instead of the custom loop iterations.

Please use list_for_each_entry_safe() instead.

You only need resend this patch, I will pick patch 1 for -fixes; this one goes
into -next.

- Danilo

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

* Re: [PATCH v2 1/2] drm/nouveau: Fix WARN_ON in nouveau_fence_context_kill()
  2025-04-15 12:19 ` [PATCH v2 1/2] drm/nouveau: Fix WARN_ON in nouveau_fence_context_kill() Philipp Stanner
@ 2025-04-23 15:54   ` Danilo Krummrich
  0 siblings, 0 replies; 6+ messages in thread
From: Danilo Krummrich @ 2025-04-23 15:54 UTC (permalink / raw)
  To: Philipp Stanner
  Cc: Lyude Paul, David Airlie, Simona Vetter, Sabrina Dubroca,
	Sumit Semwal, Christian König, dri-devel, nouveau,
	linux-kernel, netdev, linux-media, linaro-mm-sig, stable

On Tue, Apr 15, 2025 at 02:19:00PM +0200, Philipp Stanner wrote:
> Nouveau is mostly designed in a way that it's expected that fences only
> ever get signaled through nouveau_fence_signal(). However, in at least
> one other place, nouveau_fence_done(), can signal fences, too. If that
> happens (race) a signaled fence remains in the pending list for a while,
> until it gets removed by nouveau_fence_update().
> 
> Should nouveau_fence_context_kill() run in the meantime, this would be
> a bug because the function would attempt to set an error code on an
> already signaled fence.
> 
> Have nouveau_fence_context_kill() check for a fence being signaled.
> 
> Cc: <stable@vger.kernel.org> # v5.10+
> Fixes: ea13e5abf807 ("drm/nouveau: signal pending fences when channel has been killed")
> Suggested-by: Christian König <christian.koenig@amd.com>
> Signed-off-by: Philipp Stanner <phasta@kernel.org>

Applied to drm-misc-fixes, thanks!

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

end of thread, other threads:[~2025-04-23 15:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-15 12:18 [PATCH v2 0/2] drm/nouveau: Don't set signaled fences' error codes Philipp Stanner
2025-04-15 12:19 ` [PATCH v2 1/2] drm/nouveau: Fix WARN_ON in nouveau_fence_context_kill() Philipp Stanner
2025-04-23 15:54   ` Danilo Krummrich
2025-04-15 12:19 ` [PATCH v2 2/2] drm/nouveau: nouveau_fence: Standardize list iterations Philipp Stanner
2025-04-15 12:28   ` Christian König
2025-04-23 15:26   ` Danilo Krummrich

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).