|
53 | 53 |
|
54 | 54 | #include <asm/alternative.h> |
55 | 55 |
|
56 | | -/* |
57 | | - * Convert a kernel VA into a HYP VA. |
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 | | - */ |
65 | | -.macro kern_hyp_va reg |
66 | | -#ifndef __KVM_VHE_HYPERVISOR__ |
67 | | -alternative_cb ARM64_ALWAYS_SYSTEM, kvm_update_va_mask |
68 | | - and \reg, \reg, #1 /* mask with va_mask */ |
69 | | - ror \reg, \reg, #1 /* rotate to the first tag bit */ |
70 | | - add \reg, \reg, #0 /* insert the low 12 bits of the tag */ |
71 | | - add \reg, \reg, #0, lsl 12 /* insert the top 12 bits of the tag */ |
72 | | - ror \reg, \reg, #63 /* rotate back */ |
73 | | -alternative_cb_end |
74 | | -#endif |
75 | | -.endm |
76 | | - |
77 | 56 | /* |
78 | 57 | * Convert a hypervisor VA to a PA |
79 | 58 | * reg: hypervisor address to be converted in place |
@@ -127,14 +106,29 @@ void kvm_apply_hyp_relocations(void); |
127 | 106 |
|
128 | 107 | #define __hyp_pa(x) (((phys_addr_t)(x)) + hyp_physvirt_offset) |
129 | 108 |
|
| 109 | +/* |
| 110 | + * Convert a kernel VA into a HYP VA. |
| 111 | + * |
| 112 | + * Can be called from hyp or non-hyp context. |
| 113 | + * |
| 114 | + * The actual code generation takes place in kvm_update_va_mask(), and |
| 115 | + * the instructions below are only there to reserve the space and |
| 116 | + * perform the register allocation (kvm_update_va_mask() uses the |
| 117 | + * specific registers encoded in the instructions). |
| 118 | + */ |
130 | 119 | static __always_inline unsigned long __kern_hyp_va(unsigned long v) |
131 | 120 | { |
| 121 | +/* |
| 122 | + * This #ifndef is an optimisation for when this is called from VHE hyp |
| 123 | + * context. When called from a VHE non-hyp context, kvm_update_va_mask() will |
| 124 | + * replace the instructions with `nop`s. |
| 125 | + */ |
132 | 126 | #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", |
| 127 | + asm volatile(ALTERNATIVE_CB("and %0, %0, #1\n" /* mask with va_mask */ |
| 128 | + "ror %0, %0, #1\n" /* rotate to the first tag bit */ |
| 129 | + "add %0, %0, #0\n" /* insert the low 12 bits of the tag */ |
| 130 | + "add %0, %0, #0, lsl 12\n" /* insert the top 12 bits of the tag */ |
| 131 | + "ror %0, %0, #63\n", /* rotate back */ |
138 | 132 | ARM64_ALWAYS_SYSTEM, |
139 | 133 | kvm_update_va_mask) |
140 | 134 | : "+r" (v)); |
|
0 commit comments