From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751854AbcCVDR1 (ORCPT ); Mon, 21 Mar 2016 23:17:27 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:48710 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751056AbcCVDRZ (ORCPT ); Mon, 21 Mar 2016 23:17:25 -0400 From: Zhen Lei To: Catalin Marinas , Will Deacon , linux-arm-kernel , linux-kernel CC: Zefan Li , Xinwei Hu , "Tianhong Ding" , Hanjun Guo , Zhen Lei Subject: [PATCH v3 1/1] arm64/dma-mapping: reduce an unnecessary conversion for coherent DMA Date: Tue, 22 Mar 2016 11:18:29 +0800 Message-ID: <1458616709-21888-2-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1458616709-21888-1-git-send-email-thunder.leizhen@huawei.com> References: <1458616709-21888-1-git-send-email-thunder.leizhen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.177.23.164] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.56F0B943.006E,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 46a84f2cbdd3496d96972dd097d6a7ec Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 1.For coherent DMA In swiotlb_alloc_coherent, it directly return vaddr on success, and pass vaddr to free_pages on failure. So, we can directly transparent pass vaddr from __dma_free to swiotlb_free_coherent. According to my testing, it can save 8 clock cycles. 2.For non-coherent DMA. Keep no change for the original processing flow. Because all DDR memory mapped as cacheable by default. But for non-coherent devices, both CPUs and devices should use NC(non-cacheable) attributes to access memory, to keep consistency. So we can not directly use vaddr retured by __dma_alloc_coherent, but should further remap the physical memory as NC and return it. So in __dma_free, we first use the NC-vaddr to unmap, then get vaddr base upon dma_handle and use it to free memory back to buddy. Signed-off-by: Zhen Lei --- arch/arm64/mm/dma-mapping.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index a6e757c..ceb2018 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -187,16 +187,22 @@ static void __dma_free(struct device *dev, size_t size, void *vaddr, dma_addr_t dma_handle, struct dma_attrs *attrs) { - void *swiotlb_addr = phys_to_virt(dma_to_phys(dev, dma_handle)); - size = PAGE_ALIGN(size); if (!is_device_dma_coherent(dev)) { if (__free_from_pool(vaddr, size)) return; vunmap(vaddr); + + /* + * For non-coherent DMA, the vaddr is not part of the linear + * mapping as it has been remapped by __dma_alloc() via + * dma_common_contiguous_remap(), hence for swiotlb freeing we + * need the actual linear map address. + */ + vaddr = phys_to_virt(dma_to_phys(dev, dma_handle)); } - __dma_free_coherent(dev, size, swiotlb_addr, dma_handle, attrs); + __dma_free_coherent(dev, size, vaddr, dma_handle, attrs); } static dma_addr_t __swiotlb_map_page(struct device *dev, struct page *page, -- 2.5.0