qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2] linux-user/mmap.c: Always zero MAP_ANONYMOUS


From: Chen Gang
Subject: Re: [Qemu-devel] [PATCH v2] linux-user/mmap.c: Always zero MAP_ANONYMOUS memory inmmap_frag()
Date: Tue, 22 Dec 2015 10:00:59 +0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0

> From:  "Laurent Vivier";<address@hidden>;
> 
> Le 21/12/2015 03:33, address@hidden a écrit :
>> From: Chen Gang <address@hidden>
>>
>> When mapping MAP_ANONYMOUS memory fragments, still need notice about to
>> set it zero, or it will cause issues.
> 
> Perhaps you can explain in the commit message why this page is not
> already filled by zeros ?
> 

In fact, I don't know. when I debug related issues under sw_64 host (
almost the same as alpha) for i386 target, I found it. The host is 8KB
page, but the guest is 4KB page. So I guess:

 - Firstly, qemu allocate one !MAP_ANONYMOUS 8KB page, so it is not
   zeroed.

 - Then qemu want one MAP_ANONYMOUS fragment, just can use the the left
   room of the page above. It merges and sets the related prot, but
   forgot to reset zero for MAP_ANONYMOUS fragment.

 - For normal host 4KB and guest also 4KB page, it is rarely happen (
   may never happen, I guess). But for host 8KB and guest 4KB pages, it
   often occurs.

Our qemu, at present, let i386 use 8KB page by force, but it can not
work. Our qemu members told me to use softmmu, or we would meet many
various issues.  But at present, I do not meet softmmu related issues:

 - I can chroot with binfmt_misc successfully by using sw_64 host i386
   static qemu, and most i386 programs (e.g. gcc, vi, xclac...) are OK
   (I build i386 wine under sw_64 host i386 chroot environments).

 - After fix this issue, some wine programs can run successfully, e.g.
   cmd.exe, clock.exe, winver.exe (they almost like windows own exe),
   but initialization is very slow in qemu mmap_find_vma_reserved().

 - Now, I am just analyzing and fixing the issue about notepad.exe, is
   it related with softmmu? I am not sure.

When I really meet softmmu related issue, I have to solve it, although
it may spend much time resources.


>> Signed-off-by: Chen Gang <address@hidden>
>> ---
>>  linux-user/mmap.c |    4 +++-
>>  1 files changed, 3 insertions(+), 1 deletions(-)
>>
>> diff --git a/linux-user/mmap.c b/linux-user/mmap.c
>> index 7b459d5..29fe646 100644
>> --- a/linux-user/mmap.c
>> +++ b/linux-user/mmap.c
>> @@ -186,10 +186,12 @@ static int mmap_frag(abi_ulong real_start,
>>          if (prot_new != (prot1 | PROT_WRITE))
>>              mprotect(host_start, qemu_host_page_size, prot_new);
>>      } else {
>> -        /* just update the protection */
>>          if (prot_new != prot1) {
>>              mprotect(host_start, qemu_host_page_size, prot_new);
>>          }
>> +        if ((prot_new & PROT_WRITE) && ((flags & MAP_PRIVATE) || (fd == 
>> -1))) {
> 
> According to manpage, for MAP_ANONYMOUS, fd can be ignored.
> Why do you check if the page is MAP_PRIVATE or not ?
> 

For me, we can remove them, originally I only worry about MAP_SHARED and
fd according to the man page (it mentions MAP_SHARED and fd):

  MAP_ANONYMOUS
    The mapping is not backed by any file; its contents are initialized
    to zero. The fd and offset arguments are ignored; however, some
    implementations require fd to be -1  if MAP_ANONYMOUS (or MAP_ANON)
    is specified, and portable applications should ensure this.  The use
    of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on
    Linux only since kernel 2.4.


Thanks.
-- 
Chen Gang (陈刚)

Open, share, and attitude like air, water, and life which God blessed



reply via email to

[Prev in Thread] Current Thread [Next in Thread]