Lines Matching refs:s
23 int sidtab_init(struct sidtab *s) in sidtab_init() argument
27 memset(s->roots, 0, sizeof(s->roots)); in sidtab_init()
30 s->isids[i].set = 0; in sidtab_init()
32 s->count = 0; in sidtab_init()
33 s->convert = NULL; in sidtab_init()
34 hash_init(s->context_to_sid); in sidtab_init()
36 spin_lock_init(&s->lock); in sidtab_init()
40 static u32 context_to_sid(struct sidtab *s, struct context *context) in context_to_sid() argument
46 hash_for_each_possible_rcu(s->context_to_sid, entry, list, in context_to_sid()
57 int sidtab_set_initial(struct sidtab *s, u32 sid, struct context *context) in sidtab_set_initial() argument
65 entry = &s->isids[sid - 1]; in sidtab_set_initial()
79 if (!context_to_sid(s, context)) { in sidtab_set_initial()
81 hash_add(s->context_to_sid, &entry->leaf.list, context->hash); in sidtab_set_initial()
133 static int sidtab_alloc_roots(struct sidtab *s, u32 level) in sidtab_alloc_roots() argument
137 if (!s->roots[0].ptr_leaf) { in sidtab_alloc_roots()
138 s->roots[0].ptr_leaf = kzalloc(SIDTAB_NODE_ALLOC_SIZE, in sidtab_alloc_roots()
140 if (!s->roots[0].ptr_leaf) in sidtab_alloc_roots()
144 if (!s->roots[l].ptr_inner) { in sidtab_alloc_roots()
145 s->roots[l].ptr_inner = kzalloc(SIDTAB_NODE_ALLOC_SIZE, in sidtab_alloc_roots()
147 if (!s->roots[l].ptr_inner) in sidtab_alloc_roots()
149 s->roots[l].ptr_inner->entries[0] = s->roots[l - 1]; in sidtab_alloc_roots()
154 static struct sidtab_entry_leaf *sidtab_do_lookup(struct sidtab *s, u32 index, in sidtab_do_lookup() argument
165 if (alloc && sidtab_alloc_roots(s, level) != 0) in sidtab_do_lookup()
169 entry = &s->roots[level]; in sidtab_do_lookup()
195 static struct context *sidtab_lookup(struct sidtab *s, u32 index) in sidtab_lookup() argument
198 u32 count = smp_load_acquire(&s->count); in sidtab_lookup()
203 return &sidtab_do_lookup(s, index, 0)->context; in sidtab_lookup()
206 static struct context *sidtab_lookup_initial(struct sidtab *s, u32 sid) in sidtab_lookup_initial() argument
208 return s->isids[sid - 1].set ? &s->isids[sid - 1].leaf.context : NULL; in sidtab_lookup_initial()
211 static struct context *sidtab_search_core(struct sidtab *s, u32 sid, int force) in sidtab_search_core() argument
217 context = sidtab_lookup(s, sid_to_index(sid)); in sidtab_search_core()
219 context = sidtab_lookup_initial(s, sid); in sidtab_search_core()
224 return sidtab_lookup_initial(s, SECINITSID_UNLABELED); in sidtab_search_core()
227 struct context *sidtab_search(struct sidtab *s, u32 sid) in sidtab_search() argument
229 return sidtab_search_core(s, sid, 0); in sidtab_search()
232 struct context *sidtab_search_force(struct sidtab *s, u32 sid) in sidtab_search_force() argument
234 return sidtab_search_core(s, sid, 1); in sidtab_search_force()
237 int sidtab_context_to_sid(struct sidtab *s, struct context *context, in sidtab_context_to_sid() argument
246 *sid = context_to_sid(s, context); in sidtab_context_to_sid()
251 spin_lock_irqsave(&s->lock, flags); in sidtab_context_to_sid()
254 *sid = context_to_sid(s, context); in sidtab_context_to_sid()
259 count = smp_load_acquire(&s->count); in sidtab_context_to_sid()
260 convert = s->convert; in sidtab_context_to_sid()
269 dst = sidtab_do_lookup(s, count, 1); in sidtab_context_to_sid()
311 smp_store_release(&s->count, count + 1); in sidtab_context_to_sid()
312 hash_add_rcu(s->context_to_sid, &dst->list, dst->context.hash); in sidtab_context_to_sid()
316 spin_unlock_irqrestore(&s->lock, flags); in sidtab_context_to_sid()
320 static void sidtab_convert_hashtable(struct sidtab *s, u32 count) in sidtab_convert_hashtable() argument
326 entry = sidtab_do_lookup(s, i, 0); in sidtab_convert_hashtable()
329 hash_add_rcu(s->context_to_sid, &entry->list, in sidtab_convert_hashtable()
383 int sidtab_convert(struct sidtab *s, struct sidtab_convert_params *params) in sidtab_convert() argument
389 spin_lock_irqsave(&s->lock, flags); in sidtab_convert()
392 if (s->convert) { in sidtab_convert()
393 spin_unlock_irqrestore(&s->lock, flags); in sidtab_convert()
397 count = s->count; in sidtab_convert()
405 spin_unlock_irqrestore(&s->lock, flags); in sidtab_convert()
413 s->convert = params; in sidtab_convert()
416 spin_unlock_irqrestore(&s->lock, flags); in sidtab_convert()
423 &s->roots[level], &pos, count, level, params); in sidtab_convert()
426 spin_lock_irqsave(&s->lock, flags); in sidtab_convert()
427 s->convert = NULL; in sidtab_convert()
428 spin_unlock_irqrestore(&s->lock, flags); in sidtab_convert()
435 spin_lock_irqsave(&s->lock, flags); in sidtab_convert()
437 spin_unlock_irqrestore(&s->lock, flags); in sidtab_convert()
467 void sidtab_destroy(struct sidtab *s) in sidtab_destroy() argument
472 if (s->isids[i].set) in sidtab_destroy()
473 context_destroy(&s->isids[i].leaf.context); in sidtab_destroy()
476 while (level && !s->roots[level].ptr_inner) in sidtab_destroy()
479 sidtab_destroy_tree(s->roots[level], level); in sidtab_destroy()