@@ -1072,7 +1072,7 @@ static int show_spu_loadavg(struct seq_file *s, void *private)
LOAD_INT(c), LOAD_FRAC(c),
count_active_contexts(),
atomic_read(&nr_spu_contexts),
- idr_get_cursor(&task_active_pid_ns(current)->idr) - 1);
+ READ_ONCE(task_active_pid_ns(current)->pid_next) - 1);
return 0;
}
#endif
@@ -21,7 +21,7 @@ static int loadavg_proc_show(struct seq_file *m, void *v)
LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
nr_running(), nr_threads,
- idr_get_cursor(&task_active_pid_ns(current)->idr) - 1);
+ READ_ONCE(task_active_pid_ns(current)->pid_next) - 1);
return 0;
}
@@ -18,6 +18,7 @@ struct fs_pin;
struct pid_namespace {
struct idr idr;
+ unsigned int pid_next;
struct rcu_head rcu;
unsigned int pid_allocated;
struct task_struct *child_reaper;
@@ -75,6 +75,7 @@ int pid_max_max = PID_MAX_LIMIT;
struct pid_namespace init_pid_ns = {
.ns.count = REFCOUNT_INIT(2),
.idr = IDR_INIT(init_pid_ns.idr),
+ .pid_next = 0,
.pid_allocated = PIDNS_ADDING,
.level = 0,
.child_reaper = &init_task,
@@ -208,7 +209,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
* init really needs pid 1, but after reaching the
* maximum wrap back to RESERVED_PIDS
*/
- if (idr_get_cursor(&tmp->idr) > RESERVED_PIDS)
+ if (tmp->pid_next > RESERVED_PIDS)
pid_min = RESERVED_PIDS;
/*
@@ -217,6 +218,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
*/
nr = idr_alloc_cyclic(&tmp->idr, NULL, pid_min,
pid_max, GFP_ATOMIC);
+ tmp->pid_next = nr + 1;
}
xa_unlock_irq(&tmp->idr.idr_rt);
idr_preload_end();
@@ -278,7 +280,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
/* On failure to allocate the first pid, reset the state */
if (tmp == ns && tmp->pid_allocated == PIDNS_ADDING)
- idr_set_cursor(&ns->idr, 0);
+ ns->pid_next = 0;
idr_remove(&tmp->idr, upid->nr);
xa_unlock_irq(&tmp->idr.idr_rt);
@@ -272,12 +272,12 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
* it should synchronize its usage with external means.
*/
- next = idr_get_cursor(&pid_ns->idr) - 1;
+ next = READ_ONCE(pid_ns->pid_next) - 1;
tmp.data = &next;
ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
if (!ret && write)
- idr_set_cursor(&pid_ns->idr, next + 1);
+ WRITE_ONCE(pid_ns->pid_next, next + 1);
return ret;
}