KVM
Functions
stacktrace.c File Reference
#include <linux/kvm.h>
#include <linux/kvm_host.h>
#include <asm/stacktrace/nvhe.h>
Include dependency graph for stacktrace.c:

Go to the source code of this file.

Functions

static struct stack_info stackinfo_get_overflow (void)
 
static struct stack_info stackinfo_get_overflow_kern_va (void)
 
static struct stack_info stackinfo_get_hyp (void)
 
static struct stack_info stackinfo_get_hyp_kern_va (void)
 
static bool kvm_nvhe_stack_kern_va (unsigned long *addr, unsigned long size)
 
static bool kvm_nvhe_stack_kern_record_va (unsigned long *addr)
 
static int unwind_next (struct unwind_state *state)
 
static void unwind (struct unwind_state *state, stack_trace_consume_fn consume_entry, void *cookie)
 
static bool kvm_nvhe_dump_backtrace_entry (void *arg, unsigned long where)
 
static void kvm_nvhe_dump_backtrace_start (void)
 
static void kvm_nvhe_dump_backtrace_end (void)
 
static void hyp_dump_backtrace (unsigned long hyp_offset)
 
static void pkvm_dump_backtrace (unsigned long hyp_offset)
 
void kvm_nvhe_dump_backtrace (unsigned long hyp_offset)
 

Function Documentation

◆ hyp_dump_backtrace()

static void hyp_dump_backtrace ( unsigned long  hyp_offset)
static

Definition at line 178 of file stacktrace.c.

179 {
180  struct kvm_nvhe_stacktrace_info *stacktrace_info;
181  struct stack_info stacks[] = {
184  };
185  struct unwind_state state = {
186  .stacks = stacks,
187  .nr_stacks = ARRAY_SIZE(stacks),
188  };
189 
190  stacktrace_info = this_cpu_ptr_nvhe_sym(kvm_stacktrace_info);
191 
192  kvm_nvhe_unwind_init(&state, stacktrace_info->fp, stacktrace_info->pc);
193 
195  unwind(&state, kvm_nvhe_dump_backtrace_entry, (void *)hyp_offset);
197 }
static struct stack_info stackinfo_get_hyp_kern_va(void)
Definition: stacktrace.c:61
static void unwind(struct unwind_state *state, stack_trace_consume_fn consume_entry, void *cookie)
Definition: stacktrace.c:126
static bool kvm_nvhe_dump_backtrace_entry(void *arg, unsigned long where)
Definition: stacktrace.c:146
static void kvm_nvhe_dump_backtrace_start(void)
Definition: stacktrace.c:158
static void kvm_nvhe_dump_backtrace_end(void)
Definition: stacktrace.c:163
static struct stack_info stackinfo_get_overflow_kern_va(void)
Definition: stacktrace.c:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_nvhe_dump_backtrace()

void kvm_nvhe_dump_backtrace ( unsigned long  hyp_offset)

Definition at line 239 of file stacktrace.c.

240 {
241  if (is_protected_kvm_enabled())
242  pkvm_dump_backtrace(hyp_offset);
243  else
244  hyp_dump_backtrace(hyp_offset);
245 }
static void hyp_dump_backtrace(unsigned long hyp_offset)
Definition: stacktrace.c:178
static void pkvm_dump_backtrace(unsigned long hyp_offset)
Definition: stacktrace.c:228
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_nvhe_dump_backtrace_end()

static void kvm_nvhe_dump_backtrace_end ( void  )
static

Definition at line 163 of file stacktrace.c.

164 {
165  kvm_err("---[ end nVHE call trace ]---\n");
166 }
Here is the caller graph for this function:

◆ kvm_nvhe_dump_backtrace_entry()

static bool kvm_nvhe_dump_backtrace_entry ( void *  arg,
unsigned long  where 
)
static

Definition at line 146 of file stacktrace.c.

147 {
148  unsigned long va_mask = GENMASK_ULL(vabits_actual - 1, 0);
149  unsigned long hyp_offset = (unsigned long)arg;
150 
151  /* Mask tags and convert to kern addr */
152  where = (where & va_mask) + hyp_offset;
153  kvm_err(" [<%016lx>] %pB\n", where, (void *)(where + kaslr_offset()));
154 
155  return true;
156 }
static u64 va_mask
Definition: va_layout.c:24
Here is the caller graph for this function:

◆ kvm_nvhe_dump_backtrace_start()

static void kvm_nvhe_dump_backtrace_start ( void  )
static

Definition at line 158 of file stacktrace.c.

159 {
160  kvm_err("nVHE call trace:\n");
161 }
Here is the caller graph for this function:

◆ kvm_nvhe_stack_kern_record_va()

static bool kvm_nvhe_stack_kern_record_va ( unsigned long *  addr)
static

Definition at line 109 of file stacktrace.c.

110 {
111  return kvm_nvhe_stack_kern_va(addr, 16);
112 }
static bool kvm_nvhe_stack_kern_va(unsigned long *addr, unsigned long size)
Definition: stacktrace.c:85
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_nvhe_stack_kern_va()

static bool kvm_nvhe_stack_kern_va ( unsigned long *  addr,
unsigned long  size 
)
static

Definition at line 85 of file stacktrace.c.

86 {
87  struct stack_info stack_hyp, stack_kern;
88 
89  stack_hyp = stackinfo_get_hyp();
90  stack_kern = stackinfo_get_hyp_kern_va();
91  if (stackinfo_on_stack(&stack_hyp, *addr, size))
92  goto found;
93 
94  stack_hyp = stackinfo_get_overflow();
95  stack_kern = stackinfo_get_overflow_kern_va();
96  if (stackinfo_on_stack(&stack_hyp, *addr, size))
97  goto found;
98 
99  return false;
100 
101 found:
102  *addr = *addr - stack_hyp.low + stack_kern.low;
103  return true;
104 }
size_t size
Definition: gen-hyprel.c:133
static struct stack_info stackinfo_get_overflow(void)
Definition: stacktrace.c:24
static struct stack_info stackinfo_get_hyp(void)
Definition: stacktrace.c:48
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pkvm_dump_backtrace()

static void pkvm_dump_backtrace ( unsigned long  hyp_offset)
static

Definition at line 228 of file stacktrace.c.

229 {
230  kvm_err("Cannot dump pKVM nVHE stacktrace: !CONFIG_PROTECTED_NVHE_STACKTRACE\n");
231 }
Here is the caller graph for this function:

◆ stackinfo_get_hyp()

static struct stack_info stackinfo_get_hyp ( void  )
static

Definition at line 1 of file stacktrace.c.

49 {
50  struct kvm_nvhe_stacktrace_info *stacktrace_info
51  = this_cpu_ptr_nvhe_sym(kvm_stacktrace_info);
52  unsigned long low = (unsigned long)stacktrace_info->stack_base;
53  unsigned long high = low + PAGE_SIZE;
54 
55  return (struct stack_info) {
56  .low = low,
57  .high = high,
58  };
59 }
Here is the caller graph for this function:

◆ stackinfo_get_hyp_kern_va()

static struct stack_info stackinfo_get_hyp_kern_va ( void  )
static

Definition at line 1 of file stacktrace.c.

62 {
63  unsigned long low = (unsigned long)*this_cpu_ptr(&kvm_arm_hyp_stack_page);
64  unsigned long high = low + PAGE_SIZE;
65 
66  return (struct stack_info) {
67  .low = low,
68  .high = high,
69  };
70 }
Here is the caller graph for this function:

◆ stackinfo_get_overflow()

static struct stack_info stackinfo_get_overflow ( void  )
static

Definition at line 1 of file stacktrace.c.

25 {
26  struct kvm_nvhe_stacktrace_info *stacktrace_info
27  = this_cpu_ptr_nvhe_sym(kvm_stacktrace_info);
28  unsigned long low = (unsigned long)stacktrace_info->overflow_stack_base;
29  unsigned long high = low + OVERFLOW_STACK_SIZE;
30 
31  return (struct stack_info) {
32  .low = low,
33  .high = high,
34  };
35 }
Here is the caller graph for this function:

◆ stackinfo_get_overflow_kern_va()

static struct stack_info stackinfo_get_overflow_kern_va ( void  )
static

Definition at line 1 of file stacktrace.c.

38 {
39  unsigned long low = (unsigned long)this_cpu_ptr_nvhe_sym(overflow_stack);
40  unsigned long high = low + OVERFLOW_STACK_SIZE;
41 
42  return (struct stack_info) {
43  .low = low,
44  .high = high,
45  };
46 }
Here is the caller graph for this function:

◆ unwind()

static void unwind ( struct unwind_state *  state,
stack_trace_consume_fn  consume_entry,
void *  cookie 
)
static

Definition at line 126 of file stacktrace.c.

128 {
129  while (1) {
130  int ret;
131 
132  if (!consume_entry(cookie, state->pc))
133  break;
134  ret = unwind_next(state);
135  if (ret < 0)
136  break;
137  }
138 }
static int unwind_next(struct unwind_state *state)
Definition: stacktrace.c:114
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unwind_next()

static int unwind_next ( struct unwind_state *  state)
static

Definition at line 114 of file stacktrace.c.

115 {
116  /*
117  * The FP is in the hypervisor VA space. Convert it to the kernel VA
118  * space so it can be unwound by the regular unwind functions.
119  */
120  if (!kvm_nvhe_stack_kern_record_va(&state->fp))
121  return -EINVAL;
122 
123  return unwind_next_frame_record(state);
124 }
static bool kvm_nvhe_stack_kern_record_va(unsigned long *addr)
Definition: stacktrace.c:109
Here is the call graph for this function:
Here is the caller graph for this function: