From: Matthew Auld <matthew.auld@intel.com>
To: Andi Shyti <andi.shyti@linux.intel.com>
Cc: intel-gfx@lists.freedesktop.org,
Jonathan Cavitt <jonathan.cavitt@intel.com>,
andrzej.hajda@intel.com, nirmoy.das@intel.com
Subject: Re: [Intel-gfx] [PATCH] drm/i915/ttm: Fix access_memory null pointer exception
Date: Fri, 14 Oct 2022 10:44:11 +0100 [thread overview]
Message-ID: <d6b14cec-ef71-15ff-161b-de9c5e9e4d1c@intel.com> (raw)
In-Reply-To: <Y0kkIzaDeMxpuawT@ashyti-mobl2.lan>
On 14/10/2022 09:56, Andi Shyti wrote:
> On Fri, Oct 14, 2022 at 09:39:52AM +0100, Matthew Auld wrote:
>> On 13/10/2022 18:56, Jonathan Cavitt wrote:
>>> i915_ttm_to_gem can return a NULL pointer, which is
>>> dereferenced in i915_ttm_access_memory without first
>>> checking if it is NULL. Inspecting
>>> i915_ttm_io_mem_reserve, it appears the correct
>>> behavior in this case is to return -EINVAL.
>>
>> The GEM object has already been dereferenced before this point, if you look
>> at the caller (vm_access_ttm). The NULL obj thing is to identify "ttm ghost
>> objects", and I don't think a normal userpace object can suddenly become one
>> (access_memory comes from ptrace). AFAIK ghost objects are just for
>> temporarily hanging on to some memory/state, while the dma-resv is busy. In
>> the places where ttm is the one giving us the object, then it might be
>> possible to see these types of objects, since ttm could in theory pass one
>> in (like during eviction).
>
> True that, but because from a code persepctive we can still receive
> NULL, I think the check is correct, perhaps we could:
>
> if (unlikely(!obj))
> return -EINVAL;
Hmm, so that will dereference some pointer, and then later check if it
is NULL here? Or do you mean to move this into vm_access()? If we are
given a "ghost object" for ptrace this would likely mean we have a very
nasty bug somewhere (unless I'm misunderstanding something), and so
returning a normal user error here doesn't seem right to me (maybe this
just hides the issue)? Letting it crash seems fine to me tbh. It also
makes the code harder to understand IMO, because looking at this it now
suggests that it is somehow possible to have a "ghost object" here. Also
there are a fair few places calling i915_ttm_to_gem() which already
don't check for NULL, since it should be impossible, like it should be here.
>
> Andi
>
>>> Fixes: 26b15eb0 ("drm/i915/ttm: implement access_memory")
>>> Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
>>> Suggested-by: John C Harrison <John.C.Harrison@intel.com>
>>> CC: Matthew Auld <matthew.auld@intel.com>
>>> CC: Andrzej Hajda <andrzej.hajda@intel.com>
>>> CC: Nirmoy Das <nirmoy.das@intel.com>
>>> CC: Andi Shyti <andi.shyti@linux.intel.com>
>>> ---
>>> drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 9 +++++++--
>>> 1 file changed, 7 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
>>> index d63f30efd631..b569624f2ed9 100644
>>> --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
>>> +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
>>> @@ -704,11 +704,16 @@ static int i915_ttm_access_memory(struct ttm_buffer_object *bo,
>>> int len, int write)
>>> {
>>> struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
>>> - resource_size_t iomap = obj->mm.region->iomap.base -
>>> - obj->mm.region->region.start;
>>> + resource_size_t iomap;
>>> unsigned long page = offset >> PAGE_SHIFT;
>>> unsigned long bytes_left = len;
>>> + if (!obj)
>>> + return -EINVAL;
>>> +
>>> + iomap = obj->mm.region->iomap.base -
>>> + obj->mm.region->region.start;
>>> +
>>> /*
>>> * TODO: For now just let it fail if the resource is non-mappable,
>>> * otherwise we need to perform the memcpy from the gpu here, without
next prev parent reply other threads:[~2022-10-14 9:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-13 17:56 [Intel-gfx] [PATCH] drm/i915/ttm: Fix access_memory null pointer exception Jonathan Cavitt
2022-10-13 19:28 ` [Intel-gfx] ✓ Fi.CI.BAT: success for " Patchwork
2022-10-13 23:07 ` [Intel-gfx] ✓ Fi.CI.IGT: " Patchwork
2022-10-14 8:39 ` [Intel-gfx] [PATCH] " Matthew Auld
2022-10-14 8:56 ` Andi Shyti
2022-10-14 9:44 ` Matthew Auld [this message]
2022-10-14 14:49 ` Andi Shyti
2022-10-14 9:27 ` Das, Nirmoy
2022-10-14 10:13 ` Matthew Auld
2022-10-14 10:38 ` Das, Nirmoy
2022-10-14 10:52 ` Matthew Auld
2022-10-14 10:56 ` Das, Nirmoy
2022-10-14 8:47 ` Andi Shyti
2022-10-14 9:02 ` Andrzej Hajda
2022-10-14 9:52 ` Tvrtko Ursulin
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=d6b14cec-ef71-15ff-161b-de9c5e9e4d1c@intel.com \
--to=matthew.auld@intel.com \
--cc=andi.shyti@linux.intel.com \
--cc=andrzej.hajda@intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jonathan.cavitt@intel.com \
--cc=nirmoy.das@intel.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