* [PATCH 0/2] A couple exec IOCTL fixes
@ 2024-11-05 0:38 Matthew Brost
2024-11-05 0:38 ` [PATCH 1/2] drm/xe: Fix possible exec queue leak in exec IOCTL Matthew Brost
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Matthew Brost @ 2024-11-05 0:38 UTC (permalink / raw)
To: intel-xe
Noticed a couple of bug in exec IOCTL while working on something else.
Matt
Matthew Brost (2):
drm/xe: Fix possible exec queue leak in exec IOCTL
drm/xe: Drop VM dma-resv lock on xe_sync_in_fence_get failure in exec
IOCTL
drivers/gpu/drm/xe/xe_exec.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 1/2] drm/xe: Fix possible exec queue leak in exec IOCTL
2024-11-05 0:38 [PATCH 0/2] A couple exec IOCTL fixes Matthew Brost
@ 2024-11-05 0:38 ` Matthew Brost
2024-11-05 2:44 ` Rodrigo Vivi
2024-11-05 0:38 ` [PATCH 2/2] drm/xe: Drop VM dma-resv lock on xe_sync_in_fence_get failure " Matthew Brost
2024-11-05 0:38 ` [PATCH v2] drm/xe: Restore system memory GGTT mappings Matthew Brost
2 siblings, 1 reply; 8+ messages in thread
From: Matthew Brost @ 2024-11-05 0:38 UTC (permalink / raw)
To: intel-xe
In a couple of places after an exec queue is looked up the exec IOCTL
returns on input errors without dropping the exec queue ref. Fix this
ensuring the exec queue ref is dropped on input error.
Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
Cc: stable <stable@kernel.org>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_exec.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_exec.c b/drivers/gpu/drm/xe/xe_exec.c
index f23ac1e2ed88..6de12f91b865 100644
--- a/drivers/gpu/drm/xe/xe_exec.c
+++ b/drivers/gpu/drm/xe/xe_exec.c
@@ -132,12 +132,16 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
if (XE_IOCTL_DBG(xe, !q))
return -ENOENT;
- if (XE_IOCTL_DBG(xe, q->flags & EXEC_QUEUE_FLAG_VM))
- return -EINVAL;
+ if (XE_IOCTL_DBG(xe, q->flags & EXEC_QUEUE_FLAG_VM)) {
+ err = -EINVAL;
+ goto err_exec_queue;
+ }
if (XE_IOCTL_DBG(xe, args->num_batch_buffer &&
- q->width != args->num_batch_buffer))
- return -EINVAL;
+ q->width != args->num_batch_buffer)) {
+ err = -EINVAL;
+ goto err_exec_queue;
+ }
if (XE_IOCTL_DBG(xe, q->ops->reset_status(q))) {
err = -ECANCELED;
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 1/2] drm/xe: Fix possible exec queue leak in exec IOCTL
2024-11-05 0:38 ` [PATCH 1/2] drm/xe: Fix possible exec queue leak in exec IOCTL Matthew Brost
@ 2024-11-05 2:44 ` Rodrigo Vivi
2024-11-05 4:45 ` Matthew Brost
0 siblings, 1 reply; 8+ messages in thread
From: Rodrigo Vivi @ 2024-11-05 2:44 UTC (permalink / raw)
To: Matthew Brost; +Cc: intel-xe
On Mon, Nov 04, 2024 at 04:38:30PM -0800, Matthew Brost wrote:
> In a couple of places after an exec queue is looked up the exec IOCTL
> returns on input errors without dropping the exec queue ref. Fix this
> ensuring the exec queue ref is dropped on input error.
>
> Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
> Cc: stable <stable@kernel.org>
> Signed-off-by: Matthew Brost <matthew.brost@intel.com>
> ---
> drivers/gpu/drm/xe/xe_exec.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_exec.c b/drivers/gpu/drm/xe/xe_exec.c
> index f23ac1e2ed88..6de12f91b865 100644
> --- a/drivers/gpu/drm/xe/xe_exec.c
> +++ b/drivers/gpu/drm/xe/xe_exec.c
> @@ -132,12 +132,16 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
> if (XE_IOCTL_DBG(xe, !q))
> return -ENOENT;
>
> - if (XE_IOCTL_DBG(xe, q->flags & EXEC_QUEUE_FLAG_VM))
> - return -EINVAL;
> + if (XE_IOCTL_DBG(xe, q->flags & EXEC_QUEUE_FLAG_VM)) {
> + err = -EINVAL;
> + goto err_exec_queue;
> + }
>
> if (XE_IOCTL_DBG(xe, args->num_batch_buffer &&
> - q->width != args->num_batch_buffer))
> - return -EINVAL;
> + q->width != args->num_batch_buffer)) {
> + err = -EINVAL;
> + goto err_exec_queue;
this function is so huge... it probably deserves some splits...
but the patch is correct
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> + }
>
> if (XE_IOCTL_DBG(xe, q->ops->reset_status(q))) {
> err = -ECANCELED;
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 1/2] drm/xe: Fix possible exec queue leak in exec IOCTL
2024-11-05 2:44 ` Rodrigo Vivi
@ 2024-11-05 4:45 ` Matthew Brost
0 siblings, 0 replies; 8+ messages in thread
From: Matthew Brost @ 2024-11-05 4:45 UTC (permalink / raw)
To: Rodrigo Vivi; +Cc: intel-xe
On Mon, Nov 04, 2024 at 09:44:26PM -0500, Rodrigo Vivi wrote:
> On Mon, Nov 04, 2024 at 04:38:30PM -0800, Matthew Brost wrote:
> > In a couple of places after an exec queue is looked up the exec IOCTL
> > returns on input errors without dropping the exec queue ref. Fix this
> > ensuring the exec queue ref is dropped on input error.
> >
> > Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
> > Cc: stable <stable@kernel.org>
> > Signed-off-by: Matthew Brost <matthew.brost@intel.com>
>
> > ---
> > drivers/gpu/drm/xe/xe_exec.c | 12 ++++++++----
> > 1 file changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/xe/xe_exec.c b/drivers/gpu/drm/xe/xe_exec.c
> > index f23ac1e2ed88..6de12f91b865 100644
> > --- a/drivers/gpu/drm/xe/xe_exec.c
> > +++ b/drivers/gpu/drm/xe/xe_exec.c
> > @@ -132,12 +132,16 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
> > if (XE_IOCTL_DBG(xe, !q))
> > return -ENOENT;
> >
> > - if (XE_IOCTL_DBG(xe, q->flags & EXEC_QUEUE_FLAG_VM))
> > - return -EINVAL;
> > + if (XE_IOCTL_DBG(xe, q->flags & EXEC_QUEUE_FLAG_VM)) {
> > + err = -EINVAL;
> > + goto err_exec_queue;
> > + }
> >
> > if (XE_IOCTL_DBG(xe, args->num_batch_buffer &&
> > - q->width != args->num_batch_buffer))
> > - return -EINVAL;
> > + q->width != args->num_batch_buffer)) {
> > + err = -EINVAL;
> > + goto err_exec_queue;
>
> this function is so huge... it probably deserves some splits...
> but the patch is correct
>
Thanks for the review. Yes, big function. Let me look at this, I see a
couple of logical places to split.
But I think in general our exec IOCTL is pretty tidy...
mbrost@lstrano-desk:xe$ wc xe_exec.c
354 1320 10399 xe_exec.c
mbrost@lstrano-desk:xe$ wc ../i915/gem/i915_gem_execbuffer.c
3645 11483 95597 ../i915/gem/i915_gem_execbuffer.c
Matt
> Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
>
> > + }
> >
> > if (XE_IOCTL_DBG(xe, q->ops->reset_status(q))) {
> > err = -ECANCELED;
> > --
> > 2.34.1
> >
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/2] drm/xe: Drop VM dma-resv lock on xe_sync_in_fence_get failure in exec IOCTL
2024-11-05 0:38 [PATCH 0/2] A couple exec IOCTL fixes Matthew Brost
2024-11-05 0:38 ` [PATCH 1/2] drm/xe: Fix possible exec queue leak in exec IOCTL Matthew Brost
@ 2024-11-05 0:38 ` Matthew Brost
2024-11-05 2:46 ` Rodrigo Vivi
2024-11-05 0:38 ` [PATCH v2] drm/xe: Restore system memory GGTT mappings Matthew Brost
2 siblings, 1 reply; 8+ messages in thread
From: Matthew Brost @ 2024-11-05 0:38 UTC (permalink / raw)
To: intel-xe
Upon failure all locks need to be dropped before returning to the user.
Fixes: 58480c1c912f ("drm/xe: Skip VMAs pin when requesting signal to the last XE_EXEC")
Cc: stable <stable@kernel.org>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_exec.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/gpu/drm/xe/xe_exec.c b/drivers/gpu/drm/xe/xe_exec.c
index 6de12f91b865..756b492f13b0 100644
--- a/drivers/gpu/drm/xe/xe_exec.c
+++ b/drivers/gpu/drm/xe/xe_exec.c
@@ -224,6 +224,7 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
fence = xe_sync_in_fence_get(syncs, num_syncs, q, vm);
if (IS_ERR(fence)) {
err = PTR_ERR(fence);
+ xe_vm_unlock(vm);
goto err_unlock_list;
}
for (i = 0; i < num_syncs; i++)
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 2/2] drm/xe: Drop VM dma-resv lock on xe_sync_in_fence_get failure in exec IOCTL
2024-11-05 0:38 ` [PATCH 2/2] drm/xe: Drop VM dma-resv lock on xe_sync_in_fence_get failure " Matthew Brost
@ 2024-11-05 2:46 ` Rodrigo Vivi
0 siblings, 0 replies; 8+ messages in thread
From: Rodrigo Vivi @ 2024-11-05 2:46 UTC (permalink / raw)
To: Matthew Brost; +Cc: intel-xe
On Mon, Nov 04, 2024 at 04:38:31PM -0800, Matthew Brost wrote:
> Upon failure all locks need to be dropped before returning to the user.
>
> Fixes: 58480c1c912f ("drm/xe: Skip VMAs pin when requesting signal to the last XE_EXEC")
> Cc: stable <stable@kernel.org>
> Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> ---
> drivers/gpu/drm/xe/xe_exec.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/gpu/drm/xe/xe_exec.c b/drivers/gpu/drm/xe/xe_exec.c
> index 6de12f91b865..756b492f13b0 100644
> --- a/drivers/gpu/drm/xe/xe_exec.c
> +++ b/drivers/gpu/drm/xe/xe_exec.c
> @@ -224,6 +224,7 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
> fence = xe_sync_in_fence_get(syncs, num_syncs, q, vm);
> if (IS_ERR(fence)) {
> err = PTR_ERR(fence);
> + xe_vm_unlock(vm);
> goto err_unlock_list;
> }
> for (i = 0; i < num_syncs; i++)
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2] drm/xe: Restore system memory GGTT mappings
2024-11-05 0:38 [PATCH 0/2] A couple exec IOCTL fixes Matthew Brost
2024-11-05 0:38 ` [PATCH 1/2] drm/xe: Fix possible exec queue leak in exec IOCTL Matthew Brost
2024-11-05 0:38 ` [PATCH 2/2] drm/xe: Drop VM dma-resv lock on xe_sync_in_fence_get failure " Matthew Brost
@ 2024-11-05 0:38 ` Matthew Brost
2 siblings, 0 replies; 8+ messages in thread
From: Matthew Brost @ 2024-11-05 0:38 UTC (permalink / raw)
To: intel-xe
GGTT mappings reside on the device and this state is lost during suspend
/ d3cold thus this state must be restored resume regardless if the BO is
in system memory or VRAM.
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 14 +++++++++++---
drivers/gpu/drm/xe/xe_bo_evict.c | 1 -
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 5b232f2951b1..d79d8ef5c7d5 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -888,8 +888,8 @@ int xe_bo_evict_pinned(struct xe_bo *bo)
if (WARN_ON(!xe_bo_is_pinned(bo)))
return -EINVAL;
- if (WARN_ON(!xe_bo_is_vram(bo)))
- return -EINVAL;
+ if (!xe_bo_is_vram(bo))
+ return 0;
ret = ttm_bo_mem_space(&bo->ttm, &placement, &new_mem, &ctx);
if (ret)
@@ -939,6 +939,7 @@ int xe_bo_restore_pinned(struct xe_bo *bo)
.interruptible = false,
};
struct ttm_resource *new_mem;
+ struct ttm_place *place = &(bo->placements[0]);
int ret;
xe_bo_assert_held(bo);
@@ -952,6 +953,9 @@ int xe_bo_restore_pinned(struct xe_bo *bo)
if (WARN_ON(xe_bo_is_vram(bo) || !bo->ttm.ttm))
return -EINVAL;
+ if (!mem_type_is_vram(place->mem_type))
+ return 0;
+
ret = ttm_bo_mem_space(&bo->ttm, &bo->placement, &new_mem, &ctx);
if (ret)
return ret;
@@ -1804,7 +1808,10 @@ int xe_bo_pin(struct xe_bo *bo)
place->fpfn = (xe_bo_addr(bo, 0, PAGE_SIZE) -
vram_region_gpu_offset(bo->ttm.resource)) >> PAGE_SHIFT;
place->lpfn = place->fpfn + (bo->size >> PAGE_SHIFT);
+ }
+ if (mem_type_is_vram(place->mem_type) ||
+ bo->flags & XE_BO_FLAG_GGTT) {
spin_lock(&xe->pinned.lock);
list_add_tail(&bo->pinned_link, &xe->pinned.kernel_bo_present);
spin_unlock(&xe->pinned.lock);
@@ -1865,7 +1872,8 @@ void xe_bo_unpin(struct xe_bo *bo)
bo->flags & XE_BO_FLAG_INTERNAL_TEST)) {
struct ttm_place *place = &(bo->placements[0]);
- if (mem_type_is_vram(place->mem_type)) {
+ if (mem_type_is_vram(place->mem_type) ||
+ bo->flags & XE_BO_FLAG_GGTT) {
spin_lock(&xe->pinned.lock);
xe_assert(xe, !list_empty(&bo->pinned_link));
list_del_init(&bo->pinned_link);
diff --git a/drivers/gpu/drm/xe/xe_bo_evict.c b/drivers/gpu/drm/xe/xe_bo_evict.c
index 541b49007d73..32043e1e5a86 100644
--- a/drivers/gpu/drm/xe/xe_bo_evict.c
+++ b/drivers/gpu/drm/xe/xe_bo_evict.c
@@ -159,7 +159,6 @@ int xe_bo_restore_kernel(struct xe_device *xe)
* should setup the iosys map.
*/
xe_assert(xe, !iosys_map_is_null(&bo->vmap));
- xe_assert(xe, xe_bo_is_vram(bo));
xe_bo_put(bo);
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2] drm/xe: Restore system memory GGTT mappings
@ 2024-10-31 18:22 Matthew Brost
0 siblings, 0 replies; 8+ messages in thread
From: Matthew Brost @ 2024-10-31 18:22 UTC (permalink / raw)
To: intel-xe; +Cc: matthew.auld, riana.tauro
GGTT mappings reside on the device and this state is lost during suspend
/ d3cold thus this state must be restored resume regardless if the BO is
in system memory or VRAM.
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 14 +++++++++++---
drivers/gpu/drm/xe/xe_bo_evict.c | 1 -
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 5b232f2951b1..d79d8ef5c7d5 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -888,8 +888,8 @@ int xe_bo_evict_pinned(struct xe_bo *bo)
if (WARN_ON(!xe_bo_is_pinned(bo)))
return -EINVAL;
- if (WARN_ON(!xe_bo_is_vram(bo)))
- return -EINVAL;
+ if (!xe_bo_is_vram(bo))
+ return 0;
ret = ttm_bo_mem_space(&bo->ttm, &placement, &new_mem, &ctx);
if (ret)
@@ -939,6 +939,7 @@ int xe_bo_restore_pinned(struct xe_bo *bo)
.interruptible = false,
};
struct ttm_resource *new_mem;
+ struct ttm_place *place = &(bo->placements[0]);
int ret;
xe_bo_assert_held(bo);
@@ -952,6 +953,9 @@ int xe_bo_restore_pinned(struct xe_bo *bo)
if (WARN_ON(xe_bo_is_vram(bo) || !bo->ttm.ttm))
return -EINVAL;
+ if (!mem_type_is_vram(place->mem_type))
+ return 0;
+
ret = ttm_bo_mem_space(&bo->ttm, &bo->placement, &new_mem, &ctx);
if (ret)
return ret;
@@ -1804,7 +1808,10 @@ int xe_bo_pin(struct xe_bo *bo)
place->fpfn = (xe_bo_addr(bo, 0, PAGE_SIZE) -
vram_region_gpu_offset(bo->ttm.resource)) >> PAGE_SHIFT;
place->lpfn = place->fpfn + (bo->size >> PAGE_SHIFT);
+ }
+ if (mem_type_is_vram(place->mem_type) ||
+ bo->flags & XE_BO_FLAG_GGTT) {
spin_lock(&xe->pinned.lock);
list_add_tail(&bo->pinned_link, &xe->pinned.kernel_bo_present);
spin_unlock(&xe->pinned.lock);
@@ -1865,7 +1872,8 @@ void xe_bo_unpin(struct xe_bo *bo)
bo->flags & XE_BO_FLAG_INTERNAL_TEST)) {
struct ttm_place *place = &(bo->placements[0]);
- if (mem_type_is_vram(place->mem_type)) {
+ if (mem_type_is_vram(place->mem_type) ||
+ bo->flags & XE_BO_FLAG_GGTT) {
spin_lock(&xe->pinned.lock);
xe_assert(xe, !list_empty(&bo->pinned_link));
list_del_init(&bo->pinned_link);
diff --git a/drivers/gpu/drm/xe/xe_bo_evict.c b/drivers/gpu/drm/xe/xe_bo_evict.c
index 541b49007d73..32043e1e5a86 100644
--- a/drivers/gpu/drm/xe/xe_bo_evict.c
+++ b/drivers/gpu/drm/xe/xe_bo_evict.c
@@ -159,7 +159,6 @@ int xe_bo_restore_kernel(struct xe_device *xe)
* should setup the iosys map.
*/
xe_assert(xe, !iosys_map_is_null(&bo->vmap));
- xe_assert(xe, xe_bo_is_vram(bo));
xe_bo_put(bo);
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-11-05 4:45 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-05 0:38 [PATCH 0/2] A couple exec IOCTL fixes Matthew Brost
2024-11-05 0:38 ` [PATCH 1/2] drm/xe: Fix possible exec queue leak in exec IOCTL Matthew Brost
2024-11-05 2:44 ` Rodrigo Vivi
2024-11-05 4:45 ` Matthew Brost
2024-11-05 0:38 ` [PATCH 2/2] drm/xe: Drop VM dma-resv lock on xe_sync_in_fence_get failure " Matthew Brost
2024-11-05 2:46 ` Rodrigo Vivi
2024-11-05 0:38 ` [PATCH v2] drm/xe: Restore system memory GGTT mappings Matthew Brost
-- strict thread matches above, loose matches on Subject: below --
2024-10-31 18:22 Matthew Brost
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox