mttcg: Handle EXCP_ATOMIC exception
PATCH 1/1 mttcg: Handle EXCP_ATOMIC exception
The patch enables handling atomic code in the guest. This should be preferably done in cpu_handle_exception(), but the current assumptions regarding when we can execute atomic sections cause a deadlock.
--- cpus.c | 7 +++++++ 1 file changed, 7 insertions(+)
cpus.c +7 -0
@@ -1315,6 +1315,9 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg)if (r ==EXCP_DEBUG ) {cpu_handle_guest_debug (cpu);break ; + }else if (r ==EXCP_ATOMIC ) { +cpu_exec_step_atomic (cpu); +break ; } }else if (cpu->stop) {if (cpu->unplug) {
@@ -1385,6 +1388,10 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)*/ g_assert (cpu->halted);break ; +case EXCP_ATOMIC : +qemu_mutex_unlock_iothread (); +cpu_exec_step_atomic (cpu); +qemu_mutex_lock_iothread ();default :/* Ignore everything else? */ break ;
Signature · 1 line
2.10.2
Quoted 14 lines · Pranith Kumar
The patch enables handling atomic code in the guest. This should be preferably done in
cpu_handle_exception(), but the current assumptions regarding when we can execute atomic sections cause a deadlock.Signed-off-by Pranith Kumar <[email protected]>--- cpus.c | 7 +++++++ 1 file changed, 7 insertions(+)cpus.c +0
-0
cpus.c static void *qemu_tcg_rr_cpu_thread_fn(void *arg) · line 1320
Quoted 6 lines
cpus.c +3
-0@@ -1315,6 +1315,9 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg)if (r ==EXCP_DEBUG ) {cpu_handle_guest_debug (cpu);break ; + }else if (r ==EXCP_ATOMIC ) { +cpu_exec_step_atomic (cpu); +break ;
Hmm don't we need to unlock the iothread here as well? I suspect you never see a deadlock because the rr thread can't by definition race with itself but the locking practice should be the same for both cases.
Quoted 4 lines
cpus.c +0
-0} }else if (cpu->stop) {if (cpu->unplug) {
cpus.c static void *qemu_tcg_cpu_thread_fn(void *arg) · line 1397
Quoted 10 lines
cpus.c +4
-0@@ -1385,6 +1388,10 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)*/ g_assert (cpu->halted);break ; +case EXCP_ATOMIC : +qemu_mutex_unlock_iothread (); +cpu_exec_step_atomic (cpu); +qemu_mutex_lock_iothread ();default :/* Ignore everything else? */ break ;
--
Alex Bennée
Quoted 11 lines · Alex Bennée
Quoted 9 lines · Pranith Kumar
The patch enables handling atomic code in the guest. This should be preferably done in
cpu_handle_exception(), but the current assumptions regarding when we can execute atomic sections cause a deadlock.Signed-off-by Pranith Kumar <[email protected]>--- cpus.c | 7 +++++++ 1 file changed, 7 insertions(+)
Quoted 16 lines
cpus.c static void *qemu_tcg_rr_cpu_thread_fn(void *arg) · line 1320
Quoted 11 lines
cpus.c +3
-0@@ -1315,6 +1315,9 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg)if (r ==EXCP_DEBUG ) {cpu_handle_guest_debug (cpu);break ; + }else if (r ==EXCP_ATOMIC ) { +cpu_exec_step_atomic (cpu); +break ;Hmm don't we need to unlock the iothread here as well? I suspect you never see a deadlock because the rr thread can't by definition race with itself but the locking practice should be the same for both cases.
Yes, not having any other thread to race with is the reason I did not unlock the iothread. But, I agree that the semantics need to be the same.
I will send an updated patch.
Thanks,
Signature · 1 line
Pranith
PATCH v2 1/1 mttcg: Handle EXCP_ATOMIC exception
In reply to Pranith KumarThe patch enables handling atomic code in the guest. This should be preferably done in cpu_handle_exception(), but the current assumptions regarding when we can execute atomic sections cause a deadlock.
--- cpus.c | 9 +++++++++ 1 file changed, 9 insertions(+)
cpus.c +9 -0
@@ -1315,6 +1315,11 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg)if (r ==EXCP_DEBUG ) {cpu_handle_guest_debug (cpu);break ; + }else if (r ==EXCP_ATOMIC ) { +qemu_mutex_unlock_iothread (); +cpu_exec_step_atomic (cpu); +qemu_mutex_lock_iothread (); +break ; } }else if (cpu->stop) {if (cpu->unplug) {
@@ -1385,6 +1390,10 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)*/ g_assert (cpu->halted);break ; +case EXCP_ATOMIC : +qemu_mutex_unlock_iothread (); +cpu_exec_step_atomic (cpu); +qemu_mutex_lock_iothread ();default :/* Ignore everything else? */ break ;
Signature · 1 line
2.10.2
Quoted 27 lines · Pranith Kumar
The patch enables handling atomic code in the guest. This should be preferably done in
cpu_handle_exception(), but the current assumptions regarding when we can execute atomic sections cause a deadlock.Signed-off-by Pranith Kumar <[email protected]>--- cpus.c | 9 +++++++++ 1 file changed, 9 insertions(+)cpus.c +5
-0@@ -1315,6 +1315,11 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg)if (r ==EXCP_DEBUG ) {cpu_handle_guest_debug (cpu);break ; + }else if (r ==EXCP_ATOMIC ) { +qemu_mutex_unlock_iothread (); +cpu_exec_step_atomic (cpu); +qemu_mutex_lock_iothread (); +break ; } }else if (cpu->stop) {if (cpu->unplug) {
cpus.c static void *qemu_tcg_cpu_thread_fn(void *arg) · line 1399
Quoted 10 lines
cpus.c +4
-0@@ -1385,6 +1390,10 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)*/ g_assert (cpu->halted);break ; +case EXCP_ATOMIC : +qemu_mutex_unlock_iothread (); +cpu_exec_step_atomic (cpu); +qemu_mutex_lock_iothread ();default :/* Ignore everything else? */ break ;
Alex, please pick up this patch yourself.
Paolo
Quoted 32 lines · Paolo Bonzini
Quoted 31 lines · Pranith Kumar
The patch enables handling atomic code in the guest. This should be preferably done in
cpu_handle_exception(), but the current assumptions regarding when we can execute atomic sections cause a deadlock.Signed-off-by Pranith Kumar <[email protected]>--- cpus.c | 9 +++++++++ 1 file changed, 9 insertions(+)cpus.c +7
-0@@ -1315,6 +1315,11 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg)if (r ==EXCP_DEBUG ) {cpu_handle_guest_debug (cpu);break ; + }else if (r ==EXCP_ATOMIC ) { +qemu_mutex_unlock_iothread (); +cpu_exec_step_atomic (cpu); +qemu_mutex_lock_iothread (); +break ; } }else if (cpu->stop) {if (cpu->unplug) {@@ -1385,6 +1390,10 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)*/ g_assert (cpu->halted);break ; +case EXCP_ATOMIC : +qemu_mutex_unlock_iothread ();
Quoted 8 lines
cpus.c static void *qemu_tcg_cpu_thread_fn(void *arg) · line 1399
Quoted 6 lines
cpus.c +2
-0+cpu_exec_step_atomic (cpu); +qemu_mutex_lock_iothread ();default :/* Ignore everything else? */ break ;Alex, please pick up this patch yourself.
Yep, I'll apply it to my tree.
Quoted 2 lines
Paolo
--
Alex Bennée