[PATCH 2/4] drm/vmwgfx: use the new drm_exec object v2

Ian Forbes ian.forbes at broadcom.com
Mon Nov 25 20:11:43 UTC 2024


Breaks userspace command submission. Here's the log with lock debugging on.

```
[   20.438106] ================================================
[   20.439696] WARNING: lock held when returning to user space!
[   20.441730] 6.12.0+ #11 Not tainted
[   20.442389] ------------------------------------------------
[   20.443663] gnome-shell/1853 is leaving the kernel with locks still held!
[   20.445519] 1 lock held by gnome-shell/1853:
[   20.446524]  #0: ffff9ae5892431a0
(reservation_ww_class_mutex){....}-{3:3}, at:
ww_mutex_trylock+0x186/0x3a0
```

Ian,

On Thu, Nov 21, 2024 at 4:27 AM Christian König
<ckoenig.leichtzumerken at gmail.com> wrote:
>
> Basically just switching over to the new infrastructure like we did for
> other drivers as well.
>
> No intentional functional change, but only compile tested.
>
> v2: fix kerneldoc issues
>
> Signed-off-by: Christian König <christian.koenig at amd.com>
> ---
>  drivers/gpu/drm/vmwgfx/vmwgfx_validation.c | 57 +++++++++++++++++++++-
>  drivers/gpu/drm/vmwgfx/vmwgfx_validation.h | 41 ++--------------
>  2 files changed, 60 insertions(+), 38 deletions(-)
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c
> index e7625b3f71e0..fdcc45cd4f57 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c
> @@ -817,6 +817,60 @@ int vmw_validation_preload_res(struct vmw_validation_context *ctx,
>         return 0;
>  }
>
> +/**
> + * vmw_validation_bo_reserve - Reserve buffer objects registered with a
> + * validation context
> + * @ctx: The validation context
> + * @intr: Perform waits interruptible
> + *
> + * Return: Zero on success, -ERESTARTSYS when interrupted, negative error
> + * code on failure
> + */
> +int vmw_validation_bo_reserve(struct vmw_validation_context *ctx, bool intr)
> +{
> +       struct vmw_validation_bo_node *entry;
> +       int ret;
> +
> +       drm_exec_init(&ctx->exec, intr ? DRM_EXEC_INTERRUPTIBLE_WAIT : 0, 0);
> +       drm_exec_until_all_locked(&ctx->exec) {
> +               list_for_each_entry(entry, &ctx->bo_list, base.head) {
> +                       ret = drm_exec_prepare_obj(&ctx->exec,
> +                                                  &entry->base.bo->base, 1);
> +                       drm_exec_retry_on_contention(&ctx->exec);
> +                       if (ret)
> +                               goto error;
> +               }
> +       }
> +       return 0;
> +
> +error:
> +       drm_exec_fini(&ctx->exec);
> +       return ret;
> +}
> +
> +/**
> + * vmw_validation_bo_fence - Unreserve and fence buffer objects registered
> + * with a validation context
> + * @ctx: The validation context
> + * @fence: The fence to add
> + *
> + * This function unreserves the buffer objects previously reserved using
> + * vmw_validation_bo_reserve, and fences them with a fence object.
> + */
> +void vmw_validation_bo_fence(struct vmw_validation_context *ctx,
> +                            struct vmw_fence_obj *fence)
> +{
> +       struct vmw_validation_bo_node *entry;
> +
> +       list_for_each_entry(entry, &ctx->bo_list, base.head) {
> +               dma_resv_add_fence(entry->base.bo->base.resv, &fence->base,
> +                                  DMA_RESV_USAGE_READ);
> +       }
> +       drm_exec_fini(&ctx->exec);
> +}
> +
> +
> +
>  /**
>   * vmw_validation_bo_backoff - Unreserve buffer objects registered with a
>   * validation context
> @@ -842,6 +896,5 @@ void vmw_validation_bo_backoff(struct vmw_validation_context *ctx)
>                                 vmw_bo_dirty_release(vbo);
>                 }
>         }
> -
> -       ttm_eu_backoff_reservation(&ctx->ticket, &ctx->bo_list);
> +       drm_exec_fini(&ctx->exec);
>  }
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
> index 353d837907d8..55a7d8b68d5c 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
> @@ -31,8 +31,7 @@
>  #include <linux/list.h>
>  #include <linux/hashtable.h>
>  #include <linux/ww_mutex.h>
> -
> -#include <drm/ttm/ttm_execbuf_util.h>
> +#include <drm/drm_exec.h>
>
>  #define VMW_RES_DIRTY_NONE 0
>  #define VMW_RES_DIRTY_SET BIT(0)
> @@ -59,7 +58,7 @@ struct vmw_validation_context {
>         struct list_head resource_ctx_list;
>         struct list_head bo_list;
>         struct list_head page_list;
> -       struct ww_acquire_ctx ticket;
> +       struct drm_exec exec;
>         struct mutex *res_mutex;
>         unsigned int merge_dups;
>         unsigned int mem_size_left;
> @@ -106,39 +105,6 @@ vmw_validation_has_bos(struct vmw_validation_context *ctx)
>         return !list_empty(&ctx->bo_list);
>  }
>
> -/**
> - * vmw_validation_bo_reserve - Reserve buffer objects registered with a
> - * validation context
> - * @ctx: The validation context
> - * @intr: Perform waits interruptible
> - *
> - * Return: Zero on success, -ERESTARTSYS when interrupted, negative error
> - * code on failure
> - */
> -static inline int
> -vmw_validation_bo_reserve(struct vmw_validation_context *ctx,
> -                         bool intr)
> -{
> -       return ttm_eu_reserve_buffers(&ctx->ticket, &ctx->bo_list, intr,
> -                                     NULL);
> -}
> -
> -/**
> - * vmw_validation_bo_fence - Unreserve and fence buffer objects registered
> - * with a validation context
> - * @ctx: The validation context
> - *
> - * This function unreserves the buffer objects previously reserved using
> - * vmw_validation_bo_reserve, and fences them with a fence object.
> - */
> -static inline void
> -vmw_validation_bo_fence(struct vmw_validation_context *ctx,
> -                       struct vmw_fence_obj *fence)
> -{
> -       ttm_eu_fence_buffer_objects(&ctx->ticket, &ctx->bo_list,
> -                                   (void *) fence);
> -}
> -
>  /**
>   * vmw_validation_align - Align a validation memory allocation
>   * @val: The size to be aligned
> @@ -185,6 +151,9 @@ int vmw_validation_preload_res(struct vmw_validation_context *ctx,
>                                unsigned int size);
>  void vmw_validation_res_set_dirty(struct vmw_validation_context *ctx,
>                                   void *val_private, u32 dirty);
> +int vmw_validation_bo_reserve(struct vmw_validation_context *ctx, bool intr);
> +void vmw_validation_bo_fence(struct vmw_validation_context *ctx,
> +                            struct vmw_fence_obj *fence);
>  void vmw_validation_bo_backoff(struct vmw_validation_context *ctx);
>
>  #endif
> --
> 2.34.1
>


More information about the dri-devel mailing list