dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@collabora.com>
To: Tomeu Vizoso <tomeu@tomeuvizoso.net>
Cc: Rob Herring <robh+dt@kernel.org>,
	dri-devel <dri-devel@lists.freedesktop.org>,
	stable@vger.kernel.org
Subject: Re: [PATCH] drm/panfrost: Make sure a BO is only unmapped when appropriate
Date: Sat, 1 Jun 2019 10:55:47 +0200	[thread overview]
Message-ID: <20190601105547.5efe481d@collabora.com> (raw)
In-Reply-To: <CAAObsKBYvVKVTJf6ZwSarAVr6FSCz-NDYNhEqrDhBWUM3q57Nw@mail.gmail.com>

On Fri, 31 May 2019 14:54:54 +0200
Tomeu Vizoso <tomeu@tomeuvizoso.net> wrote:

> On Wed, 29 May 2019 at 11:18, Boris Brezillon
> <boris.brezillon@collabora.com> wrote:
> >
> > mmu_ops->unmap() will fail when called on a BO that has not been
> > previously mapped, and the error path in panfrost_ioctl_create_bo()
> > can call drm_gem_object_put_unlocked() (which in turn calls
> > panfrost_mmu_unmap()) on a BO that has not been mapped yet.
> >
> > Keep track of the mapped/unmapped state to avoid such issues.
> >
> > Fixes: f3ba91228e8e ("drm/panfrost: Add initial panfrost driver")
> > Cc: <stable@vger.kernel.org>
> > Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> > ---
> >  drivers/gpu/drm/panfrost/panfrost_gem.h | 1 +
> >  drivers/gpu/drm/panfrost/panfrost_mmu.c | 8 ++++++++
> >  2 files changed, 9 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.h b/drivers/gpu/drm/panfrost/panfrost_gem.h
> > index 045000eb5fcf..6dbcaba020fc 100644
> > --- a/drivers/gpu/drm/panfrost/panfrost_gem.h
> > +++ b/drivers/gpu/drm/panfrost/panfrost_gem.h
> > @@ -11,6 +11,7 @@ struct panfrost_gem_object {
> >         struct drm_gem_shmem_object base;
> >
> >         struct drm_mm_node node;
> > +       bool is_mapped;
> >  };
> >
> >  static inline
> > diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c
> > index 762b1bd2a8c2..fb556aa89203 100644
> > --- a/drivers/gpu/drm/panfrost/panfrost_mmu.c
> > +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c
> > @@ -156,6 +156,9 @@ int panfrost_mmu_map(struct panfrost_gem_object *bo)
> >         struct sg_table *sgt;
> >         int ret;
> >
> > +       if (bo->is_mapped)
> > +               return 0;  
> 
> In what circumstances we want to silently go on? I would expect that
> for this function to be called when the BO has been mapped already
> would mean that we have a bug in the kernel, so why not a WARN?
> 
> > +
> >         sgt = drm_gem_shmem_get_pages_sgt(obj);
> >         if (WARN_ON(IS_ERR(sgt)))
> >                 return PTR_ERR(sgt);
> > @@ -189,6 +192,7 @@ int panfrost_mmu_map(struct panfrost_gem_object *bo)
> >
> >         pm_runtime_mark_last_busy(pfdev->dev);
> >         pm_runtime_put_autosuspend(pfdev->dev);
> > +       bo->is_mapped = true;
> >
> >         return 0;
> >  }
> > @@ -203,6 +207,9 @@ void panfrost_mmu_unmap(struct panfrost_gem_object *bo)
> >         size_t unmapped_len = 0;
> >         int ret;
> >
> > +       if (!bo->is_mapped)
> > +               return;  
> 
> Similarly, I think that what we should do is not to call
> panfrost_mmu_unmap when a BO is freed if we know it isn't mapped. And
> probably add a WARN here if it still gets called when the BO isn't
> mapped.

Okay, will add WARN_ON()s and add a check in the caller.

      reply	other threads:[~2019-06-01  8:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-29  9:18 [PATCH] drm/panfrost: Make sure a BO is only unmapped when appropriate Boris Brezillon
2019-05-31 12:54 ` Tomeu Vizoso
2019-06-01  8:55   ` Boris Brezillon [this message]

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=20190601105547.5efe481d@collabora.com \
    --to=boris.brezillon@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=robh+dt@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tomeu@tomeuvizoso.net \
    /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