[Freedreno] [PATCH libdrm 4/4] freedreno: use drmPrime wrappers to import/export prime bo's

Rob Clark robdclark at gmail.com
Sun Aug 23 09:37:37 PDT 2015


thanks.. fyi, I've pushed the first 3..  would you mind splitting this
last patch up into two (drmPrime wrappers as one, and locking changes
as the 2nd).  Probably I was confusing with my comment on irc about
adding the locking while you make these changes.. (I *meant* as part
of the same patchset, but that was probably not clear..  but splitting
them out will make the version history cleaner)

BR,
-R

On Fri, Aug 21, 2015 at 12:44 PM, Varad Gautam <varadgautam at gmail.com> wrote:
> Use drmPrimeFDToHandle() and drmPrimeHandleToFD() over drmIoctl() and
> lock fd import to prevent race when importing a bo that's currently
> being freed.
>
> Signed-off-by: Varad Gautam <varadgautam at gmail.com>
> ---
>  freedreno/freedreno_bo.c | 30 ++++++++++++++++++++----------
>  1 file changed, 20 insertions(+), 10 deletions(-)
>
> diff --git a/freedreno/freedreno_bo.c b/freedreno/freedreno_bo.c
> index 596bfbc..aece972 100644
> --- a/freedreno/freedreno_bo.c
> +++ b/freedreno/freedreno_bo.c
> @@ -230,20 +230,31 @@ fd_bo_from_dmabuf(struct fd_device *dev, int fd)
>                         .fd = fd,
>         };
>         int ret, size;
> +       uint32_t handle;
>         struct fd_bo *bo;
>
> -       ret = drmIoctl(dev->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &req);
> +       pthread_mutex_lock(&table_lock);
> +       ret = drmPrimeFDToHandle(dev->fd, fd, &handle);
> +
>         if (ret) {
> -               return NULL;
> +               bo = NULL;
> +               goto out_unlock;
>         }
>
> +       bo = lookup_bo(dev->handle_table, handle);
> +       if (bo)
> +               goto out_unlock;
> +
>         /* lseek() to get bo size */
>         size = lseek(fd, 0, SEEK_END);
>         lseek(fd, 0, SEEK_CUR);
>
> -       bo = fd_bo_from_handle(dev, req.handle, size);
> +       bo = bo_from_handle(dev, size, handle);
>         bo->fd = fd;
>
> +out_unlock:
> +       pthread_mutex_unlock(&table_lock);
> +
>         return bo;
>  }
>
> @@ -381,19 +392,18 @@ uint32_t fd_bo_handle(struct fd_bo *bo)
>  int fd_bo_dmabuf(struct fd_bo *bo)
>  {
>         if (bo->fd < 0) {
> -               struct drm_prime_handle req = {
> -                               .handle = bo->handle,
> -                               .flags = DRM_CLOEXEC,
> -               };
> -               int ret;
> +               int ret, prime_fd;
> +
> +               ret = drmPrimeHandleToFD(bo->dev->fd, bo->handle, DRM_CLOEXEC,
> +                                        &prime_fd);
>
> -               ret = drmIoctl(bo->dev->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &req);
>                 if (ret) {
>                         return ret;
>                 }
>
> -               bo->fd = req.fd;
> +               bo->fd = prime_fd;
>         }
> +
>         return dup(bo->fd);
>  }
>
> --
> 2.4.6
>
> _______________________________________________
> Freedreno mailing list
> Freedreno at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/freedreno


More information about the Freedreno mailing list