From patchwork Thu Jan 19 18:39:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9526627 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3A51960113 for ; Thu, 19 Jan 2017 18:41:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 291EC25D99 for ; Thu, 19 Jan 2017 18:41:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19B11285F9; Thu, 19 Jan 2017 18:41:38 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 74B4C25D99 for ; Thu, 19 Jan 2017 18:41:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cUHcD-0004Gd-Lj; Thu, 19 Jan 2017 18:39:17 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cUHcD-0004GX-5P for xen-devel@lists.xenproject.org; Thu, 19 Jan 2017 18:39:17 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id CC/60-29113-4D701885; Thu, 19 Jan 2017 18:39:16 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrJIsWRWlGSWpSXmKPExsVybKJsh+5l9sY IgxmN+hbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bvG3eZC+byVcx5fYC1gfE5dxcjF4eQwFRG ibnX/7BDOLOZJHZsOgDkcHKwCGhL7NvynxHEZhMwlPj7ZBNbFyMHhwSQveQzB0hYREBJ4t6qy UwgvcwCzYwSLxfuAqsRFnCSePQkBsTkFfCWuLCKE6RcVEBX4tC/P2wgNq+AoMTJmU9YQGxmAS 2J5dO3gdkSAhkS83rmsELYXhKLblyCstUkrp7bxDyBkX8WkvZZSNoXMDKtYtQoTi0qSy3SNTT SSyrKTM8oyU3MzNE1NDDVy00tLk5MT81JTCrWS87P3cQIDDYGINjB2DfL+RCjJAeTkijv7o8N EUJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeFewNUYICRalpqdWpGXmAMMeJi3BwaMkwisCkuYtL kjMLc5Mh0idYtTlOHXj9EsmIZa8/LxUKXHe6SBFAiBFGaV5cCNgMXiJUVZKmJcR6CghnoLUot zMElT5V4ziHIxKwrzTQKbwZOaVwG16BXQEE9ARVsr1IEeUJCKkpBoYG08H20y1UxMw/avm05r Ubzjr5/O0Dcfbprd2O63a8PjxlIM711jkzdrguLRWIW2RSYyAwNTrPfPWvpjHa7x39tsHPK9E yovlPKXSustP7W8P9egTXjhxNufCgxO5vi2ZtvNnhkSwRj+3ZanAdVE+pwiBVx/5Dv6bJDSf6 U5Y8l//E5cWnZ2jpMRSnJFoqMVcVJwIAOAAWkq8AgAA X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-15.tower-206.messagelabs.com!1484851154!66815402!1 X-Originating-IP: [198.145.29.136] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5329 invoked from network); 19 Jan 2017 18:39:15 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.136) by server-15.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 19 Jan 2017 18:39:15 -0000 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 07A662060F; Thu, 19 Jan 2017 18:39:13 +0000 (UTC) Received: from [10.1.10.56] (96-82-76-110-static.hfc.comcastbusiness.net [96.82.76.110]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CC6632060A; Thu, 19 Jan 2017 18:39:11 +0000 (UTC) Date: Thu, 19 Jan 2017 10:39:09 -0800 (PST) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-X260 To: xen-devel@lists.xenproject.org Message-ID: User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP Cc: jgross@suse.com, Pooya.Keshavarzi@de.bosch.com, sstabellini@kernel.org, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com Subject: [Xen-devel] [PATCH] swiotlb-xen: update dev_addr after swapping pages X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP In xen_swiotlb_map_page and xen_swiotlb_map_sg_attrs, if the original page is not suitable, we swap it for another page from the swiotlb pool. In these cases, we don't update the previously calculated dma address for the page before calling xen_dma_map_page. Thus, we end up calling xen_dma_map_page passing the wrong dev_addr, resulting in xen_dma_map_page mistakenly assuming that the page is foreign when it is local. Fix the bug by updating dev_addr appropriately. This change has no effect on x86, because xen_dma_map_page is a stub there. Signed-off-by: Stefano Stabellini Signed-off-by: Pooya Keshavarzi Tested-by: Pooya Keshavarzi Reviewed-by: Boris Ostrovsky Acked-by: Konrad Rzeszutek Wilk diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index f905d6e..f8afc6d 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -414,9 +414,9 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, if (map == SWIOTLB_MAP_ERROR) return DMA_ERROR_CODE; + dev_addr = xen_phys_to_bus(map); xen_dma_map_page(dev, pfn_to_page(map >> PAGE_SHIFT), dev_addr, map & ~PAGE_MASK, size, dir, attrs); - dev_addr = xen_phys_to_bus(map); /* * Ensure that the address returned is DMA'ble @@ -575,13 +575,14 @@ void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, sg_dma_len(sgl) = 0; return 0; } + dev_addr = xen_phys_to_bus(map); xen_dma_map_page(hwdev, pfn_to_page(map >> PAGE_SHIFT), dev_addr, map & ~PAGE_MASK, sg->length, dir, attrs); - sg->dma_address = xen_phys_to_bus(map); + sg->dma_address = dev_addr; } else { /* we are not interested in the dma_addr returned by * xen_dma_map_page, only in the potential cache flushes executed