All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: Lucas Stach <l.stach@pengutronix.de>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	dri-devel <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH 2/6] drm/omap: gem: Merge __omap_gem_get_pages() and omap_gem_attach_pages()
Date: Wed, 4 Apr 2018 18:18:42 +0200	[thread overview]
Message-ID: <CAKMK7uF9tRP5wKubCftxHMvkCToGEgUpS-84Whve=cc4FioKjA@mail.gmail.com> (raw)
In-Reply-To: <1522849077.3779.8.camel@pengutronix.de>

On Wed, Apr 4, 2018 at 3:37 PM, Lucas Stach <l.stach@pengutronix.de> wrote:
> Am Montag, den 02.04.2018, 21:50 +0300 schrieb Laurent Pinchart:
>> The __omap_gem_get_pages() function is a wrapper around
>> omap_gem_attach_pages() that returns the omap_obj->pages pointer through
>> a function argument. Some callers don't need the pages pointer, and all
>> of them can access omap_obj->pages directly. To simplify the code merge
>> the __omap_gem_get_pages() wrapper with omap_gem_attach_pages() and
>> update the callers accordingly.
>>
>> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>> ---
>>  drivers/gpu/drm/omapdrm/omap_gem.c | 62 ++++++++++++++------------------------
>>  1 file changed, 23 insertions(+), 39 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c b/drivers/gpu/drm/omapdrm/omap_gem.c
>> index 6cfcf60cffe3..13fea207343e 100644
>> --- a/drivers/gpu/drm/omapdrm/omap_gem.c
>> +++ b/drivers/gpu/drm/omapdrm/omap_gem.c
>> @@ -222,7 +222,10 @@ static void omap_gem_evict(struct drm_gem_object *obj)
>>   * Page Management
>>   */
>>
>> -/** ensure backing pages are allocated */
>> +/*
>> + * Ensure backing pages are allocated. Must be called with the omap_obj.lock
>> + * held.
>> + */
>
> Drive-by comment: I always find it hard to validate those comment-only
> lock prerequisites, especially if callstacks get deeper.
>
> What we do in etnaviv is to make those lock comments executable by
> using lockdep_assert_held() to validate the locking assumptions. This
> makes sure that if you ever manage to violate the locking in a code
> rework, a lockdep enabled debug build will explode right at the spot.

+1 on this. I've gone as far as removing all the locking related
comments in core drm code because most of it was misleading or
outright wrong. The runtime checks have a much higher chance of
actually being correct :-)
-Daniel

>
> Regards,
> Lucas
>
>>  static int omap_gem_attach_pages(struct drm_gem_object *obj)
>>  {
>> >     struct drm_device *dev = obj->dev;
>> @@ -232,7 +235,12 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj)
>> >     int i, ret;
>> >     dma_addr_t *addrs;
>>
>> > -   WARN_ON(omap_obj->pages);
>> > +   /*
>> > +    * If not using shmem (in which case backing pages don't need to be
>> > +    * allocated) or if pages are already allocated we're done.
>> > +    */
>> > +   if (!(omap_obj->flags & OMAP_BO_MEM_SHMEM) || omap_obj->pages)
>> > +           return 0;
>>
>> >     pages = drm_gem_get_pages(obj);
>> >     if (IS_ERR(pages)) {
>> @@ -288,29 +296,6 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj)
>> >     return ret;
>>  }
>>
>> -/* acquire pages when needed (for example, for DMA where physically
>> - * contiguous buffer is not required
>> - */
>> -static int __omap_gem_get_pages(struct drm_gem_object *obj,
>> > -                           struct page ***pages)
>> -{
>> > -   struct omap_gem_object *omap_obj = to_omap_bo(obj);
>> > -   int ret = 0;
>> -
>> > -   if ((omap_obj->flags & OMAP_BO_MEM_SHMEM) && !omap_obj->pages) {
>> > -           ret = omap_gem_attach_pages(obj);
>> > -           if (ret) {
>> > -                   dev_err(obj->dev->dev, "could not attach pages\n");
>> > -                   return ret;
>> > -           }
>> > -   }
>> -
>> > -   /* TODO: even phys-contig.. we should have a list of pages? */
>> > -   *pages = omap_obj->pages;
>> -
>> > -   return 0;
>> -}
>> -
>>  /** release backing pages */
>>  static void omap_gem_detach_pages(struct drm_gem_object *obj)
>>  {
>> @@ -516,7 +501,6 @@ int omap_gem_fault(struct vm_fault *vmf)
>> >     struct drm_gem_object *obj = vma->vm_private_data;
>> >     struct omap_gem_object *omap_obj = to_omap_bo(obj);
>> >     struct drm_device *dev = obj->dev;
>> > -   struct page **pages;
>> >     int ret;
>>
>> >     /* Make sure we don't parallel update on a fault, nor move or remove
>> @@ -525,7 +509,7 @@ int omap_gem_fault(struct vm_fault *vmf)
>> >     mutex_lock(&dev->struct_mutex);
>>
>> >     /* if a shmem backed object, make sure we have pages attached now */
>> > -   ret = __omap_gem_get_pages(obj, &pages);
>> > +   ret = omap_gem_attach_pages(obj);
>> >     if (ret)
>> >             goto fail;
>>
>> @@ -694,12 +678,12 @@ int omap_gem_roll(struct drm_gem_object *obj, u32 roll)
>>
>> >     /* if we aren't mapped yet, we don't need to do anything */
>> >     if (omap_obj->block) {
>> > -           struct page **pages;
>> -
>> > -           ret = __omap_gem_get_pages(obj, &pages);
>> > +           ret = omap_gem_attach_pages(obj);
>> >             if (ret)
>> >                     goto fail;
>> > -           ret = tiler_pin(omap_obj->block, pages, npages, roll, true);
>> +
>> > +           ret = tiler_pin(omap_obj->block, omap_obj->pages, npages,
>> > +                           roll, true);
>> >             if (ret)
>> >                     dev_err(obj->dev->dev, "could not repin: %d\n", ret);
>> >     }
>> @@ -810,14 +794,13 @@ int omap_gem_pin(struct drm_gem_object *obj, dma_addr_t *dma_addr)
>>
>> >     if (!omap_gem_is_contiguous(omap_obj) && priv->has_dmm) {
>> >             if (omap_obj->dma_addr_cnt == 0) {
>> > -                   struct page **pages;
>> >                     u32 npages = obj->size >> PAGE_SHIFT;
>> >                     enum tiler_fmt fmt = gem2fmt(omap_obj->flags);
>> >                     struct tiler_block *block;
>>
>> >                     BUG_ON(omap_obj->block);
>>
>> > -                   ret = __omap_gem_get_pages(obj, &pages);
>> > +                   ret = omap_gem_attach_pages(obj);
>> >                     if (ret)
>> >                             goto fail;
>>
>> @@ -837,7 +820,7 @@ int omap_gem_pin(struct drm_gem_object *obj, dma_addr_t *dma_addr)
>> >                     }
>>
>> >                     /* TODO: enable async refill.. */
>> > -                   ret = tiler_pin(block, pages, npages,
>> > +                   ret = tiler_pin(block, omap_obj->pages, npages,
>> >                                     omap_obj->roll, true);
>> >                     if (ret) {
>> >                             tiler_release(block);
>> @@ -946,16 +929,18 @@ int omap_gem_tiled_stride(struct drm_gem_object *obj, u32 orient)
>>  int omap_gem_get_pages(struct drm_gem_object *obj, struct page ***pages,
>> >             bool remap)
>>  {
>> > +   struct omap_gem_object *omap_obj = to_omap_bo(obj);
>> >     int ret;
>> +
>> >     if (!remap) {
>> > -           struct omap_gem_object *omap_obj = to_omap_bo(obj);
>> >             if (!omap_obj->pages)
>> >                     return -ENOMEM;
>> >             *pages = omap_obj->pages;
>> >             return 0;
>> >     }
>> >     mutex_lock(&obj->dev->struct_mutex);
>> > -   ret = __omap_gem_get_pages(obj, pages);
>> > +   ret = omap_gem_attach_pages(obj);
>> > +   *pages = omap_obj->pages;
>> >     mutex_unlock(&obj->dev->struct_mutex);
>> >     return ret;
>>  }
>> @@ -980,13 +965,12 @@ void *omap_gem_vaddr(struct drm_gem_object *obj)
>> >     struct omap_gem_object *omap_obj = to_omap_bo(obj);
>> >     WARN_ON(!mutex_is_locked(&obj->dev->struct_mutex));
>> >     if (!omap_obj->vaddr) {
>> > -           struct page **pages;
>> >             int ret;
>>
>> > -           ret = __omap_gem_get_pages(obj, &pages);
>> > +           ret = omap_gem_attach_pages(obj);
>> >             if (ret)
>> >                     return ERR_PTR(ret);
>> > -           omap_obj->vaddr = vmap(pages, obj->size >> PAGE_SHIFT,
>> > +           omap_obj->vaddr = vmap(omap_obj->pages, obj->size >> PAGE_SHIFT,
>> >                             VM_MAP, pgprot_writecombine(PAGE_KERNEL));
>> >     }
>> >     return omap_obj->vaddr;



-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2018-04-04 16:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-02 18:50 [PATCH 0/6] omapdrm: struct_mutex removal Laurent Pinchart
2018-04-02 18:50 ` [PATCH 1/6] drm/omap: gem: Rename GEM function with omap_gem_* prefix Laurent Pinchart
2018-04-02 18:50 ` [PATCH 2/6] drm/omap: gem: Merge __omap_gem_get_pages() and omap_gem_attach_pages() Laurent Pinchart
2018-04-04 13:37   ` Lucas Stach
2018-04-04 16:18     ` Daniel Vetter [this message]
2018-04-24 11:42       ` Laurent Pinchart
2018-04-02 18:50 ` [PATCH 3/6] drm/omap: gem: Don't take struct_mutex to get GEM object mmap offset Laurent Pinchart
2018-04-03  8:55   ` Daniel Vetter
2018-04-02 18:50 ` [PATCH 4/6] drm/omap: gem: Replace struct_mutex usage with omap_obj private lock Laurent Pinchart
2018-04-02 18:50 ` [PATCH 5/6] drm/omap: gem: Fix mm_list locking Laurent Pinchart
2018-04-02 18:50 ` [PATCH 6/6] drm/omap: gem: Switch to gem_free_object_unlocked() Laurent Pinchart
2018-05-23  9:42 ` [PATCH 0/6] omapdrm: struct_mutex removal Tomi Valkeinen
2018-05-25 11:15   ` Laurent Pinchart

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='CAKMK7uF9tRP5wKubCftxHMvkCToGEgUpS-84Whve=cc4FioKjA@mail.gmail.com' \
    --to=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=l.stach@pengutronix.de \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=tomi.valkeinen@ti.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 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.