Skip to contentSkip to conversation

mttcg: Handle exception and flags in atomic execution

PATCH New Pranith Kumar 1 participant 3 messages Feb 10, 2017

lore
Share & tools
lore
#0 lore raw

v2 cover mttcg: Handle exception and flags in atomic execution

The previous version, though ideal, needs more work to enable calling start_exclusive() from cpu_exec() and also does not properly handle exception from atomic context. Exceptions in atomic context will not call exclusive_end() and would go to the outer most loop causing a deadlock.

The following patches allow proper handling of flags set and exceptions from the atomic exectuion context.

Alex, please fold/squash them as you feel necessary.

Pranith Kumar (2):
tcg: Save cpu flags in atomic execution
tcg: Set jmp_env to handle exceptions from atomic execution

 cpu-exec.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH v2 1/2 tcg: Save cpu flags in atomic execution

The current mechanism discards the flags which were set in atomic execution. Properly save them.

CC Alex Bennée <[email protected]>
CC Richard Henderson <[email protected]>
CC Paolo Bonzini <[email protected]>
---
 cpu-exec.c | 5 +++++
 1 file changed, 5 insertions(+)
cpu-exec.c +5 -0
index b0ddada8c1..9200c643c2 100644
@@ -228,6 +228,7 @@ static void cpu_exec_nocache(CPUState *cpu, int max_cycles,
 
 static void cpu_exec_step(CPUState *cpu)
 {
+    CPUClass *cc = CPU_GET_CLASS(cpu);
     CPUArchState *env = (CPUArchState *)cpu->env_ptr;
     TranslationBlock *tb;
     target_ulong cs_base, pc;
@@ -239,9 +240,13 @@ static void cpu_exec_step(CPUState *cpu)
                      1 | CF_NOCACHE | CF_IGNORE_ICOUNT);
     tb->orig_tb = NULL;
     tb_unlock();
+
+    cc->cpu_exec_enter(cpu);
     /* execute the generated code */
     trace_exec_tb_nocache(tb, pc);
     cpu_tb_exec(cpu, tb);
+
+    cc->cpu_exec_exit(cpu);
     tb_lock();
     tb_phys_invalidate(tb, -1);
     tb_free(tb);
Signature · 1 line
2.11.0
#2 lore raw

PATCH v2 2/2 tcg: Set jmp_env for exceptions from atomic execution

In reply to Pranith Kumar

The current method of executing atomic code in a guest uses cpu_exec_step_atomic() from the outermost loop. This causes an abort() when single stepping over atomic code since debug exception longjmp will point to the the setlongjmp in cpu_exec(). Properly set jmp_env so that it jumps back here on an exception.

CC Alex Bennée <[email protected]>
CC Richard Henderson <[email protected]>
CC Paolo Bonzini <[email protected]>
---
 cpu-exec.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
cpu-exec.c +6 -3
index 9200c643c2..e61f5747c8 100644
@@ -242,9 +242,12 @@ static void cpu_exec_step(CPUState *cpu)
     tb_unlock();
 
     cc->cpu_exec_enter(cpu);
-    /* execute the generated code */
-    trace_exec_tb_nocache(tb, pc);
-    cpu_tb_exec(cpu, tb);
+
+    if (sigsetjmp(cpu->jmp_env, 0) == 0) {
+        /* execute the generated code */
+        trace_exec_tb_nocache(tb, pc);
+        cpu_tb_exec(cpu, tb);
+    }
 
     cc->cpu_exec_exit(cpu);
     tb_lock();
Signature · 1 line
2.11.0