From patchwork Wed Nov 14 05:23:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 198828 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 46B1C2C008F for ; Wed, 14 Nov 2012 16:22:32 +1100 (EST) Received: from localhost ([::1]:42249 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYVQk-0002jF-8o for incoming@patchwork.ozlabs.org; Wed, 14 Nov 2012 00:22:30 -0500 Received: from eggs.gnu.org ([208.118.235.92]:39248) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYVQb-0002iz-D5 for qemu-devel@nongnu.org; Wed, 14 Nov 2012 00:22:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TYVQY-0007vT-B2 for qemu-devel@nongnu.org; Wed, 14 Nov 2012 00:22:21 -0500 Received: from ozlabs.org ([203.10.76.45]:57114) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYVQX-0007v7-W6 for qemu-devel@nongnu.org; Wed, 14 Nov 2012 00:22:18 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 174BA2C008C; Wed, 14 Nov 2012 16:22:13 +1100 (EST) From: David Gibson To: kraxel@redhat.com Date: Wed, 14 Nov 2012 16:23:50 +1100 Message-Id: <1352870630-18311-1-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 1.7.10.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 203.10.76.45 Cc: qemu-devel@nongnu.org, David Gibson Subject: [Qemu-devel] [PATCH] usb: Fix (another) bug in usb_packet_map() for IOMMU handling 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 Elements in qemu SGLists can cross IOMMU page boundaries. So, in commit 39c138c8420f51a7da7b35233a8d7400a0b589ac "usb: Fix usb_packet_map() in the presence of IOMMUs", I changed usb_packet_map() to split up each SGList element on IOMMU page boundaries and each resulting piece of qemu's memory space separately to the iovec the usb code uses internally. That was correct in concept, but the patch has a bug. The 'base' variable correctly steps through the dma address of each piece, but then we call the dma_memory_map() function on the base address of the whole SGList element every time. This patch fixes at least one problem using XHCI on the pseries guest machine. It didn't affect OHCI because that doesn't use usb_packet_map(). In theory it also affects EHCI, but we haven't observed that in practice. I think the transfers were small enough on EHCI that they never crossed an IOMMU page boundary in practice. Signed-off-by: David Gibson --- hw/usb/libhw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/usb/libhw.c b/hw/usb/libhw.c index 703e2d2..24d3cad 100644 --- a/hw/usb/libhw.c +++ b/hw/usb/libhw.c @@ -37,7 +37,7 @@ int usb_packet_map(USBPacket *p, QEMUSGList *sgl) while (len) { dma_addr_t xlen = len; - mem = dma_memory_map(sgl->dma, sgl->sg[i].base, &xlen, dir); + mem = dma_memory_map(sgl->dma, base, &xlen, dir); if (!mem) { goto err; }