memcpy/memset on arm64 platforms
Hi All,
I am trying to enable CONFIG_USE_ARCH_MEMSET/MEMCPY on arm64 platforms and
realized that there is no arm64 specific memcpy available in u-boot. So I tried porting arm64 specific memcpy from kernel[1]. Memcpy stopped working after that and observed that if destination address is unaligned then system hangs.
After doing a bit more research, understood that unaligned access to device or strongly ordered memories will fail. And the memory system (even normal RAM) behaves like strongly ordered memory when the MMU is disabled[2]. In u-boot MMU is enabled very late after relocation and SPL doesn't enable MMU at all.
Before I proceed any further wanted to hear from others if anyone have already tried and have any working solution. If not should we update the kernel memcpy to use unaligned destination address and use it in u-boot?
[1]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/lib/memcpy.S
[2]
https://community.arm.com/processors/f/discussions/7557/when-and-where-will-the-ldp-instruction-trigger-an-exception
Thanks and regards,
Lokesh
Hi All,
Any help is much appreciated.
Thanks and regards,
Lokesh
Quoted 28 lines · Lokesh Vutla
Hi All,
I am trying to enable CONFIG_USE_ARCH_MEMSET/MEMCPY on arm64 platforms and realized that there is no arm64 specific memcpy available in u-boot. So I tried porting arm64 specific memcpy from kernel[1]. Memcpy stopped working after that and observed that if destination address is unaligned then system hangs.After doing a bit more research, understood that unaligned access to device or strongly ordered memories will fail. And the memory system (even normal RAM) behaves like strongly ordered memory when the MMU is disabled[2]. In u-boot MMU is enabled very late after relocation and SPL doesn't enable MMU at all.
Before I proceed any further wanted to hear from others if anyone have already tried and have any working solution. If not should we update the kernel memcpy to use unaligned destination address and use it in u-boot?
[1]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/lib/memcpy.SThanks and regards,
Lokesh
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot
Quoted 13 lines · Lokesh Vutla
Hi All,
I am trying to enable CONFIG_USE_ARCH_MEMSET/MEMCPY on arm64 platforms and
realized that there is no arm64 specific memcpy available in u-boot. So I tried porting arm64 specific memcpy from kernel[1]. Memcpy stopped working after that and observed that if destination address is unaligned then system hangs.After doing a bit more research, understood that unaligned access to device or strongly ordered memories will fail. And the memory system (even normal RAM) behaves like strongly ordered memory when the MMU is disabled[2]. In u-boot MMU is enabled very late after relocation and SPL doesn't enable MMU at all.
Quoted 6 lines
Before I proceed any further wanted to hear from others if anyone have already tried and have any working solution. If not should we update the kernel memcpy to use unaligned destination address and use it in u-boot?
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/lib/memcpy.S
[2] https://community.arm.com/processors/f/discussions/7557/when-and-where-will-the-ldp-instruction-trigger-an-exception
I suspect we should, yes. Adding in some custodians of other arm64 platforms for comment.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190111/8e6caa83/attachment.sig>
Quoted 8 lines · Tom Rini
Quoted 6 lines · Lokesh Vutla
Hi All,
I am trying to enable CONFIG_USE_ARCH_MEMSET/MEMCPY on arm64 platforms and
realized that there is no arm64 specific memcpy available in u-boot. So I tried porting arm64 specific memcpy from kernel[1]. Memcpy stopped working after that and observed that if destination address is unaligned then system hangs.
Why do you want a custom memcpy() implementation in the first place ?
Quoted 5 lines
Quoted 5 lines
After doing a bit more research, understood that unaligned access to device or strongly ordered memories will fail. And the memory system (even normal RAM) behaves like strongly ordered memory when the MMU is disabled[2]. In u-boot MMU is enabled very late after relocation and SPL doesn't enable MMU at all.
The ARM64 MMU table setup seems to be a mess, it could indeed use some improvement.
Quoted 9 lines
Quoted 6 lines
Before I proceed any further wanted to hear from others if anyone have already tried and have any working solution. If not should we update the kernel memcpy to use unaligned destination address and use it in u-boot?
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/lib/memcpy.S
[2] https://community.arm.com/processors/f/discussions/7557/when-and-where-will-the-ldp-instruction-trigger-an-exceptionI suspect we should, yes. Adding in some custodians of other arm64 platforms for comment.
Does the unaligned access exception happen only before the MMU is enabled or even after ?
Signature · 2 lines
Best regards, Marek Vasut
Quoted 20 lines · Tom Rini
Quoted 17 lines · Lokesh Vutla
Hi All,
I am trying to enable CONFIG_USE_ARCH_MEMSET/MEMCPY on arm64 platforms and
realized that there is no arm64 specific memcpy available in u-boot. So I tried porting arm64 specific memcpy from kernel[1]. Memcpy stopped working after that and observed that if destination address is unaligned then system hangs.After doing a bit more research, understood that unaligned access to device or strongly ordered memories will fail. And the memory system (even normal RAM) behaves like strongly ordered memory when the MMU is disabled[2]. In u-boot MMU is enabled very late after relocation and SPL doesn't enable MMU at all.
Before I proceed any further wanted to hear from others if anyone have already tried and have any working solution. If not should we update the kernel memcpy to use unaligned destination address and use it in u-boot?
Quoted 5 lines
Quoted 2 lines
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/lib/memcpy.S
[2] https://community.arm.com/processors/f/discussions/7557/when-and-where-will-the-ldp-instruction-trigger-an-exceptionI suspect we should, yes. Adding in some custodians of other arm64 platforms for comment.
Right now we still use it from lib/string.c we don't enable ARCH_MEMCPY for arm64, indeed there is no code for doing that, if I'm not wrong.
Quoted 7 lines · Lokesh Vutla
Hi All,
I am trying to enable CONFIG_USE_ARCH_MEMSET/MEMCPY on arm64 platforms and realized that there is no arm64 specific memcpy available in u-boot. So I tried porting arm64 specific memcpy from kernel[1]. Memcpy stopped working after that and observed that if destination address is unaligned then system hangs.After doing a bit more research, understood that unaligned access to device or strongly ordered memories will fail. And the memory system (even normal RAM) behaves like strongly ordered memory when the MMU is disabled[2]. In u-boot MMU is enabled very late after relocation and SPL doesn't enable MMU at all.
ARMv8 does not allow unaligned accesses in privileged (i.e. except in EL0) modes.
Quoted 11 lines
Before I proceed any further wanted to hear from others if anyone have already tried and have any working solution. If not should we update the kernel memcpy to use unaligned destination address and use it in u-boot?
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/lib/memcpy.S
[2] https://community.arm.com/processors/f/discussions/7557/when-and-where-will-the-ldp-instruction-trigger-an-exceptionThanks and regards,
Lokesh
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot
Quoted 9 lines · Philipp Tomsich
Quoted 7 lines · Lokesh Vutla
Hi All,
I am trying to enable CONFIG_USE_ARCH_MEMSET/MEMCPY on arm64 platforms and realized that there is no arm64 specific memcpy available in u-boot. So I tried porting arm64 specific memcpy from kernel[1]. Memcpy stopped working after that and observed that if destination address is unaligned then system hangs.After doing a bit more research, understood that unaligned access to device or strongly ordered memories will fail. And the memory system (even normal RAM) behaves like strongly ordered memory when the MMU is disabled[2]. In u-boot MMU is enabled very late after relocation and SPL doesn't enable MMU at all.
ARMv8 does not allow unaligned accesses in privileged (i.e. except in EL0) modes.
Do you have a reference to this in the spec somewhere?
So far, I always assumed that the only constraint on AArch64 to have workable unaligned accesses is to enable caching and have the maps be declared as normal (for which you need to enable the MMU and provide PTEs that do so).
Quoted 2 lines
Quoted 2 lines
Before I proceed any further wanted to hear from others if anyone have already tried and have any working solution. If not should we update the kernel memcpy to use unaligned destination address and use it in u-boot?
Just make sure you're only doing aligned accesses and you're fine? Most memcpy code checks start and end for alignment, does aligned operations on those bits and then bigger chunks for the middle piece. I would assume you will find something like that in glibc for example.
The reason the kernel gets away without is that it knows that hardware unaligned access is always available, because it controls the page tables and it only ever runs from normal ram.
In SPL however, we may run from XIP or SRAM or whatever. In that case, even if you wanted to, you could not declare memory as normal and thus could not rely on hardware unaligned fixups.
Alex
Quoted 15 lines · Alexander Graf
Quoted 8 lines · Philipp Tomsich
Quoted 7 lines · Lokesh Vutla
Hi All,
I am trying to enable CONFIG_USE_ARCH_MEMSET/MEMCPY on arm64 platforms and realized that there is no arm64 specific memcpy available in u-boot. So I tried porting arm64 specific memcpy from kernel[1]. Memcpy stopped working after that and observed that if destination address is unaligned then system hangs.After doing a bit more research, understood that unaligned access to device or strongly ordered memories will fail. And the memory system (even normal RAM) behaves like strongly ordered memory when the MMU is disabled[2]. In u-boot MMU is enabled very late after relocation and SPL doesn't enable MMU at all.
Quoted 8 lines
Quoted 1 line
ARMv8 does not allow unaligned accesses in privileged (i.e. except in EL0) modes.
Do you have a reference to this in the spec somewhere?
So far, I always assumed that the only constraint on AArch64 to have workable unaligned accesses is to enable caching and have the maps be declared as normal (for which you need to enable the MMU and provide PTEs that do so).
"B2.5.2 Alignment of data accesses” in the AArch64 Architecture Manual has the full rules.
For non-normal memory, unaligned accesses will almost always spell trouble. They are specifically forbidden for device memory.
And yes, I oversimplified a bit: there’s the SCTLR_ELx register that controls whether alignment checks are performed. Unfortunately, this field resets to "a value that is architecturally UNKNOWN”, so unless explicitly enabled these will be disallowed… which is the default on a number of implementations.
There’s some added ugliness in the specification of alignment faults, if the faulting access crosses cache lines (I don’t want to go dig for the specific reference in the AArch64 ARM).
Unless we have trap handlers installed, the alignment fault will stop us with a data abort…
So from a bootloader-perspective it will probably be best to stay away from unaligned accesses unless we want to deal with the complexity of setting up SCTLR fully and differentiating between normal and non-normal memory for things like a memcpy.
Quoted 19 lines
Quoted 3 lines
Quoted 3 lines
Before I proceed any further wanted to hear from others if anyone have already tried and have any working solution. If not should we update the kernel memcpy to use unaligned destination address and use it in u-boot?
Just make sure you're only doing aligned accesses and you're fine? Most memcpy code checks start and end for alignment, does aligned operations on those bits and then bigger chunks for the middle piece. I would assume you will find something like that in glibc for example.
The reason the kernel gets away without is that it knows that hardware unaligned access is always available, because it controls the page tables and it only ever runs from normal ram.
In SPL however, we may run from XIP or SRAM or whatever. In that case, even if you wanted to, you could not declare memory as normal and thus could not rely on hardware unaligned fixups.
Alex