summaryrefslogtreecommitdiffstats
path: root/arch/arm64/kvm/hyp/include/nvhe/trace.h
blob: 8813ff250f8e07b068f0de516008314b5efd93d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef __ARM64_KVM_HYP_NVHE_TRACE_H
#define __ARM64_KVM_HYP_NVHE_TRACE_H

#include <linux/trace_remote_event.h>

#include <asm/kvm_hyptrace.h>

static inline pid_t __tracing_get_vcpu_pid(struct kvm_cpu_context *host_ctxt)
{
	struct kvm_vcpu *vcpu;

	if (!host_ctxt)
		host_ctxt = host_data_ptr(host_ctxt);

	vcpu = host_ctxt->__hyp_running_vcpu;

	return vcpu ? vcpu->arch.pid : 0;
}

#define HE_PROTO(__args...)	__args
#define HE_ASSIGN(__args...)	__args
#define HE_STRUCT		RE_STRUCT
#define he_field		re_field

#ifdef CONFIG_NVHE_EL2_TRACING

#define HYP_EVENT(__name, __proto, __struct, __assign, __printk)		\
	REMOTE_EVENT_FORMAT(__name, __struct);					\
	extern struct hyp_event_id hyp_event_id_##__name;			\
	static __always_inline void trace_##__name(__proto)			\
	{									\
		struct remote_event_format_##__name *__entry;			\
		size_t length = sizeof(*__entry);				\
										\
		if (!atomic_read(&hyp_event_id_##__name.enabled))		\
			return;							\
		__entry = tracing_reserve_entry(length);			\
		if (!__entry)							\
			return;							\
		__entry->hdr.id = hyp_event_id_##__name.id;			\
		__assign							\
		tracing_commit_entry();						\
	}

void *tracing_reserve_entry(unsigned long length);
void tracing_commit_entry(void);

int __tracing_load(unsigned long desc_va, size_t desc_size);
void __tracing_unload(void);
int __tracing_enable(bool enable);
int __tracing_swap_reader(unsigned int cpu);
void __tracing_update_clock(u32 mult, u32 shift, u64 epoch_ns, u64 epoch_cyc);
int __tracing_reset(unsigned int cpu);
int __tracing_enable_event(unsigned short id, bool enable);
#else
static inline void *tracing_reserve_entry(unsigned long length) { return NULL; }
static inline void tracing_commit_entry(void) { }
#define HYP_EVENT(__name, __proto, __struct, __assign, __printk)      \
	static inline void trace_##__name(__proto) {}

static inline int __tracing_load(unsigned long desc_va, size_t desc_size) { return -ENODEV; }
static inline void __tracing_unload(void) { }
static inline int __tracing_enable(bool enable) { return -ENODEV; }
static inline int __tracing_swap_reader(unsigned int cpu) { return -ENODEV; }
static inline void __tracing_update_clock(u32 mult, u32 shift, u64 epoch_ns, u64 epoch_cyc) { }
static inline int __tracing_reset(unsigned int cpu) { return -ENODEV; }
static inline int __tracing_enable_event(unsigned short id, bool enable)  { return -ENODEV; }
#endif
#endif