30 #include <linux/export.h>
31 #include <linux/slab.h>
35 #include <linux/hash.h>
40 #define pid_hashfn(nr, ns) \
41 hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
43 static unsigned int pidhash_shift = 4;
48 #define RESERVED_PIDS 300
53 #define BITS_PER_PAGE (PAGE_SIZE*8)
54 #define BITS_PER_PAGE_MASK (BITS_PER_PAGE-1)
62 #define find_next_offset(map, off) \
63 find_next_zero_bit((map)->page, BITS_PER_PAGE, off)
115 static void free_pidmap(
struct upid *
upid)
128 static int pid_before(
int base,
int a,
int b)
136 return (
unsigned)(a - base) < (
unsigned)(b - base);
157 int last_write = base;
161 }
while ((prev != last_write) && (pid_before(base, last_write, pid)));
180 for (i = 0; i <= max_scan; ++
i) {
187 spin_lock_irq(&pidmap_lock);
192 spin_unlock_irq(&pidmap_lock);
201 set_last_pid(pid_ns, last, pid);
205 pid = mk_pid(pid_ns, map, offset);
217 pid = mk_pid(pid_ns, map, offset);
230 offset = (last + 1) & BITS_PER_PAGE_MASK;
233 for (; map <
end; map++, offset = 0) {
238 return mk_pid(pid_ns, map, offset);
259 static void delayed_put_pid(
struct rcu_head *rhp)
272 for (i = 0; i <= pid->
level; i++)
273 hlist_del_rcu(&pid->
numbers[i].pid_chain);
274 spin_unlock_irqrestore(&pidmap_lock, flags);
276 for (i = 0; i <= pid->
level; i++)
295 for (i = ns->
level; i >= 0; i--) {
296 nr = alloc_pidmap(tmp);
312 spin_lock_irq(&pidmap_lock);
316 spin_unlock_irq(&pidmap_lock);
322 while (++i <= ns->
level)
335 hlist_for_each_entry_rcu(pnr, elem,
337 if (pnr->
nr == nr && pnr->
ns == ns)
361 hlist_add_head_rcu(&link->
node, &pid->
tasks[type]);
374 hlist_del_rcu(&link->
node);
378 if (!hlist_empty(&pid->
tasks[tmp]))
386 __change_pid(task, type,
NULL);
392 __change_pid(task, type, pid);
401 hlist_replace_rcu(&old->
pids[type].node, &new->pids[type].node);
410 lockdep_tasklist_lock_is_held());
424 "find_task_by_pid_ns() needs rcu_read_lock()"
440 pid = get_pid(task->
pids[type].pid);
498 if (
likely(pid_alive(task))) {
517 return ns_of_pid(task_pid(tsk));
547 unsigned int i, pidhash_size;
551 &pidhash_shift,
NULL,
553 pidhash_size = 1
U << pidhash_shift;
555 for (i = 0; i < pidhash_size; i++)