diff mbox series

[2/3] plugins: Avoid deadlock in qemu_plugin_user_exit

Message ID 20230117035701.168514-3-richard.henderson@linaro.org
State New
Headers show
Series tests: Fix some deadlocks | expand

Commit Message

Richard Henderson Jan. 17, 2023, 3:57 a.m. UTC
Use of start_exclusive on this exit path leads to deadlock,
in particular when called from dump_core_and_abort.  There
does not appear to be a need for it.

While we're at it, skip the entire function if no plugins.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 plugins/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Alex Bennée Jan. 20, 2023, 5:35 p.m. UTC | #1
Richard Henderson <richard.henderson@linaro.org> writes:

> Use of start_exclusive on this exit path leads to deadlock,
> in particular when called from dump_core_and_abort.  There
> does not appear to be a need for it.

We don't want to be doing any translation while un-registering things
lest things get confused. You could split the patch in two though as the
early return seems reasonable.

>
> While we're at it, skip the entire function if no plugins.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  plugins/core.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/plugins/core.c b/plugins/core.c
> index ccb770a485..35aca0266d 100644
> --- a/plugins/core.c
> +++ b/plugins/core.c
> @@ -502,7 +502,9 @@ void qemu_plugin_user_exit(void)
>  
>      QEMU_LOCK_GUARD(&plugin.lock);
>  
> -    start_exclusive();
> +    if (QTAILQ_EMPTY(&plugin.ctxs)) {
> +        return;
> +    }
>  
>      /* un-register all callbacks except the final AT_EXIT one */
>      for (ev = 0; ev < QEMU_PLUGIN_EV_MAX; ev++) {
> @@ -520,8 +522,6 @@ void qemu_plugin_user_exit(void)
>          qemu_plugin_disable_mem_helpers(cpu);
>      }
>  
> -    end_exclusive();
> -
>      /* now it's safe to handle the exit case */
>      qemu_plugin_atexit_cb();
>  }
diff mbox series

Patch

diff --git a/plugins/core.c b/plugins/core.c
index ccb770a485..35aca0266d 100644
--- a/plugins/core.c
+++ b/plugins/core.c
@@ -502,7 +502,9 @@  void qemu_plugin_user_exit(void)
 
     QEMU_LOCK_GUARD(&plugin.lock);
 
-    start_exclusive();
+    if (QTAILQ_EMPTY(&plugin.ctxs)) {
+        return;
+    }
 
     /* un-register all callbacks except the final AT_EXIT one */
     for (ev = 0; ev < QEMU_PLUGIN_EV_MAX; ev++) {
@@ -520,8 +522,6 @@  void qemu_plugin_user_exit(void)
         qemu_plugin_disable_mem_helpers(cpu);
     }
 
-    end_exclusive();
-
     /* now it's safe to handle the exit case */
     qemu_plugin_atexit_cb();
 }