lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 1 Sep 2009 17:19:26 +0200
From:	Oleg Nesterov <oleg@...hat.com>
To:	Américo Wang <xiyou.wangcong@...il.com>
Cc:	Ingo Molnar <mingo@...e.hu>, arjan@...radead.org, jeremy@...p.org,
	mschmidt@...hat.com, mingo@...hat.com, hpa@...or.com,
	linux-kernel@...r.kernel.org, tj@...nel.org, tglx@...utronix.de,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Andrew Morton <akpm@...ux-foundation.org>,
	linux-tip-commits@...r.kernel.org
Subject: Re: [PATCH] kthreads: Fix startup synchronization boot crash

On 09/01, Américo Wang wrote:
>
> On Tue, Sep 01, 2009 at 03:37:09PM +0200, Oleg Nesterov wrote:
> >On 09/01, Ingo Molnar wrote:
> >>
> >> * Oleg Nesterov <oleg@...hat.com> wrote:
> >>
> >> > Yes, this should work. But I _think_ we can make the better fix...
> >> >
> >> > I'll try to make the patch soon. Afaics we don't need
> >> > kthreadd_task_init_done.
> >>
> >> ok.
> >
> >Just in case, the patch is ready. I need to re-check my thinking
> >and test it somehow...
> >
> >- remove kthreadd_task initialization from rest_init()
> >
> >- change kthreadd() to initialize kthreadd_task = current
> >
> >- change the main loop in kthreadd() to take kthread_create_lock
> >  before the first schedule() (just shift schedule() down)
>
> This is the only part that I can't understand, why moving it down?

This way kthreadd() always takes kthread_create_lock before it
schedules.

IOW. Before the patch, kthreadd() does

	for (;;) {
		if (list_empty(kthread_create_list))
			schedule();

		lock(kthread_create_lock);
		while (!list_empty(&kthread_create_list))
			... create kthreads ...
		unlock(kthread_create_lock);
	}

This means kthread_create() can't do

	if (!kthreadd_task)
		wake_up_process(kthreadd_task);

we can read kthreadd_task before kthreadd() sets kthreadd_task = current,
and it is possible that kthreadd() has already checked list_empty() == T.

But if we shift schedule() down, so that kthreadd() does

	for (;;) {
		lock(kthread_create_lock);
		while (!list_empty(&kthread_create_list))
			... create kthreads ...
		unlock(kthread_create_lock);

		if (list_empty(kthread_create_list))
			schedule();
	}

Then we can rely on kthread_create_lock: either kthreadd must see the
addition to create_list, or kthreadd() must see kthreadd_task != NULL.

Because both checks, !kthreadd_task and list_empty(), are done after
lock+unlock of the same lock. The 2nd task which takes the lock must
see the changes which were done by the 1st task which locked this lock.

Do you see any holes?

Oleg.

--
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

Powered by Openwall GNU/*/Linux Powered by OpenVZ