[Mesa-dev] [PATCH] vulkan/wsi: check if the display_fd given is master

Bas Nieuwenhuizen bas at basnieuwenhuizen.nl
Wed Apr 17 18:22:45 UTC 2019


This will not work as-is for radv, as failure to initialize from
wsi_display_init_wsi (->wsi_device_init -> radv_init_wsi) will cause
us to fail initializing the whole device.

On Wed, Apr 17, 2019 at 7:02 PM Emil Velikov <emil.l.velikov at gmail.com> wrote:
>
> From: Emil Velikov <emil.velikov at collabora.com>
>
> As effectively required by the extension, we need to ensure we're master
>
> Currently drivers employ vendor specific solutions, which check if the
> device behind the fd is capable*, yet none of them do the master check.
>
> *In the radv case, if acceleration is available.
>
> Instead of duplicating the check in each driver, keep it where it's
> needed and used.
>
> Note this copies libdrm's drmIsMaster() to avoid depending on bleeding
> edge version of the library.
>
> Cc: Keith Packard <keithp at keithp.com>
> Cc: Jason Ekstrand <jason at jlekstrand.net>
> Cc: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
> Cc: Andres Rodriguez <andresx7 at gmail.com>
> Reported-by: Andres Rodriguez <andresx7 at gmail.com>
> Fixes: da997ebec92 ("vulkan: Add KHR_display extension using DRM [v10]")
> Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
> ---
>  src/vulkan/wsi/wsi_common_display.c | 30 +++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
>
> diff --git a/src/vulkan/wsi/wsi_common_display.c b/src/vulkan/wsi/wsi_common_display.c
> index 74ed36ed646..d6b2ae004ce 100644
> --- a/src/vulkan/wsi/wsi_common_display.c
> +++ b/src/vulkan/wsi/wsi_common_display.c
> @@ -1812,6 +1812,30 @@ fail_attr_init:
>     return ret;
>  }
>
> +
> +/*
> + * Local version fo the libdrm helper. Added to avoid depending on bleeding
> + * edge version of the library.
> + */
> +static int
> +local_drmIsMaster(int fd)
> +{
> +   /* Detect master by attempting something that requires master.
> +    *
> +    * Authenticating magic tokens requires master and 0 is an
> +    * internal kernel detail which we could use. Attempting this on
> +    * a master fd would fail therefore fail with EINVAL because 0
> +    * is invalid.
> +    *
> +    * A non-master fd will fail with EACCES, as the kernel checks
> +    * for master before attempting to do anything else.
> +    *
> +    * Since we don't want to leak implementation details, use
> +    * EACCES.
> +    */
> +   return drmAuthMagic(fd, 0) != -EACCES;
> +}
> +
>  VkResult
>  wsi_display_init_wsi(struct wsi_device *wsi_device,
>                       const VkAllocationCallbacks *alloc,
> @@ -1826,6 +1850,11 @@ wsi_display_init_wsi(struct wsi_device *wsi_device,
>        goto fail;
>     }
>
> +   if (!local_drmIsMaster(display_fd)) {
> +      result = VK_ERROR_INITIALIZATION_FAILED;
> +      goto fail_fd;
> +   }
> +
>     wsi->fd = display_fd;
>     wsi->alloc = alloc;
>
> @@ -1857,6 +1886,7 @@ wsi_display_init_wsi(struct wsi_device *wsi_device,
>  fail_cond:
>     pthread_mutex_destroy(&wsi->wait_mutex);
>  fail_mutex:
> +fail_fd:
>     vk_free(alloc, wsi);
>  fail:
>     return result;
> --
> 2.21.0
>


More information about the mesa-dev mailing list