From patchwork Fri Dec 28 01:00:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inki Dae X-Patchwork-Id: 13728 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 4303A23EAB for ; Fri, 28 Dec 2012 01:01:03 +0000 (UTC) Received: from mail-vb0-f52.google.com (mail-vb0-f52.google.com [209.85.212.52]) by fiordland.canonical.com (Postfix) with ESMTP id C78CBA18B3F for ; Fri, 28 Dec 2012 01:01:02 +0000 (UTC) Received: by mail-vb0-f52.google.com with SMTP id ez10so10379609vbb.11 for ; Thu, 27 Dec 2012 17:01:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-auditid:from:to:date:message-id:x-mailer :x-brightmail-tracker:cc:subject:x-beenthere:x-mailman-version :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-gm-message-state; bh=2LXgt4j2ioKvpASIONrdy78SXSRDu027Vp0uahD+ABE=; b=aCwfNxyS9gND2Ovv9qg0va0LtFb+JB977iN0GgnllqIJ0xyYpGGnw+EP3fL6QkhnG/ XYY0DFNtdeqC8FSimAuBlfnDjJnQaucIrR7HEATmFYUZhmoL0741qXGuQY6vNgceN1FJ 584mkNPZAD4vyo1Y/4nMpKD/4oARKcFYVCSyo9CphPS6xbGSh4aifNZAiMankvjOCigZ /dyMEtL7NuVnjFoi86hXrxJt+kiCkO/Ij+B2U8cl96xQkYT+WRylCisZT2iTqJYKrzJ2 /AFM9uyEzE1homV/rjq+3lotJaBPxtzYeMMdEKdrtYPBv/xFKADUv+6SA9D+RzrnW4rM qQCQ== X-Received: by 10.52.176.6 with SMTP id ce6mr42955720vdc.57.1356656462195; Thu, 27 Dec 2012 17:01:02 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.214.195 with SMTP id oc3csp40355vec; Thu, 27 Dec 2012 17:01:01 -0800 (PST) X-Received: by 10.14.203.8 with SMTP id e8mr81988987eeo.2.1356656460744; Thu, 27 Dec 2012 17:01:00 -0800 (PST) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id j49si79873731eep.69.2012.12.27.17.00.58; Thu, 27 Dec 2012 17:01:00 -0800 (PST) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1ToOJi-0006jH-8S; Fri, 28 Dec 2012 01:00:54 +0000 Received: from mailout2.samsung.com ([203.254.224.25]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1ToOJg-0006jB-CZ for linaro-mm-sig@lists.linaro.org; Fri, 28 Dec 2012 01:00:52 +0000 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MFP00H8GUSLZ770@mailout2.samsung.com> for linaro-mm-sig@lists.linaro.org; Fri, 28 Dec 2012 10:00:49 +0900 (KST) X-AuditID: cbfee61a-b7fa66d0000004cf-86-50dcef41dc35 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id C0.A5.01231.14FECD05; Fri, 28 Dec 2012 10:00:49 +0900 (KST) Received: from daeinki-desktop.10.32.193.11 ([10.90.51.53]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MFP00H0HUTD0A30@mmp1.samsung.com> for linaro-mm-sig@lists.linaro.org; Fri, 28 Dec 2012 10:00:49 +0900 (KST) From: daeinki@gmail.com To: linux-mm@kvack.org, linaro-mm-sig@lists.linaro.org Date: Fri, 28 Dec 2012 10:00:33 +0900 Message-id: <1356656433-2278-1-git-send-email-daeinki@gmail.com> X-Mailer: git-send-email 1.7.4.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrBJMWRmVeSWpSXmKPExsVy+t9jAV3H93cCDKYulbf4cuUhkwOjx+1/ j5kDGKO4bFJSczLLUov07RK4MqY/b2Is6BWumPTRvIHxKn8XIyeHhICJxLo//SwQtpjEhXvr 2UBsIYFFjBJ3j9ZA2OuYJM4eTgCx2QTEJeY2fGQCsUUEzCTeNP9hBLGZBaIkVrw4DxYXFnCR OHH/JZjNIqAq0b7oAzOIzSvgILHr6D1miF0KEgvuvWWbwMi9gJFhFaNoakFyQXFSeq6hXnFi bnFpXrpecn7uJkaw/55J7WBc2WBxiFGAg1GJh3dhz50AIdbEsuLK3EOMEhzMSiK8S64ChXhT EiurUovy44tKc1KLDzFKc7AoifM2e6QECAmkJ5akZqemFqQWwWSZODilGhhPXn3ksXfCdBe3 oPBJUv+rRHNuLl3xZ7EbS/Ss3I3dJ2ftm3HTTIVtbaEwJ/PME3lfle2fTngwz40pyFRPZeGl ZcoS+SXdVcGcO7rYNmWqn12kr+t7gI81LXyvpF3pr2mc0QK3cts3FATNeClk2u9jsXH/jbJa o8oVge9FZbPX/biwSoTz3wklluKMREMt5qLiRACId52Z2wEAAA== Cc: Inki Dae , kyungmin.park@samsung.com Subject: [Linaro-mm-sig] [RFC] ARM: DMA-Mapping: add a new attribute to clear buffer X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQkIL8kXhMwTL1b0v2Dik77/CeOwbdYHlVOPytex+Q64/2XSrpiMhvYMQrfW4F201LlcpYRK From: Inki Dae This patch adds a new attribute, DMA_ATTR_SKIP_BUFFER_CLEAR to skip buffer clearing. The buffer clearing also flushes CPU cache so this operation has performance deterioration a little bit. With this patch, allocated buffer region is cleared as default. So if you want to skip the buffer clearing, just set this attribute. But this flag should be used carefully because this use might get access to some vulnerable content such as security data. So with this patch, we make sure that all pages will be somehow cleared before exposing to userspace. For example, let's say that the security data had been stored in some memory and freed without clearing it. And then malicious process allocated the region though some buffer allocator such as gem and ion without clearing it, and requested blit operation with cleared another buffer though gpu or other drivers. At this time, the malicious process could access the security data. Signed-off-by: Inki Dae Signed-off-by: Kyungmin Park --- arch/arm/mm/dma-mapping.c | 6 ++++-- include/linux/dma-attrs.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 6b2fb87..fbe9dff 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1058,7 +1058,8 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, if (!page) goto error; - __dma_clear_buffer(page, size); + if (!dma_get_attr(DMA_ATTR_SKIP_BUFFER_CLEAR, attrs)) + __dma_clear_buffer(page, size); for (i = 0; i < count; i++) pages[i] = page + i; @@ -1082,7 +1083,8 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, pages[i + j] = pages[i] + j; } - __dma_clear_buffer(pages[i], PAGE_SIZE << order); + if (!dma_get_attr(DMA_ATTR_SKIP_BUFFER_CLEAR, attrs)) + __dma_clear_buffer(pages[i], PAGE_SIZE << order); i += 1 << order; count -= 1 << order; } diff --git a/include/linux/dma-attrs.h b/include/linux/dma-attrs.h index c8e1831..2592c05 100644 --- a/include/linux/dma-attrs.h +++ b/include/linux/dma-attrs.h @@ -18,6 +18,7 @@ enum dma_attr { DMA_ATTR_NO_KERNEL_MAPPING, DMA_ATTR_SKIP_CPU_SYNC, DMA_ATTR_FORCE_CONTIGUOUS, + DMA_ATTR_SKIP_BUFFER_CLEAR, DMA_ATTR_MAX, };