From patchwork Mon Jan 20 10:52:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 23371 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f70.google.com (mail-pb0-f70.google.com [209.85.160.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EB4D7218CB for ; Mon, 20 Jan 2014 10:54:40 +0000 (UTC) Received: by mail-pb0-f70.google.com with SMTP id rq2sf8581128pbb.9 for ; Mon, 20 Jan 2014 02:54:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id :mime-version:cc:subject:precedence:list-id:list-unsubscribe :list-post:list-help:list-subscribe:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=Nildk/O4pkc6RKSTT0mmZKk6rh43WCVA0IUeD/Z0gys=; b=MyrJo8J2c/NZNz1LLycf2azdKZ2Mc2WGn9JZrxTZIOKVfBNDMSFXveKhiw7EC/UwW3 zD+V+E+GcrMMzZHZ0sc1TH145BIw2oeJ6UoTsd97MvGiim/6EjHUQVA55nOAZOFp49kn 9xvbissk/QeLn29vhohWsI8QxUm5dSZEIOH3M85xhUuu/zktMWGyMC0SkUX4yDFBiHdP 6+ClPKGVKO4momviJCX80aj3mxUuXdgCG1Mkj8l2qws81iUQiWYmXLohhwvMKWOFGSkS tN6LH5/dJDT9rtM3XRbXNztiemdgtMPqK0cwRiNKoih/vuPdIcqNfuDq4aqNiZ2YKQpY lqSQ== X-Gm-Message-State: ALoCoQnp7jMrxxvHBcwuw0fmikuHiHV9QXecPlllFKtbBO2g0f78Qdd3mFLGG8iBTOO8U9orDENq X-Received: by 10.66.227.103 with SMTP id rz7mr6018242pac.37.1390215280047; Mon, 20 Jan 2014 02:54:40 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.13.33 with SMTP id e1ls1722214qec.2.gmail; Mon, 20 Jan 2014 02:54:39 -0800 (PST) X-Received: by 10.221.34.211 with SMTP id st19mr10123219vcb.5.1390215279899; Mon, 20 Jan 2014 02:54:39 -0800 (PST) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id k6si214839veh.17.2014.01.20.02.54.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 20 Jan 2014 02:54:39 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id lf12so2767272vcb.3 for ; Mon, 20 Jan 2014 02:54:39 -0800 (PST) X-Received: by 10.220.164.80 with SMTP id d16mr9879280vcy.15.1390215279798; Mon, 20 Jan 2014 02:54:39 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp51657vcz; Mon, 20 Jan 2014 02:54:39 -0800 (PST) X-Received: by 10.140.22.41 with SMTP id 38mr24715964qgm.59.1390215279200; Mon, 20 Jan 2014 02:54:39 -0800 (PST) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id e7si378609qga.166.2014.01.20.02.54.38 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 20 Jan 2014 02:54:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xen.org designates 50.57.142.19 as permitted sender) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1W5CTQ-0000av-3B; Mon, 20 Jan 2014 10:52:56 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1W5CTN-0000aq-R7 for xen-devel@lists.xen.org; Mon, 20 Jan 2014 10:52:54 +0000 Received: from [85.158.143.35:29161] by server-2.bemta-4.messagelabs.com id CB/9C-11386-5000DD25; Mon, 20 Jan 2014 10:52:53 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-3.tower-21.messagelabs.com!1390215171!12728912!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n X-StarScan-Received: X-StarScan-Version: 6.9.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3934 invoked from network); 20 Jan 2014 10:52:52 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-3.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 20 Jan 2014 10:52:52 -0000 X-IronPort-AV: E=Sophos;i="4.95,689,1384300800"; d="scan'208";a="94439337" Received: from accessns.citrite.net (HELO FTLPEX01CL02.citrite.net) ([10.9.154.239]) by FTLPIPO01.CITRIX.COM with ESMTP; 20 Jan 2014 10:52:50 +0000 Received: from norwich.cam.xci-test.com (10.80.248.129) by smtprelay.citrix.com (10.13.107.79) with Microsoft SMTP Server id 14.2.342.4; Mon, 20 Jan 2014 05:52:50 -0500 Received: from drall.uk.xensource.com ([10.80.16.71] helo=drall.uk.xensource.com.) by norwich.cam.xci-test.com with esmtp (Exim 4.72) (envelope-from ) id 1W5CTJ-0008EC-9X; Mon, 20 Jan 2014 10:52:49 +0000 From: Ian Campbell To: Date: Mon, 20 Jan 2014 10:52:48 +0000 Message-ID: <1390215168-23269-1-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 X-DLP: MIA1 Cc: Ian Campbell , stefano.stabellini@eu.citrix.com Subject: [Xen-devel] [PATCH v2] xen: swiotlb: handle sizeof(dma_addr_t) != sizeof(phys_addr_t) X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ian.campbell@citrix.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: The use of phys_to_machine and machine_to_phys in the phys<=>bus conversions causes us to lose the top bits of the DMA address if the size of a DMA address is not the same as the size of the phyiscal address. This can happen in practice on ARM where foreign pages can be above 4GB even though the local kernel does not have LPAE page tables enabled (which is totally reasonable if the guest does not itself have >4GB of RAM). In this case the kernel still maps the foreign pages at a phys addr below 4G (as it must) but the resulting DMA address (returned by the grant map operation) is much higher. This is analogous to a hardware device which has its view of RAM mapped up high for some reason. This patch makes I/O to foreign pages (specifically blkif) work on 32-bit ARM systems with more than 4GB of RAM. Signed-off-by: Ian Campbell Acked-by: Stefano Stabellini --- v2: Add comment on avoiding PFN_PHYS, and remove accidental truncation due to it in xen_bus_to_phys. --- arch/arm/Kconfig | 1 + drivers/xen/swiotlb-xen.c | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index c1f1a7e..24307dc 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1885,6 +1885,7 @@ config XEN depends on !GENERIC_ATOMIC64 select ARM_PSCI select SWIOTLB_XEN + select ARCH_DMA_ADDR_T_64BIT help Say Y if you want to run Linux in a Virtual Machine on Xen on ARM. diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 1eac073..ebd8f21 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -75,14 +75,32 @@ static unsigned long xen_io_tlb_nslabs; static u64 start_dma_addr; +/* + * Both of these functions should avoid PFN_PHYS because phys_addr_t + * can be 32bit when dma_addr_t is 64bit leading to a loss in + * information if the shift is done before casting to 64bit. + */ static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr) { - return phys_to_machine(XPADDR(paddr)).maddr; + unsigned long mfn = pfn_to_mfn(PFN_DOWN(paddr)); + dma_addr_t dma = (dma_addr_t)mfn << PAGE_SHIFT; + + dma |= paddr & ~PAGE_MASK; + + return dma; } static inline phys_addr_t xen_bus_to_phys(dma_addr_t baddr) { - return machine_to_phys(XMADDR(baddr)).paddr; + unsigned long pfn = mfn_to_pfn(PFN_DOWN(baddr)); + dma_addr_t dma = (dma_addr_t)pfn << PAGE_SHIFT; + phys_addr_t paddr = dma; + + BUG_ON(paddr != dma); /* truncation has occurred, should never happen */ + + paddr |= baddr & ~PAGE_MASK; + + return paddr; } static inline dma_addr_t xen_virt_to_bus(void *address)