From 8705a3d94302a65f17b6b726517336dabfa0e5fc Mon Sep 17 00:00:00 2001 From: Vincent Donnefort Date: Thu, 2 Feb 2023 10:19:52 +0000 Subject: [PATCH] ANDROID: KVM: arm64: Add header_page userspace descriptor for nVHE tracing Added userspace file that describes the content of each hyp tracing ring-buffer page. This follows the same format as the descriptor found in the tracefs root to ensure compatibility with userspace trace tools. Bug: 229972309 Change-Id: Ideebf37cb285b581c4cbe2a991a0df8c7ed61c0f Signed-off-by: Vincent Donnefort --- arch/arm64/kvm/hyp_events.c | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/arch/arm64/kvm/hyp_events.c b/arch/arm64/kvm/hyp_events.c index 7786f3b226ed..64b88dc85093 100644 --- a/arch/arm64/kvm/hyp_events.c +++ b/arch/arm64/kvm/hyp_events.c @@ -236,6 +236,42 @@ static const struct file_operations hyp_event_format_fops = { .release = single_release, }; +static int hyp_header_page_show(struct seq_file *m, void *v) +{ + struct buffer_data_page bpage; + + seq_printf(m, "\tfield: u64 timestamp;\t" + "offset:0;\tsize:%lu;\tsigned:%d;\n", + sizeof(bpage.time_stamp), + is_signed_type(u64)); + + seq_printf(m, "\tfield: local_t commit;\t" + "offset:%lu;\tsize:%lu;\tsigned:%d;\n", + offsetof(typeof(bpage), commit), + sizeof(bpage.commit), + is_signed_type(long)); + + seq_printf(m, "\tfield: char data;\t" + "offset:%lu;\tsize:%lu;\tsigned:%d;\n", + offsetof(typeof(bpage), data), + BUF_EXT_PAGE_SIZE, + is_signed_type(char)); + + return 0; +} + +static int hyp_header_page_open(struct inode *inode, struct file *file) +{ + return single_open(file, hyp_header_page_show, NULL); +} + +static const struct file_operations hyp_header_page_fops = { + .open = hyp_header_page_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + static char early_events[COMMAND_LINE_SIZE]; static __init int setup_hyp_event_early(char *str) @@ -292,6 +328,12 @@ void kvm_hyp_init_events_tracefs(struct dentry *parent) return; } + d = tracefs_create_file("header_page", 0400, parent, NULL, + &hyp_header_page_fops); + if (!d) + pr_err("Failed to create events/header_page\n"); + + for (; (unsigned long)event < (unsigned long)__stop_hyp_events; event++) { event_dir = tracefs_create_dir(event->name, parent); if (!event_dir) {