amd-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: "Christian König" <ckoenig.leichtzumerken@gmail.com>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	alexander.deucher@amd.com, airlied@linux.ie, daniel@ffwll.ch,
	bskeggs@redhat.com, ray.huang@amd.com,
	linux-graphics-maintainer@vmware.com, sroland@vmware.com,
	zackr@vmware.com, shashank.sharma@amd.com, sam@ravnborg.org,
	emil.velikov@collabora.com, Felix.Kuehling@amd.com,
	nirmoy.das@amd.com
Cc: nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v3 5/7] drm/vmwgfx: Inline ttm_bo_mmap() into vmwgfx driver
Date: Fri, 16 Apr 2021 15:51:25 +0200	[thread overview]
Message-ID: <80012c09-6975-f694-420f-72b2236dcf4e@amd.com> (raw)
In-Reply-To: <b7008944-fbe5-bd59-d2a9-ff62bea38237@gmail.com>

Am 16.04.21 um 15:46 schrieb Christian König:
> Am 16.04.21 um 15:31 schrieb Thomas Zimmermann:
>> The vmwgfx driver is the only remaining user of ttm_bo_mmap(). Inline
>> the code. The internal helper ttm_bo_vm_lookup() is now also part of
>> vmwgfx as vmw_bo_vm_lookup().
>>
>> v2:
>>     * replace pr_err() with drm_err() (Zack)
>>
>> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
>> Reviewed-by: Zack Rusin <zackr@vmware.com>
>> ---
>>   drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 56 ++++++++++++++++++++++--
>>   1 file changed, 53 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c 
>> b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
>> index cb9975889e2f..c8b6543b4e39 100644
>> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
>> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
>> @@ -27,6 +27,32 @@
>>     #include "vmwgfx_drv.h"
>>   +static struct ttm_buffer_object *vmw_bo_vm_lookup(struct 
>> ttm_device *bdev,
>> +                          unsigned long offset,
>> +                          unsigned long pages)
>> +{
>> +    struct vmw_private *dev_priv = container_of(bdev, struct 
>> vmw_private, bdev);
>> +    struct drm_device *drm = &dev_priv->drm;
>> +    struct drm_vma_offset_node *node;
>> +    struct ttm_buffer_object *bo = NULL;
>> +
>> +    drm_vma_offset_lock_lookup(bdev->vma_manager);
>> +
>> +    node = drm_vma_offset_lookup_locked(bdev->vma_manager, offset, 
>> pages);
>> +    if (likely(node)) {
>> +        bo = container_of(node, struct ttm_buffer_object,
>> +                  base.vma_node);
>> +        bo = ttm_bo_get_unless_zero(bo);
>> +    }
>> +
>> +    drm_vma_offset_unlock_lookup(bdev->vma_manager);
>> +
>> +    if (!bo)
>> +        drm_err(drm, "Could not find buffer object to map\n");
>> +
>> +    return bo;
>> +}
>> +
>>   int vmw_mmap(struct file *filp, struct vm_area_struct *vma)
>>   {
>>       static const struct vm_operations_struct vmw_vm_ops = {
>> @@ -41,10 +67,28 @@ int vmw_mmap(struct file *filp, struct 
>> vm_area_struct *vma)
>>       };
>>       struct drm_file *file_priv = filp->private_data;
>>       struct vmw_private *dev_priv = vmw_priv(file_priv->minor->dev);
>> -    int ret = ttm_bo_mmap(filp, vma, &dev_priv->bdev);
>> +    struct ttm_device *bdev = &dev_priv->bdev;
>> +    struct ttm_buffer_object *bo;
>> +    int ret;
>> +
>> +    if (unlikely(vma->vm_pgoff < DRM_FILE_PAGE_OFFSET_START))
>> +        return -EINVAL;
>> +
>> +    bo = vmw_bo_vm_lookup(bdev, vma->vm_pgoff, vma_pages(vma));
>> +    if (unlikely(!bo))
>> +        return -EINVAL;
>>   -    if (ret)
>> -        return ret;
>> +    if (unlikely(!bo->bdev->funcs->verify_access)) {
>> +        ret = -EPERM;
>> +        goto out_unref;
>> +    }
>> +    ret = bo->bdev->funcs->verify_access(bo, filp);
>
> Is there any reason we can't call vmw_verify_access() directly here?
>
> Would allow us to completely nuke the verify_access callback as well 
> as far as I can see.

Forget what I said, couldn't see the next patch in my mailbox at time of 
writing.

Whole series is Reviewed-by: Christian König <christian.koenig@amd.com>

Thanks for the nice cleanup,
Christian.

>
> Regards,
> Christian.
>
>> +    if (unlikely(ret != 0))
>> +        goto out_unref;
>> +
>> +    ret = ttm_bo_mmap_obj(vma, bo);
>> +    if (unlikely(ret != 0))
>> +        goto out_unref;
>>         vma->vm_ops = &vmw_vm_ops;
>>   @@ -52,7 +96,13 @@ int vmw_mmap(struct file *filp, struct 
>> vm_area_struct *vma)
>>       if (!is_cow_mapping(vma->vm_flags))
>>           vma->vm_flags = (vma->vm_flags & ~VM_MIXEDMAP) | VM_PFNMAP;
>>   +    ttm_bo_put(bo); /* release extra ref taken by 
>> ttm_bo_mmap_obj() */
>> +
>>       return 0;
>> +
>> +out_unref:
>> +    ttm_bo_put(bo);
>> +    return ret;
>>   }
>>     /* struct vmw_validation_mem callback */
>

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  reply	other threads:[~2021-04-16 13:51 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-16 13:31 [PATCH v3 0/7] drm: Clean up mmap for TTM-based GEM drivers Thomas Zimmermann
2021-04-16 13:31 ` [PATCH v3 1/7] drm/ttm: Don't override vm_ops callbacks, if set Thomas Zimmermann
2021-04-16 13:31 ` [PATCH v3 2/7] drm/amdgpu: Implement mmap as GEM object function Thomas Zimmermann
2021-04-16 13:31 ` [PATCH v3 3/7] drm/radeon: " Thomas Zimmermann
2021-04-16 13:31 ` [PATCH v3 4/7] drm/nouveau: " Thomas Zimmermann
2021-04-16 13:31 ` [PATCH v3 5/7] drm/vmwgfx: Inline ttm_bo_mmap() into vmwgfx driver Thomas Zimmermann
2021-04-16 13:46   ` Christian König
2021-04-16 13:51     ` Christian König [this message]
2021-04-20  7:51       ` Thomas Zimmermann
2021-04-20  8:51         ` Daniel Vetter
2021-04-20 20:22           ` Felix Kuehling
2021-04-20 20:53             ` Daniel Vetter
2021-04-21  7:01               ` Christian König
2021-04-21  9:12                 ` Daniel Vetter
2021-04-16 14:00     ` Thomas Zimmermann
2021-04-16 13:31 ` [PATCH v3 6/7] drm/vmwgfx: Inline vmw_verify_access() Thomas Zimmermann
2021-04-16 13:31 ` [PATCH v3 7/7] drm/ttm: Remove ttm_bo_mmap() and friends Thomas Zimmermann
2021-04-16 13:44 ` [PATCH v3 0/7] drm: Clean up mmap for TTM-based GEM drivers 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=80012c09-6975-f694-420f-72b2236dcf4e@amd.com \
    --to=christian.koenig@amd.com \
    --cc=Felix.Kuehling@amd.com \
    --cc=airlied@linux.ie \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=bskeggs@redhat.com \
    --cc=ckoenig.leichtzumerken@gmail.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=emil.velikov@collabora.com \
    --cc=linux-graphics-maintainer@vmware.com \
    --cc=nirmoy.das@amd.com \
    --cc=nouveau@lists.freedesktop.org \
    --cc=ray.huang@amd.com \
    --cc=sam@ravnborg.org \
    --cc=shashank.sharma@amd.com \
    --cc=sroland@vmware.com \
    --cc=tzimmermann@suse.de \
    --cc=zackr@vmware.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;
as well as URLs for NNTP newsgroup(s).