Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1339093 > unrolled thread

[RFC] mm: why we should clear page when do anonymous page fault

Started byXishi Qiu <qiuxishi@huawei.com>
First post2016-02-22 04:00 +0100
Last post2016-02-22 04:20 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [RFC] mm: why we should clear page when do anonymous page fault Xishi Qiu <qiuxishi@huawei.com> - 2016-02-22 04:00 +0100
    Re: [RFC] mm: why we should clear page when do anonymous page fault Jianyu Zhan <nasa4836@gmail.com> - 2016-02-22 04:20 +0100

#1339093 — [RFC] mm: why we should clear page when do anonymous page fault

FromXishi Qiu <qiuxishi@huawei.com>
Date2016-02-22 04:00 +0100
Subject[RFC] mm: why we should clear page when do anonymous page fault
Message-ID<r4OT8-7hh-25@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1339108

FromJianyu Zhan <nasa4836@gmail.com>
Date2016-02-22 04:20 +0100
Message-ID<r4Pcu-7KX-11@gated-at.bofh.it>
In reply to#1339093
On Mon, Feb 22, 2016 at 10:56 AM, Xishi Qiu <qiuxishi@huawei.com> 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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web