Skip to content

Commit f50b6f6

Browse files
AndrewScullMarc Zyngier
authored andcommitted
KVM: arm64: Handle calls to prefixed hyp functions
Once hyp functions are moved to a hyp object, they will have prefixed symbols. This change declares and gets the address of the prefixed version for calls to the hyp functions. To aid migration, the hyp functions that have not yet moved have their prefixed versions aliased to their non-prefixed version. This begins with all the hyp functions being listed and will reduce to none of them once the migration is complete. Signed-off-by: Andrew Scull <[email protected]> [David: Extracted kvm_call_hyp nVHE branches into own helper macros, added comments around symbol aliases.] Signed-off-by: David Brazdil <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 53b6711 commit f50b6f6

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

arch/arm64/include/asm/kvm_asm.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@
4242

4343
#include <linux/mm.h>
4444

45+
/*
46+
* Translate name of a symbol defined in nVHE hyp to the name seen
47+
* by kernel proper. All nVHE symbols are prefixed by the build system
48+
* to avoid clashes with the VHE variants.
49+
*/
50+
#define kvm_nvhe_sym(sym) __kvm_nvhe_##sym
51+
52+
#define DECLARE_KVM_VHE_SYM(sym) extern char sym[]
53+
#define DECLARE_KVM_NVHE_SYM(sym) extern char kvm_nvhe_sym(sym)[]
54+
55+
/*
56+
* Define a pair of symbols sharing the same name but one defined in
57+
* VHE and the other in nVHE hyp implementations.
58+
*/
59+
#define DECLARE_KVM_HYP_SYM(sym) \
60+
DECLARE_KVM_VHE_SYM(sym); \
61+
DECLARE_KVM_NVHE_SYM(sym)
62+
4563
/* Translate a kernel address of @sym into its equivalent linear mapping */
4664
#define kvm_ksym_ref(sym) \
4765
({ \
@@ -50,6 +68,7 @@
5068
val = lm_alias(&sym); \
5169
val; \
5270
})
71+
#define kvm_ksym_ref_nvhe(sym) kvm_ksym_ref(kvm_nvhe_sym(sym))
5372

5473
struct kvm;
5574
struct kvm_vcpu;

arch/arm64/include/asm/kvm_host.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,18 @@ void kvm_arm_resume_guest(struct kvm *kvm);
448448

449449
u64 __kvm_call_hyp(void *hypfn, ...);
450450

451+
#define kvm_call_hyp_nvhe(f, ...) \
452+
do { \
453+
DECLARE_KVM_NVHE_SYM(f); \
454+
__kvm_call_hyp(kvm_ksym_ref_nvhe(f), ##__VA_ARGS__); \
455+
} while(0)
456+
457+
#define kvm_call_hyp_nvhe_ret(f, ...) \
458+
({ \
459+
DECLARE_KVM_NVHE_SYM(f); \
460+
__kvm_call_hyp(kvm_ksym_ref_nvhe(f), ##__VA_ARGS__); \
461+
})
462+
451463
/*
452464
* The couple of isb() below are there to guarantee the same behaviour
453465
* on VHE as on !VHE, where the eret to EL1 acts as a context
@@ -459,7 +471,7 @@ u64 __kvm_call_hyp(void *hypfn, ...);
459471
f(__VA_ARGS__); \
460472
isb(); \
461473
} else { \
462-
__kvm_call_hyp(kvm_ksym_ref(f), ##__VA_ARGS__); \
474+
kvm_call_hyp_nvhe(f, ##__VA_ARGS__); \
463475
} \
464476
} while(0)
465477

@@ -471,8 +483,7 @@ u64 __kvm_call_hyp(void *hypfn, ...);
471483
ret = f(__VA_ARGS__); \
472484
isb(); \
473485
} else { \
474-
ret = __kvm_call_hyp(kvm_ksym_ref(f), \
475-
##__VA_ARGS__); \
486+
ret = kvm_call_hyp_nvhe_ret(f, ##__VA_ARGS__); \
476487
} \
477488
\
478489
ret; \

arch/arm64/kernel/image-vars.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,32 @@ __efistub__ctype = _ctype;
6363

6464
#define KVM_NVHE_ALIAS(sym) __kvm_nvhe_##sym = sym;
6565

66+
/* Symbols defined in debug-sr.c (not yet compiled with nVHE build rules). */
67+
KVM_NVHE_ALIAS(__kvm_get_mdcr_el2);
68+
69+
/* Symbols defined in switch.c (not yet compiled with nVHE build rules). */
70+
KVM_NVHE_ALIAS(__kvm_vcpu_run_nvhe);
71+
72+
/* Symbols defined in sysreg-sr.c (not yet compiled with nVHE build rules). */
73+
KVM_NVHE_ALIAS(__kvm_enable_ssbs);
74+
75+
/* Symbols defined in timer-sr.c (not yet compiled with nVHE build rules). */
76+
KVM_NVHE_ALIAS(__kvm_timer_set_cntvoff);
77+
78+
/* Symbols defined in tlb.c (not yet compiled with nVHE build rules). */
79+
KVM_NVHE_ALIAS(__kvm_flush_vm_context);
80+
KVM_NVHE_ALIAS(__kvm_tlb_flush_local_vmid);
81+
KVM_NVHE_ALIAS(__kvm_tlb_flush_vmid);
82+
KVM_NVHE_ALIAS(__kvm_tlb_flush_vmid_ipa);
83+
84+
/* Symbols defined in vgic-v3-sr.c (not yet compiled with nVHE build rules). */
85+
KVM_NVHE_ALIAS(__vgic_v3_get_ich_vtr_el2);
86+
KVM_NVHE_ALIAS(__vgic_v3_init_lrs);
87+
KVM_NVHE_ALIAS(__vgic_v3_read_vmcr);
88+
KVM_NVHE_ALIAS(__vgic_v3_restore_aprs);
89+
KVM_NVHE_ALIAS(__vgic_v3_save_aprs);
90+
KVM_NVHE_ALIAS(__vgic_v3_write_vmcr);
91+
6692
#endif /* CONFIG_KVM */
6793

6894
#endif /* __ARM64_KERNEL_IMAGE_VARS_H */

0 commit comments

Comments
 (0)