From nobody Sat May 18 07:08:57 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 1548833987162376.76015677798375; Tue, 29 Jan 2019 23:39:47 -0800 (PST) Received: from localhost ([127.0.0.1]:33547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokTI-0008S4-0n for importer@patchew.org; Wed, 30 Jan 2019 02:39:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45535) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokOT-0004v8-F8 for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gokOR-000787-O3 for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57306) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gokOR-00073l-DM for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:43 -0500 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 B1A7D7AE9E; Wed, 30 Jan 2019 07:34:30 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-190.ams2.redhat.com [10.36.117.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DE275C21E; Wed, 30 Jan 2019 07:34:27 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 686A9EDF; Wed, 30 Jan 2019 08:34:26 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 30 Jan 2019 08:34:19 +0100 Message-Id: <20190130073426.11525-2-kraxel@redhat.com> In-Reply-To: <20190130073426.11525-1-kraxel@redhat.com> References: <20190130073426.11525-1-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.25]); Wed, 30 Jan 2019 07:34:30 +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] [PULL 1/8] 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: 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 Message-id: 20190110125108.22834-1-kraxel@redhat.com --- hw/core/machine.c | 3 +++ hw/usb/dev-hid.c | 26 +++++++++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 2629515363..077fbd182a 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -30,6 +30,9 @@ GlobalProperty hw_compat_3_1[] =3D { { "memory-backend-memfd", "x-use-canonical-path-for-ramblock-id", "tru= e" }, { "tpm-crb", "ppi", "false" }, { "tpm-tis", "ppi", "false" }, + { "usb-kbd", "serial", "42" }, + { "usb-mouse", "serial", "42" }, + { "usb-kbd", "serial", "42" }, }; const size_t hw_compat_3_1_len =3D G_N_ELEMENTS(hw_compat_3_1); =20 diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c index 90cd745f06..f9ea3033a1 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 From nobody Sat May 18 07:08:57 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548833826791301.7672102326875; Tue, 29 Jan 2019 23:37:06 -0800 (PST) Received: from localhost ([127.0.0.1]:33519 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokQY-00067p-5z for importer@patchew.org; Wed, 30 Jan 2019 02:36:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokOS-0004v6-Pj for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gokOR-00078D-Oh for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33246) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gokOR-00073h-GR for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:43 -0500 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 6554A13821D; Wed, 30 Jan 2019 07:34:30 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-190.ams2.redhat.com [10.36.117.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70BF15C224; Wed, 30 Jan 2019 07:34:27 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 7075A59E9; Wed, 30 Jan 2019 08:34:26 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 30 Jan 2019 08:34:20 +0100 Message-Id: <20190130073426.11525-3-kraxel@redhat.com> In-Reply-To: <20190130073426.11525-1-kraxel@redhat.com> References: <20190130073426.11525-1-kraxel@redhat.com> MIME-Version: 1.0 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.38]); Wed, 30 Jan 2019 07:34:30 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 2/8] usb: dev-mtp: close fd in usb_mtp_object_readdir() 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: Li Qiang , Eduardo Habkost , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Li Qiang Spotted by Coverity: CID 1397070 Signed-off-by: Li Qiang Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20190103133113.49599-1-liq3ea@163.com [ kraxel: dropped chunk which adds close() after successful fdopendir() call, that is not needed according to POSIX even though Coverity flags it as bug ] Signed-off-by: Gerd Hoffmann --- hw/usb/dev-mtp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index 68c5eb8eaa..837c9d9449 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -666,6 +666,7 @@ static void usb_mtp_object_readdir(MTPState *s, MTPObje= ct *o) } dir =3D fdopendir(fd); if (!dir) { + close(fd); return; } #ifdef CONFIG_INOTIFY1 --=20 2.9.3 From nobody Sat May 18 07:08:57 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548833832616774.380727534827; Tue, 29 Jan 2019 23:37:12 -0800 (PST) Received: from localhost ([127.0.0.1]:33525 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokQg-0006EW-28 for importer@patchew.org; Wed, 30 Jan 2019 02:37:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45532) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokOT-0004v7-DS for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gokOR-00077l-Ab for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57302) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gokON-00073i-ER for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:41 -0500 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 917CF7AE9D; Wed, 30 Jan 2019 07:34:30 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-190.ams2.redhat.com [10.36.117.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B8C662671; Wed, 30 Jan 2019 07:34:27 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 7D6707700; Wed, 30 Jan 2019 08:34:26 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 30 Jan 2019 08:34:21 +0100 Message-Id: <20190130073426.11525-4-kraxel@redhat.com> In-Reply-To: <20190130073426.11525-1-kraxel@redhat.com> References: <20190130073426.11525-1-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.25]); Wed, 30 Jan 2019 07:34:30 +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] [PULL 3/8] hw/usb: Fix LGPL information in the file headers 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: Thomas Huth , 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" From: Thomas Huth It's either "GNU *Library* General Public version 2" or "GNU Lesser General Public version *2.1*", but there was no "version 2.0" of the "Lesser" library. So assume that version 2.1 is meant here. Additionally, suggest that the user should have received a copy of the LGPL, and not the GPL here. Signed-off-by: Thomas Huth Message-id: 1548254454-7659-1-git-send-email-thuth@redhat.com Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-ehci.h | 4 ++-- hw/usb/combined-packet.c | 4 ++-- hw/usb/hcd-ehci-pci.c | 4 ++-- hw/usb/hcd-ehci-sysbus.c | 4 ++-- hw/usb/hcd-ehci.c | 5 ++--- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h index d6601706ee..fedf82c611 100644 --- a/hw/usb/hcd-ehci.h +++ b/hw/usb/hcd-ehci.h @@ -4,14 +4,14 @@ * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either - * version 2 of the License, or(at your option) any later version. + * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License + * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, see . */ =20 diff --git a/hw/usb/combined-packet.c b/hw/usb/combined-packet.c index fc98383d30..37b23e20ef 100644 --- a/hw/usb/combined-packet.c +++ b/hw/usb/combined-packet.c @@ -9,14 +9,14 @@ * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either - * version 2 of the License, or(at your option) any later version. + * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License + * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, see . */ #include "qemu/osdep.h" diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c index 69abbf7b7b..38b24b160a 100644 --- a/hw/usb/hcd-ehci-pci.c +++ b/hw/usb/hcd-ehci-pci.c @@ -4,14 +4,14 @@ * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either - * version 2 of the License, or(at your option) any later version. + * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License + * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, see . */ =20 diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c index 331faf8bc3..9f7f128f19 100644 --- a/hw/usb/hcd-ehci-sysbus.c +++ b/hw/usb/hcd-ehci-sysbus.c @@ -4,14 +4,14 @@ * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either - * version 2 of the License, or(at your option) any later version. + * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License + * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, see . */ =20 diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index e233681962..9b132cb0d3 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -12,18 +12,17 @@ * Niels de Vos. David S. Ahern continued working on it. Kevin Wolf, * Jan Kiszka and Vincent Palatin contributed bugfixes. * - * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either - * version 2 of the License, or(at your option) any later version. + * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License + * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, see . */ =20 --=20 2.9.3 From nobody Sat May 18 07:08:57 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 15488339874971022.1502632303543; Tue, 29 Jan 2019 23:39:47 -0800 (PST) Received: from localhost ([127.0.0.1]:33549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokTH-0008SG-Gu for importer@patchew.org; Wed, 30 Jan 2019 02:39:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45581) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokOV-0004vw-Gb for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gokOT-00079Z-De for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51886) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gokOS-000745-Jd for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:44 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 393419B309; Wed, 30 Jan 2019 07:34:31 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-190.ams2.redhat.com [10.36.117.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E6AC1A92D; Wed, 30 Jan 2019 07:34:27 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 8576A7701; Wed, 30 Jan 2019 08:34:26 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 30 Jan 2019 08:34:22 +0100 Message-Id: <20190130073426.11525-5-kraxel@redhat.com> In-Reply-To: <20190130073426.11525-1-kraxel@redhat.com> References: <20190130073426.11525-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 30 Jan 2019 07:34:31 +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] [PULL 4/8] usb: XHCI shall not halt isochronous endpoints 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: Yuri Benditovich , 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" From: Yuri Benditovich According to the XHCI spec (4.10.2) the controller never halts isochronous endpoints. This commit prevent stop of isochronous streaming when sporadic errors status received from backends. Signed-off-by: Yuri Benditovich Message-id: 20190128200444.5128-2-yuri.benditovich@janustech.com Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-xhci.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 8f1a01a405..1a8fd9644e 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -1571,6 +1571,11 @@ static void xhci_stall_ep(XHCITransfer *xfer) uint32_t err; XHCIStreamContext *sctx; =20 + if (epctx->type =3D=3D ET_ISO_IN || epctx->type =3D=3D ET_ISO_OUT) { + /* never halt isoch endpoints, 4.10.2 */ + return; + } + if (epctx->nr_pstreams) { sctx =3D xhci_find_stream(epctx, xfer->streamid, &err); if (sctx =3D=3D NULL) { --=20 2.9.3 From nobody Sat May 18 07:08:57 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 1548833986490623.5457431401616; Tue, 29 Jan 2019 23:39:46 -0800 (PST) Received: from localhost ([127.0.0.1]:33545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokTH-0008S2-EP for importer@patchew.org; Wed, 30 Jan 2019 02:39:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokOT-0004v9-FB for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gokOR-00078L-TW for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34920) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gokOR-00074h-Fg for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:43 -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 E51F7804F5; Wed, 30 Jan 2019 07:34:34 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-190.ams2.redhat.com [10.36.117.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 32854608C1; Wed, 30 Jan 2019 07:34:31 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 8E8E57702; Wed, 30 Jan 2019 08:34:26 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 30 Jan 2019 08:34:23 +0100 Message-Id: <20190130073426.11525-6-kraxel@redhat.com> In-Reply-To: <20190130073426.11525-1-kraxel@redhat.com> References: <20190130073426.11525-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.27]); Wed, 30 Jan 2019 07:34:35 +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] [PULL 5/8] usb: implement XHCI underrun/overrun events 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: Yuri Benditovich , 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" From: Yuri Benditovich Implement underrun/overrun events of isochronous endpoints according to XHCI spec (4.10.3.1) Guest software restarts data streaming when receives these events. The XHCI reports these events using interrupter assigned to the slot (as these events do not have TRB), so current commit adds the field of assigned interrupter to the XHCISlot structure. Guest software assigns interrupter to the slot on 'Address Device' and 'Evaluate Context' commands. Signed-off-by: Yuri Benditovich Message-id: 20190128200444.5128-3-yuri.benditovich@janustech.com Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-xhci.h | 1 + hw/usb/hcd-xhci.c | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/hw/usb/hcd-xhci.h b/hw/usb/hcd-xhci.h index fc36a4c787..240caa4e51 100644 --- a/hw/usb/hcd-xhci.h +++ b/hw/usb/hcd-xhci.h @@ -140,6 +140,7 @@ typedef struct XHCIPort { typedef struct XHCISlot { bool enabled; bool addressed; + uint16_t intr; dma_addr_t ctx; USBPort *uport; XHCIEPContext *eps[31]; diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 1a8fd9644e..19c64f7ff4 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -1949,6 +1949,16 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, un= signed int streamid) while (1) { length =3D xhci_ring_chain_length(xhci, ring); if (length <=3D 0) { + if (epctx->type =3D=3D ET_ISO_OUT || epctx->type =3D=3D ET_ISO= _IN) { + /* 4.10.3.1 */ + XHCIEvent ev =3D { ER_TRANSFER }; + ev.ccode =3D epctx->type =3D=3D ET_ISO_IN ? + CC_RING_OVERRUN : CC_RING_UNDERRUN; + ev.slotid =3D epctx->slotid; + ev.epid =3D epctx->epid; + ev.ptr =3D epctx->ring.dequeue; + xhci_event(xhci, &ev, xhci->slots[epctx->slotid-1].intr); + } break; } xfer =3D xhci_ep_alloc_xfer(epctx, length); @@ -2028,6 +2038,7 @@ static TRBCCode xhci_disable_slot(XHCIState *xhci, un= signed int slotid) xhci->slots[slotid-1].enabled =3D 0; xhci->slots[slotid-1].addressed =3D 0; xhci->slots[slotid-1].uport =3D NULL; + xhci->slots[slotid-1].intr =3D 0; return CC_SUCCESS; } =20 @@ -2127,6 +2138,7 @@ static TRBCCode xhci_address_slot(XHCIState *xhci, un= signed int slotid, slot =3D &xhci->slots[slotid-1]; slot->uport =3D uport; slot->ctx =3D octx; + slot->intr =3D get_field(slot_ctx[2], TRB_INTR); =20 /* Make sure device is in USB_STATE_DEFAULT state */ usb_device_reset(dev); @@ -2300,8 +2312,9 @@ static TRBCCode xhci_evaluate_slot(XHCIState *xhci, u= nsigned int slotid, =20 slot_ctx[1] &=3D ~0xFFFF; /* max exit latency */ slot_ctx[1] |=3D islot_ctx[1] & 0xFFFF; - slot_ctx[2] &=3D ~0xFF00000; /* interrupter target */ - slot_ctx[2] |=3D islot_ctx[2] & 0xFF000000; + /* update interrupter target field */ + xhci->slots[slotid-1].intr =3D get_field(islot_ctx[2], TRB_INTR); + set_field(&slot_ctx[2], xhci->slots[slotid-1].intr, TRB_INTR); =20 DPRINTF("xhci: output slot context: %08x %08x %08x %08x\n", slot_ctx[0], slot_ctx[1], slot_ctx[2], slot_ctx[3]); --=20 2.9.3 From nobody Sat May 18 07:08:57 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548833828138185.59459471810237; Tue, 29 Jan 2019 23:37:08 -0800 (PST) Received: from localhost ([127.0.0.1]:33523 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokQa-0006B2-4N for importer@patchew.org; Wed, 30 Jan 2019 02:36:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45501) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokOS-0004v5-Op for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gokOR-00077e-9W for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37882) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gokOL-00074p-F4 for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:40 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 92E10C05CDFC; Wed, 30 Jan 2019 07:34:35 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-190.ams2.redhat.com [10.36.117.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 338A061370; Wed, 30 Jan 2019 07:34:31 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 968C87703; Wed, 30 Jan 2019 08:34:26 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 30 Jan 2019 08:34:24 +0100 Message-Id: <20190130073426.11525-7-kraxel@redhat.com> In-Reply-To: <20190130073426.11525-1-kraxel@redhat.com> References: <20190130073426.11525-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 30 Jan 2019 07:34:35 +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] [PULL 6/8] usb-mtp: Reallocate buffer in multiples of MTP_WRITE_BUF_SZ 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: Bandan Das , 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" From: Bandan Das This is a "pre-patch" to breaking up the write buffer for MTP writes. Instead of allocating a mtp buffer equal to size sent by the initiator, we start with a small size and reallocate multiples (of that small size) as needed. Signed-off-by: Bandan Das Message-id: 20190129131908.27924-2-bsd@redhat.com Signed-off-by: Gerd Hoffmann --- hw/usb/dev-mtp.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index 837c9d9449..2e342c7745 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -25,6 +25,7 @@ #include "trace.h" #include "hw/usb.h" #include "desc.h" +#include "qemu/units.h" =20 /* -----------------------------------------------------------------------= */ =20 @@ -152,7 +153,6 @@ struct MTPData { bool first; /* Used for >4G file sizes */ bool pending; - uint64_t cached_length; int fd; }; =20 @@ -244,6 +244,7 @@ typedef struct { =20 #define MTP_MANUFACTURER "QEMU" #define MTP_PRODUCT "QEMU filesharing" +#define MTP_WRITE_BUF_SZ (512 * KiB) =20 enum { STR_MANUFACTURER =3D 1, @@ -1659,7 +1660,7 @@ static void usb_mtp_write_data(MTPState *s) d->fd =3D mkdir(path, mask); goto free; } - if ((s->dataset.size !=3D 0xFFFFFFFF) && (s->dataset.size < d->len= gth)) { + if ((s->dataset.size !=3D 0xFFFFFFFF) && (s->dataset.size !=3D d->= offset)) { usb_mtp_queue_result(s, RES_STORE_FULL, d->trans, 0, 0, 0, 0); goto done; @@ -1777,17 +1778,21 @@ static void usb_mtp_get_data(MTPState *s, mtp_conta= iner *container, total_len =3D cpu_to_le32(container->length) - sizeof(mtp_containe= r); /* Length of data in this packet */ data_len -=3D sizeof(mtp_container); - usb_mtp_realloc(d, total_len); - d->length +=3D total_len; + if (total_len < MTP_WRITE_BUF_SZ) { + usb_mtp_realloc(d, total_len); + d->length +=3D total_len; + } else { + usb_mtp_realloc(d, MTP_WRITE_BUF_SZ - sizeof(mtp_container= )); + d->length +=3D MTP_WRITE_BUF_SZ - sizeof(mtp_container); + } d->offset =3D 0; - d->cached_length =3D total_len; d->first =3D false; d->pending =3D false; } =20 if (d->pending) { - usb_mtp_realloc(d, d->cached_length); - d->length +=3D d->cached_length; + usb_mtp_realloc(d, MTP_WRITE_BUF_SZ); + d->length +=3D MTP_WRITE_BUF_SZ; d->pending =3D false; } =20 @@ -1795,12 +1800,6 @@ static void usb_mtp_get_data(MTPState *s, mtp_contai= ner *container, dlen =3D data_len; } else { dlen =3D d->length - d->offset; - /* Check for cached data for large files */ - if ((s->dataset.size =3D=3D 0xFFFFFFFF) && (dlen < p->iov.size)) { - usb_mtp_realloc(d, p->iov.size - dlen); - d->length +=3D p->iov.size - dlen; - dlen =3D p->iov.size; - } } =20 switch (d->code) { @@ -1822,7 +1821,7 @@ static void usb_mtp_get_data(MTPState *s, mtp_contain= er *container, d->offset +=3D dlen; if ((p->iov.size % 64) || !p->iov.size) { assert((s->dataset.size =3D=3D 0xFFFFFFFF) || - (s->dataset.size =3D=3D d->length)); + (s->dataset.size =3D=3D d->offset)); =20 usb_mtp_write_data(s); usb_mtp_data_free(s->data_out); --=20 2.9.3 From nobody Sat May 18 07:08:57 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 1548834123872992.4968685745836; Tue, 29 Jan 2019 23:42:03 -0800 (PST) Received: from localhost ([127.0.0.1]:33599 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokVT-0001tf-RW for importer@patchew.org; Wed, 30 Jan 2019 02:41:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokOT-0004vA-Ef for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gokOR-000781-Mw for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49973) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gokOR-00075X-Bm for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:43 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6D38C7FD43; Wed, 30 Jan 2019 07:34:38 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-190.ams2.redhat.com [10.36.117.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E9E9BAA0; Wed, 30 Jan 2019 07:34:31 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 9ECBD7704; Wed, 30 Jan 2019 08:34:26 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 30 Jan 2019 08:34:25 +0100 Message-Id: <20190130073426.11525-8-kraxel@redhat.com> In-Reply-To: <20190130073426.11525-1-kraxel@redhat.com> References: <20190130073426.11525-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 30 Jan 2019 07:34:38 +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] [PULL 7/8] usb-mtp: breakup MTP write into smaller chunks 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: Bandan Das , 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" From: Bandan Das For every MTP_WRITE_BUF_SZ copied, this patch writes it to file before getting the next block of data. The file is kept opened for the duration of the operation but the sanity checks on the write operation are performed only once when the write operation starts. Additionally, we also update the file size in the object metadata once the file has completely been written. Suggested-by: Gerd Hoffman Signed-off-by: Bandan Das Message-id: 20190129131908.27924-3-bsd@redhat.com Signed-off-by: Gerd Hoffmann --- hw/usb/dev-mtp.c | 134 +++++++++++++++++++++++++++++++++++++--------------= ---- 1 file changed, 91 insertions(+), 43 deletions(-) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index 2e342c7745..2ca25c9da5 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -36,6 +36,13 @@ enum mtp_container_type { TYPE_EVENT =3D 4, }; =20 +/* MTP write stage, for internal use only */ +enum mtp_write_status { + WRITE_START =3D 1, + WRITE_CONTINUE =3D 2, + WRITE_END =3D 3, +}; + enum mtp_code { /* command codes */ CMD_GET_DEVICE_INFO =3D 0x1001, @@ -154,6 +161,9 @@ struct MTPData { /* Used for >4G file sizes */ bool pending; int fd; + uint8_t write_status; + /* Internal pointer per every MTP_WRITE_BUF_SZ */ + uint64_t data_offset; }; =20 struct MTPObject { @@ -1620,10 +1630,14 @@ static char *utf16_to_str(uint8_t len, uint16_t *ar= r) } =20 /* Wrapper around write, returns 0 on failure */ -static uint64_t write_retry(int fd, void *buf, uint64_t size) +static uint64_t write_retry(int fd, void *buf, uint64_t size, off_t offset) { uint64_t bytes_left =3D size, ret; =20 + if (lseek(fd, offset, SEEK_SET) < 0) { + goto done; + } + while (bytes_left > 0) { ret =3D write(fd, buf, bytes_left); if ((ret =3D=3D -1) && (errno !=3D EINTR || errno !=3D EAG= AIN || @@ -1634,9 +1648,20 @@ static uint64_t write_retry(int fd, void *buf, uint6= 4_t size) buf +=3D ret; } =20 +done: return size - bytes_left; } =20 +static void usb_mtp_update_object(MTPObject *parent, char *name) +{ + MTPObject *o =3D + usb_mtp_object_lookup_name(parent, name, strlen(name)); + + if (o) { + lstat(o->path, &o->stat); + } +} + static void usb_mtp_write_data(MTPState *s) { MTPData *d =3D s->data_out; @@ -1648,48 +1673,56 @@ static void usb_mtp_write_data(MTPState *s) =20 assert(d !=3D NULL); =20 - if (parent =3D=3D NULL || !s->write_pending) { - usb_mtp_queue_result(s, RES_INVALID_OBJECTINFO, d->trans, - 0, 0, 0, 0); + switch (d->write_status) { + case WRITE_START: + if (!parent || !s->write_pending) { + usb_mtp_queue_result(s, RES_INVALID_OBJECTINFO, d->trans, + 0, 0, 0, 0); return; - } - - if (s->dataset.filename) { - path =3D g_strdup_printf("%s/%s", parent->path, s->dataset.filenam= e); - if (s->dataset.format =3D=3D FMT_ASSOCIATION) { - d->fd =3D mkdir(path, mask); - goto free; - } - if ((s->dataset.size !=3D 0xFFFFFFFF) && (s->dataset.size !=3D d->= offset)) { - usb_mtp_queue_result(s, RES_STORE_FULL, d->trans, - 0, 0, 0, 0); - goto done; - } - d->fd =3D open(path, O_CREAT | O_WRONLY | O_CLOEXEC | O_NOFOLLOW, = mask); - if (d->fd =3D=3D -1) { - usb_mtp_queue_result(s, RES_STORE_FULL, d->trans, - 0, 0, 0, 0); - goto done; } =20 - /* - * Return success if initiator sent 0 sized data - */ - if (!s->dataset.size) { - goto success; - } + if (s->dataset.filename) { + path =3D g_strdup_printf("%s/%s", parent->path, s->dataset.fil= ename); + if (s->dataset.format =3D=3D FMT_ASSOCIATION) { + d->fd =3D mkdir(path, mask); + goto free; + } + d->fd =3D open(path, O_CREAT | O_WRONLY | + O_CLOEXEC | O_NOFOLLOW, mask); + if (d->fd =3D=3D -1) { + usb_mtp_queue_result(s, RES_STORE_FULL, d->trans, + 0, 0, 0, 0); + goto done; + } =20 - rc =3D write_retry(d->fd, d->data, d->offset); - if (rc !=3D d->offset) { + /* Return success if initiator sent 0 sized data */ + if (!s->dataset.size) { + goto success; + } + if (d->length !=3D MTP_WRITE_BUF_SZ && !d->pending) { + d->write_status =3D WRITE_END; + } + } + /* fall through */ + case WRITE_CONTINUE: + case WRITE_END: + rc =3D write_retry(d->fd, d->data, d->data_offset, + d->offset - d->data_offset); + if (rc !=3D d->data_offset) { usb_mtp_queue_result(s, RES_STORE_FULL, d->trans, 0, 0, 0, 0); goto done; + } + if (d->write_status !=3D WRITE_END) { + return; + } else { + /* Only for < 4G file sizes */ + if (s->dataset.size !=3D 0xFFFFFFFF && d->offset !=3D s->datas= et.size) { + usb_mtp_queue_result(s, RES_INCOMPLETE_TRANSFER, d->trans, + 0, 0, 0, 0); + goto done; } - /* Only for < 4G file sizes */ - if (s->dataset.size !=3D 0xFFFFFFFF && rc !=3D s->dataset.size) { - usb_mtp_queue_result(s, RES_INCOMPLETE_TRANSFER, d->trans, - 0, 0, 0, 0); - goto done; + usb_mtp_update_object(parent, s->dataset.filename); } } =20 @@ -1788,25 +1821,33 @@ static void usb_mtp_get_data(MTPState *s, mtp_conta= iner *container, d->offset =3D 0; d->first =3D false; d->pending =3D false; + d->data_offset =3D 0; + d->write_status =3D WRITE_START; } =20 if (d->pending) { - usb_mtp_realloc(d, MTP_WRITE_BUF_SZ); - d->length +=3D MTP_WRITE_BUF_SZ; + memset(d->data, 0, d->length); + if (d->length !=3D MTP_WRITE_BUF_SZ) { + usb_mtp_realloc(d, MTP_WRITE_BUF_SZ - d->length); + d->length +=3D (MTP_WRITE_BUF_SZ - d->length); + } d->pending =3D false; + d->write_status =3D WRITE_CONTINUE; + d->data_offset =3D 0; } =20 - if (d->length - d->offset > data_len) { + if (d->length - d->data_offset > data_len) { dlen =3D data_len; } else { - dlen =3D d->length - d->offset; + dlen =3D d->length - d->data_offset; } =20 switch (d->code) { case CMD_SEND_OBJECT_INFO: - usb_packet_copy(p, d->data + d->offset, dlen); + usb_packet_copy(p, d->data + d->data_offset, dlen); d->offset +=3D dlen; - if (d->offset =3D=3D d->length) { + d->data_offset +=3D dlen; + if (d->data_offset =3D=3D d->length) { /* The operation might have already failed */ if (!s->result) { usb_mtp_write_metadata(s, dlen); @@ -1817,19 +1858,26 @@ static void usb_mtp_get_data(MTPState *s, mtp_conta= iner *container, } break; case CMD_SEND_OBJECT: - usb_packet_copy(p, d->data + d->offset, dlen); + usb_packet_copy(p, d->data + d->data_offset, dlen); d->offset +=3D dlen; + d->data_offset +=3D dlen; if ((p->iov.size % 64) || !p->iov.size) { assert((s->dataset.size =3D=3D 0xFFFFFFFF) || (s->dataset.size =3D=3D d->offset)); =20 + if (d->length =3D=3D MTP_WRITE_BUF_SZ) { + d->write_status =3D WRITE_END; + } else { + d->write_status =3D WRITE_START; + } usb_mtp_write_data(s); usb_mtp_data_free(s->data_out); s->data_out =3D NULL; return; } - if (d->offset =3D=3D d->length) { + if (d->data_offset =3D=3D d->length) { d->pending =3D true; + usb_mtp_write_data(s); } break; default: --=20 2.9.3 From nobody Sat May 18 07:08:57 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 1548834121972421.1612730019957; Tue, 29 Jan 2019 23:42:01 -0800 (PST) Received: from localhost ([127.0.0.1]:33595 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokVR-0001sZ-Fy for importer@patchew.org; Wed, 30 Jan 2019 02:41:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45579) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokOV-0004vs-G1 for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gokOS-000796-QY for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57372) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gokOR-00074a-SI for qemu-devel@nongnu.org; Wed, 30 Jan 2019 02:34:44 -0500 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 5E9EE8553D; Wed, 30 Jan 2019 07:34:34 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-190.ams2.redhat.com [10.36.117.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 506725C21E; Wed, 30 Jan 2019 07:34:31 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id A696E7705; Wed, 30 Jan 2019 08:34:26 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 30 Jan 2019 08:34:26 +0100 Message-Id: <20190130073426.11525-9-kraxel@redhat.com> In-Reply-To: <20190130073426.11525-1-kraxel@redhat.com> References: <20190130073426.11525-1-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.28]); Wed, 30 Jan 2019 07:34:34 +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] [PULL 8/8] usb-mtp: replace the homebrew write with qemu_write_full 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: Bandan Das , 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" From: Bandan Das qemu_write_full takes care of partial blocking writes, as in cases of larger file sizes Suggested-by: Peter Maydell Signed-off-by: Bandan Das Message-id: 20190129131908.27924-4-bsd@redhat.com Signed-off-by: Gerd Hoffmann --- hw/usb/dev-mtp.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index 2ca25c9da5..f1d20fa1b9 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -1632,24 +1632,16 @@ static char *utf16_to_str(uint8_t len, uint16_t *ar= r) /* Wrapper around write, returns 0 on failure */ static uint64_t write_retry(int fd, void *buf, uint64_t size, off_t offset) { - uint64_t bytes_left =3D size, ret; + uint64_t ret =3D 0; =20 if (lseek(fd, offset, SEEK_SET) < 0) { goto done; } =20 - while (bytes_left > 0) { - ret =3D write(fd, buf, bytes_left); - if ((ret =3D=3D -1) && (errno !=3D EINTR || errno !=3D EAG= AIN || - errno !=3D EWOULDBLOCK)) { - break; - } - bytes_left -=3D ret; - buf +=3D ret; - } + ret =3D qemu_write_full(fd, buf, size); =20 done: - return size - bytes_left; + return ret; } =20 static void usb_mtp_update_object(MTPObject *parent, char *name) --=20 2.9.3