ANDROID: KVM: arm64: Return a token for a pKVM module registration

Later introduction of custom HVCs will require to store some data.
Conviniently, the only thing we need is the start addr (in the hyp VA) of
the text section. So use this value as a token to avoid having to store
it anywhere.

Bug: 244543039
Bug: 244373730
Change-Id: Idd0bcbbb36d189aa4932833ca5b40382c2cddb08
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Quentin Perret <qperret@google.com>
This commit is contained in:
Vincent Donnefort
2022-11-25 18:02:30 +00:00
committed by Quentin Perret
parent fc7032826c
commit a8f7fefd69
2 changed files with 15 additions and 4 deletions

View File

@@ -38,9 +38,10 @@ struct pkvm_el2_module {
};
#ifdef MODULE
int __pkvm_load_el2_module(struct pkvm_el2_module *mod, struct module *this);
int __pkvm_load_el2_module(struct pkvm_el2_module *mod, struct module *this,
unsigned long *token);
#define pkvm_load_el2_module(init_fn) \
#define pkvm_load_el2_module(init_fn, token) \
({ \
extern char __kvm_nvhe___hypmod_text_start[]; \
extern char __kvm_nvhe___hypmod_text_end[]; \
@@ -67,7 +68,7 @@ int __pkvm_load_el2_module(struct pkvm_el2_module *mod, struct module *this);
sizeof(*mod.relocs); \
mod.init = init_fn; \
\
__pkvm_load_el2_module(&mod, THIS_MODULE); \
__pkvm_load_el2_module(&mod, THIS_MODULE, token); \
})
#endif
#endif

View File

@@ -490,7 +490,8 @@ static int __pkvm_cmp_mod_sec(const void *p1, const void *p2)
return s1->sec->start < s2->sec->start ? -1 : s1->sec->start > s2->sec->start;
}
int __pkvm_load_el2_module(struct pkvm_el2_module *mod, struct module *this)
int __pkvm_load_el2_module(struct pkvm_el2_module *mod, struct module *this,
unsigned long *token)
{
struct pkvm_mod_sec_mapping secs_map[] = {
{ &mod->text, KVM_PGTABLE_PROT_R | KVM_PGTABLE_PROT_X },
@@ -529,6 +530,15 @@ int __pkvm_load_el2_module(struct pkvm_el2_module *mod, struct module *this)
module_put(this);
return -ENOMEM;
}
/*
* The token can be used for other calls related to this module.
* Conveniently the only information needed is this addr so let's use it
* as an identifier.
*/
if (token)
*token = (unsigned long)hyp_va;
endrel = (void *)mod->relocs + mod->nr_relocs * sizeof(*endrel);
kvm_apply_hyp_module_relocations(start, hyp_va, mod->relocs, endrel);