From patchwork Mon Jan 20 11:30:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 23373 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-gg0-f198.google.com (mail-gg0-f198.google.com [209.85.161.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5DD74203C6 for ; Mon, 20 Jan 2014 11:31:28 +0000 (UTC) Received: by mail-gg0-f198.google.com with SMTP id x14sf10943753ggx.9 for ; Mon, 20 Jan 2014 03:31:27 -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:subject:date:message-id :mime-version:cc:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=/+TLg5iKaCpJytqvozf+PRA9vxqVvSU0X/bpO4I3Fmo=; b=eL7jCwxpZKvO6JdAmOXRbDfAIzL6wgALi3XHLi07EBs62bLLhm5Pev9/I1FZWWL+ea grmPk3vUKk0C2RThU1ztPUJqxTUizdYYifETH97wJUsHNii8MsUH3KHd62/ovmnMuJaU nniQikKuWavUVdxCGDqrpm9hKJ1nNcMS6KQwqQCCvqbOzwmF7fiRHi9z572kYWdw45F+ c1WwZvS33l6/TNJddpLpwHDBzf+MZkrSRU0lH2gPsN5nBMkdhCSE+KNxZWIIy57HCRSI c0KSAPFYGGJpSmKJMd2aKDMIiACb83yEIBfQqL7yui2BiKvz5c33yMohQ8E9V4PVJJob ENJA== X-Gm-Message-State: ALoCoQlbMl2dDcsIiv52vDWetPCbtix4fsMTNO7S1IjU+KYoWBqd1vUH9xKYkh98gNMptkOJfjgT X-Received: by 10.236.149.198 with SMTP id x46mr6088095yhj.7.1390217487595; Mon, 20 Jan 2014 03:31:27 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.84.102 with SMTP id k93ls1076182qgd.73.gmail; Mon, 20 Jan 2014 03:31:27 -0800 (PST) X-Received: by 10.52.251.68 with SMTP id zi4mr1077571vdc.25.1390217487375; Mon, 20 Jan 2014 03:31:27 -0800 (PST) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id n10si245821vcf.3.2014.01.20.03.31.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 20 Jan 2014 03:31:27 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.174; Received: by mail-ve0-f174.google.com with SMTP id pa12so756934veb.19 for ; Mon, 20 Jan 2014 03:31:27 -0800 (PST) X-Received: by 10.58.75.6 with SMTP id y6mr20369vev.23.1390217487291; Mon, 20 Jan 2014 03:31:27 -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 u4csp52956vcz; Mon, 20 Jan 2014 03:31:26 -0800 (PST) X-Received: by 10.194.61.84 with SMTP id n20mr1189216wjr.61.1390217486057; Mon, 20 Jan 2014 03:31:26 -0800 (PST) Received: from casper.infradead.org (casper.infradead.org. [2001:770:15f::2]) by mx.google.com with ESMTPS id jd17si124571wic.47.2014.01.20.03.31.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jan 2014 03:31:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:770:15f::2 as permitted sender) client-ip=2001:770:15f::2; Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W5D4T-0003RC-4W; Mon, 20 Jan 2014 11:31:13 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1W5D4Q-0002mQ-Jl; Mon, 20 Jan 2014 11:31:10 +0000 Received: from smtp02.citrix.com ([66.165.176.63]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W5D4N-0002l4-G6 for linux-arm-kernel@lists.infradead.org; Mon, 20 Jan 2014 11:31:08 +0000 X-IronPort-AV: E=Sophos;i="4.95,689,1384300800"; d="scan'208";a="92362589" Received: from accessns.citrite.net (HELO FTLPEX01CL02.citrite.net) ([10.9.154.239]) by FTLPIPO02.CITRIX.COM with ESMTP; 20 Jan 2014 11:30:43 +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 06:30:43 -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 1W5D3x-0008Pa-Rs; Mon, 20 Jan 2014 11:30:41 +0000 From: Ian Campbell To: Subject: [PATCH v3] xen: swiotlb: handle sizeof(dma_addr_t) != sizeof(phys_addr_t) Date: Mon, 20 Jan 2014 11:30:41 +0000 Message-ID: <1390217441-9910-1-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 X-DLP: MIA1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140120_063107_653004_6F3B47E3 X-CRM114-Status: GOOD ( 16.11 ) X-Spam-Score: -3.2 (---) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-3.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [66.165.176.63 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.6 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Konrad Rzeszutek Wilk , Russell King , Ian Campbell , linux-arm-kernel@lists.infradead.org, stefano.stabellini@eu.citrix.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.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.128.174 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 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 Cc: Russell King Cc: Konrad Rzeszutek Wilk Cc: linux-arm-kernel@lists.infradead.org --- v3: Added Stefano's ack, added accidentally forgotten Ccs to Russell and l-a-k. 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)