summaryrefslogtreecommitdiff
path: root/include/linux/unwind_deferred.h
blob: bc7ae7d2190069a27a6567e362396ffcaae01e0e (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
71
72
73
74
75
76
77
78
79
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _LINUX_UNWIND_USER_DEFERRED_H
#define _LINUX_UNWIND_USER_DEFERRED_H

#include <linux/task_work.h>
#include <linux/unwind_user.h>
#include <linux/unwind_deferred_types.h>

#ifdef CONFIG_UNWIND_USER

enum {
	UNWIND_PENDING_BIT = 0,
	UNWIND_USED_BIT,
};

enum {
	UNWIND_PENDING		= BIT(UNWIND_PENDING_BIT),

	/* Set if the unwinding was used (directly or deferred) */
	UNWIND_USED		= BIT(UNWIND_USED_BIT)
};

void unwind_task_init(struct task_struct *task);
void unwind_task_free(struct task_struct *task);

int unwind_user_faultable(struct unwind_stacktrace *trace);

int unwind_deferred_init(struct unwind_work *work, unwind_callback_t func);
int unwind_deferred_request(struct unwind_work *work, u64 *cookie);
void unwind_deferred_cancel(struct unwind_work *work);

void unwind_deferred_task_exit(struct task_struct *task);

static __always_inline void unwind_reset_info(void)
{
	struct unwind_task_info *info = &current->unwind_info;
	unsigned long bits = atomic_long_read(&info->unwind_mask);

	/* Was there any unwinding? */
	if (likely(!bits))
		return;

	do {
		/* Is a task_work going to run again before going back */
		if (bits & UNWIND_PENDING)
			return;
	} while (!atomic_long_try_cmpxchg(&info->unwind_mask, &bits, 0UL));
	current->unwind_info.id.id = 0;

	if (unlikely(info->cache)) {
		info->cache->nr_entries = 0;
		info->cache->unwind_completed = 0;
	}
}

#else /* !CONFIG_UNWIND_USER */

static inline void unwind_task_init(struct task_struct *task) {}
static inline void unwind_task_free(struct task_struct *task) {}

static inline int unwind_user_faultable(struct unwind_stacktrace *trace)
{ return -ENOSYS; }

static inline int
unwind_deferred_init(struct unwind_work *work, unwind_callback_t func)
{ return -ENOSYS; }

static inline int
unwind_deferred_request(struct unwind_work *work, u64 *timestamp)
{ return -ENOSYS; }

static inline void unwind_deferred_cancel(struct unwind_work *work) {}

static inline void unwind_deferred_task_exit(struct task_struct *task) {}
static inline void unwind_reset_info(void) {}

#endif /* !CONFIG_UNWIND_USER */

#endif /* _LINUX_UNWIND_USER_DEFERRED_H */