[PATCH v4 04/36] linux-user: Remove qemu_host_page_size from create_elf_tables

Richard Henderson posted 36 patches 1 year, 12 months ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Riku Voipio <riku.voipio@iki.fi>, Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Stefan Berger <stefanb@linux.vnet.ibm.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, Laurent Vivier <laurent@vivier.eu>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, David Hildenbrand <david@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Nicholas Piggin <npiggin@gmail.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, "Cédric Le Goater" <clg@kaod.org>, "Alex Bennée" <alex.bennee@linaro.org>, Yoshinori Sato <ysato@users.sourceforge.jp>
[PATCH v4 04/36] linux-user: Remove qemu_host_page_size from create_elf_tables
Posted by Richard Henderson 1 year, 12 months ago
AT_PAGESZ is supposed to advertise the guest page size.
The random adjustment made here using qemu_host_page_size
does not match anything else within linux-user.

The idea here is good, but should be done more systemically
via adjustment to TARGET_PAGE_SIZE.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20240102015808.132373-5-richard.henderson@linaro.org>
---
 linux-user/elfload.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index e84a201448..dfb152bfcb 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2679,13 +2679,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
     NEW_AUX_ENT(AT_PHDR, (abi_ulong)(info->load_addr + exec->e_phoff));
     NEW_AUX_ENT(AT_PHENT, (abi_ulong)(sizeof (struct elf_phdr)));
     NEW_AUX_ENT(AT_PHNUM, (abi_ulong)(exec->e_phnum));
-    if ((info->alignment & ~qemu_host_page_mask) != 0) {
-        /* Target doesn't support host page size alignment */
-        NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(TARGET_PAGE_SIZE));
-    } else {
-        NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(MAX(TARGET_PAGE_SIZE,
-                                               qemu_host_page_size)));
-    }
+    NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(TARGET_PAGE_SIZE));
     NEW_AUX_ENT(AT_BASE, (abi_ulong)(interp_info ? interp_info->load_addr : 0));
     NEW_AUX_ENT(AT_FLAGS, (abi_ulong)0);
     NEW_AUX_ENT(AT_ENTRY, info->entry);
-- 
2.34.1
Re: [PATCH v4 04/36] linux-user: Remove qemu_host_page_size from create_elf_tables
Posted by Michael Tokarev 5 months ago
On 15.02.2024 09:19, Richard Henderson wrote:
> AT_PAGESZ is supposed to advertise the guest page size.
> The random adjustment made here using qemu_host_page_size
> does not match anything else within linux-user.
> 
> The idea here is good, but should be done more systemically
> via adjustment to TARGET_PAGE_SIZE.

Hi!

This change broke execution of armhf binaries on 16k-pagesized
aarch64 host.  See https://bugs.debian.org/1114725 for a few more
details and the reproducer.

 From the commit message this seems to be intentional to remove
such support.  But is it really intentional that it doesn't work
anymore?  Should the mentioned adjustments to TARGET_PAGE_SIZE
compensate for this change?

Thanks,

/mjt
Re: [PATCH v4 04/36] linux-user: Remove qemu_host_page_size from create_elf_tables
Posted by Richard Henderson 5 months ago
On 9/9/25 07:36, Michael Tokarev wrote:
> On 15.02.2024 09:19, Richard Henderson wrote:
>> AT_PAGESZ is supposed to advertise the guest page size.
>> The random adjustment made here using qemu_host_page_size
>> does not match anything else within linux-user.
>>
>> The idea here is good, but should be done more systemically
>> via adjustment to TARGET_PAGE_SIZE.
> 
> Hi!
> 
> This change broke execution of armhf binaries on 16k-pagesized
> aarch64 host.  See https://bugs.debian.org/1114725 for a few more
> details and the reproducer.
> 
>  From the commit message this seems to be intentional to remove
> such support.  But is it really intentional that it doesn't work
> anymore?  Should the mentioned adjustments to TARGET_PAGE_SIZE
> compensate for this change?

We have only trivial support for host page size != guest page size.
Any time it does work is purely by accident.

Older systems like arm32 and i386 are more likely to fail than others, due to program layout.

The only reliable solution is to use softmmu with linux-user in these cases, so that host 
and guest page size, memory layout, etc are properly disconnected.  This is a significant 
amount of work which no one has volunteered to do.


r~