newbie trouble with destroy_dev

John Baldwin jhb at freebsd.org
Thu Sep 23 21:02:33 UTC 2010


On Thursday, September 23, 2010 1:42:33 pm Ricky Charlet wrote:
> Thanks.
>         That totally worked. Lesson learned = destroy_dev sooner than 
destroy cv's and mutexes's and internal state.
> 
>         One question though... I did not find any "DYING" flag in relation 
to cv's or mutexes. So I just skipped that step in your advice. I only found 
the string "DYING" in relation to jails, sound-drivers, some network stuff and 
ipsec. Will you give me a little more specific pointer to what "DYING" flag 
you were referring to?

I meant a flag specific to your driver.  Basically a way for the code you are 
sending the cv_broadcast to to know they should break out of whatever loop 
they are in, etc.

>         FYI, my userland program sitting in the read loop exited cleanly and 
got errno=ENXIO, which is beautiful.
> 
> Thanks again.
> 
> ---
> Ricky Charlet
> Adara Networks
> USA 408-433-4942
> 
> 
> 
> 
> -----Original Message-----
> From: John Baldwin [mailto:jhb at freebsd.org]
> Sent: Thursday, September 23, 2010 6:49 AM
> To: freebsd-drivers at freebsd.org
> Cc: Ricky Charlet
> Subject: Re: newbie trouble with destroy_dev
> 
> On Wednesday, September 22, 2010 3:11:10 pm Ricky Charlet wrote:
> > Howdy,
> >
> >                 My goal is to destroy a character device which is 
currently
> open for read. Is that allowable? I'm hoping the userland program doing the
> reading will simply get a read error back (possibly with no data or 
truncated
> data).
> >
> >                 My experience so far is that I crash the box.
> >
> >                 I'm using BSD 8.0.  My program with the driver is a kernel
> module. Upon using the `kldunload` utility, the d_close() method is called.  
I
> have tried these logic flows:
> >
> > Test 1
> > ---------------------
> >  Unhook my packet-filter-hooks
> >  cv_broadcast;
> > cv_destory
> > mMtx_destroy
> > destroy_dev
> > free associated buffers
> >
> > Test 2
> > --------------------
> > Unhook my packet-filter-hooks
> >  cv_broadcast;
> > cv_destory
> > mMtx_destroy
> > destroy_dev_sched_cb
> > free associated buffers
> >
> >   Test 3
> > ----------------------
> > Unhook my packet-filter-hooks
> >  cv_broadcast;
> > cv_destory
> > mMtx_destroy
> > free associated buffers
> >
> >
> >                 In all cases I get a kernel crash and the system reboots.
> Note that the userland program has the associated charater device open and 
is
> in a for-ever loop reading the fd.
> >
> >                 I'm a newbie and have not yet attached a debugger. I'll go
> start reading about that and trying it out while I hopefully await replies.
> 
> Call destroy_dev() earlier, before you destroy any state.  Your cdevsw
> routines can be invoked right up until destroy_dev() returns, so if you
> destroy the mutex before destroy_dev() you might destroy it before a cdevsw
> routine tries to use it.  I suspect you might need something like:
> 
>         unhook_packet_filters
>         set DYING flag (for listeners to the cv to know to exit, etc.)
>         cv_broadcast()
>         destroy_dev()
>         free buffers
>         cv_destroy()
>         mtx_destroy()
> 
> --
> John Baldwin
> 

-- 
John Baldwin


More information about the freebsd-drivers mailing list