Skip to contentSkip to conversation

Requesting review about a bugfix in touch_all_pages

PATCH Applied bauerchen(陈蒙蒙) 2 participants 2 messages Apr 6, 2020

lore
Share & tools
lore
#0 lore raw

From faf903f7b8892179e64bd1a37fe3585a6441bc51 Mon Sep 17 00:00:00 2001
From: Bauerchen <[email protected]>
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;

---
 util/oslib-posix.c | 3 +++

 1 file changed, 3 insertions(+)
util/oslib-posix.c +0 -0
index 4dd6d7d..062236a 100644
@@ -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

#1 lore raw
Quoted 28 lines · bauerchen(陈蒙蒙)

From faf903f7b8892179e64bd1a37fe3585a6441bc51 Mon Sep 17 00:00:00 2001
From: Bauerchen <[email protected]>
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;

---
 util/oslib-posix.c | 3 +++

 1 file changed, 3 insertions(+)
util/oslib-posix.c +3 -0
index 4dd6d7d..062236a 100644
@@ -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);
Quoted 6 lines


     for (i = 0; i < memset_num_threads; i++) { qemu_thread_join(&memset_thread[i].pgthread); --
1.8.3.1

Queued, thanks.

Paolo