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 <vdonnefort@google.com>
This commit is contained in:
Vincent Donnefort
2022-12-09 18:10:43 +00:00
parent 7923a25bf9
commit 93ed9e00b1
2 changed files with 19 additions and 19 deletions

View File

@@ -44,8 +44,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)
@@ -53,14 +52,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; \
})
/*
* function_nocfi() does not work with function pointers, hence the macro in
* lieu of a function.
@@ -73,10 +84,8 @@ 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(function_nocfi(hfn), token, \
hyp_text_kern_va); \
__pkvm_register_el2_call(pkvm_el2_mod_va(function_nocfi(hfn), \
token)); \
})
#define pkvm_el2_mod_call(id, ...) \

View File

@@ -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 */