ARM: HYP/non-sec: Propagate stack pointer to hyp mode
PATCH 1/1 ARM: HYP/non-sec: Propagate stack pointer to hyp mode
Some users of the u-boot API (specifically grub) use the initial SP as a hint regarding where to look for the u-boot API signature.
---
This applies on top of Marc's "ARMv7: add PSCI support to u-boot" and allows me to chainload grub on a cubieboard2. (I don't think that has been applied anywhere yet?)
--- arch/arm/cpu/armv7/nonsec_virt.S | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm/cpu/armv7/nonsec_virt.S +4 -0
@@ -60,6 +60,10 @@ _secure_monitor: #ifdef CONFIG_ARMV7_VIRT orreq r5, r5, #0x100 @ allow HVC instruction moveq r6, #HYP_MODE @ Enter the kernel as HYP + + mrseq r4, sp_svc @ Propagate SP to HYP mode + msreq sp_hyp, r4 @ it serves as a "hint" to + @ find the u-boot API root. #endif mcr p15, 0, r5, c1, c1, 0 @ write SCR (with NS bit set)
Signature · 1 line
1.8.4.rc3
PATCH 1/1 ARM: HYP/non-sec: Propagate stack pointer to hyp mode
Hi Ian,
Quoted 2 lines · Ian Campbell
Some users of the u-boot API (specifically grub) use the initial SP as a hint regarding where to look for the u-boot API signature.
That looks really fragile...
Quoted 6 lines
Signed-off-by Ian Campbell <[email protected]>Cc Marc Zyngier <[email protected]>---
This applies on top of Marc's "ARMv7: add PSCI support to u-boot" and allows me to chainload grub on a cubieboard2. (I don't think that has been applied anywhere yet?)
Not yet, I'm still tinkering with it. See the current state at:git://git.kernel.org/pub/scm/linux/kernel/git/maz/u-boot.git wip/psci
Quoted 9 lines
--- arch/arm/cpu/armv7/nonsec_virt.S | 4 ++++ 1 file changed, 4 insertions(+)arch/arm/cpu/armv7/nonsec_virt.S +0
-0
arch/arm/cpu/armv7/nonsec_virt.S _secure_monitor: · line 66
Quoted 7 lines
arch/arm/cpu/armv7/nonsec_virt.S +4
-0@@ -60,6 +60,10 @@ _secure_monitor: #ifdef CONFIG_ARMV7_VIRT orreq r5, r5, #0x100 @ allow HVC instruction moveq r6, #HYP_MODE @ Enter the kernel as HYP + + mrseq r4, sp_svc @ Propagate SP to HYP mode + msreq sp_hyp, r4 @ it serves as a "hint" to + @ find the u-boot API root.
So how does it work? Grub knows the range in which to find the signature? And then what?
Not saying this patch is wrong (it seems to solve a real problem), but I'd like to understand it a bit more.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
PATCH 1/1 ARM: HYP/non-sec: Propagate stack pointer to hyp mode
Quoted 7 lines · Marc Zyngier
Hi Ian,
Quoted 2 lines · Ian Campbell
Some users of the u-boot API (specifically grub) use the initial SP as a hint regarding where to look for the u-boot API signature.
That looks really fragile...
No kidding, but it does appear to be The Way (i.e. u-boot.git/examples/api does it too).
TBH my impression of the API stuff is that it is a prototype which got out of hand and became a real thing without some of the stuff which needed doing properly getting redone. That said, I'm not offering to fix it so I suppose I shouldn't throw stones.
Quoted 10 lines
Quoted 7 lines
Signed-off-by Ian Campbell <[email protected]>Cc Marc Zyngier <[email protected]>---
This applies on top of Marc's "ARMv7: add PSCI support to u-boot" and allows me to chainload grub on a cubieboard2. (I don't think that has been applied anywhere yet?)Not yet, I'm still tinkering with it. See the current state at:
git://git.kernel.org/pub/scm/linux/kernel/git/maz/u-boot.gitwip/psci
Thanks for the pointer.
Quoted 7 lines
arch/arm/cpu/armv7/nonsec_virt.S _secure_monitor: · line 66
Quoted 4 lines
arch/arm/cpu/armv7/nonsec_virt.S +4
-0+ + mrseq r4, sp_svc @ Propagate SP to HYP mode + msreq sp_hyp, r4 @ it serves as a "hint" to + @ find the u-boot API root.So how does it work? Grub knows the range in which to find the signature? And then what?
It scrobbles over the region either side of this hint looking for the signature and a valid checksum. Or as u-boot.git/api/README says:
- consumer application will recognize the API is available by searching a specified (assumed by convention) range of address space for the signature
(where the "convention" is "around about sp on entry")
Easiest place to look is u-boot.git/examples/api/glue.c api_search_sig and valid_sig.
On the grub side the code is grub.git/grub-core/kern/uboot/uboot.c in grub_uboot_api_init (although it doesn't seem to check the checksum).
There isn't actually any special handling of sp on call into the guest kernel which I can find though. It appears to rely on u-boot's malloc placing "struct api_signature *sig" somewhere near the sp, either this relies implicitly on the specifics of the memory layout and/or the malloc allocator's behaviour or it is doing something too clever for me to spot.
Quoted 2 lines
Not saying this patch is wrong (it seems to solve a real problem), but I'd like to understand it a bit more.
There be dragons...