From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: "Christian König" <ckoenig.leichtzumerken@gmail.com>,
dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/5] drm/ttm: add a weak BO reference to the resource v2
Date: Mon, 23 Aug 2021 09:56:25 +0200 [thread overview]
Message-ID: <eb38fc76abf1a30d272ee76f6cb3ba2324297c25.camel@linux.intel.com> (raw)
In-Reply-To: <20210719115145.1260-1-christian.koenig@amd.com>
Hi, Christian,
Still working through some backlog and this series appears to have
slipped under the radar.
Still I think a cover letter would benefit reviewers...
On Mon, 2021-07-19 at 13:51 +0200, Christian König wrote:
> Keep track for which BO a resource was allocated.
> This is necessary to move the LRU handling into the resources.
So is this needed, when looking up a resource from the LRU, to find the
bo the resource is currently attached to?
>
> A bit problematic is i915 since it tries to use the resource
> interface without a BO which is illegal from the conceptional
s/conceptional/conceptual/ ?
> point of view.
>
> v2: Document that this is a weak reference and add a workaround for
> i915
Hmm. As pointed out in my previous review the weak pointer should
really be cleared under a lookup lock to avoid use-after-free bugs.
I don't see that happening here. Doesn't this series aim for a future
direction of early destruction of bos and ditching the ghost objects?
In that case IMHO you need to allow for a NULL bo pointer and any bo
information needed at resource destruction needs to be copied on the
resource... (That would also ofc help with the i915 problem).
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
> drivers/gpu/drm/i915/intel_region_ttm.c | 5 +++++
> drivers/gpu/drm/ttm/ttm_bo_util.c | 7 +++++--
> drivers/gpu/drm/ttm/ttm_resource.c | 1 +
> include/drm/ttm/ttm_resource.h | 2 ++
> 4 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/intel_region_ttm.c
> b/drivers/gpu/drm/i915/intel_region_ttm.c
> index 27fe0668d094..980b10a7debf 100644
> --- a/drivers/gpu/drm/i915/intel_region_ttm.c
> +++ b/drivers/gpu/drm/i915/intel_region_ttm.c
> @@ -88,6 +88,7 @@ intel_region_ttm_node_reserve(struct
> intel_memory_region *mem,
> place.fpfn = offset >> PAGE_SHIFT;
> place.lpfn = place.fpfn + (size >> PAGE_SHIFT);
> mock_bo.base.size = size;
> + mock_bo.bdev = &mem->i915->bdev;
> ret = man->func->alloc(man, &mock_bo, &place, &res);
> if (ret == -ENOSPC)
> ret = -ENXIO;
> @@ -104,7 +105,11 @@ void intel_region_ttm_node_free(struct
> intel_memory_region *mem,
> struct ttm_resource *res)
> {
> struct ttm_resource_manager *man = mem->region_private;
> + struct ttm_buffer_object mock_bo = {};
>
> + mock_bo.base.size = res->num_pages * PAGE_SIZE;
> + mock_bo.bdev = &mem->i915->bdev;
> + res->bo = &mock_bo;
> man->func->free(man, res);
> }
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c
> b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index 2f57f824e6db..a1570aa8ff56 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -239,6 +239,11 @@ static int ttm_buffer_object_transfer(struct
> ttm_buffer_object *bo,
> if (bo->type != ttm_bo_type_sg)
> fbo->base.base.resv = &fbo->base.base._resv;
>
> + if (fbo->base.resource) {
> + fbo->base.resource->bo = &fbo->base;
This is scary: What if someone else (LRU lookup) just dereferenced the
previous resource->bo pointer? I think this needs proper weak reference
locking and lifetime handling, as mentioned above.
> + bo->resource = NULL;
> + }
> +
/Thomas
next prev parent reply other threads:[~2021-08-23 7:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-19 11:51 [PATCH 1/5] drm/ttm: add a weak BO reference to the resource v2 Christian König
2021-07-19 11:51 ` [PATCH 2/5] drm/ttm: add ttm_resource_fini Christian König
2021-07-19 11:51 ` [PATCH 3/5] drm/ttm: add common accounting to the resource mgr Christian König
2021-07-19 11:51 ` [PATCH 4/5] drm/ttm: move the LRU into resource handling Christian König
2021-08-23 8:10 ` Thomas Hellström
2021-07-19 11:51 ` [PATCH 5/5] drm/ttm: add resource iterator Christian König
2021-08-23 7:56 ` Thomas Hellström [this message]
2021-08-23 10:02 ` [PATCH 1/5] drm/ttm: add a weak BO reference to the resource v2 Christian König
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=eb38fc76abf1a30d272ee76f6cb3ba2324297c25.camel@linux.intel.com \
--to=thomas.hellstrom@linux.intel.com \
--cc=ckoenig.leichtzumerken@gmail.com \
--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