Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2734622yba; Mon, 22 Apr 2019 11:59:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqzjrfS3Kb0Z3EhmbCEDDjlwTdRaaP82dQnp3rTGGIN2coQkl7sCof9ml1X18TNpzdUiNBTz X-Received: by 2002:a17:902:a50d:: with SMTP id s13mr21724376plq.58.1555959591116; Mon, 22 Apr 2019 11:59:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555959591; cv=none; d=google.com; s=arc-20160816; b=01LZJJffhZ87rwmBU9kjW9T0iK+sBFLns0K1qOv/rLSZ2pRpXnUb+SkX+1lahqH5cd 30oLO9DoR2xioWg3iKsImjJecYSiqQmCRS1LkP91u3bXixLmkMKMIAGpkW3RjaA1YhPV oL9hYyTfFLxrYzfuAr3t4u+oudWG6p8d1q6dt4F0lxiblKluXhwTskiheBWjttcL2eEZ eirX36eYnQC41qeuHU9j03iekJPY5y+DHbcABDwayie+0z8bsOVTaEAY2Y+MVluQslsp 2mO0+CXLioi+7qO9T4irdJymdM7BjulL54myNWTVnwfJ/+55CA9CledVBBhiT84SeWZD rc/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Xc4vgRNOU6UqrzSfhO5+HE+B0ex/Pov896FW0iTW8qs=; b=UzdRhQmOMRZuLqW4v1zDPfUJGwW2wvQRpH+jbGj5P5v7tPxzR6aKJVnkcS+GBght5x ZLnt4wFPeY8qpS2WX3Dlxp73gBm4E00ddz89lFJ4zQ89Lp0JqQktlpNbkvu0ExmjJRcN msQF0nGn2i9d8/umD0nqhEx3J/d41UmTLjEPxj68XM7fQAiSng5jsvzD33vbUnYN5Pwy KjH9CQ0ruAIzlvNpFonr0dAeVPKIVbJM8sJ77j6B4fZEcVj5pXUiUa3NSRXEKXAg3tab 2tR2YOS1uzGSI5M/EgimyEjg1BN13+7jWT57xeTc2ZkZmk/nEfpLvK3LsjZEQkk2RVDL 03RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Jq14eyBl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a190si13061675pge.88.2019.04.22.11.59.35; Mon, 22 Apr 2019 11:59:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Jq14eyBl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728592AbfDVSA7 (ORCPT + 99 others); Mon, 22 Apr 2019 14:00:59 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:39142 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728583AbfDVSA5 (ORCPT ); Mon, 22 Apr 2019 14:00:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Xc4vgRNOU6UqrzSfhO5+HE+B0ex/Pov896FW0iTW8qs=; b=Jq14eyBlILIJE9JszGK9VIbBFv eAdpXiTZF5ZPowlH1wauH8pxPy3AjiHXyT1Z4i9Q4/FiRwatfeCUWzXhRQToF5+cBx3FFz3sUCr/d 7z3CCE5H5T7fGRZAZ3l54tDexjkL9O/AoozcFdyJB61Gb3HaNpsBtqFNh3vdVq2/X77l0qtagQjXD GB3yuPE98Am6lcFGXUsj5gP0ZlJxR0dcAXnctt0aZOhRgjfqy8mBKlJxG/Bkam3l2lJIf6Vvtf/6h S16yaTgYkAsU3d7xN7vsJGgSO+mdPwysRcJS/J5BVDFHzC7sG3nIUBBDzfjjTr54ZTuIUaBMFM2gh RJsPTuzw==; Received: from 213-225-37-80.nat.highway.a1.net ([213.225.37.80] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hIdFK-0002EQ-5A; Mon, 22 Apr 2019 18:00:50 +0000 From: Christoph Hellwig To: Robin Murphy Cc: Joerg Roedel , Catalin Marinas , Will Deacon , Tom Lendacky , iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 16/26] iommu/dma: Don't remap CMA unnecessarily Date: Mon, 22 Apr 2019 19:59:32 +0200 Message-Id: <20190422175942.18788-17-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190422175942.18788-1-hch@lst.de> References: <20190422175942.18788-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Robin Murphy Always remapping CMA allocations was largely a bodge to keep the freeing logic manageable when it was split between here and an arch wrapper. Now that it's all together and streamlined, we can relax that limitation. Signed-off-by: Robin Murphy Signed-off-by: Christoph Hellwig --- drivers/iommu/dma-iommu.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 504dd27312bb..6f4febf5e1de 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -956,7 +956,6 @@ static void *iommu_dma_alloc(struct device *dev, size_t size, { bool coherent = dev_is_dma_coherent(dev); int ioprot = dma_info_to_prot(DMA_BIDIRECTIONAL, coherent, attrs); - pgprot_t prot = arch_dma_mmap_pgprot(dev, PAGE_KERNEL, attrs); size_t iosize = size; struct page *page; void *addr; @@ -1004,13 +1003,19 @@ static void *iommu_dma_alloc(struct device *dev, size_t size, if (*handle == DMA_MAPPING_ERROR) goto out_free_pages; - addr = dma_common_contiguous_remap(page, size, VM_USERMAP, prot, - __builtin_return_address(0)); - if (!addr) - goto out_unmap; + if (!coherent || PageHighMem(page)) { + pgprot_t prot = arch_dma_mmap_pgprot(dev, PAGE_KERNEL, attrs); - if (!coherent) - arch_dma_prep_coherent(page, iosize); + addr = dma_common_contiguous_remap(page, size, VM_USERMAP, prot, + __builtin_return_address(0)); + if (!addr) + goto out_unmap; + + if (!coherent) + arch_dma_prep_coherent(page, iosize); + } else { + addr = page_address(page); + } memset(addr, 0, size); return addr; out_unmap: -- 2.20.1