1
2
3
4
5
6#ifndef _RDMA_RESTRACK_H_
7#define _RDMA_RESTRACK_H_
8
9#include <linux/typecheck.h>
10#include <linux/sched.h>
11#include <linux/kref.h>
12#include <linux/completion.h>
13#include <linux/sched/task.h>
14#include <uapi/rdma/rdma_netlink.h>
15#include <linux/xarray.h>
16
17
18
19
20enum rdma_restrack_type {
21
22
23
24 RDMA_RESTRACK_PD,
25
26
27
28 RDMA_RESTRACK_CQ,
29
30
31
32 RDMA_RESTRACK_QP,
33
34
35
36 RDMA_RESTRACK_CM_ID,
37
38
39
40 RDMA_RESTRACK_MR,
41
42
43
44 RDMA_RESTRACK_CTX,
45
46
47
48 RDMA_RESTRACK_MAX
49};
50
51struct ib_device;
52
53
54
55
56struct rdma_restrack_entry {
57
58
59
60
61
62
63
64
65 bool valid;
66
67
68
69 struct kref kref;
70
71
72
73 struct completion comp;
74
75
76
77
78
79
80
81
82
83 struct task_struct *task;
84
85
86
87 const char *kern_name;
88
89
90
91 enum rdma_restrack_type type;
92
93
94
95 bool user;
96
97
98
99 u32 id;
100};
101
102int rdma_restrack_count(struct ib_device *dev,
103 enum rdma_restrack_type type,
104 struct pid_namespace *ns);
105
106void rdma_restrack_kadd(struct rdma_restrack_entry *res);
107void rdma_restrack_uadd(struct rdma_restrack_entry *res);
108
109
110
111
112
113
114void rdma_restrack_del(struct rdma_restrack_entry *res);
115
116
117
118
119
120static inline bool rdma_is_kernel_res(struct rdma_restrack_entry *res)
121{
122 return !res->user;
123}
124
125
126
127
128
129int __must_check rdma_restrack_get(struct rdma_restrack_entry *res);
130
131
132
133
134
135int rdma_restrack_put(struct rdma_restrack_entry *res);
136
137
138
139
140
141
142void rdma_restrack_set_task(struct rdma_restrack_entry *res,
143 const char *caller);
144
145
146
147
148
149int rdma_nl_put_driver_u32(struct sk_buff *msg, const char *name, u32 value);
150int rdma_nl_put_driver_u32_hex(struct sk_buff *msg, const char *name,
151 u32 value);
152int rdma_nl_put_driver_u64(struct sk_buff *msg, const char *name, u64 value);
153int rdma_nl_put_driver_u64_hex(struct sk_buff *msg, const char *name,
154 u64 value);
155struct rdma_restrack_entry *rdma_restrack_get_byid(struct ib_device *dev,
156 enum rdma_restrack_type type,
157 u32 id);
158#endif
159