diff mbox

[v2] mttcg: Handle EXCP_ATOMIC exception

Message ID 20161102164008.28401-1-bobby.prani@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Pranith Kumar Nov. 2, 2016, 4:40 p.m. UTC
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 <bobby.prani@gmail.com>
---
 cpus.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Paolo Bonzini Nov. 2, 2016, 4:49 p.m. UTC | #1
On 02/11/2016 17:40, Pranith Kumar wrote:
> 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 <bobby.prani@gmail.com>
> ---
>  cpus.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/cpus.c b/cpus.c
> index 8f98060..299ce7e 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -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;
> 

Alex, please pick up this patch yourself.

Paolo
Alex Bennée Nov. 2, 2016, 6:17 p.m. UTC | #2
Paolo Bonzini <pbonzini@redhat.com> writes:

> On 02/11/2016 17:40, Pranith Kumar wrote:
>> 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 <bobby.prani@gmail.com>
>> ---
>>  cpus.c | 9 +++++++++
>>  1 file changed, 9 insertions(+)
>>
>> diff --git a/cpus.c b/cpus.c
>> index 8f98060..299ce7e 100644
>> --- a/cpus.c
>> +++ b/cpus.c
>> @@ -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;
>>
>
> Alex, please pick up this patch yourself.

Yep, I'll apply it to my tree.
>
> Paolo


--
Alex Bennée
diff mbox

Patch

diff --git a/cpus.c b/cpus.c
index 8f98060..299ce7e 100644
--- a/cpus.c
+++ b/cpus.c
@@ -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;