[PATCH v2 2/3] drm/amdgpu: introduce kfd user flag for amdgpu_bo

Christian König christian.koenig at amd.com
Wed Mar 3 12:46:02 UTC 2021



Am 03.03.21 um 13:41 schrieb Nirmoy:
> [SNIP]
>>
>>> +             struct amdgpu_bo_param *bp,
>>> +             struct amdgpu_bo **bo_ptr)
>>> +{
>>> +    u64 flags = bp->flags;
>>> +    int r;
>>> +
>>> +    bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW;
>>> +    bp->flags = bp->flags | AMDGPU_GEM_CREATE_KFD;
>>> +    r = amdgpu_bo_do_create(adev, bp, bo_ptr);
>>> +    if (r)
>>> +        return r;
>>> +
>>> +    if ((flags & AMDGPU_GEM_CREATE_SHADOW) && !(adev->flags & 
>>> AMD_IS_APU)) {
>>> +        if (!bp->resv)
>>> + WARN_ON(dma_resv_lock((*bo_ptr)->tbo.base.resv,
>>> +                            NULL));
>>> +
>>> +        r = amdgpu_bo_create_shadow(adev, bp->size, *bo_ptr);
>>> +
>>> +        if (!bp->resv)
>>> +            dma_resv_unlock((*bo_ptr)->tbo.base.resv);
>>> +
>>> +        if (r)
>>> +            amdgpu_bo_unref(bo_ptr);
>>> +    }
>>
>> I don't think the KFD should ever have a reason to use the shadow 
>> buffer functionality.
>
>
> This is interesting, I didn't know. I will remove 
> amdgpu_bo_create_shadow().

Well the VM code is using the shadow stuff.

>
>
>>
>>> +
>>> +    return r;
>>> +}
>>> +
>>> +
>>>   /**
>>>    * amdgpu_bo_validate - validate an &amdgpu_bo buffer object
>>>    * @bo: pointer to the buffer object
>>> @@ -1309,7 +1355,7 @@ void amdgpu_bo_release_notify(struct 
>>> ttm_buffer_object *bo)
>>>
>>>       abo = ttm_to_amdgpu_bo(bo);
>>>
>>> -    if (abo->kfd_bo)
>>> +    if (abo->flags & AMDGPU_GEM_CREATE_KFD)
>>>           amdgpu_amdkfd_unreserve_memory_limit(abo);
>>>
>>>       /* We only remove the fence if the resv has individualized. */
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h 
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>>> index 8cd96c9330dd..665ee0015f06 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>>> @@ -245,6 +245,9 @@ void amdgpu_bo_placement_from_domain(struct 
>>> amdgpu_bo *abo, u32 domain);
>>>   int amdgpu_bo_create(struct amdgpu_device *adev,
>>>                struct amdgpu_bo_param *bp,
>>>                struct amdgpu_bo **bo_ptr);
>>> +int amdgpu_kfd_bo_create(struct amdgpu_device *adev,
>>> +             struct amdgpu_bo_param *bp,
>>> +             struct amdgpu_bo **bo_ptr);
>>>   int amdgpu_bo_create_reserved(struct amdgpu_device *adev,
>>>                     unsigned long size, int align,
>>>                     u32 domain, struct amdgpu_bo **bo_ptr,
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>>> index 7b2db779f313..030bec382f54 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>>> @@ -164,7 +164,7 @@ static int amdgpu_verify_access(struct 
>>> ttm_buffer_object *bo, struct file *filp)
>>>        * Don't verify access for KFD BOs. They don't have a GEM
>>>        * object associated with them.
>>>        */
>>> -    if (abo->kfd_bo)
>>> +    if (abo->flags & AMDGPU_GEM_CREATE_KFD)
>>>           return 0;
>>>
>>>       if (amdgpu_ttm_tt_get_usermm(bo->ttm))
>>> diff --git a/include/uapi/drm/amdgpu_drm.h 
>>> b/include/uapi/drm/amdgpu_drm.h
>>> index 8b832f7458f2..f510e8302228 100644
>>> --- a/include/uapi/drm/amdgpu_drm.h
>>> +++ b/include/uapi/drm/amdgpu_drm.h
>>> @@ -142,6 +142,11 @@ extern "C" {
>>>    */
>>>   #define AMDGPU_GEM_CREATE_ENCRYPTED        (1 << 10)
>>>
>>> +/* Flag that the allocating BO's user is KFD. It should never be 
>>> used by
>>> + * user space applications
>>> + */
>>> +#define AMDGPU_GEM_CREATE_KFD            (1 << 20)
>>
>> Why 20? 11 is the next one here.
>
>
> I feel BO owner flag is different than others so wanted to reserve 
> some bits for grouping.
>
> I can assign it to 11 if that makes more sense.

We already have other flags which userspace is not allowed to use, so 
this is nothing special here.

Christian.

>
>
> Thanks,
>
> Nirmoy
>
>
>
>>
>> Christian.
>>
>>> +
>>>   struct drm_amdgpu_gem_create_in  {
>>>       /** the requested memory size */
>>>       __u64 bo_size;
>>> -- 
>>> 2.30.1
>>>
>>> _______________________________________________
>>> amd-gfx mailing list
>>> amd-gfx at lists.freedesktop.org
>>> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=04%7C01%7Cnirmoy.das%40amd.com%7C5c41ee9032df45e36f1508d8de3c0c57%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637503696776437773%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=1Lbaor5CuBUsnxr%2BQgB6zDYbRQVPWogth7gpIOhYRFI%3D&reserved=0 
>>>
>>



More information about the amd-gfx mailing list