Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 31 Mar 2011 18:21:45 +0200
From:      Svatopluk Kraus <onwahe@gmail.com>
To:        John Baldwin <jhb@freebsd.org>
Cc:        freebsd-current@freebsd.org
Subject:   Re: schedcpu() in /sys/kern/sched_4bsd.c calls thread_lock() on thread with un-initialized td_lock
Message-ID:  <AANLkTi=Qiugq9-mU2C3bgR0p_F70OeahbtvQUu7n_K6C@mail.gmail.com>
In-Reply-To: <201103310958.51416.jhb@freebsd.org>
References:  <AANLkTimEiOW%2BkSZD6n1MHiRou3UWibU6Oy3fr9RO4_O4@mail.gmail.com> <201103310958.51416.jhb@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Mar 31, 2011 at 3:58 PM, John Baldwin <jhb@freebsd.org> wrote:
> On Thursday, March 31, 2011 7:32:26 am Svatopluk Kraus wrote:
>> Hi,
>>
>> =A0 I've got a page fault (because of NULL td_lock) in
>> thread_lock_flags() called from schedcpu() in /sys/kern/sched_4bsd.c
>> file. During process fork, new thread is linked to new process which
>> is linked to allproc list and both allproc_lock and new process lock
>> are unlocked before sched_fork() is called, where new thread td_lock
>> is initialized. Only PRS_NEW process status is on sentry but not
>> checked in schedcpu().
>
> I think this should fix it:
>
> Index: sched_4bsd.c
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> --- sched_4bsd.c =A0 =A0 =A0 =A0(revision 220190)
> +++ sched_4bsd.c =A0 =A0 =A0 =A0(working copy)
> @@ -463,6 +463,10 @@ schedcpu(void)
> =A0 =A0 =A0 =A0sx_slock(&allproc_lock);
> =A0 =A0 =A0 =A0FOREACH_PROC_IN_SYSTEM(p) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0PROC_LOCK(p);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (p->p_state =3D=3D PRS_NEW) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 PROC_UNLOCK(p);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0FOREACH_THREAD_IN_PROC(p, td) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0awake =3D 0;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0thread_lock(td);
>

Thanks for patch. Maybe, test p_state not to be PRS_NORMAL could be better?

I've got next (same reason) page fault in thread_lock_flags() called
from scheduler() in sys/vm/vm_glue.c. I try to search for
FOREACH_THREAD_IN_PROC() together with FOREACH_PROC_IN_SYSTEM() in
/sys subtree and next problem could be in deadlkres() in
sys/kern/kern_clock.c at least.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTi=Qiugq9-mU2C3bgR0p_F70OeahbtvQUu7n_K6C>