xen/arm64: Zero the top 32 bits of gp registers on entry...
authorMichal Orzel <michal.orzel@arm.com>
Fri, 17 Dec 2021 07:21:59 +0000 (08:21 +0100)
committerStefano Stabellini <stefano.stabellini@xilinx.com>
Thu, 10 Mar 2022 17:41:19 +0000 (09:41 -0800)
commit04c7cc2b79053e7d358631d3450bf1b35fbc5f8d
tree2a2431ccf36392c72d12fe420515b6adc081a887
parentee4d66242eef4d4c4215a432dece577093bfcbbc
xen/arm64: Zero the top 32 bits of gp registers on entry...

to hypervisor when switching from AArch32 state.

According to section D1.20.2 of Arm Arm(DDI 0487A.j):
"If the general-purpose register was accessible from AArch32 state the
upper 32 bits either become zero, or hold the value that the same
architectural register held before any AArch32 execution.
The choice between these two options is IMPLEMENTATION DEFINED"

Currently Xen does not ensure that the top 32 bits are zeroed and this
needs to be fixed. The reason why is that there are places in Xen
where we assume that top 32bits are zero for AArch32 guests.
If they are not, this can lead to misinterpretation of Xen regarding
what the guest requested. For example hypercalls returning an error
encoded in a signed long like do_sched_op, do_hmv_op, do_memory_op
would return -ENOSYS if the command passed as the first argument was
clobbered.

Create a macro clobber_gp_top_halves to clobber top 32 bits of gp
registers when hyp == 0 (guest mode) and compat == 1 (AArch32 mode).
Add a compile time check to ensure that save_x0_x1 == 1 if
compat == 1.

Signed-off-by: Michal Orzel <michal.orzel@arm.com>
[julieng: Tweak the comment in clobber_gp_top_halves]
Acked-by: Julien Grall <jgrall@amazon.com>
(cherry picked from commit 32365f3476ac4655f2f26111cd7879912808cd77)
xen/arch/arm/arm64/entry.S