Re: [Qemu-devel] [Bug 1675108] [NEW] Cocoa UI always crashes on startup

2017-03-27 Thread Peter Maydell
On 27 March 2017 at 16:18, Alex Bennée  wrote:
> I've got two patches in my tree at the moment. I was holding off posting
> the series to see if I could make more progress with the record/replay
> bug.

rc candidates are cut on Tuesdays, so it's better in general not
to sit on a fix for rc bugs if it causes them to miss going into
the next rc tag.

thanks
-- PMM



Re: [Qemu-devel] [Bug 1675108] [NEW] Cocoa UI always crashes on startup

2017-03-27 Thread Alex Bennée

Gerd Hoffmann  writes:

> On Do, 2017-03-23 at 11:31 +, Alex Bennée wrote:
>> Peter Maydell  writes:
>>
>> > On 23 March 2017 at 11:13, Alex Bennée  wrote:
>> >> Technically its not a random thread its the vCPU context (which ensures
>> >> the vCPU isn't updating while the display is being updated). But I guess
>> >> the Cocoa is limited to not being able to update from an arbitrary
>> >> thread?
>> >
>> > Yes. It's very common for windowing libraries to mandate that you
>> > do all windowing operations from one specific thread.
>>
>> Fair enough. Well let me know if that works OK on MacOS and I'll fold it
>> in to the other console patches. In fact I might as well do the
>> start/end_exclusive dance for all OSes and it will achieve the same thing.
>
> Where do we stand with this one?

I've got two patches in my tree at the moment. I was holding off posting
the series to see if I could make more progress with the record/replay
bug. I'll post the series tomorrow morning but if you want to grab them
ahead of that see:

  
https://github.com/stsquad/qemu/commit/6c0ddfc5752f311b4c5a2956de25821cc2cd3fd6
  
https://github.com/stsquad/qemu/commit/15d2b05a20879017f20370b71d5d144947b693fe

--
Alex Bennée



Re: [Qemu-devel] [Bug 1675108] [NEW] Cocoa UI always crashes on startup

2017-03-27 Thread Gerd Hoffmann
On Do, 2017-03-23 at 11:31 +, Alex Bennée wrote:
> Peter Maydell  writes:
> 
> > On 23 March 2017 at 11:13, Alex Bennée  wrote:
> >> Technically its not a random thread its the vCPU context (which ensures
> >> the vCPU isn't updating while the display is being updated). But I guess
> >> the Cocoa is limited to not being able to update from an arbitrary
> >> thread?
> >
> > Yes. It's very common for windowing libraries to mandate that you
> > do all windowing operations from one specific thread.
> 
> Fair enough. Well let me know if that works OK on MacOS and I'll fold it
> in to the other console patches. In fact I might as well do the
> start/end_exclusive dance for all OSes and it will achieve the same thing.

Where do we stand with this one?

cheers,
  Gerd




Re: [Qemu-devel] [Bug 1675108] [NEW] Cocoa UI always crashes on startup

2017-03-23 Thread Programmingkid

On Mar 23, 2017, at 7:35 AM, qemu-devel-requ...@nongnu.org wrote:

> Message: 15
> Date: Thu, 23 Mar 2017 11:13:02 +
> From: Alex Benn?e 
> To: Peter Maydell 
> Cc: Bug 1675108 <1675...@bugs.launchpad.net>, QEMU Developers
>   , Gerd Hoffmann 
> Subject: Re: [Qemu-devel] [Bug 1675108] [NEW] Cocoa UI always crashes
>   on startup
> Message-ID: <87d1d8xn41@linaro.org>
> Content-Type: text/plain; charset=utf-8
> 
> 
> Peter Maydell  writes:
> 
>> On 22 March 2017 at 17:26, Brendan Shanks  wrote:
>>> Public bug reported:
>>> 
>>> Commit 8bb93c6f99a42c2e0943bc904b283cd622d302c5 ("ui/console: ensure
>>> graphic updates don't race with TCG vCPUs") causes the graphic update to
>>> run on a non-main thread, which Cocoa is not happy with. It crashes
>>> immediately after startup.
>> 
>> Oops. Alex, we can't just run UI code on random threads like this.
> 
> Technically its not a random thread its the vCPU context (which ensures
> the vCPU isn't updating while the display is being updated). But I guess
> the Cocoa is limited to not being able to update from an arbitrary
> thread?
> 
> There was a patch posted yesterday to ensure the BQL is held during the
> deferred work but this doesn't look like that.
> 
>> Any ideas?
> 
> Hmm a quick Google seems to imply Cocoa is inflexible in its
> requirements. You can try this ugly but untested patch (I don't have any
> Macs handy):
> 
> modified   ui/console.c
> @@ -1598,8 +1598,16 @@ static void dpy_refresh(DisplayState *s)
> QLIST_FOREACH(dcl, &s->listeners, next) {
> if (dcl->ops->dpy_refresh) {
> if (tcg_enabled()) {
> +#ifdef CONFIG_COCOA
> +qemu_mutex_unlock_iothread();
> +start_exclusive();
> +do_safe_dpy_refresh(first_cpu, RUN_ON_CPU_HOST_PTR(dcl));
> +end_exclusive();
> +qemu_mutex_lock_iothread();
> +#else
> async_safe_run_on_cpu(first_cpu, do_safe_dpy_refresh,
>   RUN_ON_CPU_HOST_PTR(dcl));
> +#endif
> } else {
> dcl->ops->dpy_refresh(dcl);
> }
> 
> 
> Other than that I guess we need to bring forward the plans to "fixed the 
> dirty tracking
> races in display adapters"
> 
>> 
>> thanks
>> -- PMM
> 
> 
> --
> Alex Benn?e

Your patch does work. I tested it on Mac OS 10.6.8 using qemu-sytem-ppc. 

Has anyone checked on the GTK front-end yet to see if it is having similar 
problems?


Re: [Qemu-devel] [Bug 1675108] [NEW] Cocoa UI always crashes on startup

2017-03-23 Thread Alex Bennée

Peter Maydell  writes:

> On 23 March 2017 at 11:13, Alex Bennée  wrote:
>> Technically its not a random thread its the vCPU context (which ensures
>> the vCPU isn't updating while the display is being updated). But I guess
>> the Cocoa is limited to not being able to update from an arbitrary
>> thread?
>
> Yes. It's very common for windowing libraries to mandate that you
> do all windowing operations from one specific thread.

Fair enough. Well let me know if that works OK on MacOS and I'll fold it
in to the other console patches. In fact I might as well do the
start/end_exclusive dance for all OSes and it will achieve the same thing.

--
Alex Bennée



Re: [Qemu-devel] [Bug 1675108] [NEW] Cocoa UI always crashes on startup

2017-03-23 Thread Peter Maydell
On 23 March 2017 at 11:13, Alex Bennée  wrote:
> Technically its not a random thread its the vCPU context (which ensures
> the vCPU isn't updating while the display is being updated). But I guess
> the Cocoa is limited to not being able to update from an arbitrary
> thread?

Yes. It's very common for windowing libraries to mandate that you
do all windowing operations from one specific thread.

thanks
-- PMM



Re: [Qemu-devel] [Bug 1675108] [NEW] Cocoa UI always crashes on startup

2017-03-23 Thread Alex Bennée

Peter Maydell  writes:

> On 22 March 2017 at 17:26, Brendan Shanks  wrote:
>> Public bug reported:
>>
>> Commit 8bb93c6f99a42c2e0943bc904b283cd622d302c5 ("ui/console: ensure
>> graphic updates don't race with TCG vCPUs") causes the graphic update to
>> run on a non-main thread, which Cocoa is not happy with. It crashes
>> immediately after startup.
>
> Oops. Alex, we can't just run UI code on random threads like this.

Technically its not a random thread its the vCPU context (which ensures
the vCPU isn't updating while the display is being updated). But I guess
the Cocoa is limited to not being able to update from an arbitrary
thread?

There was a patch posted yesterday to ensure the BQL is held during the
deferred work but this doesn't look like that.

> Any ideas?

Hmm a quick Google seems to imply Cocoa is inflexible in its
requirements. You can try this ugly but untested patch (I don't have any
Macs handy):

modified   ui/console.c
@@ -1598,8 +1598,16 @@ static void dpy_refresh(DisplayState *s)
 QLIST_FOREACH(dcl, &s->listeners, next) {
 if (dcl->ops->dpy_refresh) {
 if (tcg_enabled()) {
+#ifdef CONFIG_COCOA
+qemu_mutex_unlock_iothread();
+start_exclusive();
+do_safe_dpy_refresh(first_cpu, RUN_ON_CPU_HOST_PTR(dcl));
+end_exclusive();
+qemu_mutex_lock_iothread();
+#else
 async_safe_run_on_cpu(first_cpu, do_safe_dpy_refresh,
   RUN_ON_CPU_HOST_PTR(dcl));
+#endif
 } else {
 dcl->ops->dpy_refresh(dcl);
 }


Other than that I guess we need to bring forward the plans to "fixed the dirty 
tracking
races in display adapters"

>
> thanks
> -- PMM


--
Alex Bennée



Re: [Qemu-devel] [Bug 1675108] [NEW] Cocoa UI always crashes on startup

2017-03-23 Thread Peter Maydell
On 22 March 2017 at 17:26, Brendan Shanks  wrote:
> Public bug reported:
>
> Commit 8bb93c6f99a42c2e0943bc904b283cd622d302c5 ("ui/console: ensure
> graphic updates don't race with TCG vCPUs") causes the graphic update to
> run on a non-main thread, which Cocoa is not happy with. It crashes
> immediately after startup.

Oops. Alex, we can't just run UI code on random threads like this.
Any ideas?

thanks
-- PMM



[Qemu-devel] [Bug 1675108] [NEW] Cocoa UI always crashes on startup

2017-03-22 Thread Brendan Shanks
Public bug reported:

Commit 8bb93c6f99a42c2e0943bc904b283cd622d302c5 ("ui/console: ensure
graphic updates don't race with TCG vCPUs") causes the graphic update to
run on a non-main thread, which Cocoa is not happy with. It crashes
immediately after startup.

$ i386-softmmu/qemu-system-i386 
2017-03-22 10:09:25.113 qemu-system-i386[15968:9538245] *** Terminating app due 
to uncaught exception 'NSInternalInconsistencyException', reason: 
'nextEventMatchingMask should only be called from the Main Thread!'
*** First throw call stack:
(
0   CoreFoundation  0x7fff91e72e7b 
__exceptionPreprocess + 171
1   libobjc.A.dylib 0x7fffa6a5ccad 
objc_exception_throw + 48
2   AppKit  0x7fff900953fd 
-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] 
+ 4471
3   qemu-system-i3860x000104f75a49 
cocoa_refresh + 233
4   qemu-system-i3860x000104e0312c 
process_queued_cpu_work + 140
5   qemu-system-i3860x000104d1a73c 
qemu_tcg_rr_cpu_thread_fn + 284
6   libsystem_pthread.dylib 0x7fffa7557aab 
_pthread_body + 180
7   libsystem_pthread.dylib 0x7fffa75579f7 
_pthread_body + 0
8   libsystem_pthread.dylib 0x7fffa75571fd thread_start 
+ 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6

System: macOS 10.12.3, Xcode 8.2.1

** Affects: qemu
 Importance: Undecided
 Status: New

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1675108

Title:
  Cocoa UI always crashes on startup

Status in QEMU:
  New

Bug description:
  Commit 8bb93c6f99a42c2e0943bc904b283cd622d302c5 ("ui/console: ensure
  graphic updates don't race with TCG vCPUs") causes the graphic update
  to run on a non-main thread, which Cocoa is not happy with. It crashes
  immediately after startup.

  $ i386-softmmu/qemu-system-i386 
  2017-03-22 10:09:25.113 qemu-system-i386[15968:9538245] *** Terminating app 
due to uncaught exception 'NSInternalInconsistencyException', reason: 
'nextEventMatchingMask should only be called from the Main Thread!'
  *** First throw call stack:
  (
0   CoreFoundation  0x7fff91e72e7b 
__exceptionPreprocess + 171
1   libobjc.A.dylib 0x7fffa6a5ccad 
objc_exception_throw + 48
2   AppKit  0x7fff900953fd 
-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] 
+ 4471
3   qemu-system-i3860x000104f75a49 
cocoa_refresh + 233
4   qemu-system-i3860x000104e0312c 
process_queued_cpu_work + 140
5   qemu-system-i3860x000104d1a73c 
qemu_tcg_rr_cpu_thread_fn + 284
6   libsystem_pthread.dylib 0x7fffa7557aab 
_pthread_body + 180
7   libsystem_pthread.dylib 0x7fffa75579f7 
_pthread_body + 0
8   libsystem_pthread.dylib 0x7fffa75571fd thread_start 
+ 13
  )
  libc++abi.dylib: terminating with uncaught exception of type NSException
  Abort trap: 6

  System: macOS 10.12.3, Xcode 8.2.1

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1675108/+subscriptions