All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Zhang, Jerry (Junwei)" <Jerry.Zhang-5C7GfCeVMHo@public.gmane.org>
To: christian.koenig-5C7GfCeVMHo@public.gmane.org,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Cc: Chunming Zhou <David1.Zhou-5C7GfCeVMHo@public.gmane.org>
Subject: Re: [PATCH 1/2] drm/amdgpu: return bo itself if userptr is cpu addr of bo (v3)
Date: Tue, 31 Jul 2018 16:58:05 +0800	[thread overview]
Message-ID: <5B60249D.7030503@amd.com> (raw)
In-Reply-To: <5e8f2a76-6cbd-1f80-ec94-fcd79c0fa55c-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

On 07/31/2018 04:13 PM, Christian König wrote:
> Am 31.07.2018 um 10:05 schrieb Zhang, Jerry (Junwei):
>> On 07/31/2018 03:03 PM, Christian König wrote:
>>> Am 31.07.2018 um 08:58 schrieb Zhang, Jerry (Junwei):
>>>> On 07/30/2018 06:47 PM, Christian König wrote:
>>>>> Am 30.07.2018 um 12:02 schrieb Junwei Zhang:
>>>>>> From: Chunming Zhou <David1.Zhou@amd.com>
>>>>>>
>>>>>> v2: get original gem handle from gobj
>>>>>> v3: update find bo data structure as union(in, out)
>>>>>>      simply some code logic
>>>>>
>>>>> Do we now have an open source user for this, so that we can upstream it? One more point below.
>>>>>
>>>>>>
>>>>>> Signed-off-by: Chunming Zhou <David1.Zhou@amd.com>
>>>>>> Signed-off-by: Junwei Zhang <Jerry.Zhang@amd.com> (v3)
>>>>>> Reviewed-by: Christian König <christian.koenig@amd.com>
>>>>>> Reviewed-by: Jammy Zhou <Jammy.Zhou@amd.com>
>>>>>> ---
>>>>>>   drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  2 ++
>>>>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 63 +++++++++++++++++++++++++++++++++
>>>>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  3 +-
>>>>>>   include/uapi/drm/amdgpu_drm.h           | 21 +++++++++++
>>>>>>   4 files changed, 88 insertions(+), 1 deletion(-)
>>>>>>
>>>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>>>>>> index 4cd20e7..46c370b 100644
>>>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>>>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>>>>>> @@ -1213,6 +1213,8 @@ int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
>>>>>>                 struct drm_file *filp);
>>>>>>   int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
>>>>>>               struct drm_file *filp);
>>>>>> +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl(struct drm_device *dev, void *data,
>>>>>> +                        struct drm_file *filp);
>>>>>>   int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
>>>>>>                 struct drm_file *filp);
>>>>>>   int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
>>>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>>>>> index 71792d8..bae8417 100644
>>>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>>>>> @@ -288,6 +288,69 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
>>>>>>       return 0;
>>>>>>   }
>>>>>> +static int amdgpu_gem_get_handle_from_object(struct drm_file *filp,
>>>>>> +                         struct drm_gem_object *obj)
>>>>>> +{
>>>>>> +    int i;
>>>>>> +    struct drm_gem_object *tmp;
>>>>>> +
>>>>>> +    spin_lock(&filp->table_lock);
>>>>>> +    idr_for_each_entry(&filp->object_idr, tmp, i) {
>>>>>> +        if (obj == tmp) {
>>>>>> +            drm_gem_object_reference(obj);
>>>>>> +            spin_unlock(&filp->table_lock);
>>>>>> +            return i;
>>>>>> +        }
>>>>>> +    }
>>>>>
>>>>> Please double check if that is still up to date.
>>>>
>>>> We may have to replace drm_gem_object_reference() with drm_gem_object_get().
>>>>
>>>> On 2nd thought, do we really need to do reference every time?
>>>
>>> Yes, that's a must have. Otherwise the handle could be freed and reused already when we return.
>>>
>>>> if UMD find the same gem object for 3 times, it also need to explicitly free(put) that object for 3 times?
>>>
>>> Correct yes. Thinking more about this the real problem is to translate the handle into a structure in libdrm.
>>>
>>> Here we are back to the problem Marek and Michel has been working on for a while that we always need to be able to translate a handle into a bo structure.....
>>>
>>> So that needs to be solved before we can upstream the changes.
>>
>> Thanks for your info.
>> It's better to fix that before upstream.
>
> Thinking more about this the hash currently used in libdrm is not adequate any more.
>
> E.g. we now need to be able to find all BOs based on their handle. Since the handles are dense either an r/b tree or a radix tree now sounds like the best approach to me.

Not sure the exact reason that we added hash table in libdrm.
But it really costs much less time than calling IOCTL to find BO by their handles.

In this case, UMD seems not to be able to get BO handle and try to verify it by cpu address then.
In another word, UMD would like to find if the memory is created as BO or system memory, I suppose.

Regards,
Jerry


>
> Christian.
>
>>
>> Regards,
>> Jerry
>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2018-07-31  8:58 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-30 10:02 [PATCH 1/2] drm/amdgpu: return bo itself if userptr is cpu addr of bo (v3) Junwei Zhang
     [not found] ` <1532944950-28619-1-git-send-email-Jerry.Zhang-5C7GfCeVMHo@public.gmane.org>
2018-07-30 10:02   ` [PATCH 2/2] drm/amdgpu: bump version for API to find bo by cpu mapping Junwei Zhang
2018-07-30 10:47   ` [PATCH 1/2] drm/amdgpu: return bo itself if userptr is cpu addr of bo (v3) Christian König
     [not found]     ` <3d423f44-e47a-e70c-dfd9-80c1ff843e45-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-07-31  1:40       ` Zhou, David(ChunMing)
     [not found]         ` <SN1PR12MB051036BA7AC3560A4FAC68A1B42E0-z7L1TMIYDg5tVDmkcP8tDwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2018-07-31  1:49           ` Zhou, David(ChunMing)
     [not found]             ` <SN1PR12MB05106FBFF052EDFD49193ABCB42E0-z7L1TMIYDg5tVDmkcP8tDwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2018-07-31  2:32               ` Zhang, Jerry (Junwei)
2018-07-31  6:54           ` Christian König
2018-07-31  6:58       ` Zhang, Jerry (Junwei)
     [not found]         ` <5B6008A1.5050401-5C7GfCeVMHo@public.gmane.org>
2018-07-31  7:03           ` Christian König
     [not found]             ` <c6b11c1f-b32a-4ab8-6a78-aa7886eed60a-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-07-31  8:05               ` Zhang, Jerry (Junwei)
     [not found]                 ` <5B601844.3010405-5C7GfCeVMHo@public.gmane.org>
2018-07-31  8:13                   ` Christian König
     [not found]                     ` <5e8f2a76-6cbd-1f80-ec94-fcd79c0fa55c-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-07-31  8:58                       ` Zhang, Jerry (Junwei) [this message]
     [not found]                         ` <5B60249D.7030503-5C7GfCeVMHo@public.gmane.org>
2018-07-31  9:04                           ` Christian König
     [not found]                             ` <9dc68d5d-561c-242a-b3ba-1c8078ab670f-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-07-31  9:54                               ` Zhang, Jerry (Junwei)
     [not found]                                 ` <5B6031CA.4050102-5C7GfCeVMHo@public.gmane.org>
2018-07-31 10:13                                   ` Christian König
     [not found]                                     ` <3ffb8b8c-fae3-92d9-80e1-bd7d0498b4c7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-07-31 22:07                                       ` Marek Olšák
     [not found]                                         ` <CAAxE2A6uLe_ZMTGQ2dqFbY--Mf15qRrP+tX6pbicokpe8Wo=qQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-08-01  6:32                                           ` Christian König
     [not found]                                             ` <53eb686a-0747-394a-b0c3-4cd53ab836e2-5C7GfCeVMHo@public.gmane.org>
2018-08-01 17:39                                               ` Marek Olšák
     [not found]                                                 ` <CAAxE2A6C0mmr2vogcAQL+XNQuPU=BqHUGjqAMVnS3pK37XJa0A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-08-01 17:52                                                   ` Christian König
     [not found]                                                     ` <edbcf817-75ea-6e6a-d64a-6274a78308e7-5C7GfCeVMHo@public.gmane.org>
2018-08-01 17:59                                                       ` Marek Olšák
     [not found]                                                         ` <CAAxE2A4=k5_20jaPcM9awxQ69MhXY2wtEX9NFxZU9=43_SsRug-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-08-01 18:29                                                           ` Christian König
     [not found]                                                             ` <ba1798f5-9aa9-6d55-791a-b2fd52087ea7-5C7GfCeVMHo@public.gmane.org>
2018-08-02  0:00                                                               ` Marek Olšák
     [not found]                                                                 ` <CAAxE2A4bma0u8R+ggETPoUycC=MTkrs0oUGJFW8kGx__Sf35eQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-08-02  6:20                                                                   ` Zhang, Jerry (Junwei)
     [not found]                                                                     ` <5B62A2A0.5060508-5C7GfCeVMHo@public.gmane.org>
2018-08-02  6:29                                                                       ` 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=5B60249D.7030503@amd.com \
    --to=jerry.zhang-5c7gfcevmho@public.gmane.org \
    --cc=David1.Zhou-5C7GfCeVMHo@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=christian.koenig-5C7GfCeVMHo@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.