* [PATCH] linux-user:Fix align mistake when mmap guest space
@ 2019-12-13 2:29 Xinyu Li
2019-12-13 9:00 ` Laurent Vivier
2019-12-19 9:24 ` Laurent Vivier
0 siblings, 2 replies; 4+ messages in thread
From: Xinyu Li @ 2019-12-13 2:29 UTC (permalink / raw)
To: qemu-devel; +Cc: riku.voipio, laurent, Xinyu Li
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.
Signed-off-by: Xinyu Li <precinct@mail.ustc.edu.cn>
---
linux-user/elfload.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index f6693e5760..312ded0779 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -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) {
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] linux-user:Fix align mistake when mmap guest space
2019-12-13 2:29 [PATCH] linux-user:Fix align mistake when mmap guest space Xinyu Li
@ 2019-12-13 9:00 ` Laurent Vivier
2019-12-19 0:04 ` Richard Henderson
2019-12-19 9:24 ` Laurent Vivier
1 sibling, 1 reply; 4+ messages in thread
From: Laurent Vivier @ 2019-12-13 9:00 UTC (permalink / raw)
To: Xinyu Li, qemu-devel, Richard Henderson; +Cc: riku.voipio
Le 13/12/2019 à 03:29, Xinyu Li a écrit :
> 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.
>
> Signed-off-by: Xinyu Li <precinct@mail.ustc.edu.cn>
> ---
> linux-user/elfload.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index f6693e5760..312ded0779 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -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 patch
30ab9ef2967d ("linux-user: Fix shmat emulation by honoring host SHMLBA")
or was it voluntary to keep it?
Thanks,
Laurent
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] linux-user:Fix align mistake when mmap guest space
2019-12-13 9:00 ` Laurent Vivier
@ 2019-12-19 0:04 ` Richard Henderson
0 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2019-12-19 0:04 UTC (permalink / raw)
To: Laurent Vivier, Xinyu Li, qemu-devel; +Cc: riku.voipio
On 12/12/19 11:00 PM, Laurent Vivier wrote:
> Le 13/12/2019 à 03:29, Xinyu Li a écrit :
>> 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.
>>
>> Signed-off-by: Xinyu Li <precinct@mail.ustc.edu.cn>
>> ---
>> linux-user/elfload.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
>> index f6693e5760..312ded0779 100644
>> --- a/linux-user/elfload.c
>> +++ b/linux-user/elfload.c
>> @@ -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 patch
> 30ab9ef2967d ("linux-user: Fix shmat emulation by honoring host SHMLBA")
> or was it voluntary to keep it?
Looks like I missed it.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] linux-user:Fix align mistake when mmap guest space
2019-12-13 2:29 [PATCH] linux-user:Fix align mistake when mmap guest space Xinyu Li
2019-12-13 9:00 ` Laurent Vivier
@ 2019-12-19 9:24 ` Laurent Vivier
1 sibling, 0 replies; 4+ messages in thread
From: Laurent Vivier @ 2019-12-19 9:24 UTC (permalink / raw)
To: Xinyu Li, qemu-devel; +Cc: riku.voipio
Le 13/12/2019 à 03:29, Xinyu Li a écrit :
> 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.
>
> Signed-off-by: Xinyu Li <precinct@mail.ustc.edu.cn>
> ---
> linux-user/elfload.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index f6693e5760..312ded0779 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-12-19 9:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-13 2:29 [PATCH] linux-user:Fix align mistake when mmap guest space Xinyu Li
2019-12-13 9:00 ` Laurent Vivier
2019-12-19 0:04 ` Richard Henderson
2019-12-19 9:24 ` Laurent Vivier
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.