From owner-freebsd-current@FreeBSD.ORG Tue Jan 19 09:52:29 2010 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 16F681065701 for ; Tue, 19 Jan 2010 09:52:29 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: from mail-fx0-f227.google.com (mail-fx0-f227.google.com [209.85.220.227]) by mx1.freebsd.org (Postfix) with ESMTP id 9A3708FC1C for ; Tue, 19 Jan 2010 09:52:28 +0000 (UTC) Received: by fxm27 with SMTP id 27so3159729fxm.3 for ; Tue, 19 Jan 2010 01:52:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=oY5taU1D65AmPO6O8X5waKpGGn2gOxiyp4/1p+IOZJY=; b=c1v7fOJwhPL6yMzGF32zLxLXbblRGXhjOO4EDhDqQMnaOfhUN7/lO+jIec+xcQ/21e 3kbtB1aJoWbIEJcPmccfKMHL0n0i3oFy27f4QlHyEvsgjongR5HbYvZ5mme+MujgpsRi W2cH0pvMPVlVplVCN1tOetxuHJtfXdP9SW+G0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=aau3MFXVAo2GIonBrTl+YnxwscsBP2UWTdoRM2W/diWfqbeub1DOUanmfuHjQeY+XK VaAkgket4F2O/u8hfAxIUGMgwj7xKLWgk9U14DzBSEvV/TQu4mYtVJ0tOQROvN9sR4ba X50AHzTPt/08GK/Xg/Ce1peURnyrYMpjjtRik= MIME-Version: 1.0 Sender: asmrookie@gmail.com Received: by 10.223.13.209 with SMTP id d17mr8760697faa.100.1263894747532; Tue, 19 Jan 2010 01:52:27 -0800 (PST) In-Reply-To: References: <3bbf2fe11001171858o4568fe38l9b2db54ec9856b50@mail.gmail.com> <20100118.155352.59640143160034670.okuno.kohji@jp.panasonic.com> <3bbf2fe11001172306m69ff6544i3aaf05e2540136e1@mail.gmail.com> <20100119.103858.29593248145858473.okuno.kohji@jp.panasonic.com> Date: Tue, 19 Jan 2010 10:52:27 +0100 X-Google-Sender-Auth: 74962f5af9d25712 Message-ID: <3bbf2fe11001190152k15c24f70k876762817bf522c1@mail.gmail.com> From: Attilio Rao To: Jeff Roberson Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: freebsd-current@freebsd.org, Kohji Okuno Subject: Re: Bug about sched_4bsd? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jan 2010 09:52:29 -0000 2010/1/19 Jeff Roberson : > On Tue, 19 Jan 2010, Kohji Okuno wrote: > >> Hello, Attilio, >> >> I think setpriority() can set priority to sleeping threads. >> Is it really safe? > > I agree, in this code path maybe_resched is not properly locking curthrea= d. > =C2=A0curthread will be sched_lock and the sleeping thread will be a slee= pq lock. > =C2=A0I believe that since &sched_lock is ordered after container locks i= t would > be sufficient to compare the two td_lock pointers and acquire sched_lock = if > they are not equal. =C2=A0Someone should look at other maybe_resched call= ers or > add an assert that curthread->td_lock is always &sched_lock in this > function. I'm not sure I understand you well here, but I generally don't agree, if we speak about the current code plus the patch I posted. Without the patch, there is a general problem of maybe_preempt() because sched_switch() will handle TDF_NEEDRESCHED just in racy ways (not ensuring atomicity of td_lock operations for sleeping threads). That's, however, still not specific to maybe_preempt() only. However: * If you make a problem about the callers of maybe_resched() I agree. The callers should assert for sched_lock to be in place. But that is not a general problem of maybe_resched(), it is on the callers ballpark * If you make a problem about the locking itself, the patch IMHO should fix it or there is still something I can't see. Thanks, Attilio --=20 Peace can only be achieved by understanding - A. Einstein