[Qemu-devel] [PATCH] cpus: tcg: fix never exiting loop on unplug

Cédric Le Goater posted 1 patch 7 years, 6 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20180425131828.15604-1-clg@kaod.org
Test checkpatch passed
Test docker-build@min-glib passed
Test docker-mingw@fedora passed
Test s390x passed
cpus.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[Qemu-devel] [PATCH] cpus: tcg: fix never exiting loop on unplug
Posted by Cédric Le Goater 7 years, 6 months ago
Commit 9b0605f9837b ("cpus: tcg: unregister thread with RCU, fix
exiting of loop on unplug") changed the exit condition of the loop in
the vCPU thread function but forgot to remove the beginning 'while (1)'
statement. The resulting code :

	while (1) {
	...
	} while (!cpu->unplug || cpu_can_run(cpu));

is a sequence of two distinct two while() loops, the first not exiting
in case of an unplug event.

Remove the first while (1) to fix CPU unplug.

Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 cpus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cpus.c b/cpus.c
index 38eba8bff334..e1d94038fd0d 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1648,7 +1648,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
     /* process any pending work */
     cpu->exit_request = 1;
 
-    while (1) {
+    do {
         if (cpu_can_run(cpu)) {
             int r;
             qemu_mutex_unlock_iothread();
-- 
2.13.6


Re: [Qemu-devel] [PATCH] cpus: tcg: fix never exiting loop on unplug
Posted by Paolo Bonzini 7 years, 6 months ago
On 25/04/2018 15:18, Cédric Le Goater wrote:
> Commit 9b0605f9837b ("cpus: tcg: unregister thread with RCU, fix
> exiting of loop on unplug") changed the exit condition of the loop in
> the vCPU thread function but forgot to remove the beginning 'while (1)'
> statement. The resulting code :
> 
> 	while (1) {
> 	...
> 	} while (!cpu->unplug || cpu_can_run(cpu));
> 
> is a sequence of two distinct two while() loops, the first not exiting
> in case of an unplug event.
> 
> Remove the first while (1) to fix CPU unplug.
> 
> Signed-off-by: Cédric Le Goater <clg@kaod.org>
> ---
>  cpus.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/cpus.c b/cpus.c
> index 38eba8bff334..e1d94038fd0d 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -1648,7 +1648,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
>      /* process any pending work */
>      cpu->exit_request = 1;
>  
> -    while (1) {
> +    do {
>          if (cpu_can_run(cpu)) {
>              int r;
>              qemu_mutex_unlock_iothread();
> 

Cc: qemu-stable@nongnu.org

Queued, thanks.

Paolo