From patchwork Wed Jan 30 07:34:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 10787801 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C689184E for ; Wed, 30 Jan 2019 07:39:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 782D42CA84 for ; Wed, 30 Jan 2019 07:39:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C9EE2CADA; Wed, 30 Jan 2019 07:39:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 996822CAD5 for ; Wed, 30 Jan 2019 07:39:17 +0000 (UTC) Received: from localhost ([127.0.0.1]:33547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokSq-0008S4-TL for patchwork-qemu-devel@patchwork.kernel.org; Wed, 30 Jan 2019 02:39:16 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 == 42. (this is in rhel-6). * Then systemd + udev merged. * Then I changed the rule to check for serial != 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[] = { { "memory-backend-memfd", "x-use-canonical-path-for-ramblock-id", "true" }, { "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 = G_N_ELEMENTS(hw_compat_3_1); 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, }; static const USBDescStrings desc_strings = { @@ -72,10 +75,13 @@ static const USBDescStrings desc_strings = { [STR_PRODUCT_MOUSE] = "QEMU USB Mouse", [STR_PRODUCT_TABLET] = "QEMU USB Tablet", [STR_PRODUCT_KEYBOARD] = "QEMU USB Keyboard", - [STR_SERIALNUMBER] = "42", /* == remote wakeup works */ + [STR_SERIAL_COMPAT] = "42", [STR_CONFIG_MOUSE] = "HID Mouse", [STR_CONFIG_TABLET] = "HID Tablet", [STR_CONFIG_KEYBOARD] = "HID Keyboard", + [STR_SERIAL_MOUSE] = "89126", + [STR_SERIAL_TABLET] = "28754", + [STR_SERIAL_KEYBOARD] = "68284", }; static const USBDescIface desc_iface_mouse = { @@ -375,7 +381,7 @@ static const USBDesc desc_mouse = { .bcdDevice = 0, .iManufacturer = STR_MANUFACTURER, .iProduct = STR_PRODUCT_MOUSE, - .iSerialNumber = STR_SERIALNUMBER, + .iSerialNumber = STR_SERIAL_MOUSE, }, .full = &desc_device_mouse, .str = desc_strings, @@ -389,7 +395,7 @@ static const USBDesc desc_mouse2 = { .bcdDevice = 0, .iManufacturer = STR_MANUFACTURER, .iProduct = STR_PRODUCT_MOUSE, - .iSerialNumber = STR_SERIALNUMBER, + .iSerialNumber = STR_SERIAL_MOUSE, }, .full = &desc_device_mouse, .high = &desc_device_mouse2, @@ -404,7 +410,7 @@ static const USBDesc desc_tablet = { .bcdDevice = 0, .iManufacturer = STR_MANUFACTURER, .iProduct = STR_PRODUCT_TABLET, - .iSerialNumber = STR_SERIALNUMBER, + .iSerialNumber = STR_SERIAL_TABLET, }, .full = &desc_device_tablet, .str = desc_strings, @@ -418,7 +424,7 @@ static const USBDesc desc_tablet2 = { .bcdDevice = 0, .iManufacturer = STR_MANUFACTURER, .iProduct = STR_PRODUCT_TABLET, - .iSerialNumber = STR_SERIALNUMBER, + .iSerialNumber = STR_SERIAL_TABLET, }, .full = &desc_device_tablet, .high = &desc_device_tablet2, @@ -433,7 +439,7 @@ static const USBDesc desc_keyboard = { .bcdDevice = 0, .iManufacturer = STR_MANUFACTURER, .iProduct = STR_PRODUCT_KEYBOARD, - .iSerialNumber = STR_SERIALNUMBER, + .iSerialNumber = STR_SERIAL_KEYBOARD, }, .full = &desc_device_keyboard, .str = desc_strings, @@ -447,7 +453,7 @@ static const USBDesc desc_keyboard2 = { .bcdDevice = 0, .iManufacturer = STR_MANUFACTURER, .iProduct = STR_PRODUCT_KEYBOARD, - .iSerialNumber = STR_SERIALNUMBER, + .iSerialNumber = STR_SERIAL_KEYBOARD, }, .full = &desc_device_keyboard, .high = &desc_device_keyboard2, @@ -718,9 +724,7 @@ static void usb_hid_initfn(USBDevice *dev, int kind, return; } - if (dev->serial) { - usb_desc_set_string(dev, STR_SERIALNUMBER, dev->serial); - } + usb_desc_create_serial(dev); usb_desc_init(dev); us->intr = usb_ep_get(dev, USB_TOKEN_IN, 1); hid_init(&us->hid, kind, usb_hid_changed); From patchwork Wed Jan 30 07:34:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 10787789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5953313B5 for ; Wed, 30 Jan 2019 07:36:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45DBC2DFE2 for ; Wed, 30 Jan 2019 07:36:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39C0A2E0F4; Wed, 30 Jan 2019 07:36:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E65EB2DFE2 for ; Wed, 30 Jan 2019 07:36:22 +0000 (UTC) Received: from localhost ([127.0.0.1]:33519 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokQ1-00067p-Kp for patchwork-qemu-devel@patchwork.kernel.org; Wed, 30 Jan 2019 02:36:21 -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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Li Qiang Spotted by Coverity: CID 1397070 Signed-off-by: Li Qiang Reviewed-by: Philippe Mathieu-Daudé 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, MTPObject *o) } dir = fdopendir(fd); if (!dir) { + close(fd); return; } #ifdef CONFIG_INOTIFY1 From patchwork Wed Jan 30 07:34:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 10787795 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D638214E1 for ; Wed, 30 Jan 2019 07:36:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C09202D5E0 for ; Wed, 30 Jan 2019 07:36:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2F2F2E0D8; Wed, 30 Jan 2019 07:36:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1F4DC2D5E0 for ; Wed, 30 Jan 2019 07:36:27 +0000 (UTC) Received: from localhost ([127.0.0.1]:33525 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokQ6-0006EW-DC for patchwork-qemu-devel@patchwork.kernel.org; Wed, 30 Jan 2019 02:36:26 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 . */ 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 . */ 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 . */ 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 . */ From patchwork Wed Jan 30 07:34:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 10787803 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CC83014E1 for ; Wed, 30 Jan 2019 07:39:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F7222CA84 for ; Wed, 30 Jan 2019 07:39:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73D312CAD5; Wed, 30 Jan 2019 07:39:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F1F7A2CA87 for ; Wed, 30 Jan 2019 07:39:16 +0000 (UTC) Received: from localhost ([127.0.0.1]:33549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokSq-0008SG-8b for patchwork-qemu-devel@patchwork.kernel.org; Wed, 30 Jan 2019 02:39:16 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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; + if (epctx->type == ET_ISO_IN || epctx->type == ET_ISO_OUT) { + /* never halt isoch endpoints, 4.10.2 */ + return; + } + if (epctx->nr_pstreams) { sctx = xhci_find_stream(epctx, xfer->streamid, &err); if (sctx == NULL) { From patchwork Wed Jan 30 07:34:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 10787799 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3604113B5 for ; Wed, 30 Jan 2019 07:39:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A9392CA84 for ; Wed, 30 Jan 2019 07:39:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C12F2CAEF; Wed, 30 Jan 2019 07:39:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F1C942CA84 for ; Wed, 30 Jan 2019 07:39:16 +0000 (UTC) Received: from localhost ([127.0.0.1]:33545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokSq-0008S2-9e for patchwork-qemu-devel@patchwork.kernel.org; Wed, 30 Jan 2019 02:39:16 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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, unsigned int streamid) while (1) { length = xhci_ring_chain_length(xhci, ring); if (length <= 0) { + if (epctx->type == ET_ISO_OUT || epctx->type == ET_ISO_IN) { + /* 4.10.3.1 */ + XHCIEvent ev = { ER_TRANSFER }; + ev.ccode = epctx->type == ET_ISO_IN ? + CC_RING_OVERRUN : CC_RING_UNDERRUN; + ev.slotid = epctx->slotid; + ev.epid = epctx->epid; + ev.ptr = epctx->ring.dequeue; + xhci_event(xhci, &ev, xhci->slots[epctx->slotid-1].intr); + } break; } xfer = xhci_ep_alloc_xfer(epctx, length); @@ -2028,6 +2038,7 @@ static TRBCCode xhci_disable_slot(XHCIState *xhci, unsigned int slotid) xhci->slots[slotid-1].enabled = 0; xhci->slots[slotid-1].addressed = 0; xhci->slots[slotid-1].uport = NULL; + xhci->slots[slotid-1].intr = 0; return CC_SUCCESS; } @@ -2127,6 +2138,7 @@ static TRBCCode xhci_address_slot(XHCIState *xhci, unsigned int slotid, slot = &xhci->slots[slotid-1]; slot->uport = uport; slot->ctx = octx; + slot->intr = get_field(slot_ctx[2], TRB_INTR); /* Make sure device is in USB_STATE_DEFAULT state */ usb_device_reset(dev); @@ -2300,8 +2312,9 @@ static TRBCCode xhci_evaluate_slot(XHCIState *xhci, unsigned int slotid, slot_ctx[1] &= ~0xFFFF; /* max exit latency */ slot_ctx[1] |= islot_ctx[1] & 0xFFFF; - slot_ctx[2] &= ~0xFF00000; /* interrupter target */ - slot_ctx[2] |= islot_ctx[2] & 0xFF000000; + /* update interrupter target field */ + xhci->slots[slotid-1].intr = get_field(islot_ctx[2], TRB_INTR); + set_field(&slot_ctx[2], xhci->slots[slotid-1].intr, TRB_INTR); DPRINTF("xhci: output slot context: %08x %08x %08x %08x\n", slot_ctx[0], slot_ctx[1], slot_ctx[2], slot_ctx[3]); From patchwork Wed Jan 30 07:34:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 10787793 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D085714E1 for ; Wed, 30 Jan 2019 07:36:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCBBD2D5E0 for ; Wed, 30 Jan 2019 07:36:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B16602DFE2; Wed, 30 Jan 2019 07:36:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 51FD72E106 for ; Wed, 30 Jan 2019 07:36:23 +0000 (UTC) Received: from localhost ([127.0.0.1]:33523 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokQ2-0006B2-Ih for patchwork-qemu-devel@patchwork.kernel.org; Wed, 30 Jan 2019 02:36:22 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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" /* ----------------------------------------------------------------------- */ @@ -152,7 +153,6 @@ struct MTPData { bool first; /* Used for >4G file sizes */ bool pending; - uint64_t cached_length; int fd; }; @@ -244,6 +244,7 @@ typedef struct { #define MTP_MANUFACTURER "QEMU" #define MTP_PRODUCT "QEMU filesharing" +#define MTP_WRITE_BUF_SZ (512 * KiB) enum { STR_MANUFACTURER = 1, @@ -1659,7 +1660,7 @@ static void usb_mtp_write_data(MTPState *s) d->fd = mkdir(path, mask); goto free; } - if ((s->dataset.size != 0xFFFFFFFF) && (s->dataset.size < d->length)) { + if ((s->dataset.size != 0xFFFFFFFF) && (s->dataset.size != 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_container *container, total_len = cpu_to_le32(container->length) - sizeof(mtp_container); /* Length of data in this packet */ data_len -= sizeof(mtp_container); - usb_mtp_realloc(d, total_len); - d->length += total_len; + if (total_len < MTP_WRITE_BUF_SZ) { + usb_mtp_realloc(d, total_len); + d->length += total_len; + } else { + usb_mtp_realloc(d, MTP_WRITE_BUF_SZ - sizeof(mtp_container)); + d->length += MTP_WRITE_BUF_SZ - sizeof(mtp_container); + } d->offset = 0; - d->cached_length = total_len; d->first = false; d->pending = false; } if (d->pending) { - usb_mtp_realloc(d, d->cached_length); - d->length += d->cached_length; + usb_mtp_realloc(d, MTP_WRITE_BUF_SZ); + d->length += MTP_WRITE_BUF_SZ; d->pending = false; } @@ -1795,12 +1800,6 @@ static void usb_mtp_get_data(MTPState *s, mtp_container *container, dlen = data_len; } else { dlen = d->length - d->offset; - /* Check for cached data for large files */ - if ((s->dataset.size == 0xFFFFFFFF) && (dlen < p->iov.size)) { - usb_mtp_realloc(d, p->iov.size - dlen); - d->length += p->iov.size - dlen; - dlen = p->iov.size; - } } switch (d->code) { @@ -1822,7 +1821,7 @@ static void usb_mtp_get_data(MTPState *s, mtp_container *container, d->offset += dlen; if ((p->iov.size % 64) || !p->iov.size) { assert((s->dataset.size == 0xFFFFFFFF) || - (s->dataset.size == d->length)); + (s->dataset.size == d->offset)); usb_mtp_write_data(s); usb_mtp_data_free(s->data_out); From patchwork Wed Jan 30 07:34:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 10787813 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B242D13B5 for ; Wed, 30 Jan 2019 07:41:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0A082E019 for ; Wed, 30 Jan 2019 07:41:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 954962E024; Wed, 30 Jan 2019 07:41:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F26562E022 for ; Wed, 30 Jan 2019 07:41:35 +0000 (UTC) Received: from localhost ([127.0.0.1]:33599 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokV5-0001tf-AQ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 30 Jan 2019 02:41:35 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 = 4, }; +/* MTP write stage, for internal use only */ +enum mtp_write_status { + WRITE_START = 1, + WRITE_CONTINUE = 2, + WRITE_END = 3, +}; + enum mtp_code { /* command codes */ CMD_GET_DEVICE_INFO = 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; }; struct MTPObject { @@ -1620,10 +1630,14 @@ static char *utf16_to_str(uint8_t len, uint16_t *arr) } /* 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 = size, ret; + if (lseek(fd, offset, SEEK_SET) < 0) { + goto done; + } + while (bytes_left > 0) { ret = write(fd, buf, bytes_left); if ((ret == -1) && (errno != EINTR || errno != EAGAIN || @@ -1634,9 +1648,20 @@ static uint64_t write_retry(int fd, void *buf, uint64_t size) buf += ret; } +done: return size - bytes_left; } +static void usb_mtp_update_object(MTPObject *parent, char *name) +{ + MTPObject *o = + 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 = s->data_out; @@ -1648,48 +1673,56 @@ static void usb_mtp_write_data(MTPState *s) assert(d != NULL); - if (parent == 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 = g_strdup_printf("%s/%s", parent->path, s->dataset.filename); - if (s->dataset.format == FMT_ASSOCIATION) { - d->fd = mkdir(path, mask); - goto free; - } - if ((s->dataset.size != 0xFFFFFFFF) && (s->dataset.size != d->offset)) { - usb_mtp_queue_result(s, RES_STORE_FULL, d->trans, - 0, 0, 0, 0); - goto done; - } - d->fd = open(path, O_CREAT | O_WRONLY | O_CLOEXEC | O_NOFOLLOW, mask); - if (d->fd == -1) { - usb_mtp_queue_result(s, RES_STORE_FULL, d->trans, - 0, 0, 0, 0); - goto done; } - /* - * Return success if initiator sent 0 sized data - */ - if (!s->dataset.size) { - goto success; - } + if (s->dataset.filename) { + path = g_strdup_printf("%s/%s", parent->path, s->dataset.filename); + if (s->dataset.format == FMT_ASSOCIATION) { + d->fd = mkdir(path, mask); + goto free; + } + d->fd = open(path, O_CREAT | O_WRONLY | + O_CLOEXEC | O_NOFOLLOW, mask); + if (d->fd == -1) { + usb_mtp_queue_result(s, RES_STORE_FULL, d->trans, + 0, 0, 0, 0); + goto done; + } - rc = write_retry(d->fd, d->data, d->offset); - if (rc != d->offset) { + /* Return success if initiator sent 0 sized data */ + if (!s->dataset.size) { + goto success; + } + if (d->length != MTP_WRITE_BUF_SZ && !d->pending) { + d->write_status = WRITE_END; + } + } + /* fall through */ + case WRITE_CONTINUE: + case WRITE_END: + rc = write_retry(d->fd, d->data, d->data_offset, + d->offset - d->data_offset); + if (rc != d->data_offset) { usb_mtp_queue_result(s, RES_STORE_FULL, d->trans, 0, 0, 0, 0); goto done; + } + if (d->write_status != WRITE_END) { + return; + } else { + /* Only for < 4G file sizes */ + if (s->dataset.size != 0xFFFFFFFF && d->offset != s->dataset.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 != 0xFFFFFFFF && rc != 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); } } @@ -1788,25 +1821,33 @@ static void usb_mtp_get_data(MTPState *s, mtp_container *container, d->offset = 0; d->first = false; d->pending = false; + d->data_offset = 0; + d->write_status = WRITE_START; } if (d->pending) { - usb_mtp_realloc(d, MTP_WRITE_BUF_SZ); - d->length += MTP_WRITE_BUF_SZ; + memset(d->data, 0, d->length); + if (d->length != MTP_WRITE_BUF_SZ) { + usb_mtp_realloc(d, MTP_WRITE_BUF_SZ - d->length); + d->length += (MTP_WRITE_BUF_SZ - d->length); + } d->pending = false; + d->write_status = WRITE_CONTINUE; + d->data_offset = 0; } - if (d->length - d->offset > data_len) { + if (d->length - d->data_offset > data_len) { dlen = data_len; } else { - dlen = d->length - d->offset; + dlen = d->length - d->data_offset; } 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 += dlen; - if (d->offset == d->length) { + d->data_offset += dlen; + if (d->data_offset == 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_container *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 += dlen; + d->data_offset += dlen; if ((p->iov.size % 64) || !p->iov.size) { assert((s->dataset.size == 0xFFFFFFFF) || (s->dataset.size == d->offset)); + if (d->length == MTP_WRITE_BUF_SZ) { + d->write_status = WRITE_END; + } else { + d->write_status = WRITE_START; + } usb_mtp_write_data(s); usb_mtp_data_free(s->data_out); s->data_out = NULL; return; } - if (d->offset == d->length) { + if (d->data_offset == d->length) { d->pending = true; + usb_mtp_write_data(s); } break; default: From patchwork Wed Jan 30 07:34:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 10787811 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9F40814E1 for ; Wed, 30 Jan 2019 07:41:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DDF82E019 for ; Wed, 30 Jan 2019 07:41:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8186C2E024; Wed, 30 Jan 2019 07:41:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 35C252E019 for ; Wed, 30 Jan 2019 07:41:33 +0000 (UTC) Received: from localhost ([127.0.0.1]:33595 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gokV2-0001sZ-3D for patchwork-qemu-devel@patchwork.kernel.org; Wed, 30 Jan 2019 02:41:32 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 *arr) /* 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 = size, ret; + uint64_t ret = 0; if (lseek(fd, offset, SEEK_SET) < 0) { goto done; } - while (bytes_left > 0) { - ret = write(fd, buf, bytes_left); - if ((ret == -1) && (errno != EINTR || errno != EAGAIN || - errno != EWOULDBLOCK)) { - break; - } - bytes_left -= ret; - buf += ret; - } + ret = qemu_write_full(fd, buf, size); done: - return size - bytes_left; + return ret; } static void usb_mtp_update_object(MTPObject *parent, char *name)