From patchwork Tue Jun 12 11:08:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 10460059 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 40BFC60348 for ; Tue, 12 Jun 2018 11:10:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 201FE286DE for ; Tue, 12 Jun 2018 11:10:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1288B286E2; Tue, 12 Jun 2018 11:10:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0729D286DE for ; Tue, 12 Jun 2018 11:10:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: Message-id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:List-Owner; bh=YE2kXW8/M6t52ILrYmsVtx0BT/pd9+JqxRuADS+UYG8=; b=GY nK+mEBQWCgFyI7wxzitjOnk9d23LxoR85vJR+VO9CARdpS4MTb0fooTLX/fxmUpb6mnhhOi6aCrM0 MoAzeeF86D5KaB6nFYXJGsoDuAIF9XvLzvBZTPz9S734jpeTh2pUHA0mwf9AFZVGOYt/sEtgAttUT xlT7tAFaeI+rAi/qZkFOKqxvL/DitBWZ1FsJzzv8sfsOR2ET9+zuORknVPtapzQ/+HYJwlWy50oSY tePruMvh8bTkLDbUzjaPTbBFJkxQtVzS6vx1ZanIdl6YQNBudm1XrbGDZgT9ZQSWYNRnT1ZFHvOzY GWHCU1KjCVIjNUFpCNn6++3dklDFTyEg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fShBP-0001jl-5R; Tue, 12 Jun 2018 11:09:51 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fShAu-0001U0-9R for linux-arm-kernel@lists.infradead.org; Tue, 12 Jun 2018 11:09:27 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20180612110859euoutp025a70278324dbc8c29d2f5d134a667fa8~3ZRUdb5ND3237732377euoutp02t; Tue, 12 Jun 2018 11:08:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180612110859euoutp025a70278324dbc8c29d2f5d134a667fa8~3ZRUdb5ND3237732377euoutp02t DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1528801739; bh=orrIVfmx+Gw9eMfl89OvzjOfeNk7Ty8r8XSfRyHOYpM=; h=From:To:Cc:Subject:Date:References:From; b=GK9Zud5oZblJ+Yk/SrLwcZHVdQPRx3BJb1TcjyafI+jbKjleCHTFHihbnpeAX0Ent szTF2jdkiImW717NMOexxCFk8Tlld8FFIFh3b37TqAq81/QhALcBaLEIGwTMIgRxO9 g0HvwTobknsQrCH3LwmaJtUUrnDmeN2dquN/4gUw= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20180612110858eucas1p2e9b8b0a271fc21d8de23a6313303ee9b~3ZRTcFxLn2565825658eucas1p2m; Tue, 12 Jun 2018 11:08:58 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 15.1C.10409.AC9AF1B5; Tue, 12 Jun 2018 12:08:58 +0100 (BST) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180612110857eucas1p1f5e3b6d984d4fd7e3b3ce31418df546e~3ZRSQphgK1924419244eucas1p1S; Tue, 12 Jun 2018 11:08:57 +0000 (GMT) X-AuditID: cbfec7f5-b45ff700000028a9-67-5b1fa9caa021 Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 0A.73.04178.9C9AF1B5; Tue, 12 Jun 2018 12:08:57 +0100 (BST) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0PA700F4HIYU8E00@eusync3.samsung.com>; Tue, 12 Jun 2018 12:08:57 +0100 (BST) From: Marek Szyprowski To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2] arm64: dma-mapping: clear buffers allocated with FORCE_CONTIGUOUS flag Date: Tue, 12 Jun 2018 13:08:40 +0200 Message-id: <20180612110840.30436-1-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprMIsWRmVeSWpSXmKPExsWy7djP87qnVspHG2z+y2PxflkPo8Xc2ZMY LTY9vsZqsfbIXXaLgx+esFq8/HiCxYHNY828NYweE8/qemxeUu/Rt2UVYwBLFJdNSmpOZllq kb5dAlfGm/kbWQvu8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hRgEORiUe3ohKuWgh1sSy4srcQ4wSHMxKIry5OvLRQrwpiZVVqUX58UWlOanF hxilOViUxHnPG1RGCQmkJ5akZqemFqQWwWSZODilGhin/GzrkOvefMUve1plzcaz194KqxwO 2bnSaYuO/+vzs/u9qidUtM6cHWz/84pJ7+ljvbt+vJj5IWXzS5ll595cDN7H+3He9GCjWxEu zTYifzZvCfl1Oe6RtLSR1Lfd/glcsTkiBYu+rPOeMvFn0l1uvWVXo/oOByUFFPWHdS+q+prD GVE1ozBWiaU4I9FQi7moOBEA+EElwvgBAAA= X-CMS-MailID: 20180612110857eucas1p1f5e3b6d984d4fd7e3b3ce31418df546e X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180612110857eucas1p1f5e3b6d984d4fd7e3b3ce31418df546e References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180612_040920_755423_644F73B1 X-CRM114-Status: GOOD ( 15.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Catalin Marinas , Will Deacon , Robin Murphy , Geert Uytterhoeven , Marek Szyprowski MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP dma_alloc_*() buffers might be exposed to userspace via mmap() call, so they should be cleared on allocation. In case of IOMMU-based dma-mapping implementation such buffer clearing was missing in the code path for DMA_ATTR_FORCE_CONTIGUOUS flag handling, because dma_alloc_from_contiguous() doesn't honor __GFP_ZERO flag. This patch fixes this issue. For more information on clearing buffers allocated by dma_alloc_* functions, see commit 6829e274a623 ("arm64: dma-mapping: always clear allocated buffers"). Fixes: 44176bb38fa4 ("arm64: Add support for DMA_ATTR_FORCE_CONTIGUOUS to IOMMU") Signed-off-by: Marek Szyprowski --- v2: - fixed incorrect commit id in commit body (thanks to Geert) - extended description with information that dma_alloc_from_contiguous() lacks __GFP_ZERO support --- arch/arm64/mm/dma-mapping.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index 632d32109755..aa0037a3185f 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -629,13 +629,14 @@ static void *__iommu_alloc_attrs(struct device *dev, size_t size, size >> PAGE_SHIFT); return NULL; } - if (!coherent) - __dma_flush_area(page_to_virt(page), iosize); - addr = dma_common_contiguous_remap(page, size, VM_USERMAP, prot, __builtin_return_address(0)); - if (!addr) { + if (addr) { + memset(addr, 0, size); + if (!coherent) + __dma_flush_area(page_to_virt(page), iosize); + } else { iommu_dma_unmap_page(dev, *handle, iosize, 0, attrs); dma_release_from_contiguous(dev, page, size >> PAGE_SHIFT);