From patchwork Fri Jan 17 17:24:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 23355 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0324E203C6 for ; Fri, 17 Jan 2014 19:01:13 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id gq1sf9000692obb.8 for ; Fri, 17 Jan 2014 11:01:13 -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=YgzcFAVTkJJMNglJotMV+8xJsL4+oOubNDBoJ/mhq3w=; b=CihSI7e6fkqQQMYZBVaGGxhzZi9ZqXeg7s0N6Dy2DCNZACRARzDf6irZ9Of1b/8Xtp l4ai7MmTU+IRW3drPN59eR7sKr5CA9xb+Ua4eQnDkCxYNX6HdwyU0mttHEnnl9/exa/1 km2YRlzryJss4fo/ejQeRznJtmwqFd4Zk6AQZqPdqXNLvd8Dsbs3aEXgiF84h2zC/5gS xmnjKjs8t++xqprZyUIntVCztHhV1tK064xhFErGH3O9J7sQBaxzuq1aMJDT6ghChQ4U Ohmpf4SffVT95nC6L+euuILmtTFvQGiTRyIxUScL/+U9g25lyq50VnCoKZkTRAyhahiV UZIw== X-Gm-Message-State: ALoCoQltTIjVL90Skha3V6/H25Kh/2ywGq956zvL5xAO2xR4WWrEAwarDCf0KXTCtJkaam2WDPb0 X-Received: by 10.182.121.39 with SMTP id lh7mr1318686obb.46.1389985273129; Fri, 17 Jan 2014 11:01:13 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.44.102 with SMTP id f93ls530508qga.75.gmail; Fri, 17 Jan 2014 11:01:12 -0800 (PST) X-Received: by 10.58.50.71 with SMTP id a7mr1641922veo.32.1389985272840; Fri, 17 Jan 2014 11:01:12 -0800 (PST) Received: from mail-vb0-f51.google.com (mail-vb0-f51.google.com [209.85.212.51]) by mx.google.com with ESMTPS id qi8si5272383vec.31.2014.01.17.11.01.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 17 Jan 2014 11:01:12 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.51 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.51; Received: by mail-vb0-f51.google.com with SMTP id 11so1694481vbe.24 for ; Fri, 17 Jan 2014 11:01:12 -0800 (PST) X-Received: by 10.58.196.211 with SMTP id io19mr1657217vec.9.1389985272754; Fri, 17 Jan 2014 11:01:12 -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.59.13.131 with SMTP id ey3csp41413ved; Fri, 17 Jan 2014 11:01:12 -0800 (PST) X-Received: by 10.43.163.3 with SMTP id mm3mr3092412icc.63.1389985271944; Fri, 17 Jan 2014 11:01:11 -0800 (PST) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id ft5si4434962igd.50.2014.01.17.11.01.11 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 17 Jan 2014 11:01:11 -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 1W4DAC-00088a-Qx; Fri, 17 Jan 2014 17:25:00 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1W4DAB-00088V-F0 for xen-devel@lists.xen.org; Fri, 17 Jan 2014 17:24:59 +0000 Received: from [85.158.143.35:14037] by server-1.bemta-4.messagelabs.com id 4A/CB-02132-A6769D25; Fri, 17 Jan 2014 17:24:58 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-3.tower-21.messagelabs.com!1389979496!12425083!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 32726 invoked from network); 17 Jan 2014 17:24:58 -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; 17 Jan 2014 17:24:58 -0000 X-IronPort-AV: E=Sophos;i="4.95,675,1384300800"; d="scan'208";a="93942714" Received: from accessns.citrite.net (HELO FTLPEX01CL03.citrite.net) ([10.9.154.239]) by FTLPIPO01.CITRIX.COM with ESMTP; 17 Jan 2014 17:24:55 +0000 Received: from norwich.cam.xci-test.com (10.80.248.129) by smtprelay.citrix.com (10.13.107.80) with Microsoft SMTP Server id 14.2.342.4; Fri, 17 Jan 2014 12:24:55 -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 1W4DA6-0004fm-C0; Fri, 17 Jan 2014 17:24:54 +0000 From: Ian Campbell To: Date: Fri, 17 Jan 2014 17:24:53 +0000 Message-ID: <1389979493-22670-1-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 X-DLP: MIA2 Cc: Ian Campbell , stefano.stabellini@eu.citrix.com Subject: [Xen-devel] [PATCH] 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.212.51 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 --- arch/arm/Kconfig | 1 + drivers/xen/swiotlb-xen.c | 14 ++++++++++++-- 2 files changed, 13 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..b626c79 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -77,12 +77,22 @@ static u64 start_dma_addr; 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; + dma_addr_t dma = PFN_PHYS(mfn_to_pfn(PFN_DOWN(baddr))); + 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)