From patchwork Mon Sep 25 13:03:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "edmund.raile" X-Patchwork-Id: 1839166 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=protonmail.com header.i=@protonmail.com header.a=rsa-sha256 header.s=protonmail3 header.b=YRI9Ywgw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RvR922p37z1ynF for ; Tue, 26 Sep 2023 01:08:54 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qknBr-00069h-PY; Mon, 25 Sep 2023 11:08:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qklFa-0000sF-6x for qemu-devel@nongnu.org; Mon, 25 Sep 2023 09:03:46 -0400 Received: from mail-40138.protonmail.ch ([185.70.40.138]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qklFX-0003oX-Aq for qemu-devel@nongnu.org; Mon, 25 Sep 2023 09:03:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1695647007; x=1695906207; bh=v1NApPAABERi6sgpDg4dmIEZwYuIQc/JUNHnrbpM/Z4=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=YRI9Ywgw8ss7BSu+9cw2LQtKsm1uVkc7j8ajwrC4ym6hAQU1RSe4u2vqnANA6X8Gq 4h+/3ySXSX/VkpbMRDnY2qEIJ44w6xgzwAoaQpP/qdla0OYkxo2oHk060poL43h5Of 1/t4vUX9Ixz8TVPjNWoPxq9Axra6ELU0/ZtzfUnV/aUmDkvSWGxD2RGxrNqs4WQXL9 VfFhsZVqTa6SfJHo3ajC29pC+fhW5XdjFQCFHT95K4UvfzoaQTQa9T/BPy8P1kvzT9 ctWJ9iaZ6uhVGIMJKiKD+piNUMB6Z91YRsznkOR89LJaFePA1CWHRvd+TU41zkWKv+ +sJQGPkdkXOGA== Date: Mon, 25 Sep 2023 13:03:24 +0000 To: "qemu-devel@nongnu.org" From: "edmund.raile" Cc: "kraxel@redhat.com" , =?utf-8?q?Marc-Andr=C3=A9_Lurea?= =?utf-8?q?u?= Subject: qemu-gtk clipboard crash fixes Message-ID: Feedback-ID: 43016623:user:proton MIME-Version: 1.0 Received-SPF: pass client-ip=185.70.40.138; envelope-from=edmund.raile@protonmail.com; helo=mail-40138.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 25 Sep 2023 11:08:01 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org In response to [gemu-gtk-clipboard freezing and crashing guests](https://gitlab.com/qemu-project/qemu/-/issues/1150). I think I might have a solution for the gtk clipboard sometimes crashing guests. @kolAflash I couldn't have done it without you, figuring out `gtk_clipboard_wait_is_text_available(clipboard)` was the issue is half the work. The real issue is that it's blocking and I'd wager that's a big no-no since qemu & KVM have to run the VM + OS, preferably as real-time as possible. Something times out and you get a core dump. So as a replacement, `gtk_clipboard_request_text`, which is async and non-blocking is a better choice, hopefully. It requires an additional function to handle receiving text. Signed-off-by: Edmund Raile From 530db8b6c7adc99f540d7d8cc6122320868326e6 Mon Sep 17 00:00:00 2001 From: Edmund Raile Date: Sun, 24 Sep 2023 09:46:27 +0200 Subject: [PATCH 1/1] qemu-ui-gtk clipboard possible fix for crashes --- ui/gtk-clipboard.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) -- 2.42.0 don't forget to configure with --enable-gtk-clipboard before building I'd say my gvt-g win10 VM has become a lot more responsive (was using gtk-clipboard besides being broken). Paste from the VM is a bit delayed sometimes but I can live with that. So far my VM hasn't crashed yet. I'd like to ask you for help in evaluating my patch. The issue linked to in the first line has instructions on the crash case. It's my first time on the mailing list, I hope I've done this right. Mr. Lureau CCed here had this to add: Blocking the signal handler isn't great either, as we may miss clipboard updates. I think we could "reuse" the serial field on info and check in the callback if we don't have the latest, just ignore the result and free. diff --git a/ui/gtk-clipboard.c b/ui/gtk-clipboard.c index 8d8a636fd1..64d4f7ac9d 100644 --- a/ui/gtk-clipboard.c +++ b/ui/gtk-clipboard.c @@ -153,6 +153,18 @@ static void gd_clipboard_request(QemuClipboardInfo *info, } } +/* non-blocking clipboard receiver implementation */ +static void gd_clipboard_text_received_callback(GtkClipboard *clipboard, const gchar *text, gpointer data) +{ + QemuClipboardInfo *info = (QemuClipboardInfo *)data; + if (text) { + info->types[QEMU_CLIPBOARD_TYPE_TEXT].available = true; + } + + qemu_clipboard_update(info); + qemu_clipboard_info_unref(info); +} + static void gd_owner_change(GtkClipboard *clipboard, GdkEvent *event, gpointer data) @@ -170,12 +182,8 @@ static void gd_owner_change(GtkClipboard *clipboard, switch (event->owner_change.reason) { case GDK_OWNER_CHANGE_NEW_OWNER: info = qemu_clipboard_info_new(&gd->cbpeer, s); - if (gtk_clipboard_wait_is_text_available(clipboard)) { - info->types[QEMU_CLIPBOARD_TYPE_TEXT].available = true; - } - - qemu_clipboard_update(info); - qemu_clipboard_info_unref(info); + /* gtk_clipboard_wait_is_text_available (blocking) was used here previously and crashed guests */ + gtk_clipboard_request_text(clipboard, gd_clipboard_text_received_callback, info); break; default: qemu_clipboard_peer_release(&gd->cbpeer, s);