From nobody Sun May 5 18:19:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664450932; cv=none; d=zohomail.com; s=zohoarc; b=U9RbM5FKTNBpgFGfp+ZeuiyFmmshf05CYJ4oADuIXPidqwhbBEb+RK/3H9nwqv4399q7jgi9I/m4kocan4c2H5Rr8Nc6pCsCNZt2hn67H/KOrPmy42DkJVSL++J4kqbj7FZ5daYpaE8KuU9YBsbjLVnmyg+xq6nkVa/i7QKNFjo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664450932; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VvcfMAnfS2NXgz69qMhd9Dd+IriMC8wARf9eoTp7M9g=; b=eyMky8yqJHmIJ9F4+ff7L2mh5VD2LTuk/j9EmO+LbnN6kdnRegYkOBS07WhAnvRq91taAks8QSCBJm3Xv31/b1+VwX83iaVpgWKBMpiOh5ANnth/X3NGrM/NcEhwnYL3krhIcHJ8mnv64qZzilsKC75iRQQ5D1e72jmC+c3Fabs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664450932948432.8222853275571; Thu, 29 Sep 2022 04:28:52 -0700 (PDT) Received: from localhost ([::1]:34260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odril-00051R-NR for importer@patchew.org; Thu, 29 Sep 2022 07:28:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odrM2-0000pS-R5 for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:05:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:42303) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odrM0-0001ua-8D for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:05:21 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-635-tn4tIy-aNQucVwKABl1jqA-1; Thu, 29 Sep 2022 07:05:16 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 071F3296A62F; Thu, 29 Sep 2022 11:05:16 +0000 (UTC) Received: from localhost (unknown [10.39.208.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2F07207B34A; Thu, 29 Sep 2022 11:05:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664449519; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VvcfMAnfS2NXgz69qMhd9Dd+IriMC8wARf9eoTp7M9g=; b=f4svkk66eq4AZ1narCfhsv8gs2MwSlTfoVsAYhIk4ZNY6UsNJx2QW96QenusPs4WjAVwms qXK7VMk9A4oVJwoazU0ZFpuusQ9TxwVLn5SBXVMgO+6LEQGqfUQksRbGdlBwLZMWZRP7Ox ZKZVZsFgeEwECC/Ee3KPbjaizi2MaFA= X-MC-Unique: tn4tIy-aNQucVwKABl1jqA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Arwed Meyer , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Subject: [PULL 1/8] msmouse: Handle mouse reset Date: Thu, 29 Sep 2022 15:05:01 +0400 Message-Id: <20220929110508.1323529-2-marcandre.lureau@redhat.com> In-Reply-To: <20220929110508.1323529-1-marcandre.lureau@redhat.com> References: <20220929110508.1323529-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.08, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1664450934214100001 From: Arwed Meyer Detect mouse reset via RTS or DTR line: Don't send or process anything while in reset. When coming out of reset, send ID sequence first thing. This allows msmouse to be detected by common mouse drivers. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/77 Signed-off-by: Arwed Meyer Acked-by: Marc-Andr=C3=A9 Lureau Message-Id: <20220911181840.8933-2-arwed.meyer@gmx.de> --- chardev/msmouse.c | 63 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/chardev/msmouse.c b/chardev/msmouse.c index eb9231dcdb..95fa488339 100644 --- a/chardev/msmouse.c +++ b/chardev/msmouse.c @@ -25,17 +25,20 @@ #include "qemu/osdep.h" #include "qemu/module.h" #include "chardev/char.h" +#include "chardev/char-serial.h" #include "ui/console.h" #include "ui/input.h" #include "qom/object.h" =20 -#define MSMOUSE_LO6(n) ((n) & 0x3f) -#define MSMOUSE_HI2(n) (((n) & 0xc0) >> 6) +#define MSMOUSE_LO6(n) ((n) & 0x3f) +#define MSMOUSE_HI2(n) (((n) & 0xc0) >> 6) +#define MSMOUSE_PWR(cm) (cm & (CHR_TIOCM_RTS | CHR_TIOCM_DTR)) =20 struct MouseChardev { Chardev parent; =20 QemuInputHandlerState *hs; + int tiocm; int axis[INPUT_AXIS__MAX]; bool btns[INPUT_BUTTON__MAX]; bool btnc[INPUT_BUTTON__MAX]; @@ -109,6 +112,11 @@ static void msmouse_input_event(DeviceState *dev, Qemu= Console *src, InputMoveEvent *move; InputBtnEvent *btn; =20 + /* Ignore events if serial mouse powered down. */ + if (!MSMOUSE_PWR(mouse->tiocm)) { + return; + } + switch (evt->type) { case INPUT_EVENT_KIND_REL: move =3D evt->u.rel.data; @@ -132,6 +140,11 @@ static void msmouse_input_sync(DeviceState *dev) MouseChardev *mouse =3D MOUSE_CHARDEV(dev); Chardev *chr =3D CHARDEV(dev); =20 + /* Ignore events if serial mouse powered down. */ + if (!MSMOUSE_PWR(mouse->tiocm)) { + return; + } + msmouse_queue_event(mouse); msmouse_chr_accept_input(chr); } @@ -142,6 +155,50 @@ static int msmouse_chr_write(struct Chardev *s, const = uint8_t *buf, int len) return len; } =20 +static int msmouse_ioctl(Chardev *chr, int cmd, void *arg) +{ + MouseChardev *mouse =3D MOUSE_CHARDEV(chr); + int c; + int *targ =3D (int *)arg; + + switch (cmd) { + case CHR_IOCTL_SERIAL_SET_TIOCM: + c =3D mouse->tiocm; + mouse->tiocm =3D *(int *)arg; + if (MSMOUSE_PWR(mouse->tiocm)) { + if (!MSMOUSE_PWR(c)) { + /* + * Power on after reset: send "M3" + * cause we behave like a 3 button logitech + * mouse. + */ + mouse->outbuf[0] =3D 'M'; + mouse->outbuf[1] =3D '3'; + mouse->outlen =3D 2; + /* Start sending data to serial. */ + msmouse_chr_accept_input(chr); + } + break; + } + /* + * Reset mouse buffers on power down. + * Mouse won't send anything without power. + */ + mouse->outlen =3D 0; + memset(mouse->axis, 0, sizeof(mouse->axis)); + memset(mouse->btns, false, sizeof(mouse->btns)); + memset(mouse->btnc, false, sizeof(mouse->btns)); + break; + case CHR_IOCTL_SERIAL_GET_TIOCM: + /* Remember line control status. */ + *targ =3D mouse->tiocm; + break; + default: + return -ENOTSUP; + } + return 0; +} + static void char_msmouse_finalize(Object *obj) { MouseChardev *mouse =3D MOUSE_CHARDEV(obj); @@ -166,6 +223,7 @@ static void msmouse_chr_open(Chardev *chr, *be_opened =3D false; mouse->hs =3D qemu_input_handler_register((DeviceState *)mouse, &msmouse_handler); + mouse->tiocm =3D 0; } =20 static void char_msmouse_class_init(ObjectClass *oc, void *data) @@ -175,6 +233,7 @@ static void char_msmouse_class_init(ObjectClass *oc, vo= id *data) cc->open =3D msmouse_chr_open; cc->chr_write =3D msmouse_chr_write; cc->chr_accept_input =3D msmouse_chr_accept_input; + cc->chr_ioctl =3D msmouse_ioctl; } =20 static const TypeInfo char_msmouse_type_info =3D { --=20 2.37.3 From nobody Sun May 5 18:19:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664450692; cv=none; d=zohomail.com; s=zohoarc; b=KlkFikI6XvffwVBMF3qdeCMllmfTbL4AaBvPHh4lT1shOzKsS7o3MFbS+q/jyKUfnQykc175YeRo2zJqC4MQzEOQDDn6e6M81ob2T93MdUyjFIL1TDOFR8rW1zEBFsKBcCb9DQX/VF3G59y3qRGBpfURU/uEki5DXxDQWO6CrYc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664450692; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ezD6PhMSMxDyjMv4dDUkY1/CLp8KW3sHOvTJVy2oQGQ=; b=Tfu9MgWVUJxUtUTd/6E/StSyNmaYhtOZ2vxQpBuawjF2c2T+R+K85joA7gufU6E7pXEW62bD76feDp7U9l35lheyiOWqQhwrmrnVnP8m691opbNyi22GCx6IwV7NcD0JOJGdRhtYMNtXe02fzMNWHZ+NHxSOFFgT8mZs53NcKz8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664450692740643.1869258155089; Thu, 29 Sep 2022 04:24:52 -0700 (PDT) Received: from localhost ([::1]:39160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odret-0001RJ-JN for importer@patchew.org; Thu, 29 Sep 2022 07:24:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odrM6-0000zJ-H8 for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:05:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:28186) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odrM4-0001uv-Ue for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:05:26 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-503-EXGbTNIoNaattPQZxovEsg-1; Thu, 29 Sep 2022 07:05:20 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 618A7185A7A8; Thu, 29 Sep 2022 11:05:20 +0000 (UTC) Received: from localhost (unknown [10.39.208.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59F64112132C; Thu, 29 Sep 2022 11:05:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664449524; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ezD6PhMSMxDyjMv4dDUkY1/CLp8KW3sHOvTJVy2oQGQ=; b=c1EpUof355K/2K8UyQpQmJxxD34D9oJDPieui2Yy87egaAIUKxpbCc2iL57b/yaVXlODLN Wy2J+rPsneM2RNUkcxef+gsDvGuDTfH/u+lFJ59ZpY3eEfigR/z9o3trtwTBpzTcoyJ5d5 xkGYN+NnrAOv6Em6OVOlDUhuhZi6WHk= X-MC-Unique: EXGbTNIoNaattPQZxovEsg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Arwed Meyer , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Pavel Dovgalyuk Subject: [PULL 2/8] chardev: src buffer const for write functions Date: Thu, 29 Sep 2022 15:05:02 +0400 Message-Id: <20220929110508.1323529-3-marcandre.lureau@redhat.com> In-Reply-To: <20220929110508.1323529-1-marcandre.lureau@redhat.com> References: <20220929110508.1323529-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.08, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1664450695234100001 From: Arwed Meyer Make source buffers const for char be write functions. This allows using buffers returned by fifo as buf parameter and source buff= er should not be changed by write functions anyway. Signed-off-by: Arwed Meyer Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20220911181840.8933-3-arwed.meyer@gmx.de> --- include/chardev/char.h | 4 ++-- include/sysemu/replay.h | 2 +- chardev/char.c | 4 ++-- replay/replay-char.c | 2 +- stubs/replay-tools.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/chardev/char.h b/include/chardev/char.h index a319b5fdff..44cd82e405 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -186,7 +186,7 @@ int qemu_chr_be_can_write(Chardev *s); * the caller should call @qemu_chr_be_can_write to determine how much data * the front end can currently accept. */ -void qemu_chr_be_write(Chardev *s, uint8_t *buf, int len); +void qemu_chr_be_write(Chardev *s, const uint8_t *buf, int len); =20 /** * qemu_chr_be_write_impl: @@ -195,7 +195,7 @@ void qemu_chr_be_write(Chardev *s, uint8_t *buf, int le= n); * * Implementation of back end writing. Used by replay module. */ -void qemu_chr_be_write_impl(Chardev *s, uint8_t *buf, int len); +void qemu_chr_be_write_impl(Chardev *s, const uint8_t *buf, int len); =20 /** * qemu_chr_be_update_read_handlers: diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index 73dee9ccdf..7ec0882b50 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -198,7 +198,7 @@ uint64_t blkreplay_next_id(void); /*! Registers char driver to save it's events */ void replay_register_char_driver(struct Chardev *chr); /*! Saves write to char device event to the log */ -void replay_chr_be_write(struct Chardev *s, uint8_t *buf, int len); +void replay_chr_be_write(struct Chardev *s, const uint8_t *buf, int len); /*! Writes char write return value to the replay log. */ void replay_char_write_event_save(int res, int offset); /*! Reads char write return value from the replay log. */ diff --git a/chardev/char.c b/chardev/char.c index 0169d8dde4..b005df3ccf 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -193,7 +193,7 @@ int qemu_chr_be_can_write(Chardev *s) return be->chr_can_read(be->opaque); } =20 -void qemu_chr_be_write_impl(Chardev *s, uint8_t *buf, int len) +void qemu_chr_be_write_impl(Chardev *s, const uint8_t *buf, int len) { CharBackend *be =3D s->be; =20 @@ -202,7 +202,7 @@ void qemu_chr_be_write_impl(Chardev *s, uint8_t *buf, i= nt len) } } =20 -void qemu_chr_be_write(Chardev *s, uint8_t *buf, int len) +void qemu_chr_be_write(Chardev *s, const uint8_t *buf, int len) { if (qemu_chr_replay(s)) { if (replay_mode =3D=3D REPLAY_MODE_PLAY) { diff --git a/replay/replay-char.c b/replay/replay-char.c index d2025948cf..a31aded032 100644 --- a/replay/replay-char.c +++ b/replay/replay-char.c @@ -48,7 +48,7 @@ void replay_register_char_driver(Chardev *chr) char_drivers[drivers_count++] =3D chr; } =20 -void replay_chr_be_write(Chardev *s, uint8_t *buf, int len) +void replay_chr_be_write(Chardev *s, const uint8_t *buf, int len) { CharEvent *event =3D g_new0(CharEvent, 1); =20 diff --git a/stubs/replay-tools.c b/stubs/replay-tools.c index f2e72bb225..3e8ca3212d 100644 --- a/stubs/replay-tools.c +++ b/stubs/replay-tools.c @@ -53,7 +53,7 @@ void replay_register_char_driver(struct Chardev *chr) { } =20 -void replay_chr_be_write(struct Chardev *s, uint8_t *buf, int len) +void replay_chr_be_write(struct Chardev *s, const uint8_t *buf, int len) { abort(); } --=20 2.37.3 From nobody Sun May 5 18:19:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664451799; cv=none; d=zohomail.com; s=zohoarc; b=dQoTL3Yjay62ri440qb6tP5Z8ixLPf3CQV5AyMxV8l1UEgXnKvq2jhduGmelpagB0FBvOxG8Da2OF3klB4GAAOD1/h58hAqvvisvipV3QEKkD6I4rtYkEiXhk+l9ufFE/3oFpGQL1jf+i6vVEn6dlvAugoc/MCu2v7e6bIU+tvk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664451799; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=O3g7x/oeCPDaruCTDr++TyWSFJnjhwc317c14u9ss3w=; b=Ur4fiihT9T16g5997t1uewOeD5N9q/XDQwC2Dew5XqvNhzeOOB/7pP6vw37GbwIew9FpSkNup6c3l30+XBUn5yTSUmzBtFBGE1IPuYZ6i6ugv2HwHBDQwZa1lpqR+IS0FeeAuYj6n8Lay5zyxlMlk4GRc4w817k9EeGivnYXkvo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664451799055860.0675588571232; Thu, 29 Sep 2022 04:43:19 -0700 (PDT) Received: from localhost ([::1]:39318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odrwj-0002vS-Ge for importer@patchew.org; Thu, 29 Sep 2022 07:43:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odrMA-00016I-Ij for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:05:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33809) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odrM8-0001wp-Ng for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:05:30 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-52-C0PIwqOHO2Cap5IS9aFh3A-1; Thu, 29 Sep 2022 07:05:24 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 745391C05140; Thu, 29 Sep 2022 11:05:24 +0000 (UTC) Received: from localhost (unknown [10.39.208.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CEA5207B34A; Thu, 29 Sep 2022 11:05:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664449528; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O3g7x/oeCPDaruCTDr++TyWSFJnjhwc317c14u9ss3w=; b=SdpbghG49MZJPFvMQdsHZtNk5T6cq5YlObF6bVY7kUZE6I88Ak+okSajpXJJoE4XzDRxaH ePITSgktEDwAW4JbaQ18WdEbvzRIrecrB+R75FUyU57TQJyiRiZ9+SeJyTaKIBHDeGzGBt JgGzHlDaRRkkWXs8b69DqSVJ2T36tOs= X-MC-Unique: C0PIwqOHO2Cap5IS9aFh3A-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Arwed Meyer , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Subject: [PULL 3/8] msmouse: Use fifo8 instead of array Date: Thu, 29 Sep 2022 15:05:03 +0400 Message-Id: <20220929110508.1323529-4-marcandre.lureau@redhat.com> In-Reply-To: <20220929110508.1323529-1-marcandre.lureau@redhat.com> References: <20220929110508.1323529-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.08, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1664451800695100001 From: Arwed Meyer Make use of fifo8 functions instead of implementing own fifo code. This makes the code more readable and reduces risk of bugs. Signed-off-by: Arwed Meyer Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20220911181840.8933-4-arwed.meyer@gmx.de> --- chardev/msmouse.c | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/chardev/msmouse.c b/chardev/msmouse.c index 95fa488339..5982c15df6 100644 --- a/chardev/msmouse.c +++ b/chardev/msmouse.c @@ -24,6 +24,7 @@ =20 #include "qemu/osdep.h" #include "qemu/module.h" +#include "qemu/fifo8.h" #include "chardev/char.h" #include "chardev/char-serial.h" #include "ui/console.h" @@ -34,6 +35,12 @@ #define MSMOUSE_HI2(n) (((n) & 0xc0) >> 6) #define MSMOUSE_PWR(cm) (cm & (CHR_TIOCM_RTS | CHR_TIOCM_DTR)) =20 +/* Serial fifo size. */ +#define MSMOUSE_BUF_SZ 64 + +/* Mouse ID: Send "M3" cause we behave like a 3 button logitech mouse. */ +const uint8_t mouse_id[] =3D {'M', '3'}; + struct MouseChardev { Chardev parent; =20 @@ -42,8 +49,7 @@ struct MouseChardev { int axis[INPUT_AXIS__MAX]; bool btns[INPUT_BUTTON__MAX]; bool btnc[INPUT_BUTTON__MAX]; - uint8_t outbuf[32]; - int outlen; + Fifo8 outbuf; }; typedef struct MouseChardev MouseChardev; =20 @@ -54,20 +60,18 @@ DECLARE_INSTANCE_CHECKER(MouseChardev, MOUSE_CHARDEV, static void msmouse_chr_accept_input(Chardev *chr) { MouseChardev *mouse =3D MOUSE_CHARDEV(chr); - int len; + uint32_t len, avail; =20 len =3D qemu_chr_be_can_write(chr); - if (len > mouse->outlen) { - len =3D mouse->outlen; - } - if (!len) { - return; - } - - qemu_chr_be_write(chr, mouse->outbuf, len); - mouse->outlen -=3D len; - if (mouse->outlen) { - memmove(mouse->outbuf, mouse->outbuf + len, mouse->outlen); + avail =3D fifo8_num_used(&mouse->outbuf); + while (len > 0 && avail > 0) { + const uint8_t *buf; + uint32_t size; + + buf =3D fifo8_pop_buf(&mouse->outbuf, MIN(len, avail), &size); + qemu_chr_be_write(chr, buf, size); + len =3D qemu_chr_be_can_write(chr); + avail -=3D size; } } =20 @@ -94,12 +98,11 @@ static void msmouse_queue_event(MouseChardev *mouse) mouse->btnc[INPUT_BUTTON_MIDDLE]) { bytes[3] |=3D (mouse->btns[INPUT_BUTTON_MIDDLE] ? 0x20 : 0x00); mouse->btnc[INPUT_BUTTON_MIDDLE] =3D false; - count =3D 4; + count++; } =20 - if (mouse->outlen <=3D sizeof(mouse->outbuf) - count) { - memcpy(mouse->outbuf + mouse->outlen, bytes, count); - mouse->outlen +=3D count; + if (fifo8_num_free(&mouse->outbuf) >=3D count) { + fifo8_push_all(&mouse->outbuf, bytes, count); } else { /* queue full -> drop event */ } @@ -172,9 +175,7 @@ static int msmouse_ioctl(Chardev *chr, int cmd, void *a= rg) * cause we behave like a 3 button logitech * mouse. */ - mouse->outbuf[0] =3D 'M'; - mouse->outbuf[1] =3D '3'; - mouse->outlen =3D 2; + fifo8_push_all(&mouse->outbuf, mouse_id, sizeof(mouse_id)); /* Start sending data to serial. */ msmouse_chr_accept_input(chr); } @@ -184,7 +185,7 @@ static int msmouse_ioctl(Chardev *chr, int cmd, void *a= rg) * Reset mouse buffers on power down. * Mouse won't send anything without power. */ - mouse->outlen =3D 0; + fifo8_reset(&mouse->outbuf); memset(mouse->axis, 0, sizeof(mouse->axis)); memset(mouse->btns, false, sizeof(mouse->btns)); memset(mouse->btnc, false, sizeof(mouse->btns)); @@ -204,6 +205,7 @@ static void char_msmouse_finalize(Object *obj) MouseChardev *mouse =3D MOUSE_CHARDEV(obj); =20 qemu_input_handler_unregister(mouse->hs); + fifo8_destroy(&mouse->outbuf); } =20 static QemuInputHandler msmouse_handler =3D { @@ -224,6 +226,7 @@ static void msmouse_chr_open(Chardev *chr, mouse->hs =3D qemu_input_handler_register((DeviceState *)mouse, &msmouse_handler); mouse->tiocm =3D 0; + fifo8_create(&mouse->outbuf, MSMOUSE_BUF_SZ); } =20 static void char_msmouse_class_init(ObjectClass *oc, void *data) --=20 2.37.3 From nobody Sun May 5 18:19:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664450824; cv=none; d=zohomail.com; s=zohoarc; b=LAFfybsCOn6cqBcIwcryfZFezi8XngNT3urKZ8lVpNfVGtpeZ+xZ/GK2VIcvw/WLFeICTS60XE8ERWfly3KtSDy6yP24JX36Uf874zmYqBHwcRfKYOOvj+rRQWRGqUk+2Mn6OmOF10nlrUHZyHT5LIqiOab1eusC9GZG1YkPwxs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664450824; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3mXM23Rs8aZCO5O97Kib6Cw52DXTr/s1fYzMgrROq4g=; b=GxuQRFPmcffEKdqQ/3u7l+m4CyNQ9gBLnO4bGZ5qWCieCfJ9H2pOUxRD5cCXqe8FXcXNsbON3l2cuPK3uwm1ROZEs5PekpQtH0lwrLNrMpDfSZPcfLQfWX7jV4pOMl6yo/6zCFexoU0oVrDIHwpKtWYJkJetVoijopD26HZzOQE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664450824610193.6872857489151; Thu, 29 Sep 2022 04:27:04 -0700 (PDT) Received: from localhost ([::1]:43694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odrgr-0002to-0E for importer@patchew.org; Thu, 29 Sep 2022 07:26:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odrME-0001CF-OF for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:05:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39511) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odrMD-0001xE-2T for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:05:34 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-364-l8SjcAAuM-GXNGjEK0heXw-1; Thu, 29 Sep 2022 07:05:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D01D43C01E15; Thu, 29 Sep 2022 11:05:28 +0000 (UTC) Received: from localhost (unknown [10.39.208.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id C890B112132C; Thu, 29 Sep 2022 11:05:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664449532; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3mXM23Rs8aZCO5O97Kib6Cw52DXTr/s1fYzMgrROq4g=; b=FPv4KAT0vqDHKor0J230uxOUwkwBESTB2ZKK2FUTj/fNWkgHa8E4A0ujWvoy2SBrxLcwMY zR/GCE8Iy7Quv0jvup1XJSt3osCg6iwEyK/08JU7lX7P5pC32JojQVz2spvGYMl8OALN3c f0l53Qh4216prwp3aJVds129HO+ErrM= X-MC-Unique: l8SjcAAuM-GXNGjEK0heXw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Arwed Meyer , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Subject: [PULL 4/8] msmouse: Add pnp data Date: Thu, 29 Sep 2022 15:05:04 +0400 Message-Id: <20220929110508.1323529-5-marcandre.lureau@redhat.com> In-Reply-To: <20220929110508.1323529-1-marcandre.lureau@redhat.com> References: <20220929110508.1323529-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.08, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1664450826444100001 From: Arwed Meyer Make msmouse send serial pnp data. Enables you to see nice qemu device name in Win9x. Signed-off-by: Arwed Meyer Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20220911181840.8933-5-arwed.meyer@gmx.de> --- chardev/msmouse.c | 58 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/chardev/msmouse.c b/chardev/msmouse.c index 5982c15df6..9006703023 100644 --- a/chardev/msmouse.c +++ b/chardev/msmouse.c @@ -35,11 +35,24 @@ #define MSMOUSE_HI2(n) (((n) & 0xc0) >> 6) #define MSMOUSE_PWR(cm) (cm & (CHR_TIOCM_RTS | CHR_TIOCM_DTR)) =20 +/* Serial PnP for 6 bit devices/mice sends all ASCII chars - 0x20 */ +#define M(c) (c - 0x20) /* Serial fifo size. */ #define MSMOUSE_BUF_SZ 64 =20 /* Mouse ID: Send "M3" cause we behave like a 3 button logitech mouse. */ const uint8_t mouse_id[] =3D {'M', '3'}; +/* + * PnP start "(", PnP version (1.0), vendor ID, product ID, '\\', + * serial ID (omitted), '\\', MS class name, '\\', driver ID (omitted), '\= \', + * product description, checksum, ")" + * Missing parts are inserted later. + */ +const uint8_t pnp_data[] =3D {M('('), 1, '$', M('Q'), M('M'), M('U'), + M('0'), M('0'), M('0'), M('1'), + M('\\'), M('\\'), + M('M'), M('O'), M('U'), M('S'), M('E'), + M('\\'), M('\\')}; =20 struct MouseChardev { Chardev parent; @@ -158,11 +171,22 @@ static int msmouse_chr_write(struct Chardev *s, const= uint8_t *buf, int len) return len; } =20 +static QemuInputHandler msmouse_handler =3D { + .name =3D "QEMU Microsoft Mouse", + .mask =3D INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_REL, + .event =3D msmouse_input_event, + .sync =3D msmouse_input_sync, +}; + static int msmouse_ioctl(Chardev *chr, int cmd, void *arg) { MouseChardev *mouse =3D MOUSE_CHARDEV(chr); - int c; + int c, i, j; + uint8_t bytes[MSMOUSE_BUF_SZ / 2]; int *targ =3D (int *)arg; + const uint8_t hexchr[16] =3D {M('0'), M('1'), M('2'), M('3'), M('4'), = M('5'), + M('6'), M('7'), M('8'), M('9'), M('A'), M('B'= ), + M('C'), M('D'), M('E'), M('F')}; =20 switch (cmd) { case CHR_IOCTL_SERIAL_SET_TIOCM: @@ -171,11 +195,30 @@ static int msmouse_ioctl(Chardev *chr, int cmd, void = *arg) if (MSMOUSE_PWR(mouse->tiocm)) { if (!MSMOUSE_PWR(c)) { /* - * Power on after reset: send "M3" - * cause we behave like a 3 button logitech - * mouse. + * Power on after reset: Send ID and PnP data + * No need to check fifo space as it is empty at this poin= t. */ fifo8_push_all(&mouse->outbuf, mouse_id, sizeof(mouse_id)); + /* Add PnP data: */ + fifo8_push_all(&mouse->outbuf, pnp_data, sizeof(pnp_data)); + /* + * Add device description from qemu handler name. + * Make sure this all fits into the queue beforehand! + */ + c =3D M(')'); + for (i =3D 0; msmouse_handler.name[i]; i++) { + bytes[i] =3D M(msmouse_handler.name[i]); + c +=3D bytes[i]; + } + /* Calc more of checksum */ + for (j =3D 0; j < sizeof(pnp_data); j++) { + c +=3D pnp_data[j]; + } + c &=3D 0xff; + bytes[i++] =3D hexchr[c >> 4]; + bytes[i++] =3D hexchr[c & 0x0f]; + bytes[i++] =3D M(')'); + fifo8_push_all(&mouse->outbuf, bytes, i); /* Start sending data to serial. */ msmouse_chr_accept_input(chr); } @@ -208,13 +251,6 @@ static void char_msmouse_finalize(Object *obj) fifo8_destroy(&mouse->outbuf); } =20 -static QemuInputHandler msmouse_handler =3D { - .name =3D "QEMU Microsoft Mouse", - .mask =3D INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_REL, - .event =3D msmouse_input_event, - .sync =3D msmouse_input_sync, -}; - static void msmouse_chr_open(Chardev *chr, ChardevBackend *backend, bool *be_opened, --=20 2.37.3 From nobody Sun May 5 18:19:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664450591; cv=none; d=zohomail.com; s=zohoarc; b=Nbc/wUO74VTSAaCt7AyRxbLvlb1T5Tw24PULshNpp/Zbjg+WWofe9yZ0ke1+vIC2GxuzyxsrFbkVhQDZplNwRqvXmMjnHt2l3FoqGkV7f2eWphGb5ebIUnyzpjAgwaAjxuzspYagLbXnwhpOfd+yC3mVg0y2to+FMgt9vbDf39I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664450591; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oG/PB1KRyUcZqqWhh8GisayAgLoEnGDi0gH30odmnTg=; b=DMNtSWLUYlpF+E0f8n4aNaM0Zll0cd9dWp4crqQQh9YJoHVfk756WCCSfo34osMTFJkH+JQjZruhvwJXQOaHzYIzuiBc5V2651eniYdhGFEV4a9kQxGYUrJuv30XO+Nxaaw/JbqenV4Sdaom4sUF8rdiu8btFshBWeonE6rE8pU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664450591255778.6777613329252; Thu, 29 Sep 2022 04:23:11 -0700 (PDT) Received: from localhost ([::1]:45858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odrdA-00004s-3x for importer@patchew.org; Thu, 29 Sep 2022 07:23:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odrMK-0001F6-E4 for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:05:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:44497) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odrMI-0001yY-SH for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:05:40 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-411-6UEsBaFeOg-CZQ71caUXJw-1; Thu, 29 Sep 2022 07:05:33 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A631B1C05AC2; Thu, 29 Sep 2022 11:05:32 +0000 (UTC) Received: from localhost (unknown [10.39.208.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBAC61121339; Thu, 29 Sep 2022 11:05:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664449538; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oG/PB1KRyUcZqqWhh8GisayAgLoEnGDi0gH30odmnTg=; b=If3Z7n95zpcF8jzOe7A3mlxe/z26wqNohK0zNlEeOhEoVSBTFndQZxO/DSuMVdgkcEgCnq V86MtE3YytpCiEHI5+YLD/w7JVqAxCBoL4rnb3YAlr1AMjNZDF6ZfL59JwjxmUJx92MpsM 4tT7bD3Q5dn5c/tkcLyFtfFjvcuy+hs= X-MC-Unique: 6UEsBaFeOg-CZQ71caUXJw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Arwed Meyer , "Michael S. Tsirkin" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 5/8] serial: Allow unaligned i/o access Date: Thu, 29 Sep 2022 15:05:05 +0400 Message-Id: <20220929110508.1323529-6-marcandre.lureau@redhat.com> In-Reply-To: <20220929110508.1323529-1-marcandre.lureau@redhat.com> References: <20220929110508.1323529-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.08, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1664450593106100001 From: Arwed Meyer Unaligned i/o access on serial UART works on real PCs. This is used for example by FreeDOS CTMouse driver. Without this it can't reset and detect serial mice. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/77 Signed-off-by: Arwed Meyer Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20220911181840.8933-6-arwed.meyer@gmx.de> --- hw/char/serial.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/char/serial.c b/hw/char/serial.c index 7061aacbce..41b5e61977 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -961,6 +961,9 @@ void serial_set_frequency(SerialState *s, uint32_t freq= uency) const MemoryRegionOps serial_io_ops =3D { .read =3D serial_ioport_read, .write =3D serial_ioport_write, + .valid =3D { + .unaligned =3D 1, + }, .impl =3D { .min_access_size =3D 1, .max_access_size =3D 1, --=20 2.37.3 From nobody Sun May 5 18:19:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664451263; cv=none; d=zohomail.com; s=zohoarc; b=EgayErd4anYsORpSOBa7F5XVjN4DxQloUWLuMlrPVvubKP1CuH2cJW8J8QdyA3NGJUtP4HKpUlSsqj1GCznZQdAEc6Oe28VSabAhN27qviC/47dzr1uHBaqPt50b5Sck8gXNEdn6P6Uhax6vHcabQs+jqynyWXFoT/SilU8NLUM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664451263; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7VUhs4rAc5DdkL/r1kEvE47gIjm+3f12pZ7vfN+8Q1c=; b=menHZR4Kj/sJUAd/T9sIUvJvxdYuA8W22oFdh6Wjm7VM+5PcyFI2jT/hm7fodk4NScW2nK92HQl6kVVy4tusbaU1k1e3L1Wh/1IICYcx91GDGAdqjaTYHxAVInu1zbm3Wps0ZWlWN7rG8s/N/K+07jZNIR4nxtMKJABfNlUGUPY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664451263153278.8825156948453; Thu, 29 Sep 2022 04:34:23 -0700 (PDT) Received: from localhost ([::1]:52976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odro6-0000pr-58 for importer@patchew.org; Thu, 29 Sep 2022 07:34:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odrMK-0001F7-Q7 for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:05:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:58000) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odrMJ-0001yf-AJ for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:05:40 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-455-dKGnIhEsMviUouM0psuRiw-1; Thu, 29 Sep 2022 07:05:37 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 065701C05AC0; Thu, 29 Sep 2022 11:05:37 +0000 (UTC) Received: from localhost (unknown [10.39.208.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2F834099B52; Thu, 29 Sep 2022 11:05:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664449538; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7VUhs4rAc5DdkL/r1kEvE47gIjm+3f12pZ7vfN+8Q1c=; b=jI/s6CZKj7aQGbr4KFTSvnoGmWoVBbNEXdxUiWo0Xj/WETsE0T+dR3iQfDndxRsV94XCeu 7tzjNS7WLoI+aaIH0unrvEyKIGhyPOBph233Mi6IMOFI4VagUvbH4dpTaST5K3+MbNaroH 7grWKP5RmjWJ4m//dP/vVhknLMbaznk= X-MC-Unique: dKGnIhEsMviUouM0psuRiw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Maksim Davydov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Subject: [PULL 6/8] chardev: fix segfault in finalize Date: Thu, 29 Sep 2022 15:05:06 +0400 Message-Id: <20220929110508.1323529-7-marcandre.lureau@redhat.com> In-Reply-To: <20220929110508.1323529-1-marcandre.lureau@redhat.com> References: <20220929110508.1323529-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.08, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1664451263984100001 From: Maksim Davydov If finalize chardev-msmouse or chardev-wctable is called immediately after init it cases QEMU to crash with segfault. This happens because of QTAILQ_REMOVE in qemu_input_handler_unregister tries to dereference NULL pointer. For instance, this error can be reproduced via `qom-list-properties` command. Signed-off-by: Maksim Davydov Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Vladimir Sementsov-Ogievskiy Message-Id: <20220825165247.33704-1-davydov-max@yandex-team.ru> --- chardev/msmouse.c | 4 +++- chardev/wctablet.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/chardev/msmouse.c b/chardev/msmouse.c index 9006703023..ab8fe981d6 100644 --- a/chardev/msmouse.c +++ b/chardev/msmouse.c @@ -247,7 +247,9 @@ static void char_msmouse_finalize(Object *obj) { MouseChardev *mouse =3D MOUSE_CHARDEV(obj); =20 - qemu_input_handler_unregister(mouse->hs); + if (mouse->hs) { + qemu_input_handler_unregister(mouse->hs); + } fifo8_destroy(&mouse->outbuf); } =20 diff --git a/chardev/wctablet.c b/chardev/wctablet.c index e8b292c43c..43bdf6b608 100644 --- a/chardev/wctablet.c +++ b/chardev/wctablet.c @@ -319,7 +319,9 @@ static void wctablet_chr_finalize(Object *obj) { TabletChardev *tablet =3D WCTABLET_CHARDEV(obj); =20 - qemu_input_handler_unregister(tablet->hs); + if (tablet->hs) { + qemu_input_handler_unregister(tablet->hs); + } } =20 static void wctablet_chr_open(Chardev *chr, --=20 2.37.3 From nobody Sun May 5 18:19:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664451207; cv=none; d=zohomail.com; s=zohoarc; b=W8bZCsIvdnqNBQNMdouTw9Vn5mzS6Q+VcsqOAGyYCaaGMG37IAZp5ZGvAtT2r03Ye3QTknu/K14iWolWJA99T217QFLibPWaqVKc++y2m8RslTlzdKoMrl/XTBqhoeGBCl4zimKn2UBFInUELppZnf/6Vpag904FBAvg2ujQnXU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664451207; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Nz0okoqs97AGg9QA1bZOrRakGbAfb/yIQpkpq/jAzbA=; b=esRPXUmpTRaxMf/O5kPzE52Pe/EaKtn3PzQjlXwZfAgrvfpNBgF1Uf7vo/tnw0tLK+g0vVowKcykPXxBY/qOatjmHfjGYXLbvQgun6nqDs8ulsKHg/dojANVkWSdPYuCWPK1YhNlT9qBq+8f2vZO+m4fHgMMthinCIxLB1HTFfU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664451207794633.9974105621652; Thu, 29 Sep 2022 04:33:27 -0700 (PDT) Received: from localhost ([::1]:38128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odrnC-0008SJ-Kf for importer@patchew.org; Thu, 29 Sep 2022 07:33:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odrMn-0001PF-Um for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:06:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:57891) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odrMm-00023P-8q for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:06:09 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-35-tOU4JisnOdi6_1YfwJkf6Q-1; Thu, 29 Sep 2022 07:05:55 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3A0C738012CA; Thu, 29 Sep 2022 11:05:42 +0000 (UTC) Received: from localhost (unknown [10.39.208.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id D465C207B34A; Thu, 29 Sep 2022 11:05:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664449567; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Nz0okoqs97AGg9QA1bZOrRakGbAfb/yIQpkpq/jAzbA=; b=USJS4s/pS2U9fz3amyB13aOvQon2rQqOdZq5I8JdZp59srDUzFXnUzzPrwIBKXemF+QcQN GSkLGKSNBeOwxJ9y2WXfE2ET5Gzopf+JcUQj7DbW3iYpZCaXWHKaNgyOpX1XXsGlXCN5KB k7THc6C+t2adzg2bCylyfYmH17ujBaE= X-MC-Unique: tOU4JisnOdi6_1YfwJkf6Q-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Guoyi Tu , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini Subject: [PULL 7/8] oslib-posix: Introduce qemu_socketpair() Date: Thu, 29 Sep 2022 15:05:07 +0400 Message-Id: <20220929110508.1323529-8-marcandre.lureau@redhat.com> In-Reply-To: <20220929110508.1323529-1-marcandre.lureau@redhat.com> References: <20220929110508.1323529-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.08, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1664451209109100001 From: Guoyi Tu qemu_socketpair() will create a pair of connected sockets with FD_CLOEXEC set Signed-off-by: Guoyi Tu Reviewed-by: Christian Schoenebeck Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <17fa1eff729eeabd9a001f4639abccb127ceec81.1661240709.git.tugy@c= hinatelecom.cn> --- include/qemu/sockets.h | 18 ++++++++++++++++++ util/oslib-posix.c | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index 038faa157f..036745e586 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -14,6 +14,24 @@ int inet_aton(const char *cp, struct in_addr *ia); /* misc helpers */ bool fd_is_socket(int fd); int qemu_socket(int domain, int type, int protocol); + +#ifndef WIN32 +/** + * qemu_socketpair: + * @domain: specifies a communication domain, such as PF_UNIX + * @type: specifies the socket type. + * @protocol: specifies a particular protocol to be used with the socket + * @sv: an array to store the pair of socket created + * + * Creates an unnamed pair of connected sockets in the specified domain, + * of the specified type, and using the optionally specified protocol. + * And automatically set the close-on-exec flags on the returned sockets + * + * Return 0 on success. + */ +int qemu_socketpair(int domain, int type, int protocol, int sv[2]); +#endif + int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen); int socket_set_cork(int fd, int v); int socket_set_nodelay(int fd); diff --git a/util/oslib-posix.c b/util/oslib-posix.c index d55af69c11..827a7aadba 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -253,6 +253,25 @@ void qemu_set_cloexec(int fd) assert(f !=3D -1); } =20 +int qemu_socketpair(int domain, int type, int protocol, int sv[2]) +{ + int ret; + +#ifdef SOCK_CLOEXEC + ret =3D socketpair(domain, type | SOCK_CLOEXEC, protocol, sv); + if (ret !=3D -1 || errno !=3D EINVAL) { + return ret; + } +#endif + ret =3D socketpair(domain, type, protocol, sv);; + if (ret =3D=3D 0) { + qemu_set_cloexec(sv[0]); + qemu_set_cloexec(sv[1]); + } + + return ret; +} + char * qemu_get_local_state_dir(void) { --=20 2.37.3 From nobody Sun May 5 18:19:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664452236; cv=none; d=zohomail.com; s=zohoarc; b=U9b0Y3S98Z27dNtOC8xZl05EaDlns3zeod+6fmGJ/9AA7fMGmQvpYCQrRnp+igLOvf8kSz4AZT6lCZ3H1yOnCmuprOZhEpi9PMyBx1aKNQYnY9Ke9NJXe24Rp8I7+UsJhebY6W13Gt7hGAy0pLAPV900tI1N2IKfQQQ8UQ+uIQo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664452236; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LmCzNDuMHeFyKokJlkW6wjg5QpSu4Ucvt4LNf4ZWVDs=; b=i3R7VzP2U9Gl9nhk98X1DEUcuaRxZoxDBBuaEcHIHqRFtpEhCTQ1koGAtcwsMz1UYQxINX1riRcQvlj4g6F5kgSEO1IQP6Vbv0GW7iXmSCaaZD+eRysWkVpEXZaOciVsH7+EiGihxkuwBv0Bz+u/ayp5AY4mEC9dfI7y5jTSbdM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166445223669385.87274253211592; Thu, 29 Sep 2022 04:50:36 -0700 (PDT) Received: from localhost ([::1]:57962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ods3m-0007mt-L6 for importer@patchew.org; Thu, 29 Sep 2022 07:50:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odrMb-0001Kq-Oj for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:05:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:22996) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odrMa-00021l-4I for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:05:57 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-447-deoik13BNFyoXN3omgyuVQ-1; Thu, 29 Sep 2022 07:05:52 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 40D9238012C8; Thu, 29 Sep 2022 11:05:47 +0000 (UTC) Received: from localhost (unknown [10.39.208.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59AAE207B34B; Thu, 29 Sep 2022 11:05:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664449555; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LmCzNDuMHeFyKokJlkW6wjg5QpSu4Ucvt4LNf4ZWVDs=; b=Jfb5nM+I6RFZmVkZRjGB+o+Rlk61JZLm8IKoRue8JIaj6mDZYHhUOTEd0ImSIz5zUHuNvv EgYyyLa1aIS/uyfRnCYPvT/cQ1/T2gBbOwyDpn4SV9ul0fr2a2rpCZPoQr6MG++6c/QK1d gnMUXK/AxrizagE1gjI1kdQyVtvrWVo= X-MC-Unique: deoik13BNFyoXN3omgyuVQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Guoyi Tu , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , "Michael S. Tsirkin" Subject: [PULL 8/8] vhost-user: Call qemu_socketpair() instead of socketpair() Date: Thu, 29 Sep 2022 15:05:08 +0400 Message-Id: <20220929110508.1323529-9-marcandre.lureau@redhat.com> In-Reply-To: <20220929110508.1323529-1-marcandre.lureau@redhat.com> References: <20220929110508.1323529-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.08, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1664452237320100001 From: Guoyi Tu As the close-on-exec flags is not set on the file descriptors returned by socketpair() at default, the fds will survive across exec' function. In the case that exec' function get invoked, such as the live-update feature which is been developing, it will cause fd leaks. To address this problem, we should call qemu_socketpair() to create an pair= of connected sockets with the close-on-exec flag set. Signed-off-by: Guoyi Tu Reviewed-by: Christian Schoenebeck Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <7002b12a5fb0a30cd878e14e07da61c36da72913.1661240709.git.tugy@c= hinatelecom.cn> --- hw/display/vhost-user-gpu.c | 3 ++- hw/virtio/vhost-user.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 3340ef9e5f..19c0e20103 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -11,6 +11,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/sockets.h" #include "hw/qdev-properties.h" #include "hw/virtio/virtio-gpu.h" #include "chardev/char-fe.h" @@ -375,7 +376,7 @@ vhost_user_gpu_do_set_socket(VhostUserGPU *g, Error **e= rrp) Chardev *chr; int sv[2]; =20 - if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) =3D=3D -1) { + if (qemu_socketpair(PF_UNIX, SOCK_STREAM, 0, sv) =3D=3D -1) { error_setg_errno(errp, errno, "socketpair() failed"); return false; } diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index bd24741be8..70748e61e0 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1726,7 +1726,7 @@ static int vhost_setup_slave_channel(struct vhost_dev= *dev) return 0; } =20 - if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) =3D=3D -1) { + if (qemu_socketpair(PF_UNIX, SOCK_STREAM, 0, sv) =3D=3D -1) { int saved_errno =3D errno; error_report("socketpair() failed"); return -saved_errno; --=20 2.37.3