From nobody Fri Mar 29 05:13:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547124952158426.94366879255415; Thu, 10 Jan 2019 04:55:52 -0800 (PST) Received: from localhost ([127.0.0.1]:37914 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZsE-0008DK-KW for importer@patchew.org; Thu, 10 Jan 2019 07:55:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZnm-0004SJ-Ew for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:51:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghZnl-0007s7-Dy for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:51:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43394) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ghZnl-0007ru-6M for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:51:13 -0500 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 80834C0669A7; Thu, 10 Jan 2019 12:51:12 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-203.ams2.redhat.com [10.36.116.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2159860923; Thu, 10 Jan 2019 12:51:09 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 53007A213; Thu, 10 Jan 2019 13:51:08 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 10 Jan 2019 13:51:08 +0100 Message-Id: <20190110125108.22834-1-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.32]); Thu, 10 Jan 2019 12:51:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4] usb: assign unique serial numbers to hid devices 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: dgilbert@redhat.com, Eduardo Habkost , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Windows guests have trouble dealing with usb devices having identical serial numbers. So, assign unique serial numbers to usb hid devices. All other usb devices have this already. In the past the fixed serial number has been used to indicate working remote setup to linux guests. Here is a bit of history: * First there was nothing. * Then I added a rule to udev checking for serial =3D=3D 42. (this is in rhel-6). * Then systemd + udev merged. * Then I changed the rule to check for serial !=3D 1 instead, so we can use any serial but "1" which is the one the old broken devices had (this is in rhel-7). March 2014 in upstream systemd. * Then all usb power management rules where dropped from systemd (June 2015). Which I figured today (Sept 2018), after wondering that the rules are gone in fedora 28. So, three years ago the serial number check was dropped upstream, yet I hav't seen a single report about autosuspend issues (or cpu usage for usb emulation going up, which is the typical symtom). So I figured I can stop worring that changing the serial number will break things and just do it. And even if it turns out autosuspend is still an issue: I think meanwhile we can really stop worrying about guests running in old qemu versions with broken usb suspend (fixed in 0.13 !). If needed we can enable autosuspend unconditionally in guests. Signed-off-by: Gerd Hoffmann --- hw/core/machine.c | 12 ++++++++++++ hw/usb/dev-hid.c | 26 +++++++++++++++----------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index f8563efb86..7bb78eee9b 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -40,6 +40,18 @@ GlobalProperty hw_compat_3_1[] =3D { .driver =3D "memory-backend-memfd", .property =3D "x-use-canonical-path-for-ramblock-id", .value =3D "true", + },{ + .driver =3D "usb-kbd", + .property =3D "serial", + .value =3D "42", + },{ + .driver =3D "usb-mouse", + .property =3D "serial", + .value =3D "42", + },{ + .driver =3D "usb-tablet", + .property =3D "serial", + .value =3D "42", }, }; const size_t hw_compat_3_1_len =3D G_N_ELEMENTS(hw_compat_3_1); diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c index 62d18290dc..205236e9b1 100644 --- a/hw/usb/dev-hid.c +++ b/hw/usb/dev-hid.c @@ -61,10 +61,13 @@ enum { STR_PRODUCT_MOUSE, STR_PRODUCT_TABLET, STR_PRODUCT_KEYBOARD, - STR_SERIALNUMBER, + STR_SERIAL_COMPAT, STR_CONFIG_MOUSE, STR_CONFIG_TABLET, STR_CONFIG_KEYBOARD, + STR_SERIAL_MOUSE, + STR_SERIAL_TABLET, + STR_SERIAL_KEYBOARD, }; =20 static const USBDescStrings desc_strings =3D { @@ -72,10 +75,13 @@ static const USBDescStrings desc_strings =3D { [STR_PRODUCT_MOUSE] =3D "QEMU USB Mouse", [STR_PRODUCT_TABLET] =3D "QEMU USB Tablet", [STR_PRODUCT_KEYBOARD] =3D "QEMU USB Keyboard", - [STR_SERIALNUMBER] =3D "42", /* =3D=3D remote wakeup works */ + [STR_SERIAL_COMPAT] =3D "42", [STR_CONFIG_MOUSE] =3D "HID Mouse", [STR_CONFIG_TABLET] =3D "HID Tablet", [STR_CONFIG_KEYBOARD] =3D "HID Keyboard", + [STR_SERIAL_MOUSE] =3D "89126", + [STR_SERIAL_TABLET] =3D "28754", + [STR_SERIAL_KEYBOARD] =3D "68284", }; =20 static const USBDescIface desc_iface_mouse =3D { @@ -375,7 +381,7 @@ static const USBDesc desc_mouse =3D { .bcdDevice =3D 0, .iManufacturer =3D STR_MANUFACTURER, .iProduct =3D STR_PRODUCT_MOUSE, - .iSerialNumber =3D STR_SERIALNUMBER, + .iSerialNumber =3D STR_SERIAL_MOUSE, }, .full =3D &desc_device_mouse, .str =3D desc_strings, @@ -389,7 +395,7 @@ static const USBDesc desc_mouse2 =3D { .bcdDevice =3D 0, .iManufacturer =3D STR_MANUFACTURER, .iProduct =3D STR_PRODUCT_MOUSE, - .iSerialNumber =3D STR_SERIALNUMBER, + .iSerialNumber =3D STR_SERIAL_MOUSE, }, .full =3D &desc_device_mouse, .high =3D &desc_device_mouse2, @@ -404,7 +410,7 @@ static const USBDesc desc_tablet =3D { .bcdDevice =3D 0, .iManufacturer =3D STR_MANUFACTURER, .iProduct =3D STR_PRODUCT_TABLET, - .iSerialNumber =3D STR_SERIALNUMBER, + .iSerialNumber =3D STR_SERIAL_TABLET, }, .full =3D &desc_device_tablet, .str =3D desc_strings, @@ -418,7 +424,7 @@ static const USBDesc desc_tablet2 =3D { .bcdDevice =3D 0, .iManufacturer =3D STR_MANUFACTURER, .iProduct =3D STR_PRODUCT_TABLET, - .iSerialNumber =3D STR_SERIALNUMBER, + .iSerialNumber =3D STR_SERIAL_TABLET, }, .full =3D &desc_device_tablet, .high =3D &desc_device_tablet2, @@ -433,7 +439,7 @@ static const USBDesc desc_keyboard =3D { .bcdDevice =3D 0, .iManufacturer =3D STR_MANUFACTURER, .iProduct =3D STR_PRODUCT_KEYBOARD, - .iSerialNumber =3D STR_SERIALNUMBER, + .iSerialNumber =3D STR_SERIAL_KEYBOARD, }, .full =3D &desc_device_keyboard, .str =3D desc_strings, @@ -447,7 +453,7 @@ static const USBDesc desc_keyboard2 =3D { .bcdDevice =3D 0, .iManufacturer =3D STR_MANUFACTURER, .iProduct =3D STR_PRODUCT_KEYBOARD, - .iSerialNumber =3D STR_SERIALNUMBER, + .iSerialNumber =3D STR_SERIAL_KEYBOARD, }, .full =3D &desc_device_keyboard, .high =3D &desc_device_keyboard2, @@ -718,9 +724,7 @@ static void usb_hid_initfn(USBDevice *dev, int kind, return; } =20 - if (dev->serial) { - usb_desc_set_string(dev, STR_SERIALNUMBER, dev->serial); - } + usb_desc_create_serial(dev); usb_desc_init(dev); us->intr =3D usb_ep_get(dev, USB_TOKEN_IN, 1); hid_init(&us->hid, kind, usb_hid_changed); --=20 2.9.3