From owner-freebsd-current@FreeBSD.ORG Tue Jan 19 09:53:25 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 3CDB31065697 for ; Tue, 19 Jan 2010 09:53:25 +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 C0A9A8FC2C for ; Tue, 19 Jan 2010 09:53:24 +0000 (UTC) Received: by fxm27 with SMTP id 27so3160517fxm.3 for ; Tue, 19 Jan 2010 01:53:23 -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=L0xw2hd145sNMH0ZraiBEk0XwPaAgPysKEhzVfeLqCM=; b=piyBGl5HKH3NbWRkTEnYMlorTxM1dHmIdki1E7QGd5+GRik2oFV6TJUmYQ905c1nB2 Cm0f/IOO52J1vApandsQHRlGTMDeh14NrJQ5r4hna4ntqqE/seBDO6uhGYXkBZYzSBL8 XIoi6KuRoSSyfNysdQgU9eSWCZMrc3BOt1zMk= 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=ZUUQzonZ/IzNVlzuYdOYpO9HaWxQmiPIGz1XQoXbBFI1zDfeGQh2v8tt1Xyx6DUU7z gDKTEmUBQLeUohepf1nhGd2odDQFk5m77ojIQGdEUwhwiSw7h8/lZlWccpLmzn7T1PM2 itl/EEfulm+TXsKbFFVNHiZVmxod15cj8fs6w= MIME-Version: 1.0 Sender: asmrookie@gmail.com Received: by 10.223.76.142 with SMTP id c14mr8834045fak.92.1263894803905; Tue, 19 Jan 2010 01:53:23 -0800 (PST) In-Reply-To: <3bbf2fe11001190152k15c24f70k876762817bf522c1@mail.gmail.com> 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> <3bbf2fe11001190152k15c24f70k876762817bf522c1@mail.gmail.com> Date: Tue, 19 Jan 2010 10:53:23 +0100 X-Google-Sender-Auth: 8057d9c0f40524ed Message-ID: <3bbf2fe11001190153s1d42a020pecb343993b7971a2@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:53:25 -0000 2010/1/19 Attilio Rao : > 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 curthre= ad. >> =C2=A0curthread will be sched_lock and the sleeping thread will be a sle= epq lock. >> =C2=A0I believe that since &sched_lock is ordered after container locks = it 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 cal= lers 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. s/maybe_preempt/maybe_resched, of course :( Attilio --=20 Peace can only be achieved by understanding - A. Einstein