[Mesa-dev] [PATCH] util: Fix race condition on libgcrypt initialization

Jason Ekstrand jason at jlekstrand.net
Tue Apr 12 22:34:36 UTC 2016


On Apr 12, 2016 3:10 PM, "Mark Janes" <mark.a.janes at intel.com> wrote:
>
> Fixes intermittent Vulkan CTS failures within the test groups:
> dEQP-VK.api.object_management.multithreaded_per_thread_device
> dEQP-VK.api.object_management.multithreaded_per_thread_resources
> dEQP-VK.api.object_management.multithreaded_shared_resources

Thanks for figuring this out. Those failures have been bothering me for a
while (not as much as they higher you, I'm sure) but I've never seen it on
my local machine because I'm pretty sure I use libnettle for sha1.

Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>

> Signed-off-by: Mark Janes <mark.a.janes at intel.com>
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=94904
> ---
>  src/util/mesa-sha1.c | 19 +++++++++++--------
>  1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/src/util/mesa-sha1.c b/src/util/mesa-sha1.c
> index faa1c87..ca6b89b 100644
> --- a/src/util/mesa-sha1.c
> +++ b/src/util/mesa-sha1.c
> @@ -175,21 +175,24 @@ _mesa_sha1_final(struct mesa_sha1 *ctx, unsigned
char result[20])
>  #elif defined(HAVE_SHA1_IN_LIBGCRYPT)   /* Use libgcrypt for SHA1 */
>
>  #include <gcrypt.h>
> +#include "c11/threads.h"
> +
> +static void _mesa_libgcrypt_init(void)
> +{
> +   if (!gcry_check_version(NULL))
> +      return NULL;
> +   gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
> +   gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
> +}
>
>  struct mesa_sha1 *
>  _mesa_sha1_init(void)
>  {
> -   static int init;
> +   static once_flag flag = ONCE_FLAG_INIT;
>     gcry_md_hd_t h;
>     gcry_error_t err;
>
> -   if (!init) {
> -      if (!gcry_check_version(NULL))
> -         return NULL;
> -      gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
> -      gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
> -      init = 1;
> -   }
> +   call_once(&flag, _mesa_libgcrypt_init);
>
>     err = gcry_md_open(&h, GCRY_MD_SHA1, 0);
>     if (err)
> --
> 2.8.0.rc3
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160412/779c32a2/attachment.html>


More information about the mesa-dev mailing list