qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] plugins/hotblocks: Fix potential deadlock in plugin_exit() function
@ 2023-09-21  6:12 Cong Liu
  2023-09-21  7:43 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 4+ messages in thread
From: Cong Liu @ 2023-09-21  6:12 UTC (permalink / raw)
  To: Alex Bennée, Alexandre Iooss, Mahmoud Mandour; +Cc: Cong Liu, qemu-devel

This patch fixes a potential deadlock in the plugin_exit() function of QEMU.
The original code does not release the lock mutex if it is NULL. This patch
adds a check for it being NULL and releases the mutex in that case.

Signed-off-by: Cong Liu <liucong2@kylinos.cn>
---
 contrib/plugins/hotblocks.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c
index 6b74d25fead6..1f713f1904f3 100644
--- a/contrib/plugins/hotblocks.c
+++ b/contrib/plugins/hotblocks.c
@@ -70,6 +70,8 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
 
         g_list_free(it);
         g_mutex_unlock(&lock);
+    } else {
+        g_mutex_unlock(&lock);
     }
 
     qemu_plugin_outs(report->str);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] plugins/hotblocks: Fix potential deadlock in plugin_exit() function
  2023-09-21  6:12 [PATCH] plugins/hotblocks: Fix potential deadlock in plugin_exit() function Cong Liu
@ 2023-09-21  7:43 ` Philippe Mathieu-Daudé
  2023-09-21  9:23   ` [PATCH v2] " Cong Liu
  0 siblings, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-09-21  7:43 UTC (permalink / raw)
  To: Cong Liu, Alex Bennée, Alexandre Iooss, Mahmoud Mandour; +Cc: qemu-devel

Hi Cong,

On 21/9/23 08:12, Cong Liu wrote:
> This patch fixes a potential deadlock in the plugin_exit() function of QEMU.
> The original code does not release the lock mutex if it is NULL. This patch
> adds a check for it being NULL and releases the mutex in that case.

You are correct.

> Signed-off-by: Cong Liu <liucong2@kylinos.cn>
> ---
>   contrib/plugins/hotblocks.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c
> index 6b74d25fead6..1f713f1904f3 100644
> --- a/contrib/plugins/hotblocks.c
> +++ b/contrib/plugins/hotblocks.c
> @@ -70,6 +70,8 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
>   
>           g_list_free(it);
>           g_mutex_unlock(&lock);
> +    } else {
> +        g_mutex_unlock(&lock);
>       }

The code stays simpler if you simply move the unlock call out
of the if() statement, here.

>   
>       qemu_plugin_outs(report->str);

Regards,

Phil.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] plugins/hotblocks: Fix potential deadlock in plugin_exit() function
  2023-09-21  7:43 ` Philippe Mathieu-Daudé
@ 2023-09-21  9:23   ` Cong Liu
  2023-09-21 10:24     ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 4+ messages in thread
From: Cong Liu @ 2023-09-21  9:23 UTC (permalink / raw)
  To: philmd, Alex Bennée, Alexandre Iooss, Mahmoud Mandour
  Cc: liucong2, qemu-devel

This patch fixes a potential deadlock in the plugin_exit() function of QEMU.
The original code does not release the lock mutex if it is NULL. This patch
adds a check for it being NULL and releases the mutex in that case.

Signed-off-by: Cong Liu <liucong2@kylinos.cn>
Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 contrib/plugins/hotblocks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c
index 6b74d25fead6..b99b93ad8dc7 100644
--- a/contrib/plugins/hotblocks.c
+++ b/contrib/plugins/hotblocks.c
@@ -69,9 +69,9 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
         }
 
         g_list_free(it);
-        g_mutex_unlock(&lock);
     }
 
+    g_mutex_unlock(&lock);
     qemu_plugin_outs(report->str);
 }
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] plugins/hotblocks: Fix potential deadlock in plugin_exit() function
  2023-09-21  9:23   ` [PATCH v2] " Cong Liu
@ 2023-09-21 10:24     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-09-21 10:24 UTC (permalink / raw)
  To: Cong Liu, Alex Bennée, Alexandre Iooss, Mahmoud Mandour; +Cc: qemu-devel

On 21/9/23 11:23, Cong Liu wrote:
> This patch fixes a potential deadlock in the plugin_exit() function of QEMU.
> The original code does not release the lock mutex if it is NULL. This patch
> adds a check for it being NULL and releases the mutex in that case.
> 
> Signed-off-by: Cong Liu <liucong2@kylinos.cn>
> Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Not really suggested, just reviewed ;)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

> ---
>   contrib/plugins/hotblocks.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c
> index 6b74d25fead6..b99b93ad8dc7 100644
> --- a/contrib/plugins/hotblocks.c
> +++ b/contrib/plugins/hotblocks.c
> @@ -69,9 +69,9 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
>           }
>   
>           g_list_free(it);
> -        g_mutex_unlock(&lock);
>       }
>   
> +    g_mutex_unlock(&lock);
>       qemu_plugin_outs(report->str);
>   }
>   



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-09-21 13:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-21  6:12 [PATCH] plugins/hotblocks: Fix potential deadlock in plugin_exit() function Cong Liu
2023-09-21  7:43 ` Philippe Mathieu-Daudé
2023-09-21  9:23   ` [PATCH v2] " Cong Liu
2023-09-21 10:24     ` Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).