[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20120831130632.f7b12060.akpm@linux-foundation.org>
Date: Fri, 31 Aug 2012 13:06:32 -0700
From: Andrew Morton <akpm@...ux-foundation.org>
To: Ed Cashin <ecashin@...aid.com>
Cc: linux-kernel@...r.kernel.org
Subject: Re: [PATCH 02/14] aoe: kernel thread handles I/O completions for
simple locking
On Sat, 25 Aug 2012 10:39:46 -0400
Ed Cashin <ecashin@...aid.com> wrote:
> +static int
> +kthread(void *vp)
> +{
> + struct ktstate *k;
> + DECLARE_WAITQUEUE(wait, current);
> + int more;
> +
> + k = vp;
> + current->flags |= PF_NOFREEZE;
> + set_user_nice(current, -10);
> + complete(&k->rendez); /* tell spawner we're running */
> + do {
> + spin_lock_irq(k->lock);
> + more = k->fn();
> + if (!more) {
> + add_wait_queue(k->waitq, &wait);
> + __set_current_state(TASK_INTERRUPTIBLE);
> + }
> + spin_unlock_irq(k->lock);
> + if (!more) {
> + schedule();
> + remove_wait_queue(k->waitq, &wait);
> + } else
> + cond_resched();
> + } while (!kthread_should_stop());
> + complete(&k->rendez); /* tell spawner we're stopping */
> + return 0;
> +}
> +
> +static void
> +aoe_ktstop(struct ktstate *k)
> +{
> + kthread_stop(k->task);
> + wait_for_completion(&k->rendez);
> +}
> +
> +static int
> +aoe_ktstart(struct ktstate *k)
> +{
> + struct task_struct *task;
> +
> + init_completion(&k->rendez);
> + task = kthread_run(kthread, k, k->name);
> + if (task == NULL || IS_ERR(task))
> + return -ENOMEM;
> + k->task = task;
> + wait_for_completion(&k->rendez); /* allow kthread to start */
> + init_completion(&k->rendez); /* for waiting for exit later */
> + return 0;
> +}
It's a pretty unlikely thing, but I wonder if there's a way in which
aoe_ktstart() can run that second init_completion() _after_ kthread()
has run its second complete(). ie: someone runs aoe_ktstop()
super-early. If that can happen, the later wait_for_completion() hangs
up.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists