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:
parent
53b3a7721b
commit
fb5ea70e2e
2 changed files with 18 additions and 18 deletions
|
|
@ -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, ...) \
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue