From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753414AbcBVC5Q (ORCPT ); Sun, 21 Feb 2016 21:57:16 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:38391 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753400AbcBVC5O (ORCPT ); Sun, 21 Feb 2016 21:57:14 -0500 Message-ID: <56CA78F7.9010201@huawei.com> Date: Mon, 22 Feb 2016 10:56:55 +0800 From: Xishi Qiu User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: Linux MM , LKML Subject: [RFC] mm: why we should clear page when do anonymous page fault Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.25.179] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.56CA7903.0047,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: fc719ed4f6dbe08607448b10fc4b8392 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org handle_pte_fault() do_anonymous_page() alloc_zeroed_user_highpage_movable() We will alloc a zeroed page when do anonymous page fault, I don't know why should clear it? just for safe? If user space program do like the following, there are two memset 0, right? kernel alloc zeroed page, and user memset 0 it again, this will waste a lot of time. main() { ... vaddr = malloc(size) if (vaddr) memset(vaddr, 0, size); ... } Thanks, Xishi Qiu From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753153AbcBVDMs (ORCPT ); Sun, 21 Feb 2016 22:12:48 -0500 Received: from mail-ob0-f181.google.com ([209.85.214.181]:36278 "EHLO mail-ob0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752526AbcBVDMq (ORCPT ); Sun, 21 Feb 2016 22:12:46 -0500 MIME-Version: 1.0 In-Reply-To: <56CA78F7.9010201@huawei.com> References: <56CA78F7.9010201@huawei.com> From: Jianyu Zhan Date: Mon, 22 Feb 2016 11:12:06 +0800 Message-ID: Subject: Re: [RFC] mm: why we should clear page when do anonymous page fault To: Xishi Qiu Cc: Linux MM , LKML Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 22, 2016 at 10:56 AM, Xishi Qiu wrote: > handle_pte_fault() > do_anonymous_page() > alloc_zeroed_user_highpage_movable() > > We will alloc a zeroed page when do anonymous page fault, I don't know > why should clear it? just for safe? > > If user space program do like the following, there are two memset 0, right? > kernel alloc zeroed page, and user memset 0 it again, this will waste a > lot of time. > > main() > { > ... > vaddr = malloc(size) > if (vaddr) > memset(vaddr, 0, size); > ... > } > > > Thanks, > Xishi Qiu > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org I believe this is mainly for security reason. To zero a highmem page, we could avoid another process peeking into the page that is (highly likely) just released by another process, who might well have put its confidential data in that very page. IIRC, Windows zeros the pages at freeing time. Linux instead does it lazily. And for the userspace zeroing action, it is another problem - user just wants a clean, definitive context to act on ( and we can be sure he/she is a self-disciplined guy who does not peek into other's secret, but we can not assume that for all). Thanks, Jianyu Zhan