From: Steven Price <steven.price@arm.com>
To: Rob Herring <robh@kernel.org>
Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>,
Maxime Ripard <maxime.ripard@bootlin.com>,
Sean Paul <sean@poorly.run>,
dri-devel <dri-devel@lists.freedesktop.org>,
David Airlie <airlied@linux.ie>,
Boris Brezillon <boris.brezillon@collabora.com>,
Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>,
Robin Murphy <robin.murphy@arm.com>
Subject: Re: [PATCH v2 6/7] drm/panfrost: Add support for GPU heap allocations
Date: Wed, 31 Jul 2019 10:30:51 +0100 [thread overview]
Message-ID: <2aa4cc3f-03c2-ae7b-d3b8-683ac9b06dc6@arm.com> (raw)
In-Reply-To: <CAL_Jsq+DuZUZf27ybY=XstV_9AT1Fi=Hm+h2P_ajMyyHiBiELg@mail.gmail.com>
On 30/07/2019 21:03, Rob Herring wrote:
> On Thu, Jul 25, 2019 at 9:35 AM Steven Price <steven.price@arm.com> wrote:
>>
>> On 25/07/2019 15:59, Steven Price wrote:
>> [...]
>>> It would appear that in the following call sgt==NULL:
>>>> ret = sg_alloc_table_from_pages(sgt, pages + page_offset,
>>>> NUM_FAULT_PAGES, 0, SZ_2M, GFP_KERNEL);
>>>
>>> Which means we've ended up with a BO with bo->sgt==NULL, bo->pages set
>>> and bo->is_heap=true. My understanding is this should be impossible.
>>>
>>> I haven't yet figured out how this happens - it seems to be just before
>>> termination, so it might be a race with cleanup?
>>
>> That was a red herring - it's partly my test case doing something a bit
>> weird. This crash is caused by doing an mmap of a HEAP object before any
>> fault has occurred.
>>
>> drm_gem_shmem_mmap() calls drm_gem_shmem_get_pages() which will populate
>> bo->base.pages (even if bo->is_heap).
>>
>> Either we should prevent mapping of HEAP objects, or alternatively
>> bo->base.pages could be allocated upfront instead of during the first
>> fault. My preference would be allocating it upfront because optimising
>> for the case of a HEAP BO which isn't used seems a bit weird. Although
>> there's still the question of exactly what the behaviour should be of
>> accessing through the CPU pages which haven't been allocated yet.
>
> As preventing getting the mmap fake offset should be sufficient, I'm
> planning on doing this change:
>
> diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c
> b/drivers/gpu/drm/panfrost/panfrost_drv.c
> index 746eb4603bc2..186d5db892a9 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_drv.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c
> @@ -270,6 +270,10 @@ static int panfrost_ioctl_mmap_bo(struct
> drm_device *dev, void *data,
> return -ENOENT;
> }
>
> + /* Don't allow mmapping of heap objects as pages are not pinned. */
> + if (to_panfrost_bo(gem_obj)->is_heap))
> + return -EINVAL;
> +
> ret = drm_gem_create_mmap_offset(gem_obj);
> if (ret == 0)
> args->offset = drm_vma_node_offset_addr(&gem_obj->vma_node);
>
Seems reasonable to me - we can always add support for mmap()ing at a
later date if it becomes useful.
>> Also shmem->pages_use_count needs incrementing to stop
>> drm_gem_shmem_get_pages() replacing bo->base.pages. I haven't tested
>> what happens if you mmap *after* the first fault.
>
> I set pages_use_count to 1 when we allocate pages on the first fault.
> Or do you mean we need to set it on creation in case
> drm_gem_shmem_get_pages() is called before any GPU faults?
>
> Either way, that just shifts how/where we crash I think. We need to
> prevent drm_gem_shmem_get_pages() from being called. Besides mmap, the
> other cases are vmap and exporting. I don't think we have any paths
> that will cause vmap to get called in our case. For exporting, perhaps
> we need a wrapper around drm_gem_shmem_pin() to prevent it.
Yes, either every path to drm_gem_shmem_get_pages() needs to be blocked
for HEAP objects, or you need to set pages_use_count to 1 when you
allocate (which then means drm_gem_shmem_get_pages() will simply
increment the ref-count).
Of course if you are leaving any calls to drm_gem_shmem_get_pages()
reachable then you also need to ensure that the code that follows
understands how to deal with a sparse bo->pages array. Exporting would
be a good example - and again I suspect just preventing it is fine for now.
Steve
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2019-07-31 9:30 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-25 1:09 [PATCH v2 0/7] drm/panfrost: Add heap and no execute buffer allocation Rob Herring
2019-07-25 1:09 ` [PATCH v2 1/7] drm/gem: Allow sparsely populated page arrays in drm_gem_put_pages Rob Herring
2019-07-25 15:36 ` Steven Price
2019-07-25 1:09 ` [PATCH v2 2/7] drm/shmem: Put pages independent of a SG table being set Rob Herring
2019-07-25 15:38 ` Steven Price
2019-07-25 1:09 ` [PATCH v2 3/7] drm/panfrost: Restructure the GEM object creation Rob Herring
2019-07-25 15:40 ` Steven Price
2019-07-25 1:10 ` [PATCH v2 4/7] drm/panfrost: Split panfrost_mmu_map SG list mapping to its own function Rob Herring
2019-07-25 1:10 ` [PATCH v2 5/7] drm/panfrost: Add a no execute flag for BO allocations Rob Herring
2019-07-25 15:45 ` Steven Price
2019-07-25 1:10 ` [PATCH v2 6/7] drm/panfrost: Add support for GPU heap allocations Rob Herring
2019-07-25 13:08 ` Robin Murphy
2019-07-25 21:11 ` Rob Herring
2019-07-26 9:15 ` Steven Price
2019-07-26 9:32 ` Robin Murphy
2019-07-26 16:11 ` Rob Herring
2019-07-25 14:59 ` Steven Price
2019-07-25 15:35 ` Steven Price
2019-07-25 16:13 ` Alyssa Rosenzweig
2019-07-25 16:28 ` Steven Price
2019-07-25 17:40 ` Alyssa Rosenzweig
2019-07-26 10:43 ` Steven Price
2019-07-26 13:57 ` Alyssa Rosenzweig
2019-07-30 18:49 ` Rob Herring
[not found] ` <20190730185455.GA3205@kevin>
2019-07-30 19:08 ` Rob Herring
2019-07-31 9:22 ` Steven Price
2019-07-25 21:28 ` Rob Herring
2019-07-26 9:20 ` Steven Price
2019-07-30 20:03 ` Rob Herring
2019-07-31 9:30 ` Steven Price [this message]
2019-07-25 1:10 ` [PATCH v2 7/7] drm/panfrost: Bump driver version to 1.1 Rob Herring
2019-07-25 13:04 ` [PATCH v2 0/7] drm/panfrost: Add heap and no execute buffer allocation Alyssa Rosenzweig
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=2aa4cc3f-03c2-ae7b-d3b8-683ac9b06dc6@arm.com \
--to=steven.price@arm.com \
--cc=airlied@linux.ie \
--cc=alyssa.rosenzweig@collabora.com \
--cc=boris.brezillon@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=maxime.ripard@bootlin.com \
--cc=robh@kernel.org \
--cc=robin.murphy@arm.com \
--cc=sean@poorly.run \
--cc=tomeu.vizoso@collabora.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