Received: by 2002:a19:ee01:0:0:0:0:0 with SMTP id g1csp1326422lfb; Thu, 14 May 2020 05:29:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyVdLaDg4m3kGGLnNPbv0mBQZKv7OqMefnG776rOusFaeh47KagzN38M6F7lPGaB+biwhL X-Received: by 2002:a37:6253:: with SMTP id w80mr4382524qkb.132.1589459388761; Thu, 14 May 2020 05:29:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589459388; cv=none; d=google.com; s=arc-20160816; b=q+VyiNGvURalkjBumYYiIRP93QsnfLZg+Gt/DYHBZuamxlzAjtk4AUQURCoHU4yiMZ ZfypER/kQfVYNCzJYzYpTvG60yCcoOpMjxSotct69soTwu1x02jVNM6SWkcauJFOtzEr 4bGYVLS8l/gBmtyyCSW+ub/ulJ0EER1Xx/eNTniVXI134xj2L2k0TUF3lq7VWD6INMq1 twArlOvh6YrOaTT0Qdfvb1geOG3m0YXob2d8EYh0UaOHE3sARVZpdFtex7AajR5GMbOd cQQgqcaTAlKhStiLJTtgihhzUP+eIgOp98NobgPWufXAJZp74ZUrw4G/ubifKYkThKaE nExA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=izjIFur53yZHrqhcINIPf0xUP0mig0YAPM3oF3SDqYA=; b=kuUSMgkHyKuUgH2Msdwocxpr2XyDbB01d0bD+nhuZCBCWa7S+nHGdjIz3msxOnIVr9 A5WI1XQg+Z6GR6TOL8ihNuwJFAZVF1vq+p0HvIvOjhbY34mSm0cmsL2qwiN8HSR9r1JS gkVSW/HLB9lib07HtVPGclxrr9uWp2isxuR7oZjnehj30bRUmPfmRelorp+iU3GRA1iT ep+deRSBTK3kJs+m/wqHE3zFOFSBA1IRoPUVESYDf7grSpEnZkuAwtj1oWU8wuoYWEAj cxhxCsy/TGb3JiTSbUpHzxU0GzcpD9p46NpQnLsb/0zDrWj2UTsxMweqwz2fcATpf5+O 4dIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=cGe81opL; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p17si1367652qkh.184.2020.05.14.05.29.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 May 2020 05:29:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=cGe81opL; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:46842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZCzk-0003V6-5u for alex.bennee@linaro.org; Thu, 14 May 2020 08:29:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZCty-0001jF-60 for qemu-arm@nongnu.org; Thu, 14 May 2020 08:23:50 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:32168 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZCtw-0003aY-DY for qemu-arm@nongnu.org; Thu, 14 May 2020 08:23:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589459027; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type:in-reply-to:in-reply-to: references:references; bh=izjIFur53yZHrqhcINIPf0xUP0mig0YAPM3oF3SDqYA=; b=cGe81opLHSGNzX0sKYbfTWxJRn3C/O+Prs1d349iqFIzhiW4IGRQWOay5Qm8iNSjMoPlGQ Cau/RhGWjEJANBEPjmRBM7YxquWb9HuqNN1O/MgDvWSKtw76IWl/u7CMcBjScseFYi+vUo Md8lAW4heNpjmuaaVZ61FBIPCRRQDtU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-272-E9iZBim5N7a3IJeWCYkTwQ-1; Thu, 14 May 2020 08:23:45 -0400 X-MC-Unique: E9iZBim5N7a3IJeWCYkTwQ-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 66BD31902EA4; Thu, 14 May 2020 12:23:44 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-115-145.ams2.redhat.com [10.36.115.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8F1176E64; Thu, 14 May 2020 12:23:40 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id DF9539DAE; Thu, 14 May 2020 14:23:34 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 5/7] usb: add short-packet handling to usb-storage driver Date: Thu, 14 May 2020 14:23:32 +0200 Message-Id: <20200514122334.25089-6-kraxel@redhat.com> In-Reply-To: <20200514122334.25089-1-kraxel@redhat.com> References: <20200514122334.25089-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Received-SPF: pass client-ip=205.139.110.61; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Baumann , Paul Zimmerman , qemu-arm@nongnu.org, Gerd Hoffmann , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: HKBXQR4ytZNq From: Paul Zimmerman The dwc-hsotg (dwc2) USB host depends on a short packet to indicate the end of an IN transfer. The usb-storage driver currently doesn't provide this, so fix it. I have tested this change rather extensively using a PC emulation with xhci, ehci, and uhci controllers, and have not observed any regressions. Signed-off-by: Paul Zimmerman Message-id: 20200512064900.28554-6-pauldzim@gmail.com Signed-off-by: Gerd Hoffmann --- hw/usb/dev-storage.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index 5c4b57b06b6f..ae3c5500424f 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -229,6 +229,9 @@ static void usb_msd_copy_data(MSDState *s, USBPacket *p) usb_packet_copy(p, scsi_req_get_buf(s->req) + s->scsi_off, len); s->scsi_len -= len; s->scsi_off += len; + if (len > s->data_len) { + len = s->data_len; + } s->data_len -= len; if (s->scsi_len == 0 || s->data_len == 0) { scsi_req_continue(s->req); @@ -303,6 +306,9 @@ static void usb_msd_command_complete(SCSIRequest *req, uint32_t status, size_t r if (s->data_len) { int len = (p->iov.size - p->actual_length); usb_packet_skip(p, len); + if (len > s->data_len) { + len = s->data_len; + } s->data_len -= len; } if (s->data_len == 0) { @@ -469,6 +475,9 @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket *p) int len = p->iov.size - p->actual_length; if (len) { usb_packet_skip(p, len); + if (len > s->data_len) { + len = s->data_len; + } s->data_len -= len; if (s->data_len == 0) { s->mode = USB_MSDM_CSW; @@ -528,13 +537,17 @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket *p) int len = p->iov.size - p->actual_length; if (len) { usb_packet_skip(p, len); + if (len > s->data_len) { + len = s->data_len; + } s->data_len -= len; if (s->data_len == 0) { s->mode = USB_MSDM_CSW; } } } - if (p->actual_length < p->iov.size) { + if (p->actual_length < p->iov.size && (p->short_not_ok || + s->scsi_len >= p->ep->max_packet_size)) { DPRINTF("Deferring packet %p [wait data-in]\n", p); s->packet = p; p->status = USB_RET_ASYNC; -- 2.18.4