Re: broken do_each_pid_{thread,task}

From: Oleg Nesterov
Date: Mon Dec 15 2008 - 12:11:46 EST


On 12/15, Oleg Nesterov wrote:
>
> On 12/14, Eric W. Biederman wrote:
> >
> > Although seeing the unexpected corner case it gets us into I think it would
> > be good to reconsider this test.

So. I can't decide whether this patch is cleanup or the further
uglification, but if anyone likes it I will be happy to send it.

Then we can kill do_each_pid_task/while_each_pid_task completely.

Oleg.

--- linux-2.6.27/include/linux/pid.h~PID_FOR_EACH 2008-10-10 00:13:53.000000000 +0200
+++ linux-2.6.27/include/linux/pid.h 2008-12-15 17:51:50.000000000 +0100
@@ -144,21 +144,25 @@ static inline pid_t pid_nr(struct pid *p
pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
pid_t pid_vnr(struct pid *pid);

+/*
+ * Both old and new leaders may be attached to the same pid in the
+ * middle of de_thread(), that is why we do the special check for
+ * PIDTYPE_PID below.
+ */
+#define pid_for_each_task(pid, type, p) \
+ for (p = (pid) ? (void*)(pid)->tasks[type].first : NULL; \
+ rcu_dereference(p) && ({ \
+ prefetch(((struct hlist_node*)p)->next); \
+ p = hlist_entry((void*)p, typeof(*p), pids[type].node); \
+ 1; }); \
+ p = ((type) != PIDTYPE_PID) ? \
+ (void*)(p)->pids[type].node.next : NULL)
+
#define do_each_pid_task(pid, type, task) \
do { \
- struct hlist_node *pos___; \
- if (pid != NULL) \
- hlist_for_each_entry_rcu((task), pos___, \
- &pid->tasks[type], pids[type].node) {
+ pid_for_each_task(pid, type, task)

- /*
- * Both old and new leaders may be attached to
- * the same pid in the middle of de_thread().
- */
#define while_each_pid_task(pid, type, task) \
- if (type == PIDTYPE_PID) \
- break; \
- } \
} while (0)

#define do_each_pid_thread(pid, type, task) \

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/