diff --git a/arch/arm64/include/asm/kvm_pkvm_module.h b/arch/arm64/include/asm/kvm_pkvm_module.h index 92bb90954cfd..2a8ced4b53d5 100644 --- a/arch/arm64/include/asm/kvm_pkvm_module.h +++ b/arch/arm64/include/asm/kvm_pkvm_module.h @@ -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 diff --git a/arch/arm64/kvm/pkvm.c b/arch/arm64/kvm/pkvm.c index 4e14e055b724..77af44dc0019 100644 --- a/arch/arm64/kvm/pkvm.c +++ b/arch/arm64/kvm/pkvm.c @@ -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);