Skip to content

Commit d198e26

Browse files
jgoulyoupton
authored andcommitted
KVM: arm64: add comments to __kern_hyp_va
Document this function a little, to make it easier to understand. The assembly comments were copied from the kern_hyp_va asm macro. Signed-off-by: Joey Gouly <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Oliver Upton <[email protected]> Acked-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] [oliver: migrate a bit more detail from the asm variant] Signed-off-by: Oliver Upton <[email protected]>
1 parent 1f3ca70 commit d198e26

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

arch/arm64/include/asm/kvm_mmu.h

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@
5656
/*
5757
* Convert a kernel VA into a HYP VA.
5858
* reg: VA to be converted.
59-
*
60-
* The actual code generation takes place in kvm_update_va_mask, and
61-
* the instructions below are only there to reserve the space and
62-
* perform the register allocation (kvm_update_va_mask uses the
63-
* specific registers encoded in the instructions).
6459
*/
6560
.macro kern_hyp_va reg
6661
#ifndef __KVM_VHE_HYPERVISOR__
@@ -127,14 +122,29 @@ void kvm_apply_hyp_relocations(void);
127122

128123
#define __hyp_pa(x) (((phys_addr_t)(x)) + hyp_physvirt_offset)
129124

125+
/*
126+
* Convert a kernel VA into a HYP VA.
127+
*
128+
* Can be called from hyp or non-hyp context.
129+
*
130+
* The actual code generation takes place in kvm_update_va_mask(), and
131+
* the instructions below are only there to reserve the space and
132+
* perform the register allocation (kvm_update_va_mask() uses the
133+
* specific registers encoded in the instructions).
134+
*/
130135
static __always_inline unsigned long __kern_hyp_va(unsigned long v)
131136
{
137+
/*
138+
* This #ifndef is an optimisation for when this is called from VHE hyp
139+
* context. When called from a VHE non-hyp context, kvm_update_va_mask() will
140+
* replace the instructions with `nop`s.
141+
*/
132142
#ifndef __KVM_VHE_HYPERVISOR__
133-
asm volatile(ALTERNATIVE_CB("and %0, %0, #1\n"
134-
"ror %0, %0, #1\n"
135-
"add %0, %0, #0\n"
136-
"add %0, %0, #0, lsl 12\n"
137-
"ror %0, %0, #63\n",
143+
asm volatile(ALTERNATIVE_CB("and %0, %0, #1\n" /* mask with va_mask */
144+
"ror %0, %0, #1\n" /* rotate to the first tag bit */
145+
"add %0, %0, #0\n" /* insert the low 12 bits of the tag */
146+
"add %0, %0, #0, lsl 12\n" /* insert the top 12 bits of the tag */
147+
"ror %0, %0, #63\n", /* rotate back */
138148
ARM64_ALWAYS_SYSTEM,
139149
kvm_update_va_mask)
140150
: "+r" (v));

0 commit comments

Comments
 (0)