From nobody Fri May 3 01:52:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490627522683849.40304205306; Mon, 27 Mar 2017 08:12:02 -0700 (PDT) Received: from localhost ([::1]:47269 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWJM-0001rI-T3 for importer@patchew.org; Mon, 27 Mar 2017 11:12:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWGN-0007uE-38 for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:08:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csWGM-0000DJ-8o for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:08:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58434) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csWGM-0000Ck-3g for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:08:54 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 203FFC04BD4E for ; Mon, 27 Mar 2017 15:08:53 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-85.ams2.redhat.com [10.36.116.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 555DB71C88; Mon, 27 Mar 2017 15:08:45 +0000 (UTC) Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 97D3C80E25; Mon, 27 Mar 2017 15:28:41 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 203FFC04BD4E Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kraxel@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 203FFC04BD4E From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 15:28:33 +0200 Message-Id: <1490621317-25483-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1490621317-25483-1-git-send-email-kraxel@redhat.com> References: <1490621317-25483-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 27 Mar 2017 15:08:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL for-2.9 1/5] virtio-input: free event queue when finalizing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ladi Prosek , Gerd Hoffmann , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ladi Prosek VirtIOInput.queue was never freed. This commit adds an explicit g_free to virtio_input_finalize and switches the allocation function from realloc to g_realloc in virtio_input_send. Signed-off-by: Ladi Prosek Message-id: 1490365490-4854-2-git-send-email-lprosek@redhat.com Signed-off-by: Gerd Hoffmann --- hw/input/virtio-input.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/input/virtio-input.c b/hw/input/virtio-input.c index b678ee9..728832a 100644 --- a/hw/input/virtio-input.c +++ b/hw/input/virtio-input.c @@ -32,8 +32,8 @@ void virtio_input_send(VirtIOInput *vinput, virtio_input_= event *event) /* queue up events ... */ if (vinput->qindex =3D=3D vinput->qsize) { vinput->qsize++; - vinput->queue =3D realloc(vinput->queue, vinput->qsize * - sizeof(virtio_input_event)); + vinput->queue =3D g_realloc(vinput->queue, vinput->qsize * + sizeof(virtio_input_event)); } vinput->queue[vinput->qindex++] =3D *event; =20 @@ -272,6 +272,8 @@ static void virtio_input_finalize(Object *obj) QTAILQ_REMOVE(&vinput->cfg_list, cfg, node); g_free(cfg); } + + g_free(vinput->queue); } static void virtio_input_device_unrealize(DeviceState *dev, Error **errp) { --=20 1.8.3.1 From nobody Fri May 3 01:52:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490627593414207.91962075447952; Mon, 27 Mar 2017 08:13:13 -0700 (PDT) Received: from localhost ([::1]:47276 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWKV-0002fW-P9 for importer@patchew.org; Mon, 27 Mar 2017 11:13:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWGN-0007uy-TV for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:08:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csWGM-0000DR-DO for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:08:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45168) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csWGM-0000Cq-5P for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:08:54 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 50C088046F for ; Mon, 27 Mar 2017 15:08:53 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-85.ams2.redhat.com [10.36.116.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96B011716E; Mon, 27 Mar 2017 15:08:49 +0000 (UTC) Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 53E7880C5C; Mon, 27 Mar 2017 15:28:42 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 50C088046F Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kraxel@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 50C088046F From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 15:28:34 +0200 Message-Id: <1490621317-25483-3-git-send-email-kraxel@redhat.com> In-Reply-To: <1490621317-25483-1-git-send-email-kraxel@redhat.com> References: <1490621317-25483-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 27 Mar 2017 15:08:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL for-2.9 2/5] virtio-input: fix eventq batching X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ladi Prosek , Gerd Hoffmann , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ladi Prosek virtio_input_send buffers input events until it sees a SYNC. Then it either sends or drops the entire batch, depending on whether eventq has enough space available. The case to avoid here is partial sends where only part of the batch would get to the guest. Using virtqueue_get_avail_bytes to check the state of eventq was not correct. The queue may have a smaller number of larger buffers available so bytes may be enough but the batch would still not be possible to send, leading to the "Huh? No vq elem available" error. Instead of checking available bytes, this patch optimistically pops buffers from the queue and puts them back in case it runs out of space and the batch needs to be dropped. Signed-off-by: Ladi Prosek Message-id: 1490365490-4854-3-git-send-email-lprosek@redhat.com Signed-off-by: Gerd Hoffmann --- hw/input/virtio-input.c | 29 ++++++++++++++--------------- include/hw/virtio/virtio-input.h | 5 ++++- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/hw/input/virtio-input.c b/hw/input/virtio-input.c index 728832a..0e42f0d 100644 --- a/hw/input/virtio-input.c +++ b/hw/input/virtio-input.c @@ -22,7 +22,6 @@ void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event) { VirtQueueElement *elem; - unsigned have, need; int i, len; =20 if (!vinput->active) { @@ -33,9 +32,9 @@ void virtio_input_send(VirtIOInput *vinput, virtio_input_= event *event) if (vinput->qindex =3D=3D vinput->qsize) { vinput->qsize++; vinput->queue =3D g_realloc(vinput->queue, vinput->qsize * - sizeof(virtio_input_event)); + sizeof(vinput->queue[0])); } - vinput->queue[vinput->qindex++] =3D *event; + vinput->queue[vinput->qindex++].event =3D *event; =20 /* ... until we see a report sync ... */ if (event->type !=3D cpu_to_le16(EV_SYN) || @@ -44,24 +43,24 @@ void virtio_input_send(VirtIOInput *vinput, virtio_inpu= t_event *event) } =20 /* ... then check available space ... */ - need =3D sizeof(virtio_input_event) * vinput->qindex; - virtqueue_get_avail_bytes(vinput->evt, &have, NULL, need, 0); - if (have < need) { - vinput->qindex =3D 0; - trace_virtio_input_queue_full(); - return; - } - - /* ... and finally pass them to the guest */ for (i =3D 0; i < vinput->qindex; i++) { elem =3D virtqueue_pop(vinput->evt, sizeof(VirtQueueElement)); if (!elem) { - /* should not happen, we've checked for space beforehand */ - fprintf(stderr, "%s: Huh? No vq elem available ...\n", __func= __); + while (--i >=3D 0) { + virtqueue_unpop(vinput->evt, vinput->queue[i].elem, 0); + } + vinput->qindex =3D 0; + trace_virtio_input_queue_full(); return; } + vinput->queue[i].elem =3D elem; + } + + /* ... and finally pass them to the guest */ + for (i =3D 0; i < vinput->qindex; i++) { + elem =3D vinput->queue[i].elem; len =3D iov_from_buf(elem->in_sg, elem->in_num, - 0, vinput->queue+i, sizeof(virtio_input_event)); + 0, &vinput->queue[i].event, sizeof(virtio_input= _event)); virtqueue_push(vinput->evt, elem, len); g_free(elem); } diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-in= put.h index 55db310..91df57e 100644 --- a/include/hw/virtio/virtio-input.h +++ b/include/hw/virtio/virtio-input.h @@ -62,7 +62,10 @@ struct VirtIOInput { VirtQueue *evt, *sts; char *serial; =20 - virtio_input_event *queue; + struct { + virtio_input_event event; + VirtQueueElement *elem; + } *queue; uint32_t qindex, qsize; =20 bool active; --=20 1.8.3.1 From nobody Fri May 3 01:52:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490627417016884.9580319740479; Mon, 27 Mar 2017 08:10:17 -0700 (PDT) Received: from localhost ([::1]:47255 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWHf-0000Qg-RB for importer@patchew.org; Mon, 27 Mar 2017 11:10:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWGK-0007tQ-PL for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:08:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csWGH-0000Al-Hn for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:08:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58268) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csWGH-0000AF-C4 for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:08:49 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 90A00C0528A9 for ; Mon, 27 Mar 2017 15:08:47 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-85.ams2.redhat.com [10.36.116.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A84B17163; Mon, 27 Mar 2017 15:08:45 +0000 (UTC) Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 0B12C80E82; Mon, 27 Mar 2017 15:28:43 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 90A00C0528A9 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kraxel@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 90A00C0528A9 From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 15:28:35 +0200 Message-Id: <1490621317-25483-4-git-send-email-kraxel@redhat.com> In-Reply-To: <1490621317-25483-1-git-send-email-kraxel@redhat.com> References: <1490621317-25483-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 27 Mar 2017 15:08:47 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL for-2.9 3/5] cirrus: fix PUTPIXEL macro X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Should be "c" not "col". The macro is used with "col" as third parameter everywhere, so this tyops doesn't break something. Fixes: 026aeffcb4752054830ba203020ed6eb05bcaba8 Reported-by: Dr. David Alan Gilbert Signed-off-by: Gerd Hoffmann Reviewed-by: Dr. David Alan Gilbert Message-id: 1490168303-24588-1-git-send-email-kraxel@redhat.com --- hw/display/cirrus_vga_rop2.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/display/cirrus_vga_rop2.h b/hw/display/cirrus_vga_rop2.h index b86bcd6..b208b73 100644 --- a/hw/display/cirrus_vga_rop2.h +++ b/hw/display/cirrus_vga_rop2.h @@ -29,8 +29,8 @@ #elif DEPTH =3D=3D 24 #define PUTPIXEL(s, a, c) do { \ ROP_OP(s, a, c); \ - ROP_OP(s, a + 1, (col >> 8)); \ - ROP_OP(s, a + 2, (col >> 16)); \ + ROP_OP(s, a + 1, (c >> 8)); \ + ROP_OP(s, a + 2, (c >> 16)); \ } while (0) #elif DEPTH =3D=3D 32 #define PUTPIXEL(s, a, c) ROP_OP_32(s, a, c) --=20 1.8.3.1 From nobody Fri May 3 01:52:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490627416891897.1702934189332; Mon, 27 Mar 2017 08:10:16 -0700 (PDT) Received: from localhost ([::1]:47253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWHe-0000PU-K5 for importer@patchew.org; Mon, 27 Mar 2017 11:10:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWGK-0007tR-PP for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:08:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csWGH-0000Az-KW for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:08:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48023) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csWGH-0000AH-C0 for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:08:49 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 050E375EAB for ; Mon, 27 Mar 2017 15:08:48 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-85.ams2.redhat.com [10.36.116.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FD9817175; Mon, 27 Mar 2017 15:08:45 +0000 (UTC) Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 9EB2180EB1; Mon, 27 Mar 2017 15:28:43 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 050E375EAB Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kraxel@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 050E375EAB From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 15:28:36 +0200 Message-Id: <1490621317-25483-5-git-send-email-kraxel@redhat.com> In-Reply-To: <1490621317-25483-1-git-send-email-kraxel@redhat.com> References: <1490621317-25483-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 27 Mar 2017 15:08:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL for-2.9 4/5] ui/egl-helpers: fix egl 1.5 display init X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann , Frediano Ziglio Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Unfortunaly switching to getPlatformDisplayEXT isn't as easy as implemented by 0ea1523fb6703aa0dcd65e66b59e96fec028e60a. See the longish comment for the complete story. Cc: Frediano Ziglio Suggested-by: Hans de Goede Signed-off-by: Gerd Hoffmann Message-id: 1489997042-1824-1-git-send-email-kraxel@redhat.com --- ui/egl-helpers.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++--= ---- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c index 584dd1b..b7b6b2e 100644 --- a/ui/egl-helpers.c +++ b/ui/egl-helpers.c @@ -192,6 +192,56 @@ EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, = Window win) =20 /* ---------------------------------------------------------------------- = */ =20 +/* + * Taken from glamor_egl.h from the Xorg xserver, which is MIT licensed + * + * Create an EGLDisplay from a native display type. This is a little quirky + * for a few reasons. + * + * 1: GetPlatformDisplayEXT and GetPlatformDisplay are the API you want to + * use, but have different function signatures in the third argument; this + * happens not to matter for us, at the moment, but it means epoxy won't a= lias + * them together. + * + * 2: epoxy 1.3 and earlier don't understand EGL client extensions, which + * means you can't call "eglGetPlatformDisplayEXT" directly, as the resolv= er + * will crash. + * + * 3: You can't tell whether you have EGL 1.5 at this point, because + * eglQueryString(EGL_VERSION) is a property of the display, which we don't + * have yet. So you have to query for extensions no matter what. Fortunate= ly + * epoxy_has_egl_extension _does_ let you query for client extensions, so + * we don't have to write our own extension string parsing. + * + * 4. There is no EGL_KHR_platform_base to complement the EXT one, thus one + * needs to know EGL 1.5 is supported in order to use the eglGetPlatformDi= splay + * function pointer. + * We can workaround this (circular dependency) by probing for the EGL 1.5 + * platform extensions (EGL_KHR_platform_gbm and friends) yet it doesn't s= eem + * like mesa will be able to advertise these (even though it can do EGL 1.= 5). + */ +static EGLDisplay qemu_egl_get_display(void *native) +{ + EGLDisplay dpy =3D EGL_NO_DISPLAY; + +#ifdef EGL_MESA_platform_gbm + /* In practise any EGL 1.5 implementation would support the EXT extens= ion */ + if (epoxy_has_egl_extension(NULL, "EGL_EXT_platform_base")) { + PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplayEXT =3D + (void *) eglGetProcAddress("eglGetPlatformDisplayEXT"); + if (getPlatformDisplayEXT) { + dpy =3D getPlatformDisplayEXT(EGL_PLATFORM_GBM_MESA, native, N= ULL); + } + } +#endif + + if (dpy =3D=3D EGL_NO_DISPLAY) { + /* fallback */ + dpy =3D eglGetDisplay(native); + } + return dpy; +} + int qemu_egl_init_dpy(EGLNativeDisplayType dpy, bool gles, bool debug) { static const EGLint conf_att_gl[] =3D { @@ -222,12 +272,8 @@ int qemu_egl_init_dpy(EGLNativeDisplayType dpy, bool g= les, bool debug) setenv("LIBGL_DEBUG", "verbose", true); } =20 - egl_dbg("eglGetDisplay (dpy %p) ...\n", dpy); -#ifdef EGL_MESA_platform_gbm - qemu_egl_display =3D eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_MESA, d= py, NULL); -#else - qemu_egl_display =3D eglGetDisplay(dpy); -#endif + egl_dbg("qemu_egl_get_display (dpy %p) ...\n", dpy); + qemu_egl_display =3D qemu_egl_get_display(dpy); if (qemu_egl_display =3D=3D EGL_NO_DISPLAY) { error_report("egl: eglGetDisplay failed"); return -1; --=20 1.8.3.1 From nobody Fri May 3 01:52:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490627416972856.2161050252811; Mon, 27 Mar 2017 08:10:16 -0700 (PDT) Received: from localhost ([::1]:47254 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWHf-0000Pm-Ij for importer@patchew.org; Mon, 27 Mar 2017 11:10:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWGK-0007tS-PW for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:08:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csWGH-0000Au-Jo for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:08:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36794) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csWGH-0000AE-C3 for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:08:49 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5EDD07EBA2 for ; Mon, 27 Mar 2017 15:08:48 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-85.ams2.redhat.com [10.36.116.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5790E81C01; Mon, 27 Mar 2017 15:08:45 +0000 (UTC) Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 415F080E43; Mon, 27 Mar 2017 15:28:44 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5EDD07EBA2 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kraxel@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5EDD07EBA2 From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 15:28:37 +0200 Message-Id: <1490621317-25483-6-git-send-email-kraxel@redhat.com> In-Reply-To: <1490621317-25483-1-git-send-email-kraxel@redhat.com> References: <1490621317-25483-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 27 Mar 2017 15:08:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL for-2.9 5/5] vnc: fix reverse mode X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" vnc server in reverse mode (qemu -vnc localhost:$nr,reverse) interprets $nr as display number (i.e. with 5900 offset) in recent qemu versions. Historical and documented behavior is interpreting $nr as port number though. So we should bring code and documentation in line. Given that default listening port for viewers is 5500 the 5900 offset is pretty inconvinient, because it is simply impossible to connect to port 5500. So, lets fix the code not the docs. Signed-off-by: Gerd Hoffmann Reviewed-by: Daniel P. Berrange Message-id: 1489480018-11443-1-git-send-email-kraxel@redhat.com --- ui/vnc.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 6e93b88..821acdd 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3401,6 +3401,7 @@ vnc_display_create_creds(bool x509, =20 static int vnc_display_get_address(const char *addrstr, bool websocket, + bool reverse, int displaynum, int to, bool has_ipv4, @@ -3480,21 +3481,22 @@ static int vnc_display_get_address(const char *addr= str, inet->port =3D g_strdup(port); } } else { + int offset =3D reverse ? 0 : 5900; if (parse_uint_full(port, &baseport, 10) < 0) { error_setg(errp, "can't convert to a number: %s", port); goto cleanup; } if (baseport > 65535 || - baseport + 5900 > 65535) { + baseport + offset > 65535) { error_setg(errp, "port %s out of range", port); goto cleanup; } inet->port =3D g_strdup_printf( - "%d", (int)baseport + 5900); + "%d", (int)baseport + offset); =20 if (to) { inet->has_to =3D true; - inet->to =3D to + 5900; + inet->to =3D to + offset; } } =20 @@ -3516,6 +3518,7 @@ static int vnc_display_get_address(const char *addrst= r, } =20 static int vnc_display_get_addresses(QemuOpts *opts, + bool reverse, SocketAddress ***retsaddr, size_t *retnsaddr, SocketAddress ***retwsaddr, @@ -3555,7 +3558,7 @@ static int vnc_display_get_addresses(QemuOpts *opts, qemu_opt_iter_init(&addriter, opts, "vnc"); while ((addr =3D qemu_opt_iter_next(&addriter)) !=3D NULL) { int rv; - rv =3D vnc_display_get_address(addr, false, 0, to, + rv =3D vnc_display_get_address(addr, false, reverse, 0, to, has_ipv4, has_ipv6, ipv4, ipv6, &saddr, errp); @@ -3580,7 +3583,7 @@ static int vnc_display_get_addresses(QemuOpts *opts, =20 qemu_opt_iter_init(&addriter, opts, "websocket"); while ((addr =3D qemu_opt_iter_next(&addriter)) !=3D NULL) { - if (vnc_display_get_address(addr, true, displaynum, to, + if (vnc_display_get_address(addr, true, reverse, displaynum, to, has_ipv4, has_ipv6, ipv4, ipv6, &wsaddr, errp) < 0) { @@ -3777,7 +3780,8 @@ void vnc_display_open(const char *id, Error **errp) return; } =20 - if (vnc_display_get_addresses(opts, &saddr, &nsaddr, + reverse =3D qemu_opt_get_bool(opts, "reverse", false); + if (vnc_display_get_addresses(opts, reverse, &saddr, &nsaddr, &wsaddr, &nwsaddr, errp) < 0) { goto fail; } @@ -3803,7 +3807,6 @@ void vnc_display_open(const char *id, Error **errp) } } =20 - reverse =3D qemu_opt_get_bool(opts, "reverse", false); lock_key_sync =3D qemu_opt_get_bool(opts, "lock-key-sync", true); key_delay_ms =3D qemu_opt_get_number(opts, "key-delay-ms", 1); sasl =3D qemu_opt_get_bool(opts, "sasl", false); --=20 1.8.3.1