]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: Add selftest event support to nVHE/pKVM hyp
authorVincent Donnefort <vdonnefort@google.com>
Mon, 9 Mar 2026 16:25:15 +0000 (16:25 +0000)
committerMarc Zyngier <maz@kernel.org>
Wed, 11 Mar 2026 08:51:17 +0000 (08:51 +0000)
Add a selftest event that can be triggered from a `write_event` tracefs
file. This intends to be used by trace remote selftests.

Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
Link: https://patch.msgid.link/20260309162516.2623589-30-vdonnefort@google.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/include/asm/kvm_asm.h
arch/arm64/include/asm/kvm_hypevents.h
arch/arm64/kvm/hyp/nvhe/hyp-main.c
arch/arm64/kvm/hyp_trace.c

index 47d250436f8cab9b782106eb515dc21a3f012b55..c8eb992d3ac8e4d2e1774b380e92318bdc6ebe36 100644 (file)
@@ -96,6 +96,7 @@ enum __kvm_host_smccc_func {
        __KVM_HOST_SMCCC_FUNC___tracing_update_clock,
        __KVM_HOST_SMCCC_FUNC___tracing_reset,
        __KVM_HOST_SMCCC_FUNC___tracing_enable_event,
+       __KVM_HOST_SMCCC_FUNC___tracing_write_event,
 };
 
 #define DECLARE_KVM_VHE_SYM(sym)       extern char sym[]
index 221a1dacb2f015ca6f9a5a6dfd276ebfef51643a..743c49bd878f72db738596689aa89aebc956fa61 100644 (file)
@@ -46,4 +46,15 @@ HYP_EVENT(hyp_exit,
        ),
        HE_PRINTK("reason=%s vcpu=%d", __hyp_enter_exit_reason_str(__entry->reason), __entry->vcpu)
 );
+
+HYP_EVENT(selftest,
+       HE_PROTO(u64 id),
+       HE_STRUCT(
+               he_field(u64, id)
+       ),
+       HE_ASSIGN(
+               __entry->id = id;
+       ),
+       RE_PRINTK("id=%llu", __entry->id)
+);
 #endif
index 547d63679022338032204f674c57920656d92523..eff9cb20862757703e8266bdf5cf3c68a98ae3a5 100644 (file)
@@ -643,6 +643,13 @@ static void handle___tracing_enable_event(struct kvm_cpu_context *host_ctxt)
        cpu_reg(host_ctxt, 1) = __tracing_enable_event(id, enable);
 }
 
+static void handle___tracing_write_event(struct kvm_cpu_context *host_ctxt)
+{
+       DECLARE_REG(u64, id, host_ctxt, 1);
+
+       trace_selftest(id);
+}
+
 typedef void (*hcall_t)(struct kvm_cpu_context *);
 
 #define HANDLE_FUNC(x) [__KVM_HOST_SMCCC_FUNC_##x] = (hcall_t)handle_##x
@@ -691,6 +698,7 @@ static const hcall_t host_hcall[] = {
        HANDLE_FUNC(__tracing_update_clock),
        HANDLE_FUNC(__tracing_reset),
        HANDLE_FUNC(__tracing_enable_event),
+       HANDLE_FUNC(__tracing_write_event),
 };
 
 static void handle_host_hcall(struct kvm_cpu_context *host_ctxt)
index 1ad6a55ba95cea08b5bdd99203a646a36cf3ad1f..c1e28f6581ab8a9b128e9293e22f97b53aa6c2b8 100644 (file)
@@ -348,8 +348,30 @@ static int hyp_trace_clock_show(struct seq_file *m, void *v)
 }
 DEFINE_SHOW_ATTRIBUTE(hyp_trace_clock);
 
+static ssize_t hyp_trace_write_event_write(struct file *f, const char __user *ubuf,
+                                          size_t cnt, loff_t *pos)
+{
+       unsigned long val;
+       int ret;
+
+       ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
+       if (ret)
+               return ret;
+
+       kvm_call_hyp_nvhe(__tracing_write_event, val);
+
+       return cnt;
+}
+
+static const struct file_operations hyp_trace_write_event_fops = {
+       .write  = hyp_trace_write_event_write,
+};
+
 static int hyp_trace_init_tracefs(struct dentry *d, void *priv)
 {
+       if (!tracefs_create_file("write_event", 0200, d, NULL, &hyp_trace_write_event_fops))
+               return -ENOMEM;
+
        return tracefs_create_file("trace_clock", 0440, d, NULL, &hyp_trace_clock_fops) ?
                0 : -ENOMEM;
 }