Received: by 10.223.176.5 with SMTP id f5csp263151wra; Fri, 26 Jan 2018 22:53:18 -0800 (PST) X-Google-Smtp-Source: AH8x2267jKkXMaHo+XUqhHMNFN0o84UPOpR8byy+CgVyzeOpS6TZdD4dy5yRgpM1VzQcTZzinFxz X-Received: by 10.101.81.13 with SMTP id f13mr4854315pgq.242.1517035998132; Fri, 26 Jan 2018 22:53:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517035998; cv=none; d=google.com; s=arc-20160816; b=M0TkgPam0HEGoro3oYYwbMl9Wl10W6lhdhZ6pc6UZtSiliWnnokxI5MS6Oc+cy6BIK sKnkWOAy7dP2ZG/PBsBZBfTo/rXy//Rp6t5L/Bp4JWYL1Nsxo3OM/S29nS12q1sEP1SL riY0J6ivOKAPK3ZTpIVD9iyrlvMWTyg2YiZOxP/SRxB3fF+2Hb2du723T4R+Vm4k6eAR 43B9euKnw3I6QEtPC4994l4YF9zJNVy74JqDQNhevOwo5bGLXsmtYrlPs+8QDC+SHjRI TEAIFR2ueACRtL1EYwisy+IEfmPEugEm7qBS7Nhl/46OQUxmc1RlrLc/nwH2nPzkQdz3 vCUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=WSdOgYauL3tvKCZd1/bCcZjHclkh/L3lmVe1I/rkKC0=; b=EbhYY1W63u8SM5FxVXlFpU8+qCQ8vXHRr2l4i4i/OfDQiL1F3TJ/cURAkEYMoq7/ti Vad7UlQJ8FQpWEhmSHe3+3WvuaIzK2qJOyAJCbLJe/nz/nUuIpmwKIBqTs+fLwD/sDe7 rAsqCTSupxB5VHmB5toFE/nDuKofpcp8ldjm1L3ECLM1VCAYvw2Gvf8j36ERUfAXvMDP E5LZi6mDbA/+oWSKfsWmwNUDwh14VAVhhyTdMstVBxl2GlvDCOVlnaHttNtK+Bh4ppVC BTehRRDCCbiFyI/Qqdgjic+oPqk8D+vfuyP1V8uBdLTE0pjFNINc8sqeX1XP54paBOeW VfXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u8-v6si4008754plm.97.2018.01.26.22.53.04; Fri, 26 Jan 2018 22:53:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751793AbeA0Gwc (ORCPT + 99 others); Sat, 27 Jan 2018 01:52:32 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:33623 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751505AbeA0Gwb (ORCPT ); Sat, 27 Jan 2018 01:52:31 -0500 Received: by mail-wr0-f195.google.com with SMTP id s5so2294853wra.0 for ; Fri, 26 Jan 2018 22:52:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=WSdOgYauL3tvKCZd1/bCcZjHclkh/L3lmVe1I/rkKC0=; b=FVlvfpKy4q8aUecRHcjGKi4c5eaau/+Vp9H9phMNohB7oSEKzXlDCoaCmR0sXHy1Ka dvrL31gecc1KzMxsPWC/fV4qplZg1pXUM7MNivBV/4GbFKDcNQqC7OMwlXME1GRdgLbP eE9kUysUrdGqKmZgg9icp291yu4HlciIWotQz8cvMK4edt751tks7PF/ZrEIulJ3b/hz M9Nw8wZZySVoo6DzZFIqLXgovFMqmnDMgmEpAXBj1BBjIxHssQ8FoLzm2z1nvX6xhqmK GB8VFQtYPo3AJxRKnbBlXvSEL/Y/JdPdPpf6Y44rf0UKvE5TI2BtEOPz5FeGPszslbjp OOzA== X-Gm-Message-State: AKwxytcHcu3S9CNyy1if7w8bosiF0jFhSQuwd4bLMBtGAZLB0lWVnJLP nVvw2ivmvA25F0r1KBlMOtxK+w== X-Received: by 10.223.134.236 with SMTP id 41mr13148085wry.87.1517035949857; Fri, 26 Jan 2018 22:52:29 -0800 (PST) Received: from localhost.localdomain ([80.188.125.194]) by smtp.gmail.com with ESMTPSA id t51sm14427188wrc.21.2018.01.26.22.52.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jan 2018 22:52:28 -0800 (PST) Subject: Re: [Linaro-mm-sig] [PATCH v3] staging: android: ion: Zero CMA allocated memory To: Chen Feng , Liam Mark , Sumit Semwal Cc: devel@driverdev.osuosl.org, Greg KH , linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, Dan Carpenter , "Xiaqing (A)" , Zhuangluan Su References: <5A6BDE11.9070403@hisilicon.com> From: Laura Abbott Message-ID: Date: Fri, 26 Jan 2018 22:52:28 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <5A6BDE11.9070403@hisilicon.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/26/2018 06:04 PM, Chen Feng wrote: > > > On 2018/1/27 1:48, Liam Mark wrote: >> Since commit 204f672255c2 ("staging: android: ion: Use CMA APIs directly") >> the CMA API is now used directly and therefore the allocated memory is no >> longer automatically zeroed. >> >> Explicitly zero CMA allocated memory to ensure that no data is exposed to >> userspace. >> >> Fixes: 204f672255c2 ("staging: android: ion: Use CMA APIs directly") >> Signed-off-by: Liam Mark >> --- >> Changes in v2: >> - Clean up the commit message. >> - Add 'Fixes:' >> >> Changes in v3: >> - Add support for highmem pages >> >> drivers/staging/android/ion/ion_cma_heap.c | 17 +++++++++++++++++ >> 1 file changed, 17 insertions(+) >> >> diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c >> index 86196ffd2faf..fa3e4b7e0c9f 100644 >> --- a/drivers/staging/android/ion/ion_cma_heap.c >> +++ b/drivers/staging/android/ion/ion_cma_heap.c >> @@ -21,6 +21,7 @@ >> #include >> #include >> #include >> +#include >> >> #include "ion.h" >> >> @@ -51,6 +52,22 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer, >> if (!pages) >> return -ENOMEM; >> >> + if (PageHighMem(pages)) { >> + unsigned long nr_clear_pages = nr_pages; >> + struct page *page = pages; >> + >> + while (nr_clear_pages > 0) { >> + void *vaddr = kmap_atomic(page); >> + >> + memset(vaddr, 0, PAGE_SIZE); >> + kunmap_atomic(vaddr); > > Here. This way may cause performance latency at mapping-memset-umap page one bye one. > > Take a look at ion_heap_pages_zero. > > Not very critical, arm64 always have linear mapping. > This is under a PageHighMem check so arm64 isn't affected. It's also the same algorithm arm32 dma-mapping.c uses so I'd like to see some data about the performance improvement before we go changing things too much. Thanks, Laura > >> + page++; >> + nr_clear_pages--; >> + } >> + } else { >> + memset(page_address(pages), 0, size); >> + } >> + >> table = kmalloc(sizeof(*table), GFP_KERNEL); >> if (!table) >> goto err; >> >