From a8f7fefd69019e76d0c02abb236ddb7f7827cd49 Mon Sep 17 00:00:00 2001 From: Vincent Donnefort Date: Fri, 25 Nov 2022 18:02:30 +0000 Subject: [PATCH] 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 Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_pkvm_module.h | 7 ++++--- arch/arm64/kvm/pkvm.c | 12 +++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) 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);