Lines Matching full:shadow

3  * shadow.c - Shadow Variables
11 * DOC: Shadow variable API concurrency notes:
13 * The shadow variable API provides a simple relationship between an
15 * caller to provide any mutual exclusion required of the shadow data.
17 * Once a shadow variable is attached to its parent object via the
19 * call to klp_shadow_get() may then return the shadow variable's data
20 * pointer. Callers of klp_shadow_*alloc() should prepare shadow data
23 * The klp_shadow_*alloc() API calls may allocate memory for new shadow
42 * the shadow variables it references.
47 * struct klp_shadow - shadow variable structure
63 * klp_shadow_match() - verify a shadow variable matches given <obj, id>
64 * @shadow: shadow variable to match
68 * Return: true if the shadow variable matches.
70 static inline bool klp_shadow_match(struct klp_shadow *shadow, void *obj, in klp_shadow_match() argument
73 return shadow->obj == obj && shadow->id == id; in klp_shadow_match()
77 * klp_shadow_get() - retrieve a shadow variable data pointer
81 * Return: the shadow variable data element, NULL on failure.
85 struct klp_shadow *shadow; in klp_shadow_get() local
89 hash_for_each_possible_rcu(klp_shadow_hash, shadow, node, in klp_shadow_get()
92 if (klp_shadow_match(shadow, obj, id)) { in klp_shadow_get()
94 return shadow->data; in klp_shadow_get()
113 /* Check if the shadow variable already exists */ in __klp_shadow_get_or_alloc()
119 * Allocate a new shadow variable. Fill it with zeroes by default. in __klp_shadow_get_or_alloc()
132 * Shadow variable was found, throw away speculative in __klp_shadow_get_or_alloc()
150 pr_err("Failed to construct shadow variable <%p, %lx> (%d)\n", in __klp_shadow_get_or_alloc()
165 WARN(1, "Duplicate shadow variable <%p, %lx>\n", obj, id); in __klp_shadow_get_or_alloc()
173 * klp_shadow_alloc() - allocate and add a new shadow variable
178 * @ctor: custom constructor to initialize the shadow data (optional)
181 * Allocates @size bytes for new shadow variable data using @gfp_flags.
183 * function if it is not NULL. The new shadow variable is then added
186 * If an existing <obj, id> shadow variable can be found, this routine will
193 * Return: the shadow variable data element, NULL on duplicate or
206 * klp_shadow_get_or_alloc() - get existing or allocate a new shadow variable
211 * @ctor: custom constructor to initialize the shadow data (optional)
214 * Returns a pointer to existing shadow data if an <obj, id> shadow
215 * variable is already present. Otherwise, it creates a new shadow
218 * This function guarantees that only one shadow variable exists with the given
223 * Return: the shadow variable data element, NULL on failure.
234 static void klp_shadow_free_struct(struct klp_shadow *shadow, in klp_shadow_free_struct() argument
237 hash_del_rcu(&shadow->node); in klp_shadow_free_struct()
239 dtor(shadow->obj, shadow->data); in klp_shadow_free_struct()
240 kfree_rcu(shadow, rcu_head); in klp_shadow_free_struct()
244 * klp_shadow_free() - detach and free a <obj, id> shadow variable
248 * and/or free data that the shadow variable points to (optional)
250 * This function releases the memory for this <obj, id> shadow variable
255 struct klp_shadow *shadow; in klp_shadow_free() local
261 hash_for_each_possible(klp_shadow_hash, shadow, node, in klp_shadow_free()
264 if (klp_shadow_match(shadow, obj, id)) { in klp_shadow_free()
265 klp_shadow_free_struct(shadow, dtor); in klp_shadow_free()
275 * klp_shadow_free_all() - detach and free all <_, id> shadow variables
278 * and/or free data that the shadow variable points to (optional)
280 * This function releases the memory for all <_, id> shadow variable
285 struct klp_shadow *shadow; in klp_shadow_free_all() local
292 hash_for_each(klp_shadow_hash, i, shadow, node) { in klp_shadow_free_all()
293 if (klp_shadow_match(shadow, shadow->obj, id)) in klp_shadow_free_all()
294 klp_shadow_free_struct(shadow, dtor); in klp_shadow_free_all()