From owner-cvs-all Sun Mar 4 14:23:44 2001 Delivered-To: cvs-all@freebsd.org Received: from moby.geekhouse.net (moby.geekhouse.net [64.81.6.36]) by hub.freebsd.org (Postfix) with ESMTP id 81F0D37B719; Sun, 4 Mar 2001 14:23:27 -0800 (PST) (envelope-from jhb@FreeBSD.org) Received: from laptop.baldwin.cx (john@dhcp152.geekhouse.net [192.168.1.152]) by moby.geekhouse.net (8.11.0/8.9.3) with ESMTP id f24MOD183915; Sun, 4 Mar 2001 14:24:13 -0800 (PST) (envelope-from jhb@FreeBSD.org) Message-ID: X-Mailer: XFMail 1.4.0 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <200103042151.f24Lp6O83223@aslan.scsiguy.com> Date: Sun, 04 Mar 2001 14:23:03 -0800 (PST) From: John Baldwin To: "Justin T. Gibbs" Subject: Re: cvs commit: src/sys/kern kern_intr.c src/sys/sys interrupt.h Cc: cvs-all@FreeBSD.org, cvs-committers@FreeBSD.org Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On 04-Mar-01 Justin T. Gibbs wrote: >>> Sure there is. You can block the "releaser" until the interrupt routine >>> exits. >>> There is no other way to resolve the race condition. >> >>And what if the routine that is deregeristering the interrupt handler holds a >>mutex that the ithread is blocked on? We will deadlock if we wait for the >>ithread to exit. > > That is a driver bug or a bug in the deregistering mechanism. There > shouldn't > be a need for that code to hold any locks after it has decided whether to > accept the detach and during the removal of the interrupt handler. I'd rather have the code not care either way to make it easier on driver writers if need be. I do agree that drivers probably shouldn't be holding locks while removing handlers. Note that pccard does make a lot of the cases more extreme as the hardware can leave at any time. >>> Perhaps you should just change the >>> handler's entry point to the removal function and set the ithread runable. >>> The >>> new entry point would remove the handler and wakeup the thread waiting for >>> the >>> entry to be removed. >> >>This _still_ doesn't help if we are already executing the handler. > > Sure it does. Once the new handler is run, you are guaranteed that the old > handler > is not running and can cannot be run again. If the handler is running, the > new handler > will not be run until the next time through the ihandler list. The trick is > making > sure that the ithread loops at least one more time. So, if you sleep until > the > your new handler is run, you are always safe. Erm, did you read what my code does? If I have registerd the foo() function and the ithread blocks while it is executing foo() and while it is blocked another thread removes foo() from the list, what possible good can changing hte functino pointer do to change the fact that the ithread is executing foo()? I guess I could go rewrite the stack or something really arcane, which would break any mutexes foo() might be holding, etc. Changing the function pointer doesn't _fix_ that, and marking the intrhand as dead via IH_DEAD achieves the same result as changing the function pointer. Also, since I set it_need, I _do_ force the ithread to loop again to purge the item from the list. I guess your new change to this is you want to sleep on the intrhand until the ithread runs to release it? I don't see why that is needed. Once the intrhand is dead, we don't dereference the function pointer again, so we aren't in danger of calling the function on a free'd softc, etc. The only bad case is if the function is already running, and changing the function pointer doesn't do anything to help with that. >>It uses a normal TAILQ. Since pointer updates are atomic on all archs we >>support atm and since we fully initialize a struct intrhand before we put it >>on a list so there is currently no problem there. > > How do you avoid the race when two threads attempt to add onto the list at > the same time? A single atomic store doesn't help you unless you can safely > test and recover from a colision. The mutex protects against this. The only unprotected case is the ithread walking the list while another thread is adding an item. > -- > Justin -- John Baldwin -- http://www.FreeBSD.org/~jhb/ PGP Key: http://www.baldwin.cx/~john/pgpkey.asc "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message