Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: Matthew Brost <matthew.brost@intel.com>, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 1/2] drm/xe: Take a reference in xe_exec_queue_last_fence_get()
Date: Thu, 1 Feb 2024 20:15:40 +0100	[thread overview]
Message-ID: <384d6d2f-8edc-427c-a519-134c41eb699d@linux.intel.com> (raw)
In-Reply-To: <20240201004849.2219558-2-matthew.brost@intel.com>

Hey,

On 2024-02-01 01:48, Matthew Brost wrote:
> Take a reference in xe_exec_queue_last_fence_get(). Also fix a reference
> counting underflow bug VM bind and unbind.
> 
> Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
> Signed-off-by: Matthew Brost <matthew.brost@intel.com>
> ---
>   drivers/gpu/drm/xe/xe_exec_queue.c | 8 ++++++--
>   drivers/gpu/drm/xe/xe_migrate.c    | 5 ++++-
>   drivers/gpu/drm/xe/xe_sched_job.c  | 1 -
>   drivers/gpu/drm/xe/xe_sync.c       | 2 --
>   drivers/gpu/drm/xe/xe_vm.c         | 1 +
>   5 files changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_exec_queue.c b/drivers/gpu/drm/xe/xe_exec_queue.c
> index c0b7434e78f1..2976635be4d3 100644
> --- a/drivers/gpu/drm/xe/xe_exec_queue.c
> +++ b/drivers/gpu/drm/xe/xe_exec_queue.c
> @@ -976,20 +976,24 @@ void xe_exec_queue_last_fence_put_unlocked(struct xe_exec_queue *q)
>    * @q: The exec queue
>    * @vm: The VM the engine does a bind or exec for
>    *
> - * Get last fence, does not take a ref
> + * Get last fence, takes a ref
>    *
>    * Returns: last fence if not signaled, dma fence stub if signaled
>    */
>   struct dma_fence *xe_exec_queue_last_fence_get(struct xe_exec_queue *q,
>   					       struct xe_vm *vm)
>   {
> +	struct dma_fence *fence;
> +
>   	xe_exec_queue_last_fence_lockdep_assert(q, vm);
>   
>   	if (q->last_fence &&
>   	    test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &q->last_fence->flags))
>   		xe_exec_queue_last_fence_put(q, vm);
>   
> -	return q->last_fence ? q->last_fence : dma_fence_get_stub();
> +	fence = q->last_fence ? q->last_fence : dma_fence_get_stub();
> +	dma_fence_get(fence);
This should be:
	fence = q->last_fence ? dma_fence_get(q->last_fence) :
		dma_fence_get_stub();

Otherwise we increase refcount on stub twice.
Even though it's harmless as it's statically allocated and never 
expected to be freed, we probably shouldn't.

With that fixed for this patch
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>

> +	return fence;
>   }
>   
>   /**
> diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
> index 9ab004871f9a..894e36c28f32 100644
> --- a/drivers/gpu/drm/xe/xe_migrate.c
> +++ b/drivers/gpu/drm/xe/xe_migrate.c
> @@ -1214,8 +1214,11 @@ static bool no_in_syncs(struct xe_vm *vm, struct xe_exec_queue *q,
>   	}
>   	if (q) {
>   		fence = xe_exec_queue_last_fence_get(q, vm);
> -		if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
> +		if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
> +			dma_fence_put(fence);
>   			return false;
> +		}
> +		dma_fence_put(fence);
>   	}
>   
>   	return true;
> diff --git a/drivers/gpu/drm/xe/xe_sched_job.c b/drivers/gpu/drm/xe/xe_sched_job.c
> index cde1407867db..8151ddafb940 100644
> --- a/drivers/gpu/drm/xe/xe_sched_job.c
> +++ b/drivers/gpu/drm/xe/xe_sched_job.c
> @@ -274,7 +274,6 @@ int xe_sched_job_last_fence_add_dep(struct xe_sched_job *job, struct xe_vm *vm)
>   	struct dma_fence *fence;
>   
>   	fence = xe_exec_queue_last_fence_get(job->q, vm);
> -	dma_fence_get(fence);
>   
>   	return drm_sched_job_add_dependency(&job->drm, fence);
>   }
> diff --git a/drivers/gpu/drm/xe/xe_sync.c b/drivers/gpu/drm/xe/xe_sync.c
> index e4c220cf9115..aab92bee1d7c 100644
> --- a/drivers/gpu/drm/xe/xe_sync.c
> +++ b/drivers/gpu/drm/xe/xe_sync.c
> @@ -307,7 +307,6 @@ xe_sync_in_fence_get(struct xe_sync_entry *sync, int num_sync,
>   	/* Easy case... */
>   	if (!num_in_fence) {
>   		fence = xe_exec_queue_last_fence_get(q, vm);
> -		dma_fence_get(fence);
>   		return fence;
>   	}
>   
> @@ -322,7 +321,6 @@ xe_sync_in_fence_get(struct xe_sync_entry *sync, int num_sync,
>   		}
>   	}
>   	fences[current_fence++] = xe_exec_queue_last_fence_get(q, vm);
> -	dma_fence_get(fences[current_fence - 1]);
>   	cf = dma_fence_array_create(num_in_fence, fences,
>   				    vm->composite_fence_ctx,
>   				    vm->composite_fence_seqno++,
> diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> index 8576535c4b6a..e55161136490 100644
> --- a/drivers/gpu/drm/xe/xe_vm.c
> +++ b/drivers/gpu/drm/xe/xe_vm.c
> @@ -1959,6 +1959,7 @@ static int xe_vm_prefetch(struct xe_vm *vm, struct xe_vma *vma,
>   					xe_exec_queue_last_fence_get(wait_exec_queue, vm);
>   
>   				xe_sync_entry_signal(&syncs[i], NULL, fence);
> +				dma_fence_put(fence);
>   			}
>   		}
>   

  reply	other threads:[~2024-02-01 19:15 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-01  0:48 [PATCH 0/2] A couple of VM bind fixes Matthew Brost
2024-02-01  0:48 ` [PATCH 1/2] drm/xe: Take a reference in xe_exec_queue_last_fence_get() Matthew Brost
2024-02-01 19:15   ` Maarten Lankhorst [this message]
2024-02-01  0:48 ` [PATCH 2/2] drm/xe: Pick correct userptr VMA to repin on REMAP op failure Matthew Brost
2024-02-01 19:18   ` Maarten Lankhorst
2024-02-01 19:26     ` Matthew Brost
2024-02-01 20:00       ` Maarten Lankhorst
2024-02-02  8:37         ` Maarten Lankhorst
2024-02-01  1:46 ` ✓ CI.Patch_applied: success for A couple of VM bind fixes Patchwork
2024-02-01  1:47 ` ✗ CI.checkpatch: warning " Patchwork
2024-02-01  1:48 ` ✓ CI.KUnit: success " Patchwork
2024-02-01  1:55 ` ✓ CI.Build: " Patchwork
2024-02-01  1:55 ` ✓ CI.Hooks: " Patchwork
2024-02-01  1:57 ` ✓ CI.checksparse: " Patchwork
2024-02-01  2:20 ` ✓ CI.BAT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=384d6d2f-8edc-427c-a519-134c41eb699d@linux.intel.com \
    --to=maarten.lankhorst@linux.intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.brost@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox