Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <joey.gouly@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Oliver Upton <oliver.upton@linux.dev>
Acked-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20240208105422.3444159-2-joey.gouly@arm.com
[oliver: migrate a bit more detail from the asm variant]
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>

authored by

Joey Gouly and committed by
Oliver Upton
d198e266 1f3ca702

+20 -10
+20 -10
arch/arm64/include/asm/kvm_mmu.h
··· 56 56 /* 57 57 * Convert a kernel VA into a HYP VA. 58 58 * 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). 64 59 */ 65 60 .macro kern_hyp_va reg 66 61 #ifndef __KVM_VHE_HYPERVISOR__ ··· 122 127 123 128 #define __hyp_pa(x) (((phys_addr_t)(x)) + hyp_physvirt_offset) 124 129 130 + /* 131 + * Convert a kernel VA into a HYP VA. 132 + * 133 + * Can be called from hyp or non-hyp context. 134 + * 135 + * The actual code generation takes place in kvm_update_va_mask(), and 136 + * the instructions below are only there to reserve the space and 137 + * perform the register allocation (kvm_update_va_mask() uses the 138 + * specific registers encoded in the instructions). 139 + */ 125 140 static __always_inline unsigned long __kern_hyp_va(unsigned long v) 126 141 { 142 + /* 143 + * This #ifndef is an optimisation for when this is called from VHE hyp 144 + * context. When called from a VHE non-hyp context, kvm_update_va_mask() will 145 + * replace the instructions with `nop`s. 146 + */ 127 147 #ifndef __KVM_VHE_HYPERVISOR__ 128 - asm volatile(ALTERNATIVE_CB("and %0, %0, #1\n" 129 - "ror %0, %0, #1\n" 130 - "add %0, %0, #0\n" 131 - "add %0, %0, #0, lsl 12\n" 132 - "ror %0, %0, #63\n", 148 + asm volatile(ALTERNATIVE_CB("and %0, %0, #1\n" /* mask with va_mask */ 149 + "ror %0, %0, #1\n" /* rotate to the first tag bit */ 150 + "add %0, %0, #0\n" /* insert the low 12 bits of the tag */ 151 + "add %0, %0, #0, lsl 12\n" /* insert the top 12 bits of the tag */ 152 + "ror %0, %0, #63\n", /* rotate back */ 133 153 ARM64_ALWAYS_SYSTEM, 134 154 kvm_update_va_mask) 135 155 : "+r" (v));