linux-user:Fix align mistake when mmap guest space
PATCH 1/1 linux-user:Fix align mistake when mmap guest space
In init_guest_space, we need to mmap guest space. If the return address of first mmap is not aligned with align, which was set to MAX(SHMLBA, qemu_host_page_size), we need unmap and a new mmap(space is larger than first size). The new size is named real_size, which is aligned_size + qemu_host_page_size. alugned_size is the guest space size. And add a qemu_host_page_size to avoid memory error when we align real_start manually (ROUND_UP(real_start, align)). But when SHMLBA > qemu_host_page_size, the added size will smaller than the size to align, which can make a mistake(in a mips machine, it appears). So change real_size from aligned_size +qemu_host_page_size
to aligned_size + align will solve it.
--- linux-user/elfload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/elfload.c +1 -1
@@ -2189,7 +2189,7 @@ unsigned long init_guest_space(unsigned long host_start,* to where we need to put the commpage. */ munmap ((void *)real_start, host_size); - real_size = aligned_size + qemu_host_page_size; + real_size = aligned_size + align; real_start = (unsigned long )mmap ((void *)real_start, real_size,PROT_NONE , flags,-1 ,0 );if (real_start == (unsigned long )-1 ) {
Signature · 1 line
2.17.1
Le 13/12/2019 à 03:29, Xinyu Li a écrit :
Quoted 23 lines
In
init_guest_space, we need to mmap guest space. If the return address of first mmap is not aligned with align, which was set toMAX(SHMLBA, qemu_host_page_size), we need unmap and a new mmap(space is larger than first size). The new size is namedreal_size, which isaligned_size+qemu_host_page_size.alugned_sizeis the guest space size. And add aqemu_host_page_sizeto avoid memory error when we alignreal_startmanually (ROUND_UP(real_start, align)). But when SHMLBA >qemu_host_page_size, the added size will smaller than the size to align, which can make amistake(in a mips machine, it appears). So changereal_sizefromaligned_size+qemu_host_page_size
toaligned_size+ align will solve it.Signed-off-by Xinyu Li <[email protected]>--- linux-user/elfload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linux-user/elfload.c +0
-0
linux-user/elfload.c unsigned long init_guest_space(unsigned long host_start, · line 2195
Quoted 8 lines
linux-user/elfload.c +1
-1@@ -2189,7 +2189,7 @@ unsigned long init_guest_space(unsigned long host_start,* to where we need to put the commpage. */ munmap ((void *)real_start, host_size); - real_size = aligned_size + qemu_host_page_size; + real_size = aligned_size + align; real_start = (unsigned long )mmap ((void *)real_start, real_size,PROT_NONE , flags,-1 ,0 );if (real_start == (unsigned long )-1 ) {
Your change seems correct to me.
Richard did you miss this in your patch30ab9ef2967d ("linux-user: Fix shmat emulation by honoring host SHMLBA") or was it voluntary to keep it?
Thanks,
Laurent
Richard Henderson
Reviewed-byQuoted 35 lines · Laurent Vivier
Le 13/12/2019 à 03:29, Xinyu Li a écrit :
Quoted 23 lines
In
init_guest_space, we need to mmap guest space. If the return address of first mmap is not aligned with align, which was set toMAX(SHMLBA, qemu_host_page_size), we need unmap and a new mmap(space is larger than first size). The new size is namedreal_size, which isaligned_size+qemu_host_page_size.alugned_sizeis the guest space size. And add aqemu_host_page_sizeto avoid memory error when we alignreal_startmanually (ROUND_UP(real_start, align)). But when SHMLBA >qemu_host_page_size, the added size will smaller than the size to align, which can make amistake(in a mips machine, it appears). So changereal_sizefromaligned_size+qemu_host_page_size
toaligned_size+ align will solve it.Signed-off-by Xinyu Li <[email protected]>--- linux-user/elfload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linux-user/elfload.c +0
-0linux-user/elfload.c unsigned long init_guest_space(unsigned long host_start, · line 2195
Quoted 8 lines
linux-user/elfload.c +1
-1@@ -2189,7 +2189,7 @@ unsigned long init_guest_space(unsigned long host_start,* to where we need to put the commpage. */ munmap ((void *)real_start, host_size); - real_size = aligned_size + qemu_host_page_size; + real_size = aligned_size + align; real_start = (unsigned long )mmap ((void *)real_start, real_size,PROT_NONE , flags,-1 ,0 );if (real_start == (unsigned long )-1 ) {Your change seems correct to me.
Quoted 3 lines
Richard did you miss this in your patch
30ab9ef2967d("linux-user: Fix shmat emulation by honoring host SHMLBA") or was it voluntary to keep it?
Looks like I missed it.
r~
Laurent Vivier
AppliedLe 13/12/2019 à 03:29, Xinyu Li a écrit :
Quoted 23 lines
In
init_guest_space, we need to mmap guest space. If the return address of first mmap is not aligned with align, which was set toMAX(SHMLBA, qemu_host_page_size), we need unmap and a new mmap(space is larger than first size). The new size is namedreal_size, which isaligned_size+qemu_host_page_size.alugned_sizeis the guest space size. And add aqemu_host_page_sizeto avoid memory error when we alignreal_startmanually (ROUND_UP(real_start, align)). But when SHMLBA >qemu_host_page_size, the added size will smaller than the size to align, which can make amistake(in a mips machine, it appears). So changereal_sizefromaligned_size+qemu_host_page_size
toaligned_size+ align will solve it.Signed-off-by Xinyu Li <[email protected]>--- linux-user/elfload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linux-user/elfload.c +0
-0
linux-user/elfload.c unsigned long init_guest_space(unsigned long host_start, · line 2195
Quoted 8 lines
linux-user/elfload.c +1
-1@@ -2189,7 +2189,7 @@ unsigned long init_guest_space(unsigned long host_start,* to where we need to put the commpage. */ munmap ((void *)real_start, host_size); - real_size = aligned_size + qemu_host_page_size; + real_size = aligned_size + align; real_start = (unsigned long )mmap ((void *)real_start, real_size,PROT_NONE , flags,-1 ,0 );if (real_start == (unsigned long )-1 ) {
Applied to my linux-user branch.
Thanks,
Laurent