From fb5ea70e2e33932b5b35fedd7a30cf5d9170126c Mon Sep 17 00:00:00 2001 From: Vincent Donnefort Date: Fri, 9 Dec 2022 18:10:43 +0000 Subject: [PATCH] ANDROID: KVM: arm64: Add helper for pKVM modules addr conversion pKVM modules can't rely on the usual hyp function kern_hyp_va() to convert addr from the kernel space to the hyp's. Instead, provide pkvm_el2_mod_va() that will do the conversion using the token provided by pkvm_load_el2_module(). Bug: 244543039 Bug: 244373730 Change-Id: I7423b40f1107bb92cd732843c5cdbf1d45662f00 Signed-off-by: Vincent Donnefort --- arch/arm64/include/asm/kvm_pkvm_module.h | 23 ++++++++++++++++------- arch/arm64/kvm/pkvm.c | 13 ++----------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pkvm_module.h b/arch/arm64/include/asm/kvm_pkvm_module.h index 3e0ebde74e03..a9f7994189a7 100644 --- a/arch/arm64/include/asm/kvm_pkvm_module.h +++ b/arch/arm64/include/asm/kvm_pkvm_module.h @@ -38,8 +38,7 @@ struct pkvm_module_ops { int __pkvm_load_el2_module(struct module *this, unsigned long *token); -int __pkvm_register_el2_call(dyn_hcall_t hfn, unsigned long token, - unsigned long hyp_text_kern_va); +int __pkvm_register_el2_call(unsigned long hfn_hyp_va); #else static inline int __pkvm_load_el2_module(struct module *this, unsigned long *token) @@ -47,14 +46,26 @@ static inline int __pkvm_load_el2_module(struct module *this, return -ENOSYS; } -static inline int __pkvm_register_el2_call(dyn_hcall_t hfn, unsigned long token, - unsigned long hyp_text_kern_va) +static inline int __pkvm_register_el2_call(unsigned long hfn_hyp_va) { return -ENOSYS; } #endif /* CONFIG_MODULES */ #ifdef MODULE +/* + * Convert an EL2 module addr from the kernel VA to the hyp VA + */ +#define pkvm_el2_mod_va(kern_va, token) \ +({ \ + unsigned long hyp_text_kern_va = \ + (unsigned long)THIS_MODULE->arch.hyp.text.start; \ + unsigned long offset; \ + \ + offset = (unsigned long)kern_va - hyp_text_kern_va; \ + token + offset; \ +}) + #define pkvm_load_el2_module(init_fn, token) \ ({ \ THIS_MODULE->arch.hyp.init = init_fn; \ @@ -63,9 +74,7 @@ static inline int __pkvm_register_el2_call(dyn_hcall_t hfn, unsigned long token, #define pkvm_register_el2_mod_call(hfn, token) \ ({ \ - unsigned long hyp_text_kern_va; \ - hyp_text_kern_va = THIS_MODULE->arch.hyp.text.start; \ - __pkvm_register_el2_call(hfn, token, hyp_text_kern_va); \ + __pkvm_register_el2_call(pkvm_el2_mod_va(hfn, token)); \ }) #define pkvm_el2_mod_call(id, ...) \ diff --git a/arch/arm64/kvm/pkvm.c b/arch/arm64/kvm/pkvm.c index 57395cb8f7a9..7e2aa36b74ac 100644 --- a/arch/arm64/kvm/pkvm.c +++ b/arch/arm64/kvm/pkvm.c @@ -655,18 +655,9 @@ int __pkvm_load_el2_module(struct module *this, unsigned long *token) } EXPORT_SYMBOL_GPL(__pkvm_load_el2_module); -int __pkvm_register_el2_call(dyn_hcall_t hfn, unsigned long token, - unsigned long hyp_text_kern_va) +int __pkvm_register_el2_call(unsigned long hfn_hyp_va) { - unsigned long hfn_hyp_va, offset, text_hyp_va = token; - int ret; - - offset = (unsigned long)hfn - hyp_text_kern_va; - hfn_hyp_va = text_hyp_va + offset; - - ret = kvm_call_hyp_nvhe(__pkvm_register_hcall, - (unsigned long)hfn_hyp_va); - return ret; + return kvm_call_hyp_nvhe(__pkvm_register_hcall, hfn_hyp_va); } EXPORT_SYMBOL_GPL(__pkvm_register_el2_call); #endif /* CONFIG_MODULES */