From patchwork Sat Nov 19 09:22:46 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 126531 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1D2A8B7233 for ; Sat, 19 Nov 2011 20:22:58 +1100 (EST) Received: from localhost ([::1]:42716 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RRh8R-0000gX-Km for incoming@patchwork.ozlabs.org; Sat, 19 Nov 2011 04:22:55 -0500 Received: from eggs.gnu.org ([140.186.70.92]:34082) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RRh7t-0007hu-7c for qemu-devel@nongnu.org; Sat, 19 Nov 2011 04:22:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RRh7s-0008Aq-4V for qemu-devel@nongnu.org; Sat, 19 Nov 2011 04:22:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43575) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RRh7r-0008Aa-Se for qemu-devel@nongnu.org; Sat, 19 Nov 2011 04:22:20 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pAJ9MJS7011587 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 19 Nov 2011 04:22:19 -0500 Received: from shalem.localdomain.com (vpn1-6-161.ams2.redhat.com [10.36.6.161]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pAJ9MCq2032695; Sat, 19 Nov 2011 04:22:18 -0500 From: Hans de Goede To: Gerd Hoffmann Date: Sat, 19 Nov 2011 10:22:46 +0100 Message-Id: <1321694567-2855-5-git-send-email-hdegoede@redhat.com> In-Reply-To: <1321694567-2855-1-git-send-email-hdegoede@redhat.com> References: <1321694567-2855-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Cc: Hans de Goede , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 4/5] usb-redir: Device disconnect + re-connect robustness fixes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org These fixes mainly target the other side sending some (error status) packets after a disconnect packet. In some cases these would get queued up and then reported to the controller when a new device gets connected. * Fully reset device state on disconnect * Don't allow a connect message when already connected * Ignore iso and interrupt status messages when disconnected Signed-off-by: Hans de Goede --- usb-redir.c | 22 +++++++++++++++++++++- 1 files changed, 21 insertions(+), 1 deletions(-) diff --git a/usb-redir.c b/usb-redir.c index 9e13410..24fdd31 100644 --- a/usb-redir.c +++ b/usb-redir.c @@ -881,6 +881,11 @@ static void usbredir_device_connect(void *priv, { USBRedirDevice *dev = priv; + if (qemu_timer_pending(dev->attach_timer) || dev->dev.attached) { + ERROR("Received device connect while already connected\n"); + return; + } + switch (device_connect->speed) { case usb_redir_speed_low: DPRINTF("attaching low speed device\n"); @@ -909,19 +914,26 @@ static void usbredir_device_connect(void *priv, static void usbredir_device_disconnect(void *priv) { USBRedirDevice *dev = priv; + int i; /* Stop any pending attaches */ qemu_del_timer(dev->attach_timer); if (dev->dev.attached) { usb_device_detach(&dev->dev); - usbredir_cleanup_device_queues(dev); /* * Delay next usb device attach to give the guest a chance to see * see the detach / attach in case of quick close / open succession */ dev->next_attach_time = qemu_get_clock_ms(vm_clock) + 200; } + + /* Reset state so that the next dev connected starts with a clean slate */ + usbredir_cleanup_device_queues(dev); + memset(dev->endpoint, 0, sizeof(dev->endpoint)); + for (i = 0; i < MAX_ENDPOINTS; i++) { + QTAILQ_INIT(&dev->endpoint[i].bufpq); + } } static void usbredir_interface_info(void *priv, @@ -1013,6 +1025,10 @@ static void usbredir_iso_stream_status(void *priv, uint32_t id, DPRINTF("iso status %d ep %02X id %u\n", iso_stream_status->status, ep, id); + if (!dev->dev.attached) { + return; + } + dev->endpoint[EP2I(ep)].iso_error = iso_stream_status->status; if (iso_stream_status->status == usb_redir_stall) { DPRINTF("iso stream stopped by peer ep %02X\n", ep); @@ -1030,6 +1046,10 @@ static void usbredir_interrupt_receiving_status(void *priv, uint32_t id, DPRINTF("interrupt recv status %d ep %02X id %u\n", interrupt_receiving_status->status, ep, id); + if (!dev->dev.attached) { + return; + } + dev->endpoint[EP2I(ep)].interrupt_error = interrupt_receiving_status->status; if (interrupt_receiving_status->status == usb_redir_stall) {