diff mbox series

[05/12] tests/plugin/mem: fix race condition with callbacks

Message ID 20240111142326.1743444-6-pierrick.bouvier@linaro.org
State New
Headers show
Series TCG Plugin inline operation enhancement | expand

Commit Message

Pierrick Bouvier Jan. 11, 2024, 2:23 p.m. UTC
Introduce a lock so global count is correct.
This was found by comparing with new inline per_vcpu inline op.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 tests/plugin/mem.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Richard Henderson Jan. 11, 2024, 10:12 p.m. UTC | #1
On 1/12/24 01:23, Pierrick Bouvier wrote:
> Introduce a lock so global count is correct.
> This was found by comparing with new inline per_vcpu inline op.
> 
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   tests/plugin/mem.c | 3 +++
>   1 file changed, 3 insertions(+)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~
diff mbox series

Patch

diff --git a/tests/plugin/mem.c b/tests/plugin/mem.c
index 44e91065ba7..beca8232342 100644
--- a/tests/plugin/mem.c
+++ b/tests/plugin/mem.c
@@ -22,6 +22,7 @@  static uint64_t io_count;
 static bool do_inline, do_callback;
 static bool do_haddr;
 static enum qemu_plugin_mem_rw rw = QEMU_PLUGIN_MEM_RW;
+static GMutex lock;
 
 static void plugin_exit(qemu_plugin_id_t id, void *p)
 {
@@ -42,6 +43,7 @@  static void plugin_exit(qemu_plugin_id_t id, void *p)
 static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo,
                      uint64_t vaddr, void *udata)
 {
+    g_mutex_lock(&lock);
     if (do_haddr) {
         struct qemu_plugin_hwaddr *hwaddr;
         hwaddr = qemu_plugin_get_hwaddr(meminfo, vaddr);
@@ -53,6 +55,7 @@  static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo,
     } else {
         cb_mem_count++;
     }
+    g_mutex_unlock(&lock);
 }
 
 static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)