Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-08 Thread Paul Goyette
Just wondering here - for pseudo-devices, is it really necessary to remove the autoconf stuff at all? It's not clear to me where it even gets added in the case of modularly-loaded pseudo-devices... Yes. See, e.g., cgd_modcmd. In addition to cgd_cdevsw, there is also a struct cfdriver obj

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-08 Thread Taylor R Campbell
Date: Thu, 9 Jun 2016 07:12:08 +0800 (PHT) From: Paul Goyette For now, I'm just going to maintain a zero/non-zero "active" flag in the driver, setting it on open() and clearing on close(). Unloading of the module will first call devsw_detach(), and then check the flag. If th

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-08 Thread Paul Goyette
Thanks, everyone, for clarifying this confusing-to-me situation! For now, I'm just going to maintain a zero/non-zero "active" flag in the driver, setting it on open() and clearing on close(). Unloading of the module will first call devsw_detach(), and then check the flag. If the flag is set,

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-08 Thread Paul Goyette
On Wed, 8 Jun 2016, Robert Elz wrote: Date:Wed, 8 Jun 2016 22:16:28 +0800 (PHT) From:Paul Goyette Message-ID: | Hmmm. Would it be valid, then, for my close() routine to reset the | ref-count to zero rather than simply decrementing? Do you really need a reference

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-08 Thread Michael van Elst
p...@whooppee.com (Paul Goyette) writes: >On Wed, 8 Jun 2016, Michael van Elst wrote: >> p...@whooppee.com (Paul Goyette) writes: >> See misfs/specfs/spec_vnops.c::spec_close(). >> >>> yes, that would certainly explain the situation. It does, however, make >>> it rather difficult to maintai

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-08 Thread Taylor R Campbell
Date: Wed, 8 Jun 2016 17:34:33 + From: David Holland On Tue, Jun 07, 2016 at 06:28:11PM +0800, Paul Goyette wrote: > Can anyone suggest a reliable way to ensure that a device-driver module can > be _really_ safely detached? There's a pserialize scheme for this; see e.g.

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-08 Thread Taylor R Campbell
Date: Wed, 8 Jun 2016 19:47:38 +0800 (PHT) From: Paul Goyette For some reason, the device's open() routine is being called twice, but the close() routine is only called once. So every iteration leaves the refcount with a net increment of one. Correct! But, counterintuitively,

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-08 Thread David Holland
On Tue, Jun 07, 2016 at 06:28:11PM +0800, Paul Goyette wrote: > Can anyone suggest a reliable way to ensure that a device-driver module can > be _really_ safely detached? There's a pserialize scheme for this; see e.g. an old thread called "kicking everybody out of the softc". The catch for arbi

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-08 Thread Robert Elz
Date:Wed, 8 Jun 2016 22:16:28 +0800 (PHT) From:Paul Goyette Message-ID: | Hmmm. Would it be valid, then, for my close() routine to reset the | ref-count to zero rather than simply decrementing? Do you really need a reference count for anything? Wasn't that j

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-08 Thread Paul_Koning
> On Jun 8, 2016, at 10:16 AM, Paul Goyette wrote: > > On Wed, 8 Jun 2016, Michael van Elst wrote: > >> p...@whooppee.com (Paul Goyette) writes: >> See misfs/specfs/spec_vnops.c::spec_close(). >> >>> yes, that would certainly explain the situation. It does, however, make >>> it rather d

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-08 Thread Paul Goyette
On Wed, 8 Jun 2016, Michael van Elst wrote: p...@whooppee.com (Paul Goyette) writes: See misfs/specfs/spec_vnops.c::spec_close(). yes, that would certainly explain the situation. It does, however, make it rather difficult to maintain a valid ref-count! specfs does the open refcounting. T

device open/close (was: Locking strategy for device deletion (also see PR kern/48536))

2016-06-08 Thread Edgar Fuß
> I'll try to lookup chapter and verse for you in the next week or so 6.2, 197--198.

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-08 Thread Michael van Elst
p...@whooppee.com (Paul Goyette) writes: >> See misfs/specfs/spec_vnops.c::spec_close(). >yes, that would certainly explain the situation. It does, however, make >it rather difficult to maintain a valid ref-count! specfs does the open refcounting. The device only has a single bit, open sets it

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-08 Thread Brian Buhrow
tegy for device deletion (also see PR kern/48536) } On Wed, 8 Jun 2016, Paul Goyette wrote: } } > On Tue, 7 Jun 2016, Taylor R Campbell wrote: } > } >> Date: Tue, 7 Jun 2016 18:28:11 +0800 (PHT) } >> From: Paul Goyette } >> } >> Can anyone suggest a relia

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-08 Thread Paul Goyette
On Wed, 8 Jun 2016, J. Hannken-Illjes wrote: Well, it almost works! Just one little problem... :) For some reason, the device's open() routine is being called twice, but the close() routine is only called once. So every iteration leaves the refcount with a net increment of one. I cannot f

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-08 Thread J. Hannken-Illjes
> On 08 Jun 2016, at 13:47, Paul Goyette wrote: > > On Wed, 8 Jun 2016, Paul Goyette wrote: > >> On Tue, 7 Jun 2016, Taylor R Campbell wrote: >> >>> Date: Tue, 7 Jun 2016 18:28:11 +0800 (PHT) >>> From: Paul Goyette >>> >>> Can anyone suggest a reliable way to ensure that a device-driver m

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-08 Thread Paul Goyette
On Wed, 8 Jun 2016, Paul Goyette wrote: On Tue, 7 Jun 2016, Taylor R Campbell wrote: Date: Tue, 7 Jun 2016 18:28:11 +0800 (PHT) From: Paul Goyette Can anyone suggest a reliable way to ensure that a device-driver module can be _really_ safely detached? General approach: 1. Prevent n

re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-07 Thread matthew green
>that one i think is a much larger issue that affects *all* of our >drivers and needs a general fix where eg device_lookup_private() >returns a reference counted value that must be returned, before the >module can be considered ready to unload (this still leaves a very >minor ra

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-07 Thread Taylor R Campbell
Date: Wed, 08 Jun 2016 04:42:21 +1000 from: matthew green that one i think is a much larger issue that affects *all* of our drivers and needs a general fix where eg device_lookup_private() returns a reference counted value that must be returned, before the module can be consider

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-07 Thread Paul Goyette
On Tue, 7 Jun 2016, Taylor R Campbell wrote: Date: Tue, 7 Jun 2016 18:28:11 +0800 (PHT) From: Paul Goyette Can anyone suggest a reliable way to ensure that a device-driver module can be _really_ safely detached? General approach: 1. Prevent new references (e.g., devsw_detach). 2. Wa

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-07 Thread Paul Goyette
On Tue, 7 Jun 2016, David Young wrote: On Tue, Jun 07, 2016 at 06:28:11PM +0800, Paul Goyette wrote: Can anyone suggest a reliable way to ensure that a device-driver module can be _really_ safely detached? The module could theoretically maintain an open/ref counter, but making this MP-safe is

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-07 Thread Taylor R Campbell
Date: Tue, 7 Jun 2016 18:28:11 +0800 (PHT) From: Paul Goyette Can anyone suggest a reliable way to ensure that a device-driver module can be _really_ safely detached? General approach: 1. Prevent new references (e.g., devsw_detach). 2. Wait for existing references to drain (or rol

re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-07 Thread matthew green
Paul Goyette writes: > Can anyone suggest a reliable way to ensure that a device-driver module > can be _really_ safely detached? the method the USB drivers use seems to be fairly safe. there's one condition i'm not 100% sure about, but seems unlikely. see the usage of eg, sc_dying in ugen.c.

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-07 Thread David Young
On Tue, Jun 07, 2016 at 06:28:11PM +0800, Paul Goyette wrote: > Can anyone suggest a reliable way to ensure that a device-driver > module can be _really_ safely detached? > > The module could theoretically maintain an open/ref counter, but > making this MP-safe is "difficult"! Even if the module

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-07 Thread Paul Goyette
On Tue, 7 Jun 2016, David Brownlee wrote: Any good MP-safe suggestions? Other than having the mutex be for a nullable pointer to the device which persists after driver detach and is reattached when the driver reattaches, which adds an extra pointer dereference for every use... :/ Well, yeah,

Re: Locking strategy for device deletion (also see PR kern/48536)

2016-06-07 Thread David Brownlee
On 7 June 2016 at 11:28, Paul Goyette wrote: > Can anyone suggest a reliable way to ensure that a device-driver module can > be _really_ safely detached? > > The module could theoretically maintain an open/ref counter, but making this > MP-safe is "difficult"! Even if the module were to provide a

Locking strategy for device deletion (also see PR kern/48536)

2016-06-07 Thread Paul Goyette
Can anyone suggest a reliable way to ensure that a device-driver module can be _really_ safely detached? The module could theoretically maintain an open/ref counter, but making this MP-safe is "difficult"! Even if the module were to provide a mutex to control increment/decrement of it's count