* [Qemu-devel] [PATCH] cpu-exec(): also reload CPUClass *cc after longjmp return
@ 2013-10-03 14:09 Juergen Lock
2013-10-03 16:05 ` Peter Maydell
0 siblings, 1 reply; 7+ messages in thread
From: Juergen Lock @ 2013-10-03 14:09 UTC (permalink / raw)
To: qemu-devel; +Cc: Jan Kiszka, Dimitry Andric, Andreas Faerber
Local variable CPUClass *cc needs to be reloaded after return from longjmp
too. (This fixes the mips-softmmu crash observed on FreeBSD when qemu is
built with clang.)
Signed-off-by: Juergen Lock <nox@jelal.kn-bremen.de>
Found-by: Dimitry Andric <dim@FreeBSD.org>
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -681,6 +681,10 @@ int cpu_exec(CPUArchState *env)
* local variables as longjmp is marked 'noreturn'. */
cpu = current_cpu;
env = cpu->env_ptr;
+#if !(defined(CONFIG_USER_ONLY) && \
+ (defined(TARGET_M68K) || defined(TARGET_PPC) || defined(TARGET_S390X)))
+ cc = CPU_GET_CLASS(cpu);
+#endif
}
} /* for(;;) */
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [Qemu-devel] [PATCH] cpu-exec(): also reload CPUClass *cc after longjmp return 2013-10-03 14:09 [Qemu-devel] [PATCH] cpu-exec(): also reload CPUClass *cc after longjmp return Juergen Lock @ 2013-10-03 16:05 ` Peter Maydell 2013-10-04 7:15 ` Jan Kiszka 0 siblings, 1 reply; 7+ messages in thread From: Peter Maydell @ 2013-10-03 16:05 UTC (permalink / raw) To: Juergen Lock; +Cc: Jan Kiszka, Dimitry Andric, QEMU Developers, Andreas Faerber On 3 October 2013 23:09, Juergen Lock <qemu-l@jelal.kn-bremen.de> wrote: > Local variable CPUClass *cc needs to be reloaded after return from longjmp > too. (This fixes the mips-softmmu crash observed on FreeBSD when qemu is > built with clang.) > > Signed-off-by: Juergen Lock <nox@jelal.kn-bremen.de> > Found-by: Dimitry Andric <dim@FreeBSD.org> > > --- a/cpu-exec.c > +++ b/cpu-exec.c > @@ -681,6 +681,10 @@ int cpu_exec(CPUArchState *env) > * local variables as longjmp is marked 'noreturn'. */ > cpu = current_cpu; > env = cpu->env_ptr; > +#if !(defined(CONFIG_USER_ONLY) && \ > + (defined(TARGET_M68K) || defined(TARGET_PPC) || defined(TARGET_S390X))) > + cc = CPU_GET_CLASS(cpu); > +#endif This is a c compiler or libc bug -- the C standard says that this local variable should not be trashed by the longjmp. We were actually discussing removing the current workarounds there... -- PMM ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] cpu-exec(): also reload CPUClass *cc after longjmp return 2013-10-03 16:05 ` Peter Maydell @ 2013-10-04 7:15 ` Jan Kiszka 2013-10-05 17:54 ` Juergen Lock 0 siblings, 1 reply; 7+ messages in thread From: Jan Kiszka @ 2013-10-04 7:15 UTC (permalink / raw) To: Peter Maydell Cc: Dimitry Andric, QEMU Developers, Juergen Lock, Andreas Faerber On 2013-10-03 18:05, Peter Maydell wrote: > On 3 October 2013 23:09, Juergen Lock <qemu-l@jelal.kn-bremen.de> wrote: >> Local variable CPUClass *cc needs to be reloaded after return from longjmp >> too. (This fixes the mips-softmmu crash observed on FreeBSD when qemu is >> built with clang.) >> >> Signed-off-by: Juergen Lock <nox@jelal.kn-bremen.de> >> Found-by: Dimitry Andric <dim@FreeBSD.org> >> >> --- a/cpu-exec.c >> +++ b/cpu-exec.c >> @@ -681,6 +681,10 @@ int cpu_exec(CPUArchState *env) >> * local variables as longjmp is marked 'noreturn'. */ >> cpu = current_cpu; >> env = cpu->env_ptr; >> +#if !(defined(CONFIG_USER_ONLY) && \ >> + (defined(TARGET_M68K) || defined(TARGET_PPC) || defined(TARGET_S390X))) >> + cc = CPU_GET_CLASS(cpu); >> +#endif > > This is a c compiler or libc bug -- the C standard says that this > local variable should not be trashed by the longjmp. We were > actually discussing removing the current workarounds there... But we didn't decide if we should stop supporting the affected compiler versions. Does this issue also exist with the latest clang version available for your platform? Jan -- Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] cpu-exec(): also reload CPUClass *cc after longjmp return 2013-10-04 7:15 ` Jan Kiszka @ 2013-10-05 17:54 ` Juergen Lock 2013-10-05 18:06 ` Stefan Weil 0 siblings, 1 reply; 7+ messages in thread From: Juergen Lock @ 2013-10-05 17:54 UTC (permalink / raw) To: Jan Kiszka Cc: Peter Maydell, Dimitry Andric, QEMU Developers, Andreas Faerber On Fri, Oct 04, 2013 at 09:15:37AM +0200, Jan Kiszka wrote: > On 2013-10-03 18:05, Peter Maydell wrote: > > On 3 October 2013 23:09, Juergen Lock <qemu-l@jelal.kn-bremen.de> wrote: > >> Local variable CPUClass *cc needs to be reloaded after return from longjmp > >> too. (This fixes the mips-softmmu crash observed on FreeBSD when qemu is > >> built with clang.) > >> > >> Signed-off-by: Juergen Lock <nox@jelal.kn-bremen.de> > >> Found-by: Dimitry Andric <dim@FreeBSD.org> > >> > >> --- a/cpu-exec.c > >> +++ b/cpu-exec.c > >> @@ -681,6 +681,10 @@ int cpu_exec(CPUArchState *env) > >> * local variables as longjmp is marked 'noreturn'. */ > >> cpu = current_cpu; > >> env = cpu->env_ptr; > >> +#if !(defined(CONFIG_USER_ONLY) && \ > >> + (defined(TARGET_M68K) || defined(TARGET_PPC) || defined(TARGET_S390X))) > >> + cc = CPU_GET_CLASS(cpu); > >> +#endif > > > > This is a c compiler or libc bug -- the C standard says that this > > local variable should not be trashed by the longjmp. We were > > actually discussing removing the current workarounds there... > > But we didn't decide if we should stop supporting the affected compiler > versions. > > Does this issue also exist with the latest clang version available for > your platform? > It happens with up to date clang as it's in FreeBSD 10.0-current which is due for a release soon. I think the clang folks are looking into this issue but I don't know if a fix will make it into the release... (For now I've added the workaround to the FreeBSD qemu-devel port.) Thanx, Juergen ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] cpu-exec(): also reload CPUClass *cc after longjmp return 2013-10-05 17:54 ` Juergen Lock @ 2013-10-05 18:06 ` Stefan Weil 2013-10-05 21:45 ` Juergen Lock 0 siblings, 1 reply; 7+ messages in thread From: Stefan Weil @ 2013-10-05 18:06 UTC (permalink / raw) To: Juergen Lock, Jan Kiszka Cc: Peter Maydell, Dimitry Andric, QEMU Developers, Andreas Faerber Am 05.10.2013 19:54, schrieb Juergen Lock: > On Fri, Oct 04, 2013 at 09:15:37AM +0200, Jan Kiszka wrote: >> On 2013-10-03 18:05, Peter Maydell wrote: >>> On 3 October 2013 23:09, Juergen Lock <qemu-l@jelal.kn-bremen.de> wrote: >>>> Local variable CPUClass *cc needs to be reloaded after return from longjmp >>>> too. (This fixes the mips-softmmu crash observed on FreeBSD when qemu is >>>> built with clang.) >>>> >>>> Signed-off-by: Juergen Lock <nox@jelal.kn-bremen.de> >>>> Found-by: Dimitry Andric <dim@FreeBSD.org> >>>> >>>> --- a/cpu-exec.c >>>> +++ b/cpu-exec.c >>>> @@ -681,6 +681,10 @@ int cpu_exec(CPUArchState *env) >>>> * local variables as longjmp is marked 'noreturn'. */ >>>> cpu = current_cpu; >>>> env = cpu->env_ptr; >>>> +#if !(defined(CONFIG_USER_ONLY) && \ >>>> + (defined(TARGET_M68K) || defined(TARGET_PPC) || defined(TARGET_S390X))) >>>> + cc = CPU_GET_CLASS(cpu); >>>> +#endif >>> This is a c compiler or libc bug -- the C standard says that this >>> local variable should not be trashed by the longjmp. We were >>> actually discussing removing the current workarounds there... >> But we didn't decide if we should stop supporting the affected compiler >> versions. >> >> Does this issue also exist with the latest clang version available for >> your platform? >> > It happens with up to date clang as it's in FreeBSD 10.0-current > which is due for a release soon. I think the clang folks are looking > into this issue but I don't know if a fix will make it into the > release... (For now I've added the workaround to the FreeBSD > qemu-devel port.) > > Thanx, > Juergen Could you try whether QEMU crashes when it was configured with TCG interpreter (--enable-tcg-interpreter)? If it does not crash, it might be that TCG does not save / restore enough registers. Which register is used for the local variable 'cc'? Regards, Stefan ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] cpu-exec(): also reload CPUClass *cc after longjmp return 2013-10-05 18:06 ` Stefan Weil @ 2013-10-05 21:45 ` Juergen Lock 2013-10-07 7:28 ` Andreas Färber 0 siblings, 1 reply; 7+ messages in thread From: Juergen Lock @ 2013-10-05 21:45 UTC (permalink / raw) To: Stefan Weil Cc: Jan Kiszka, Dimitry Andric, QEMU Developers, Andreas Faerber, Peter Maydell On Sat, Oct 05, 2013 at 08:06:22PM +0200, Stefan Weil wrote: > Am 05.10.2013 19:54, schrieb Juergen Lock: > > On Fri, Oct 04, 2013 at 09:15:37AM +0200, Jan Kiszka wrote: > >> On 2013-10-03 18:05, Peter Maydell wrote: > >>> On 3 October 2013 23:09, Juergen Lock <qemu-l@jelal.kn-bremen.de> wrote: > >>>> Local variable CPUClass *cc needs to be reloaded after return from longjmp > >>>> too. (This fixes the mips-softmmu crash observed on FreeBSD when qemu is > >>>> built with clang.) > >>>> > >>>> Signed-off-by: Juergen Lock <nox@jelal.kn-bremen.de> > >>>> Found-by: Dimitry Andric <dim@FreeBSD.org> > >>>> > >>>> --- a/cpu-exec.c > >>>> +++ b/cpu-exec.c > >>>> @@ -681,6 +681,10 @@ int cpu_exec(CPUArchState *env) > >>>> * local variables as longjmp is marked 'noreturn'. */ > >>>> cpu = current_cpu; > >>>> env = cpu->env_ptr; > >>>> +#if !(defined(CONFIG_USER_ONLY) && \ > >>>> + (defined(TARGET_M68K) || defined(TARGET_PPC) || defined(TARGET_S390X))) > >>>> + cc = CPU_GET_CLASS(cpu); > >>>> +#endif > >>> This is a c compiler or libc bug -- the C standard says that this > >>> local variable should not be trashed by the longjmp. We were > >>> actually discussing removing the current workarounds there... > >> But we didn't decide if we should stop supporting the affected compiler > >> versions. > >> > >> Does this issue also exist with the latest clang version available for > >> your platform? > >> > > It happens with up to date clang as it's in FreeBSD 10.0-current > > which is due for a release soon. I think the clang folks are looking > > into this issue but I don't know if a fix will make it into the > > release... (For now I've added the workaround to the FreeBSD > > qemu-devel port.) > > > > Thanx, > > Juergen > > > Could you try whether QEMU crashes when it was configured with > TCG interpreter (--enable-tcg-interpreter)? If it does not crash, it > might be that TCG does not save / restore enough registers. > Still crashes the same. > Which register is used for the local variable 'cc'? > Here is the original debug log with part of the disassembly: http://people.freebsd.org/~nox/tmp/qemu-1.6.0-mips-softmmu-crash.txt (I wrote the comment at the top before I knew cc needs to be reloaded...) So apparently cc gets loaded from the stack before the crash: -0x40(%rbp) Thanx, Juergen ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] cpu-exec(): also reload CPUClass *cc after longjmp return 2013-10-05 21:45 ` Juergen Lock @ 2013-10-07 7:28 ` Andreas Färber 0 siblings, 0 replies; 7+ messages in thread From: Andreas Färber @ 2013-10-07 7:28 UTC (permalink / raw) To: Juergen Lock Cc: Peter Maydell, Stefan Weil, Dimitry Andric, QEMU Developers, Jan Kiszka Am 05.10.2013 23:45, schrieb Juergen Lock: > On Sat, Oct 05, 2013 at 08:06:22PM +0200, Stefan Weil wrote: >> Am 05.10.2013 19:54, schrieb Juergen Lock: >>> On Fri, Oct 04, 2013 at 09:15:37AM +0200, Jan Kiszka wrote: >>>> On 2013-10-03 18:05, Peter Maydell wrote: >>>>> On 3 October 2013 23:09, Juergen Lock <qemu-l@jelal.kn-bremen.de> wrote: >>>>>> Local variable CPUClass *cc needs to be reloaded after return from longjmp >>>>>> too. (This fixes the mips-softmmu crash observed on FreeBSD when qemu is >>>>>> built with clang.) >>>>>> >>>>>> Signed-off-by: Juergen Lock <nox@jelal.kn-bremen.de> >>>>>> Found-by: Dimitry Andric <dim@FreeBSD.org> >>>>>> >>>>>> --- a/cpu-exec.c >>>>>> +++ b/cpu-exec.c >>>>>> @@ -681,6 +681,10 @@ int cpu_exec(CPUArchState *env) >>>>>> * local variables as longjmp is marked 'noreturn'. */ >>>>>> cpu = current_cpu; >>>>>> env = cpu->env_ptr; >>>>>> +#if !(defined(CONFIG_USER_ONLY) && \ >>>>>> + (defined(TARGET_M68K) || defined(TARGET_PPC) || defined(TARGET_S390X))) >>>>>> + cc = CPU_GET_CLASS(cpu); >>>>>> +#endif >>>>> This is a c compiler or libc bug -- the C standard says that this >>>>> local variable should not be trashed by the longjmp. We were >>>>> actually discussing removing the current workarounds there... >>>> But we didn't decide if we should stop supporting the affected compiler >>>> versions. >>>> >>>> Does this issue also exist with the latest clang version available for >>>> your platform? >>>> >>> It happens with up to date clang as it's in FreeBSD 10.0-current >>> which is due for a release soon. I think the clang folks are looking >>> into this issue but I don't know if a fix will make it into the >>> release... (For now I've added the workaround to the FreeBSD >>> qemu-devel port.) >>> >>> Thanx, >>> Juergen >> >> >> Could you try whether QEMU crashes when it was configured with >> TCG interpreter (--enable-tcg-interpreter)? If it does not crash, it >> might be that TCG does not save / restore enough registers. >> > Still crashes the same. Practical bugfix beats theoretical optimization, so I'm queuing the patch (w/ message tweaked) until someone comes up with a better one: https://github.com/afaerber/qemu-cpu/commits/qom-cpu Thanks, Andreas > >> Which register is used for the local variable 'cc'? >> > Here is the original debug log with part of the disassembly: > > http://people.freebsd.org/~nox/tmp/qemu-1.6.0-mips-softmmu-crash.txt > > (I wrote the comment at the top before I knew cc needs to be reloaded...) > > So apparently cc gets loaded from the stack before the crash: -0x40(%rbp) > > Thanx, > Juergen > -- SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-10-07 7:28 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-10-03 14:09 [Qemu-devel] [PATCH] cpu-exec(): also reload CPUClass *cc after longjmp return Juergen Lock 2013-10-03 16:05 ` Peter Maydell 2013-10-04 7:15 ` Jan Kiszka 2013-10-05 17:54 ` Juergen Lock 2013-10-05 18:06 ` Stefan Weil 2013-10-05 21:45 ` Juergen Lock 2013-10-07 7:28 ` Andreas Färber
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).