diff mbox series

Requesting review about a bugfix in touch_all_pages

Message ID cfc67cbb15584a25bf44b3a644f44abc@tencent.com
State New
Headers show
Series Requesting review about a bugfix in touch_all_pages | expand

Commit Message

bauerchen(陈蒙蒙) April 6, 2020, 3:13 a.m. UTC
From faf903f7b8892179e64bd1a37fe3585a6441bc51 Mon Sep 17 00:00:00 2001
From: Bauerchen <bauerchen@tencent.com>
Date: Mon, 6 Apr 2020 10:36:54 +0800
Subject: [PATCH] Fix: In touch_all_pages, maybe we need a lock to protect
 qemu_cond_boardcast, or qemu_cond_boardcast may be called before all touch
 page threads enter qemu_cond_wait. In this case,  main thread waits touch
 page threads return, touch page threads wait main thread waking up, that is a
 dead lock ,vm will be in pause state forever;

Signed-off-by: Bauerchen <bauerchen@tencent.com>
---
 util/oslib-posix.c | 3 +++
 1 file changed, 3 insertions(+)

-- 
1.8.3.1

Comments

Paolo Bonzini April 6, 2020, 9:48 a.m. UTC | #1
On 06/04/20 05:13, bauerchen(陈蒙蒙) wrote:
> 
> From faf903f7b8892179e64bd1a37fe3585a6441bc51 Mon Sep 17 00:00:00 2001
> From: Bauerchen <bauerchen@tencent.com>
> Date: Mon, 6 Apr 2020 10:36:54 +0800
> Subject: [PATCH] Fix: In touch_all_pages, maybe we need a lock to protect
>  qemu_cond_boardcast, or qemu_cond_boardcast may be called before all touch
>  page threads enter qemu_cond_wait. In this case,  main thread waits touch
>  page threads return, touch page threads wait main thread waking up, that is a
>  dead lock ,vm will be in pause state forever;
> 
> Signed-off-by: Bauerchen <bauerchen@tencent.com>
> ---
>  util/oslib-posix.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> index 4dd6d7d..062236a 100644
> --- a/util/oslib-posix.c
> +++ b/util/oslib-posix.c
> @@ -492,8 +492,11 @@ static bool touch_all_pages(char *area, size_t hpagesize, size_t numpages,
>                             QEMU_THREAD_JOINABLE);
>          addr += memset_thread[i].numpages * hpagesize;
>      }
> +
> +    qemu_mutex_lock(&page_mutex);
>      threads_created_flag = true;
>      qemu_cond_broadcast(&page_cond);
> +    qemu_mutex_unlock(&page_mutex);
>  
>      for (i = 0; i < memset_num_threads; i++) {
>          qemu_thread_join(&memset_thread[i].pgthread);
> -- 
> 1.8.3.1
> 

Queued, thanks.

Paolo
diff mbox series

Patch

diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 4dd6d7d..062236a 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -492,8 +492,11 @@  static bool touch_all_pages(char *area, size_t hpagesize, size_t numpages,
                            QEMU_THREAD_JOINABLE);
         addr += memset_thread[i].numpages * hpagesize;
     }
+
+    qemu_mutex_lock(&page_mutex);
     threads_created_flag = true;
     qemu_cond_broadcast(&page_cond);
+    qemu_mutex_unlock(&page_mutex);
 
     for (i = 0; i < memset_num_threads; i++) {
         qemu_thread_join(&memset_thread[i].pgthread);