ANDROID: KVM: arm64: Allow enabling pKVM modules hyp event at boot

Allow to select pKVM modules declared hyp events in the kernel
commandline "hyp_event".

Bug: 357781595
Bug: 268495982
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
diff --git a/arch/arm64/kvm/hyp_events.c b/arch/arm64/kvm/hyp_events.c
index 74dc8e8..090eb40 100644
--- a/arch/arm64/kvm/hyp_events.c
+++ b/arch/arm64/kvm/hyp_events.c
@@ -353,7 +353,7 @@ static __init int setup_hyp_event_early(char *str)
 }
 __setup("hyp_event=", setup_hyp_event_early);
 
-bool hyp_trace_init_event_early(void)
+bool hyp_event_early_probe(void)
 {
 	char *token, *buf = early_events;
 	bool enabled = false;
@@ -376,8 +376,6 @@ bool hyp_trace_init_event_early(void)
 						token, ret);
 				else
 					enabled = true;
-			} else {
-				pr_warn("Couldn't find hyp event %s\n", token);
 			}
 		}
 
diff --git a/arch/arm64/kvm/hyp_trace.c b/arch/arm64/kvm/hyp_trace.c
index cca2e4c..9741c55a 100644
--- a/arch/arm64/kvm/hyp_trace.c
+++ b/arch/arm64/kvm/hyp_trace.c
@@ -990,12 +990,21 @@ static void hyp_trace_buffer_printk(struct hyp_trace_buffer *hyp_buffer)
 	}
 }
 
+void hyp_trace_enable_event_early(void)
+{
+	if (hyp_event_early_probe()) {
+		int err = hyp_trace_start();
+
+		if (err)
+			pr_warn("Failed to start early events tracing: %d\n", err);
+	}
+}
+
 int hyp_trace_init_tracefs(void)
 {
 	struct dentry *root, *per_cpu_root;
 	char per_cpu_name[16];
 	long cpu;
-	int err;
 
 	if (!is_protected_kvm_enabled())
 		return 0;
@@ -1049,17 +1058,14 @@ int hyp_trace_init_tracefs(void)
 	}
 
 	hyp_trace_init_event_tracefs(root);
+
+	hyp_trace_enable_event_early();
+
 	hyp_trace_init_testing_tracefs(root);
 
 	if (hyp_trace_buffer.printk_on &&
 	    hyp_trace_buffer_printk_init(&hyp_trace_buffer))
 		pr_warn("Failed to init ht_printk");
 
-	if (hyp_trace_init_event_early()) {
-		err = hyp_trace_start();
-		if (err)
-			pr_warn("Failed to start early events tracing: %d\n", err);
-	}
-
 	return 0;
 }
diff --git a/arch/arm64/kvm/hyp_trace.h b/arch/arm64/kvm/hyp_trace.h
index f10388bc..f2bdff4 100644
--- a/arch/arm64/kvm/hyp_trace.h
+++ b/arch/arm64/kvm/hyp_trace.h
@@ -11,10 +11,11 @@ int hyp_trace_init_tracefs(void);
 int hyp_trace_init_events(void);
 struct hyp_event *hyp_trace_find_event(int id);
 void hyp_trace_init_event_tracefs(struct dentry *parent);
-bool hyp_trace_init_event_early(void);
 int hyp_trace_init_mod_events(struct hyp_event *event,
 			      struct hyp_event_id *event_id, int nr_events,
 			      struct hyp_printk_fmt *fmt, int nr_fmts);
+bool hyp_event_early_probe(void);
+void hyp_trace_enable_event_early(void);
 #else
 static inline int hyp_trace_init_tracefs(void) { return 0; }
 static inline int hyp_trace_init_events(void) { return 0; }
@@ -25,5 +26,6 @@ hyp_trace_init_mod_events(struct hyp_event *event,
 {
 	return 0;
 }
+static inline void hyp_trace_enable_event_early(void) { }
 #endif
 #endif
diff --git a/arch/arm64/kvm/pkvm.c b/arch/arm64/kvm/pkvm.c
index 384994b..378960b 100644
--- a/arch/arm64/kvm/pkvm.c
+++ b/arch/arm64/kvm/pkvm.c
@@ -873,6 +873,8 @@ int __pkvm_load_el2_module(struct module *this, unsigned long *token)
 		return ret;
 	}
 
+	hyp_trace_enable_event_early();
+
 	return 0;
 }
 EXPORT_SYMBOL(__pkvm_load_el2_module);