dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Auld <matthew.william.auld@gmail.com>
To: "Christian König" <ckoenig.leichtzumerken@gmail.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
	ML dri-devel <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH 05/13] drm/ttm: allocate resource object instead of embedding it
Date: Fri, 30 Apr 2021 12:19:59 +0100	[thread overview]
Message-ID: <CAM0jSHNg_ZyAByYb71BWrWjJsP-CNa6nXv_o6=8AC3b4WONWzw@mail.gmail.com> (raw)
In-Reply-To: <20210430092508.60710-5-christian.koenig@amd.com>

On Fri, 30 Apr 2021 at 10:25, Christian König
<ckoenig.leichtzumerken@gmail.com> wrote:
>
> To improve the handling we want the establish the resource object as base
> class for the backend allocations.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c |  4 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    | 54 +++++++--------
>  drivers/gpu/drm/nouveau/nouveau_bo.c       |  2 +-
>  drivers/gpu/drm/radeon/radeon_ttm.c        |  2 +-
>  drivers/gpu/drm/ttm/ttm_bo.c               | 76 +++++++---------------
>  drivers/gpu/drm/ttm/ttm_bo_util.c          | 41 ++++++------
>  drivers/gpu/drm/ttm/ttm_resource.c         | 30 ++++++---
>  drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c |  2 +-
>  include/drm/ttm/ttm_bo_api.h               |  1 -
>  include/drm/ttm/ttm_bo_driver.h            | 10 ++-
>  include/drm/ttm/ttm_resource.h             |  4 +-
>  11 files changed, 101 insertions(+), 125 deletions(-)
>

<snip>

>
>  int ttm_resource_alloc(struct ttm_buffer_object *bo,
>                        const struct ttm_place *place,
> -                      struct ttm_resource *res)
> +                      struct ttm_resource **res_ptr)
>  {
>         struct ttm_resource_manager *man =
> -               ttm_manager_type(bo->bdev, res->mem_type);
> +               ttm_manager_type(bo->bdev, place->mem_type);
> +       struct ttm_resource *res;
> +       int r;
>
> +       res = kmalloc(sizeof(*res), GFP_KERNEL);

if (!res)
        return -ENOMEM;

Also there are still some places where we are not checking if
ttm_resource_alloc returns an error. I guess those are only for the
SYS cases where the ->alloc did nothing so it couldn't really fail,
but now there is a big scary kmalloc lurking in here? Is this not a
concern?

>         res->mm_node = NULL;
>         res->start = 0;
>         res->num_pages = PFN_UP(bo->base.size);
> @@ -41,18 +44,27 @@ int ttm_resource_alloc(struct ttm_buffer_object *bo,
>         res->bus.offset = 0;
>         res->bus.is_iomem = false;
>         res->bus.caching = ttm_cached;
> +       r = man->func->alloc(man, bo, place, res);
> +       if (r) {
> +               kfree(res);
> +               return r;
> +       }
>
> -       return man->func->alloc(man, bo, place, res);
> +       *res_ptr = res;
> +       return 0;
>  }
>
> -void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource *res)
> +void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res)
>  {
> -       struct ttm_resource_manager *man =
> -               ttm_manager_type(bo->bdev, res->mem_type);
> +       struct ttm_resource_manager *man;
>
> -       man->func->free(man, res);
> -       res->mm_node = NULL;
> -       res->mem_type = TTM_PL_SYSTEM;
> +       if (!*res)
> +               return;
> +
> +       man = ttm_manager_type(bo->bdev, (*res)->mem_type);
> +       man->func->free(man, *res);
> +       kfree(*res);
> +       *res = NULL;
>  }
>  EXPORT_SYMBOL(ttm_resource_free);
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> index bb1d453f7ca6..4c34216a9ab8 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> @@ -746,7 +746,7 @@ static int vmw_move(struct ttm_buffer_object *bo,
>                         goto fail;
>
>                 vmw_ttm_unbind(bo->bdev, bo->ttm);
> -               ttm_resource_free(bo, bo->resource);
> +               ttm_resource_free(bo, &bo->resource);
>                 ttm_bo_assign_mem(bo, new_mem);
>                 return 0;
>         } else {
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index 1876a3d6df73..d8bb46228cc7 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -137,7 +137,6 @@ struct ttm_buffer_object {
>          */
>
>         struct ttm_resource *resource;
> -       struct ttm_resource _mem;
>         struct ttm_tt *ttm;
>         bool deleted;
>
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 1a9ba0b13622..ead0ef7136c8 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -96,7 +96,7 @@ struct ttm_lru_bulk_move {
>   */
>  int ttm_bo_mem_space(struct ttm_buffer_object *bo,
>                      struct ttm_placement *placement,
> -                    struct ttm_resource *mem,
> +                    struct ttm_resource **mem,
>                      struct ttm_operation_ctx *ctx);
>
>  /**
> @@ -188,8 +188,8 @@ ttm_bo_move_to_lru_tail_unlocked(struct ttm_buffer_object *bo)
>  static inline void ttm_bo_assign_mem(struct ttm_buffer_object *bo,
>                                      struct ttm_resource *new_mem)
>  {
> -       bo->_mem = *new_mem;
> -       new_mem->mm_node = NULL;
> +       WARN_ON(bo->resource);
> +       bo->resource = new_mem;
>  }
>
>  /**
> @@ -202,9 +202,7 @@ static inline void ttm_bo_assign_mem(struct ttm_buffer_object *bo,
>  static inline void ttm_bo_move_null(struct ttm_buffer_object *bo,
>                                     struct ttm_resource *new_mem)
>  {
> -       struct ttm_resource *old_mem = bo->resource;
> -
> -       WARN_ON(old_mem->mm_node != NULL);
> +       ttm_resource_free(bo, &bo->resource);
>         ttm_bo_assign_mem(bo, new_mem);
>  }
>
> diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h
> index 890b9d369519..c17c1a52070d 100644
> --- a/include/drm/ttm/ttm_resource.h
> +++ b/include/drm/ttm/ttm_resource.h
> @@ -225,8 +225,8 @@ ttm_resource_manager_cleanup(struct ttm_resource_manager *man)
>
>  int ttm_resource_alloc(struct ttm_buffer_object *bo,
>                        const struct ttm_place *place,
> -                      struct ttm_resource *res);
> -void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource *res);
> +                      struct ttm_resource **res);
> +void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res);
>
>  void ttm_resource_manager_init(struct ttm_resource_manager *man,
>                                unsigned long p_size);
> --
> 2.25.1
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2021-04-30 11:20 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-30  9:24 [PATCH 01/13] drm/ttm: add ttm_sys_manager v2 Christian König
2021-04-30  9:24 ` [PATCH 02/13] drm/ttm: always initialize the full ttm_resource Christian König
2021-04-30 12:05   ` Matthew Auld
2021-04-30 12:51     ` Christian König
2021-04-30  9:24 ` [PATCH 03/13] drm/ttm: properly allocate sys resource during swapout Christian König
2021-04-30 10:22   ` Matthew Auld
2021-04-30  9:24 ` [PATCH 04/13] drm/ttm: rename bo->mem and make it a pointer Christian König
2021-04-30  9:25 ` [PATCH 05/13] drm/ttm: allocate resource object instead of embedding it Christian König
2021-04-30 11:19   ` Matthew Auld [this message]
2021-04-30  9:25 ` [PATCH 06/13] drm/ttm: flip over the range manager to self allocated nodes Christian König
2021-04-30 13:14   ` Matthew Auld
2021-05-29 15:48   ` Thomas Hellström (Intel)
2021-05-30 16:51     ` Christian König
2021-05-31  8:56       ` Thomas Hellström (Intel)
2021-04-30  9:25 ` [PATCH 07/13] drm/ttm: flip over the sys " Christian König
2021-04-30 13:16   ` Matthew Auld
2021-04-30 15:04   ` Matthew Auld
2021-05-03 11:08     ` Christian König
2021-04-30  9:25 ` [PATCH 08/13] drm/amdgpu: revert "drm/amdgpu: stop allocating dummy GTT nodes" Christian König
2021-05-05 16:48   ` Matthew Auld
2021-04-30  9:25 ` [PATCH 09/13] drm/amdgpu: switch the GTT backend to self alloc Christian König
2021-04-30 14:43   ` Matthew Auld
2021-04-30  9:25 ` [PATCH 10/13] drm/amdgpu: switch the VRAM " Christian König
2021-04-30 14:53   ` Matthew Auld
2021-04-30  9:25 ` [PATCH 11/13] drm/nouveau: switch the TTM backends " Christian König
2021-04-30 15:02   ` Matthew Auld
2021-05-03 11:14     ` Christian König
2021-05-05 16:46       ` Matthew Auld
2021-04-30  9:25 ` [PATCH 12/13] drm/vmwgfx: " Christian König
2021-05-05 16:49   ` Matthew Auld
2021-04-30  9:25 ` [PATCH 13/13] drm/ttm: flip the switch for driver allocated resources Christian König
2021-05-03 16:15   ` Nirmoy
2021-05-05 16:44   ` Matthew Auld
2021-04-30 10:09 ` [PATCH 01/13] drm/ttm: add ttm_sys_manager v2 Matthew Auld

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='CAM0jSHNg_ZyAByYb71BWrWjJsP-CNa6nXv_o6=8AC3b4WONWzw@mail.gmail.com' \
    --to=matthew.william.auld@gmail.com \
    --cc=ckoenig.leichtzumerken@gmail.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    /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;
as well as URLs for NNTP newsgroup(s).