From patchwork Mon Jun 11 05:13: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: 10457161 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 65AB760234 for ; Mon, 11 Jun 2018 05:14:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 532CB27F54 for ; Mon, 11 Jun 2018 05:14:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 47BCB27F82; Mon, 11 Jun 2018 05:14:40 +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 4576427F54 for ; Mon, 11 Jun 2018 05:14:39 +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=0z/W9HzYe9tVuZ7C3Lwculw206el6t0Ozhn1cd6QpJE=; b=H8 UIJEJAeBcHgaawYYxPYtXOLdtWwhpSZYBB7IHdaqK1j/y8Eb5mE1Zi+0NfRSy0kGrpDBnNfmZltiZ IZViFxZGdrsmZZPJ2LHx5I9dCxETQvyhty6wDJbFWofHhAyxZor8b17KBifX42HG1IIb76c0Ww26o 7kPX6HVcQnol9QVLvzuAIiqSerJaUeJJvck/TlDAmsX6+CHNiM14eNFhh3sOTmvrrxDNuHRjRfufh 93yjUipHWBRDJ+Oc2zYdDn0lnMiMopxz0l8wR0PKRIXMjfDK9cLgKW6wBFcVWRmVZOXgJjRZcumDO L4xBff4AMI18kCfhV69LiyXhEg3mXc5Q==; 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 1fSF9t-0007nG-O5; Mon, 11 Jun 2018 05:14:25 +0000 Received: from mailout1.w1.samsung.com ([210.118.77.11]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fSF9o-0007el-KM for linux-arm-kernel@lists.infradead.org; Mon, 11 Jun 2018 05:14:22 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20180611051354euoutp0135d44d45fa8e114308575da3223708a3~3Ax-uAPkZ1604316043euoutp01Y; Mon, 11 Jun 2018 05:13:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20180611051354euoutp0135d44d45fa8e114308575da3223708a3~3Ax-uAPkZ1604316043euoutp01Y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1528694034; bh=wPkkoz1pcRYfFGq6F5QKoF3BzI8Vq3afs0rauPDjk2U=; h=From:To:Cc:Subject:Date:References:From; b=DrWwTrPtstTarStEwlBveeE5RCc4emIU/b7akoZ/aRgJ2YORLaWKcLncha8Z5HrGc MXpN7FJPR5eGvJf/GZvWJtY9sT2WBFWuPy4HWU6v2WTJ99EBVOCHP9hsSH2N9O1F6k vv8fXj4yqttOsu7rz9kZfMMaoACH6rLwP9/qD+Ng= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20180611051353eucas1p2e50464f9e90e89d5846e893cc9f65b0c~3Ax_t0Vao0069900699eucas1p2R; Mon, 11 Jun 2018 05:13:53 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id C4.82.05700.0150E1B5; Mon, 11 Jun 2018 06:13:52 +0100 (BST) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180611051352eucas1p1f256a2a303da85a1e0923f012d709e39~3Ax93lmG93078030780eucas1p1b; Mon, 11 Jun 2018 05:13:52 +0000 (GMT) X-AuditID: cbfec7f2-1c1ff70000011644-ad-5b1e0510a7de Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id F8.AD.04178.0150E1B5; Mon, 11 Jun 2018 06:13:52 +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 <0PA5005XI7V02X30@eusync3.samsung.com>; Mon, 11 Jun 2018 06:13:52 +0100 (BST) From: Marek Szyprowski To: linux-arm-kernel@lists.infradead.org Subject: [PATCH] arm64: dma-mapping: clear buffers allocated with FORCE_CONTIGUOUS flag Date: Mon, 11 Jun 2018 07:13:40 +0200 Message-id: <20180611051340.9024-1-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprMIsWRmVeSWpSXmKPExsWy7djP87oCrHLRBk3dBhbvl/UwWsydPYnR YtPja6wWa4/cZbc4+OEJq8XLjydYHNg81sxbw+gx8ayux+Yl9R59W1YxBrBEcdmkpOZklqUW 6dslcGV8/jiHqeAVd8WbV7fYGxgvc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KPLwK6bLRQqyJZcWVuYcYJTiYlUR4PZ5LRwvxpiRWVqUW5ccXleak Fh9ilOZgURLnPW9QGSUkkJ5YkpqdmlqQWgSTZeLglGpg1OH4Nf+UYFvrVaXvz64c2tV85O6K ufabHJt2uXI2fzo8NSHvZi3H5ESGaZyMvx2qT65JO7BOOMY2ue+jH5v6tInXk5fENBR+efDf mLvv9rL7S/qDH2ZJlIqx3VZ3j4qJXuTS53j68PvlqTtq2r7NOmTgrqw0dzXTrOkXgo+qad1x /7P2z7tv1kosxRmJhlrMRcWJAB+JqpP4AQAA X-CMS-MailID: 20180611051352eucas1p1f256a2a303da85a1e0923f012d709e39 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180611051352eucas1p1f256a2a303da85a1e0923f012d709e39 References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180610_221420_993255_AF0B17AD X-CRM114-Status: GOOD ( 15.46 ) 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. This patch fixes this issue. For more information on clearing buffers allocated by dma_alloc_* functions, see commit 44176bb38fa4 ("arm64: dma-mapping: always clear allocated buffers"). Fixes: 44176bb38fa4 ("arm64: Add support for DMA_ATTR_FORCE_CONTIGUOUS to IOMMU") Signed-off-by: Marek Szyprowski --- 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);