[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 25/26] ui/cocoa.m: Fix updateUIInfo threading issues
From: |
Peter Maydell |
Subject: |
[PULL 25/26] ui/cocoa.m: Fix updateUIInfo threading issues |
Date: |
Wed, 2 Mar 2022 20:52:29 +0000 |
The updateUIInfo method makes Cocoa API calls. It also calls back
into QEMU functions like dpy_set_ui_info(). To do this safely, we
need to follow two rules:
* Cocoa API calls are made on the Cocoa UI thread
* When calling back into QEMU we must hold the iothread lock
Fix the places where we got this wrong, by taking the iothread lock
while executing updateUIInfo, and moving the call in cocoa_switch()
inside the dispatch_async block.
Some of the Cocoa UI methods which call updateUIInfo are invoked as
part of the initial application startup, while we're still doing the
little cross-thread dance described in the comment just above
call_qemu_main(). This meant they were calling back into the QEMU UI
layer before we'd actually finished initializing our display and
registered the DisplayChangeListener, which isn't really valid. Once
updateUIInfo takes the iothread lock, we no longer get away with
this, because during this startup phase the iothread lock is held by
the QEMU main-loop thread which is waiting for us to finish our
display initialization. So we must suppress updateUIInfo until
applicationDidFinishLaunching allows the QEMU main-loop thread to
continue.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Tested-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Message-id: 20220224101330.967429-2-peter.maydell@linaro.org
---
ui/cocoa.m | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index a8f1cdaf926..5ed1495552a 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -522,8 +522,9 @@ QemuCocoaView *cocoaView;
}
}
-- (void) updateUIInfo
+- (void) updateUIInfoLocked
{
+ /* Must be called with the iothread lock, i.e. via updateUIInfo */
NSSize frameSize;
QemuUIInfo info;
@@ -554,6 +555,25 @@ QemuCocoaView *cocoaView;
dpy_set_ui_info(dcl.con, &info, TRUE);
}
+- (void) updateUIInfo
+{
+ if (!allow_events) {
+ /*
+ * Don't try to tell QEMU about UI information in the application
+ * startup phase -- we haven't yet registered dcl with the QEMU UI
+ * layer, and also trying to take the iothread lock would deadlock.
+ * When cocoa_display_init() does register the dcl, the UI layer
+ * will call cocoa_switch(), which will call updateUIInfo, so
+ * we don't lose any information here.
+ */
+ return;
+ }
+
+ with_iothread_lock(^{
+ [self updateUIInfoLocked];
+ });
+}
+
- (void)viewDidMoveToWindow
{
[self updateUIInfo];
@@ -1985,8 +2005,6 @@ static void cocoa_switch(DisplayChangeListener *dcl,
COCOA_DEBUG("qemu_cocoa: cocoa_switch\n");
- [cocoaView updateUIInfo];
-
// The DisplaySurface will be freed as soon as this callback returns.
// We take a reference to the underlying pixman image here so it does
// not disappear from under our feet; the switchSurface method will
@@ -1994,6 +2012,7 @@ static void cocoa_switch(DisplayChangeListener *dcl,
pixman_image_ref(image);
dispatch_async(dispatch_get_main_queue(), ^{
+ [cocoaView updateUIInfo];
[cocoaView switchSurface:image];
});
[pool release];
--
2.25.1
- [PULL 11/26] target/arm: Move arm_pamax out of line, (continued)
- [PULL 11/26] target/arm: Move arm_pamax out of line, Peter Maydell, 2022/03/02
- [PULL 17/26] target/arm: Implement FEAT_LPA, Peter Maydell, 2022/03/02
- [PULL 04/26] hw/i2c: flatten pca954x mux device, Peter Maydell, 2022/03/02
- [PULL 06/26] target/arm: Fix early free of TCG temp in handle_simd_shift_fpint_conv(), Peter Maydell, 2022/03/02
- [PULL 01/26] mps3-an547: Add missing user ahb interfaces, Peter Maydell, 2022/03/02
- [PULL 05/26] target/arm: Support PSCI 1.1 and SMCCC 1.0, Peter Maydell, 2022/03/02
- [PULL 15/26] target/arm: Prepare DBGBVR and DBGWVR for FEAT_LVA, Peter Maydell, 2022/03/02
- [PULL 18/26] target/arm: Extend arm_fi_to_lfsc to level -1, Peter Maydell, 2022/03/02
- [PULL 22/26] target/arm: Advertise all page sizes for -cpu max, Peter Maydell, 2022/03/02
- [PULL 23/26] target/arm: Implement FEAT_LPA2, Peter Maydell, 2022/03/02
- [PULL 25/26] ui/cocoa.m: Fix updateUIInfo threading issues,
Peter Maydell <=
- [PULL 16/26] target/arm: Implement FEAT_LVA, Peter Maydell, 2022/03/02
- [PULL 19/26] target/arm: Introduce tlbi_aa64_get_range, Peter Maydell, 2022/03/02
- [PULL 24/26] target/arm: Report KVM's actual PSCI version to guest in dtb, Peter Maydell, 2022/03/02
- [PULL 13/26] target/arm: Use MAKE_64BIT_MASK to compute indexmask, Peter Maydell, 2022/03/02
- [PULL 20/26] target/arm: Fix TLBIRange.base for 16k and 64k pages, Peter Maydell, 2022/03/02
- [PULL 21/26] target/arm: Validate tlbi TG matches translation granule in use, Peter Maydell, 2022/03/02
- [PULL 26/26] ui/cocoa.m: Remove unnecessary NSAutoreleasePools, Peter Maydell, 2022/03/02
- Re: [PULL 00/26] target-arm queue, Peter Maydell, 2022/03/03