|
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__
|
@@ -127,14 +122,29 @@ void kvm_apply_hyp_relocations(void);
|
127 | 122 |
|
128 | 123 | #define __hyp_pa(x) (((phys_addr_t)(x)) + hyp_physvirt_offset)
|
129 | 124 |
|
| 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 | + */ |
130 | 135 | static __always_inline unsigned long __kern_hyp_va(unsigned long v)
|
131 | 136 | {
|
| 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 | + */ |
132 | 142 | #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 */ |
138 | 148 | ARM64_ALWAYS_SYSTEM,
|
139 | 149 | kvm_update_va_mask)
|
140 | 150 | : "+r" (v));
|
|
0 commit comments