Message ID | 20170220145335.591-1-bobby.prani@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Pranith Kumar <bobby.prani@gmail.com> writes: > tb_gen_code() can exit execution using cpu_exit_loop() when it cannot > allocate new tb's. To handle this, we need to properly set the jmp_env > pointer ahead of calling tb_gen_code(). > > CC:Alex Bennée <alex.bennee@linaro.org> > CC: Richard Henderson <rth@twiddle.net> > Signed-off-by: Pranith Kumar <bobby.prani@gmail.com> > --- > cpu-exec.c | 23 +++++++++++------------ > 1 file changed, 11 insertions(+), 12 deletions(-) > > diff --git a/cpu-exec.c b/cpu-exec.c > index 97d79612d9..4b70988b24 100644 > --- a/cpu-exec.c > +++ b/cpu-exec.c > @@ -236,23 +236,22 @@ static void cpu_exec_step(CPUState *cpu) > > cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags); > tb_lock(); > - tb = tb_gen_code(cpu, pc, cs_base, flags, > - 1 | CF_NOCACHE | CF_IGNORE_ICOUNT); > - tb->orig_tb = NULL; > - tb_unlock(); > - > - cc->cpu_exec_enter(cpu); > - It occurs to me we are also diverging in our locking pattern from tb_find which takes mmap_lock first. This is a NOP for system emulation but needed for user-emulation (for which we can do cpu_exec_step but not cpu_exec_nocache). > if (sigsetjmp(cpu->jmp_env, 0) == 0) { > + tb = tb_gen_code(cpu, pc, cs_base, flags, > + 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); > > - cc->cpu_exec_exit(cpu); > - tb_lock(); > - tb_phys_invalidate(tb, -1); > - tb_free(tb); > + tb_lock(); > + tb_phys_invalidate(tb, -1); > + tb_free(tb); > + } > tb_unlock(); > } -- Alex Bennée
diff --git a/cpu-exec.c b/cpu-exec.c index 97d79612d9..4b70988b24 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -236,23 +236,22 @@ static void cpu_exec_step(CPUState *cpu) cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags); tb_lock(); - tb = tb_gen_code(cpu, pc, cs_base, flags, - 1 | CF_NOCACHE | CF_IGNORE_ICOUNT); - tb->orig_tb = NULL; - tb_unlock(); - - cc->cpu_exec_enter(cpu); - if (sigsetjmp(cpu->jmp_env, 0) == 0) { + tb = tb_gen_code(cpu, pc, cs_base, flags, + 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); - cc->cpu_exec_exit(cpu); - tb_lock(); - tb_phys_invalidate(tb, -1); - tb_free(tb); + tb_lock(); + tb_phys_invalidate(tb, -1); + tb_free(tb); + } tb_unlock(); }
tb_gen_code() can exit execution using cpu_exit_loop() when it cannot allocate new tb's. To handle this, we need to properly set the jmp_env pointer ahead of calling tb_gen_code(). CC:Alex Bennée <alex.bennee@linaro.org> CC: Richard Henderson <rth@twiddle.net> Signed-off-by: Pranith Kumar <bobby.prani@gmail.com> --- cpu-exec.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)