Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2908233pxa; Tue, 18 Aug 2020 00:53:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTC9g2cphE0jMIw1zwBypjW9LLSDq25GHVTpz+oukQArQl1qKOZRpEx3TcOoeAaauxTtwX X-Received: by 2002:a17:906:46c6:: with SMTP id k6mr17964985ejs.230.1597737221538; Tue, 18 Aug 2020 00:53:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597737221; cv=none; d=google.com; s=arc-20160816; b=CQ1fqGj4Nj2UmUQLTAmMgprcsytgQfljxl9Q+0elefX2KKHTrPCJWewa7kgDDJkAnc Ty71gs2tUXY4e0vFJG/cYz/3GjfzP7uPHP9tmAZdJ1BmdMRK8YOq7qZEXnzbAJizsuO8 mQ+mrhxCZq9GS7cnrs6V7nrAT88eJQYolGiAm4QTqSfcwWtxz7jvWAgcj8XNpBweSpMa 1cegDuVyfOlhLtt+x5t80Zq54bGk7rLS5qrBK5Yf0/oXt0MS7AqEbWPkeGJauP/TPp3e SooEmzD6nxj/l7sg/t2Qnmel+upnLgf/QoTZhdpIiYux8PenmggikaCNiHEfobdYOOOK qk3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=NwOlS5cnBe1k4GJDW5Zv0HRcItTMtAfl5az4Un8KkCs=; b=asSwVYmA5pbUNU0WnHznnLbKj2x8Q+6Lsy4qOgnMUBdcf86XQ4twgZ+pX1MxETB715 vEgmSmbmDJ/eZy4JPtghDKWSIfEZyDUkLyizcp84fbw+cPCFdinHaZ3Itv05zeKqLcLZ uMdwN0wTlBEyvaXqz+Ry/hVk61eUpgYQ2KAopzTCXPDFoE0AL8ABMeUlW5oX1WLRjdtU 9HDHFBpp/jqT7muq951KZlsqjGlncyFbDvr3RMSyhlYC/a+UCaXZSZOYUPzAEoIMAOJt gaVY1e41ftphBEcoEa102369/oGn1ABR5BantgizGz/D58t51Yk5a9gfHT0ogRH7s/Sd e23g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=Oz+SgBPA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lk1si12980586ejb.504.2020.08.18.00.53.17; Tue, 18 Aug 2020 00:53:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=Oz+SgBPA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726593AbgHRHvD (ORCPT + 99 others); Tue, 18 Aug 2020 03:51:03 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:33639 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726203AbgHRHu7 (ORCPT ); Tue, 18 Aug 2020 03:50:59 -0400 Received: from epcas2p1.samsung.com (unknown [182.195.41.53]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20200818075055epoutp01dcd98a9a318a4e4029e6eb6537831934~sTWMgdYtq1582415824epoutp01W for ; Tue, 18 Aug 2020 07:50:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20200818075055epoutp01dcd98a9a318a4e4029e6eb6537831934~sTWMgdYtq1582415824epoutp01W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1597737055; bh=NwOlS5cnBe1k4GJDW5Zv0HRcItTMtAfl5az4Un8KkCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Oz+SgBPAdERFLHiA9ZsNCB1Msc7eDbYKaAx/JWym7tT7kuTAweDDbYEekpM+MEXMP 8zyglECU4MFLlIbx8TcikAnYJs4K9lrkXRTdXYuLC9E9/GKIPNJRJdEVqxcx4Mk9IE cCp3MvuzKkE/yOXxDG0tHR018OauIglgMyUF7mA8= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas2p4.samsung.com (KnoxPortal) with ESMTP id 20200818075055epcas2p435ef9a85a1e2f0dffe39d1c35136281e~sTWMA3WGs0451104511epcas2p4Y; Tue, 18 Aug 2020 07:50:55 +0000 (GMT) Received: from epsmges2p3.samsung.com (unknown [182.195.40.186]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4BW34X0WfFzMqYkq; Tue, 18 Aug 2020 07:50:52 +0000 (GMT) Received: from epcas2p2.samsung.com ( [182.195.41.54]) by epsmges2p3.samsung.com (Symantec Messaging Gateway) with SMTP id BE.30.27441.B588B3F5; Tue, 18 Aug 2020 16:50:52 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas2p3.samsung.com (KnoxPortal) with ESMTPA id 20200818075051epcas2p316edad6edd3df59444c08d392b075ea8~sTWIO-GKy2931529315epcas2p35; Tue, 18 Aug 2020 07:50:51 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200818075050epsmtrp2e2eff35d365f0d3d2457bd13553c58d7~sTWHsNWs40185501855epsmtrp2B; Tue, 18 Aug 2020 07:50:50 +0000 (GMT) X-AuditID: b6c32a47-fafff70000006b31-83-5f3b885b8fa4 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 97.09.08303.A588B3F5; Tue, 18 Aug 2020 16:50:50 +0900 (KST) Received: from KEI.dsn.sec.samsung.com (unknown [12.36.155.227]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200818075050epsmtip13728894ac95b41ac3557af485c3cde3d~sTWHbvejq2278422784epsmtip1r; Tue, 18 Aug 2020 07:50:50 +0000 (GMT) From: Cho KyongHo To: joro@8bytes.org, catalin.marinas@arm.com, will@kernel.org Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, janghyuck.kim@samsung.com, hyesoo.yu@samsung.com, Cho KyongHo Subject: [PATCH 2/2] arm64: dma-mapping: add relaxed DMA sync Date: Tue, 18 Aug 2020 16:43:11 +0900 Message-Id: <1597736591-20457-2-git-send-email-pullip.cho@samsung.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1597736591-20457-1-git-send-email-pullip.cho@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrKKsWRmVeSWpSXmKPExsWy7bCmmW5Mh3W8wbtEi/fLehgt/nZeYLVY sN/aYvOcYovO2RvYLTY9vsZqcXnXHDaLtUfuslv86z3IaHHwwxNWi5Y7pg7cHk8OzmPyWDNv DaPHplWdbB6bl9R7TL6xnNGjb8sqRo/Pm+QC2KNybDJSE1NSixRS85LzUzLz0m2VvIPjneNN zQwMdQ0tLcyVFPISc1NtlVx8AnTdMnOA7lNSKEvMKQUKBSQWFyvp29kU5ZeWpCpk5BeX2Cql FqTkFBgaFugVJ+YWl+al6yXn51oZGhgYmQJVJuRk7Fh4g61gg0XFn9lXWBoYZ+p1MXJySAiY SOx7uIGxi5GLQ0hgB6NE648XUM4nRomV3U/ZIZzPjBInjl1lhGlZcm0qG0RiF6PEi6VzoKq+ MkrcvvGBHaSKTUBLYvXc42AdIgK2Ej+/T2QGKWIW+MYosevHXSaQhDBQ4nL3I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5kgbGGJ+y1HWCGKPjNK zJ3UzgKSYBPQklg99zhjFyMHh4iAo0TDexOQGmaBf4wSR690gw0SFrCVuNy9iBmkhkVAVeL1 Bi6QMK+Am8Slq3eh5stJ3DzXCVbCKeAu0ThBCSQsBFQy8dp0pgmMfAsYGVYxSqYWFOem5xYb FhjlpZbrFSfmFpfmpesl5+duYgSHqZbWDsY9qz7oHWJk4mA8xCjBwawkwpt0wjxeiDclsbIq tSg/vqg0J7X4EKM0B4uSOO/XWQvjhATSE0tSs1NTC1KLYLJMHJxSDUxrYgJ9RDLPPdruU+3z kO2YU2ZW45kyt/6sf6untO/N45e8NS1Zkt3HvfHbMo79WZv2h+aH3zy6dWHS9MMO4WJbmy+x 53zodBP4tN6m02Pz1QXtRTfv9qxnjy1wf23I8D3z0JOl696L9O09MI2BtVHjkXe8oHzbmS+m J/7XvzeK3Vc5zfDMRl6/ud8zJjB52xmkvgnxnCJ4cY/Vw1wvVdmZqctSKyKTNKreXEw5nuBu z3UkV8RixtpZKZXOCvIKMxYH1Gp9umVzN/x7fN6Kmpcvqx/I3EhjlDVrt2TsX7BvV/GMD3uO ZIV+Ljq08Mi3trMTlp1d2xBs/oDdPm6CwcQ/F7e6WzBLyPy5vt92A58SS3FGoqEWc1FxIgDG OMHdwgIAAA== X-CMS-MailID: 20200818075051epcas2p316edad6edd3df59444c08d392b075ea8 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20200818075051epcas2p316edad6edd3df59444c08d392b075ea8 References: <1597736591-20457-1-git-send-email-pullip.cho@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org __dma_[un]map_area() is the implementation of cache maintenance operations for DMA in arm64. 'dsb sy' in the subroutine guarantees the view of given memory area is consistent to all memory observers. So, it is required. However, dma_sync_sg_for_{device|cpu}() and dma_[un]map_sg() calls __dma_[un]map_area() nents number of times and 'dsb sy' instruction is executed the same number of times. We have observed that 'dsb sy' consumes more time than cleaning or invalidating 4KiB area. arch_sync_dma_for_{device|cpu}_relaxed() and arch_sync_barrier_for_{device|cpu}() are introduced since commit 6a9356234 ("dma-mapping: introduce relaxed version of dma sync") to reduce redundant memory barriers in sg versions of DMA sync API. Implementing relaxed version of DMA sync API will dramatically increase the performance of dma_sync_sg_for_{device|cpu}(). Signed-off-by: Cho KyongHo --- arch/arm64/Kconfig | 4 ++-- arch/arm64/include/asm/assembler.h | 33 ++++++++++++++++++++++++++++++++- arch/arm64/include/asm/barrier.h | 13 +++++++++++++ arch/arm64/mm/cache.S | 34 +++++++++++----------------------- arch/arm64/mm/dma-mapping.c | 4 ++-- include/linux/dma-noncoherent.h | 1 + 6 files changed, 61 insertions(+), 28 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 6d23283..4fc7ef4 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -31,8 +31,8 @@ config ARM64 select ARCH_HAS_SET_MEMORY select ARCH_HAS_STRICT_KERNEL_RWX select ARCH_HAS_STRICT_MODULE_RWX - select ARCH_HAS_SYNC_DMA_FOR_DEVICE - select ARCH_HAS_SYNC_DMA_FOR_CPU + select ARCH_HAS_SYNC_DMA_FOR_DEVICE_RELAXED + select ARCH_HAS_SYNC_DMA_FOR_CPU_RELAXED select ARCH_HAS_SYSCALL_WRAPPER select ARCH_HAS_TEARDOWN_DMA_OPS if IOMMU_SUPPORT select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 54d1811..1f87d98 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -345,6 +345,33 @@ alternative_endif .endm /* + * Macro to perform a data cache invalidation for the interval + * [kaddr, kaddr + size) + * + * kaddr: starting virtual address of the region + * size: size of the region + * Corrupts: kaddr, size, tmp1, tmp2 + */ + .macro __dcache_inv_by_line kaddr, size, tmp1, tmp2 + add \size, \size, \kaddr + dcache_line_size \tmp1, \tmp2 + sub \tmp2, \tmp1, #1 + tst \size, \tmp2 // end cache line aligned? + bic \size, \size, \tmp2 + b.eq 9997f + dc civac, \size // clean & invalidate D / U line +9997: tst \kaddr, \tmp2 // start cache line aligned? + bic \kaddr, \kaddr, \tmp2 + b.eq 9998f + dc civac, \kaddr // clean & invalidate D / U line + b 9999f +9998: dc ivac, \kaddr // invalidate D / U line +9999: add \kaddr, \kaddr, \tmp1 + cmp \kaddr, \size + b.lo 9998b + .endm + +/* * Macro to perform a data cache maintenance for the interval * [kaddr, kaddr + size) * @@ -362,7 +389,7 @@ alternative_else alternative_endif .endm - .macro dcache_by_line_op op, domain, kaddr, size, tmp1, tmp2 + .macro __dcache_by_line_op op, kaddr, size, tmp1, tmp2 dcache_line_size \tmp1, \tmp2 add \size, \kaddr, \size sub \tmp2, \tmp1, #1 @@ -388,6 +415,10 @@ alternative_endif add \kaddr, \kaddr, \tmp1 cmp \kaddr, \size b.lo 9998b + .endm + + .macro dcache_by_line_op op, domain, kaddr, size, tmp1, tmp2 + __dcache_by_line_op \op, \kaddr, \size, \tmp1, \tmp2 dsb \domain .endm diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h index fb4c275..96bbbf6 100644 --- a/arch/arm64/include/asm/barrier.h +++ b/arch/arm64/include/asm/barrier.h @@ -167,6 +167,19 @@ do { \ #include +#include + +static inline void arch_sync_barrier_for_device(enum dma_data_direction dir) +{ + dsb(sy); +} + +static inline void arch_sync_barrier_for_cpu(enum dma_data_direction dir) +{ + if (dir == DMA_FROM_DEVICE) + dsb(sy); +} + #endif /* __ASSEMBLY__ */ #endif /* __ASM_BARRIER_H */ diff --git a/arch/arm64/mm/cache.S b/arch/arm64/mm/cache.S index 2d881f3..7180256 100644 --- a/arch/arm64/mm/cache.S +++ b/arch/arm64/mm/cache.S @@ -138,34 +138,20 @@ SYM_FUNC_END(__clean_dcache_area_pou) * - kaddr - kernel address * - size - size in question */ -SYM_FUNC_START_LOCAL(__dma_inv_area) SYM_FUNC_START_PI(__inval_dcache_area) - /* FALLTHROUGH */ + __dcache_inv_by_line x0, x1, x2, x3 + dsb sy + ret +SYM_FUNC_END_PI(__inval_dcache_area) /* * __dma_inv_area(start, size) * - start - virtual start address of region * - size - size in question */ - add x1, x1, x0 - dcache_line_size x2, x3 - sub x3, x2, #1 - tst x1, x3 // end cache line aligned? - bic x1, x1, x3 - b.eq 1f - dc civac, x1 // clean & invalidate D / U line -1: tst x0, x3 // start cache line aligned? - bic x0, x0, x3 - b.eq 2f - dc civac, x0 // clean & invalidate D / U line - b 3f -2: dc ivac, x0 // invalidate D / U line -3: add x0, x0, x2 - cmp x0, x1 - b.lo 2b - dsb sy +SYM_FUNC_START_LOCAL(__dma_inv_area) + __dcache_inv_by_line x0, x1, x2, x3 ret -SYM_FUNC_END_PI(__inval_dcache_area) SYM_FUNC_END(__dma_inv_area) /* @@ -177,16 +163,18 @@ SYM_FUNC_END(__dma_inv_area) * - kaddr - kernel address * - size - size in question */ -SYM_FUNC_START_LOCAL(__dma_clean_area) SYM_FUNC_START_PI(__clean_dcache_area_poc) - /* FALLTHROUGH */ + dcache_by_line_op cvac, sy, x0, x1, x2, x3 + ret +SYM_FUNC_END_PI(__clean_dcache_area_poc) /* * __dma_clean_area(start, size) * - start - virtual start address of region * - size - size in question */ - dcache_by_line_op cvac, sy, x0, x1, x2, x3 +SYM_FUNC_START_LOCAL(__dma_clean_area) + __dcache_by_line_op cvac, x0, x1, x2, x3 ret SYM_FUNC_END_PI(__clean_dcache_area_poc) SYM_FUNC_END(__dma_clean_area) diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index 6c45350..12943b3 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -13,13 +13,13 @@ #include -void arch_sync_dma_for_device(phys_addr_t paddr, size_t size, +void arch_sync_dma_for_device_relaxed(phys_addr_t paddr, size_t size, enum dma_data_direction dir) { __dma_map_area(phys_to_virt(paddr), size, dir); } -void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size, +void arch_sync_dma_for_cpu_relaxed(phys_addr_t paddr, size_t size, enum dma_data_direction dir) { __dma_unmap_area(phys_to_virt(paddr), size, dir); diff --git a/include/linux/dma-noncoherent.h b/include/linux/dma-noncoherent.h index 0a31e6c..f88fc0f 100644 --- a/include/linux/dma-noncoherent.h +++ b/include/linux/dma-noncoherent.h @@ -5,6 +5,7 @@ #include #include +#include #ifdef CONFIG_ARCH_HAS_DMA_COHERENCE_H #include #elif defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \ -- 2.7.4