ANDROID: KVM: arm64: Automate pKVM module event registration

Previously, modules had to register themselves the .event_ids ELF
section. This is now on done on their behalf before jumping into the
module init function.

Bug: 357781595
Bug: 268495982
Change-Id: Iebe839dc096d3020921e2c97a75a5284c518dee7
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
This commit is contained in:
Vincent Donnefort
2024-09-24 15:06:24 +01:00
parent 58a9340b99
commit 4821a718ef
6 changed files with 11 additions and 13 deletions
-1
View File
@@ -210,7 +210,6 @@ struct pkvm_module_ops {
phys_addr_t (*hyp_pa)(void *x);
void* (*hyp_va)(phys_addr_t phys);
unsigned long (*kern_hyp_va)(unsigned long x);
int (*register_hyp_event_ids)(unsigned long start, unsigned long end);
void* (*tracing_reserve_entry)(unsigned long length);
void (*tracing_commit_entry)(void);
void (*tracing_mod_hyp_printk)(u8 fmt_id, u64 a, u64 b, u64 c, u64 d);
@@ -7,7 +7,7 @@
#ifdef CONFIG_TRACING
void *tracing_reserve_entry(unsigned long length);
void tracing_commit_entry(void);
int register_hyp_event_ids(unsigned long start, unsigned long end);
int register_hyp_event_ids(void *event_ids, size_t nr_events);
#define HYP_EVENT(__name, __proto, __struct, __assign, __printk) \
HYP_EVENT_FORMAT(__name, __struct); \
@@ -80,7 +80,7 @@ do { \
#else
static inline void *tracing_reserve_entry(unsigned long length) { return NULL; }
static inline void tracing_commit_entry(void) { }
static inline int register_hyp_event_ids(unsigned long start, unsigned long end)
static inline int register_hyp_event_ids(void *event_ids, size_t nr_events)
{
return -ENODEV;
}
+3 -3
View File
@@ -72,7 +72,7 @@ static bool try_set_mod_event(unsigned short id, bool enable)
return false;
}
int register_hyp_event_ids(unsigned long start, unsigned long end)
int register_hyp_event_ids(void *event_ids, size_t nr_events)
{
int mod, ret = -ENOMEM;
@@ -80,8 +80,8 @@ int register_hyp_event_ids(unsigned long start, unsigned long end)
mod = atomic_read(&num_event_id_mod);
if (mod < MAX_EVENT_ID_MOD) {
event_id_mod[mod].start = (struct hyp_event_id *)start;
event_id_mod[mod].end = (struct hyp_event_id *)end;
event_id_mod[mod].start = (struct hyp_event_id *)event_ids;
event_id_mod[mod].end = (struct hyp_event_id *)event_ids + nr_events;
/*
* Order access between num_event_id_mod and event_id_mod.
* Paired with try_set_mod_event()
-2
View File
@@ -21,9 +21,7 @@ SECTIONS {
.hyp.event_ids : {
HYP_SECTION_SYMBOL_NAME(.event_ids) = .;
__hyp_event_ids_start = .;
*(HYP_SECTION_NAME(.event_ids))
__hyp_event_ids_end = .;
*(HYP_SECTION_NAME(.printk_fmt_offset))
}
+6 -1
View File
@@ -244,7 +244,6 @@ const struct pkvm_module_ops module_ops = {
.hyp_pa = hyp_virt_to_phys,
.hyp_va = hyp_phys_to_virt,
.kern_hyp_va = __kern_hyp_va,
.register_hyp_event_ids = register_hyp_event_ids,
.tracing_reserve_entry = tracing_reserve_entry,
.tracing_commit_entry = tracing_commit_entry,
.tracing_mod_hyp_printk = tracing_mod_hyp_printk,
@@ -277,6 +276,12 @@ int __pkvm_init_module(void *host_mod)
{
int (*do_module_init)(const struct pkvm_module_ops *ops);
struct pkvm_el2_module *mod = kern_hyp_va(host_mod);
void *event_ids;
event_ids = pkvm_module_hyp_va(mod, mod->event_ids.start);
if (mod->nr_hyp_events)
register_hyp_event_ids(event_ids, mod->nr_hyp_events);
do_module_init = pkvm_module_hyp_va(mod, (void *)mod->init);
-4
View File
@@ -134,10 +134,6 @@ bool filter_smc(struct user_pt_regs *regs)
int pkvm_smc_filter_hyp_init(const struct pkvm_module_ops *ops)
{
#ifdef CONFIG_TRACING
ops->register_hyp_event_ids((unsigned long)__hyp_event_ids_start,
(unsigned long)__hyp_event_ids_end);
#endif
pkvm_ops = ops;
return ops->register_host_smc_handler(filter_smc);
}