diff mbox

arm64: Enable CONFIG_COMPAT also for 64k page size

Message ID 550025E0.7030008@suse.de (mailing list archive)
State New, archived
Headers show

Commit Message

Alexander Graf March 11, 2015, 11:24 a.m. UTC
On 08.12.14 04:10, Will Deacon wrote:
> On Sat, Dec 06, 2014 at 05:23:59PM +0000, Alexander Graf wrote:
>> On 04.12.14 19:20, Will Deacon wrote:
>>> On Thu, Dec 04, 2014 at 03:46:33PM +0000, Alexander Graf wrote:
>>>> With binutils 2.25 the default alignment for 32bit arm sections changed to
>>>> have everything 64k aligned. Armv7 binaries built with this binutils version
>>>> run successfully on an arm64 system.
>>>>
>>>> Since effectively there is now the chance to run armv7 code on arm64 even
>>>> with 64k page size, it doesn't make sense to block people from enabling
>>>> CONFIG_COMPAT on those configurations.
>>>
>>> Is there a distro available that is built with a recent enough binutils for
>>> this? I'd really like to run our regression tests to check that page-size
>>> assumptions don't exist for things like shm.
>>
>> So how much of a distro do you need? I could probably assemble a simple
>> very minimalistic rootfs with only bash if that helps.
> 
> I'd like to run LTP, so I'd probably need slightly more than that but I
> certainly don't need the whole world.

So after recompiling all of the distribution with newer binutils we now
have an openSUSE Factory tree that has 64k aligned 32bit binaries.

Unfortunately however, the 32bit glibc has a bogus mmap() implementation
that hard codes 4k page size.

With the patch below applied to glibc, I can successfully run 32bit user
space on Seattle with 64k PAGE_SIZE though. So I guess we'll need to fix
up glibc next.

Do you know of anyone who's fluent enough in 32bit ARM assembly to
convert the hard coded assumptions in there to instead use a variable
that takes the actual host page size into account?


Alex

Comments

Andreas Schwab March 11, 2015, 12:43 p.m. UTC | #1
Alexander Graf <agraf@suse.de> writes:

> Unfortunately however, the 32bit glibc has a bogus mmap() implementation
> that hard codes 4k page size.

Which is correct (it's not a page size).

Andreas.
Arnd Bergmann March 11, 2015, 12:47 p.m. UTC | #2
On Wednesday 11 March 2015 06:24:16 Alexander Graf wrote:
> So after recompiling all of the distribution with newer binutils we now
> have an openSUSE Factory tree that has 64k aligned 32bit binaries.
> 
> Unfortunately however, the 32bit glibc has a bogus mmap() implementation
> that hard codes 4k page size.
> 
> With the patch below applied to glibc, I can successfully run 32bit user
> space on Seattle with 64k PAGE_SIZE though. So I guess we'll need to fix
> up glibc next.
> 
> Do you know of anyone who's fluent enough in 32bit ARM assembly to
> convert the hard coded assumptions in there to instead use a variable
> that takes the actual host page size into account?

I believe this is a kernel bug, and the kernel API for 32-bit emulation
should always take the pgoff argument in 4KB units instead of PAGE_SIZE
units, see the implementation of sys_mmap2 in
arch/powerpc/kernel/sys_ppc32.c.

All user space programs that call mmap2 still need to make sure that
their arguments are PAGE_SIZE aligned, but the libc need not care
about this here.

	Arnd
Alexander Graf March 11, 2015, 1:08 p.m. UTC | #3
> Am 11.03.2015 um 07:47 schrieb Arnd Bergmann <arnd@arndb.de>:
> 
>> On Wednesday 11 March 2015 06:24:16 Alexander Graf wrote:
>> So after recompiling all of the distribution with newer binutils we now
>> have an openSUSE Factory tree that has 64k aligned 32bit binaries.
>> 
>> Unfortunately however, the 32bit glibc has a bogus mmap() implementation
>> that hard codes 4k page size.
>> 
>> With the patch below applied to glibc, I can successfully run 32bit user
>> space on Seattle with 64k PAGE_SIZE though. So I guess we'll need to fix
>> up glibc next.
>> 
>> Do you know of anyone who's fluent enough in 32bit ARM assembly to
>> convert the hard coded assumptions in there to instead use a variable
>> that takes the actual host page size into account?
> 
> I believe this is a kernel bug, and the kernel API for 32-bit emulation
> should always take the pgoff argument in 4KB units instead of PAGE_SIZE
> units, see the implementation of sys_mmap2 in
> arch/powerpc/kernel/sys_ppc32.c.
> 
> All user space programs that call mmap2 still need to make sure that
> their arguments are PAGE_SIZE aligned, but the libc need not care
> about this here.

Awesome, that makes my life a lot easier. Let me cook up a patch that fixes the compat mmap call later today :).


Alex
Christopher Covington March 16, 2015, 2:16 p.m. UTC | #4
Hi,

On 03/11/2015 08:47 AM, Arnd Bergmann wrote:
> On Wednesday 11 March 2015 06:24:16 Alexander Graf wrote:
>> So after recompiling all of the distribution with newer binutils we now
>> have an openSUSE Factory tree that has 64k aligned 32bit binaries.
>>
>> Unfortunately however, the 32bit glibc has a bogus mmap() implementation
>> that hard codes 4k page size.
>>
>> With the patch below applied to glibc, I can successfully run 32bit user
>> space on Seattle with 64k PAGE_SIZE though. So I guess we'll need to fix
>> up glibc next.
>>
>> Do you know of anyone who's fluent enough in 32bit ARM assembly to
>> convert the hard coded assumptions in there to instead use a variable
>> that takes the actual host page size into account?
> 
> I believe this is a kernel bug, and the kernel API for 32-bit emulation
> should always take the pgoff argument in 4KB units instead of PAGE_SIZE
> units, see the implementation of sys_mmap2 in
> arch/powerpc/kernel/sys_ppc32.c.
> 
> All user space programs that call mmap2 still need to make sure that
> their arguments are PAGE_SIZE aligned, but the libc need not care
> about this here.

What is the correct behavior for /proc/pid/pagemap, /proc/kpagecount, and
/proc/kpageflags for a AArch32 process running on an AArch64 kernel with
non-4K translation granule? Actual page frame number or units-of-4K frame number?

Thanks,
Chris
Arnd Bergmann March 16, 2015, 2:19 p.m. UTC | #5
On Monday 16 March 2015 10:16:37 Christopher Covington wrote:
> 
> On 03/11/2015 08:47 AM, Arnd Bergmann wrote:
> > On Wednesday 11 March 2015 06:24:16 Alexander Graf wrote:
> >> So after recompiling all of the distribution with newer binutils we now
> >> have an openSUSE Factory tree that has 64k aligned 32bit binaries.
> >>
> >> Unfortunately however, the 32bit glibc has a bogus mmap() implementation
> >> that hard codes 4k page size.
> >>
> >> With the patch below applied to glibc, I can successfully run 32bit user
> >> space on Seattle with 64k PAGE_SIZE though. So I guess we'll need to fix
> >> up glibc next.
> >>
> >> Do you know of anyone who's fluent enough in 32bit ARM assembly to
> >> convert the hard coded assumptions in there to instead use a variable
> >> that takes the actual host page size into account?
> > 
> > I believe this is a kernel bug, and the kernel API for 32-bit emulation
> > should always take the pgoff argument in 4KB units instead of PAGE_SIZE
> > units, see the implementation of sys_mmap2 in
> > arch/powerpc/kernel/sys_ppc32.c.
> > 
> > All user space programs that call mmap2 still need to make sure that
> > their arguments are PAGE_SIZE aligned, but the libc need not care
> > about this here.
> 
> What is the correct behavior for /proc/pid/pagemap, /proc/kpagecount, and
> /proc/kpageflags for a AArch32 process running on an AArch64 kernel with
> non-4K translation granule? Actual page frame number or units-of-4K frame number?
> 

Not sure, see what PowerPC does in that case.

	Arnd
diff mbox

Patch

Index: glibc-2.21/sysdeps/unix/sysv/linux/arm/mmap.S
===================================================================
--- glibc-2.21.orig/sysdeps/unix/sysv/linux/arm/mmap.S
+++ glibc-2.21/sysdeps/unix/sysv/linux/arm/mmap.S
@@ -36,7 +36,7 @@  ENTRY (__mmap)
 	/* convert offset to pages */
 	movs	ip, r5, lsl #20
 	bne	.Linval
-	mov	r5, r5, lsr #12
+	mov	r5, r5, lsr #16

 	/* do the syscall */
 	DO_CALL (mmap2, 0)
Index: glibc-2.21/sysdeps/unix/sysv/linux/arm/mmap64.S
===================================================================
--- glibc-2.21.orig/sysdeps/unix/sysv/linux/arm/mmap64.S
+++ glibc-2.21/sysdeps/unix/sysv/linux/arm/mmap64.S
@@ -43,9 +43,9 @@  ENTRY (__mmap64)
 	cfi_rel_offset (r4, 0)
 	cfi_remember_state
 	movs	r4, ip, lsl $20		@ check that offset is page-aligned
-	mov	ip, ip, lsr $12
+	mov	ip, ip, lsr $16
 	it	eq
-	movseq	r4, r5, lsr $12		@ check for overflow
+	movseq	r4, r5, lsr $16		@ check for overflow
 	bne	.Linval
 	ldr	r4, [sp, $8]		@ load fd
 	orr	r5, ip, r5, lsl $20	@ compose page offset