Re: kldunload DIAGNOSTIC idea...

From: Andrea Campi (andrea_at_webcom.it)
Date: 07/21/04

  • Next message: Poul-Henning Kamp: "Re: kldunload DIAGNOSTIC idea..."
    Date: Wed, 21 Jul 2004 08:16:56 +0200
    To: Poul-Henning Kamp <phk@phk.freebsd.dk>
    
    

    On Tue, Jul 20, 2004 at 08:20:23PM +0200, Poul-Henning Kamp wrote:
    > I'm pulling hair out trying to make it guaranteed safe to unload device
    > driver modules, and the major pain here is to make sure there is no
    > thread stuck somewhere inside the code.
    >
    > That gave me the idea for a simple little DIAGNOSTIC check for kldunload:
    > run through the proc/thread table and look for any thread with an
    > instruction counter inside the range of pages we are going to unload.

    A wild idea just struck; I'm going to just expose it as I think, so bear
    with me.

    Assumption: the main reason for wanting to unload the driver is to be able
    to reload a new (maybe different) one. The main concern is not freeing
    memory.

    Assumption: we are talking about cases where the driver wasn't able to
    clean everything up in the quiesce phase. This means SOME resources failed
    to be cleaned up, or we couldn't even try to free them, or we don't even
    know them.

    Assumption: we are NOT talking about the case you mentioned in a previous
    thread, where you may have some buffer, maybe mapped in common by an
    expansion card and by the driver. There's not much we can do there. We're
    just talking of a simpler case where we (think we) know we have a thread
    stuck somewhere, but apart from that, we're reasonably sure we can detach.

    Right?

    Ok, under this assumptions I guess the cleanest way is to go forward and
    detach the driver leaving it in memory. Either the quiesce or the unload
    should set appropriate flags that instruct the driver to abort any
    further activity, so you can simply and safely do:

    xx_send() {
            if (quiesced)
                    return;

            ...
            lengthy_function(); <<< we are sleeping somewhere down there
            if (gone)
                    return;
            ...
    }

    Yes, this requires additional checks to be scattered around, but it's going
    to be opt-in. In addition, it only needs to be done in places where
    lenghty_function() can't be cancelled, and I guess that's not going to be
    an awful lot of places. But I can be wrong.

    In addition, this may still leak memory, unless the driver is capable of
    keeping track and still free data in the gone case.

    Thoughts?

    Bye,
            Andrea

    -- 
                  The best things in life are free, but the
                    expensive ones are still worth a look.
    _______________________________________________
    freebsd-arch@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-arch
    To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
    

  • Next message: Poul-Henning Kamp: "Re: kldunload DIAGNOSTIC idea..."

    Relevant Pages

    • Re: newbus integration of MOD_QUIESCE (was Re: cvs commit: src/sbin/kldunload kldunload.8 kldunload.
      ... > detach all instances of devices contained in that module. ... I.e., unattached driver, ... MOD_STRONGUNLOAD - Unload even though you're in use. ... deadfs the file system, wither the geom, sever the sockets, etc. ...
      (freebsd-arch)
    • Re: 1394 + WinXP SP2
      ... >> all unload paths for your device. ... My own drivers do very light async I/O, ... I did not do extensive SP2 testing. ... you try your device with CUV and driver verifier with SP1? ...
      (microsoft.public.development.device.drivers)
    • Re: 2.6.10 : kernel BUG at mm/rmap.c:483!
      ... Hugh Dickins wrote: ... > kind, the driver would offer its own device and mmap entry point, ... space program mmaps a superset of the same memory. ... unmapping memory on unload. ...
      (Linux-Kernel)
    • Re: Self-removing driver
      ... I ended up following Volodymyr M. Shcherbyna's suggestion: ... Incremented HandleCount on IRP_MJ_CREATE ... to my Unload routine to prevent a closing conflict as suggested by Pavel A. ... Windows Filesystem and Driver Consulting ...
      (microsoft.public.development.device.drivers)
    • Re: Device driver unload
      ... I think we have some inconsistency around device driver unloading. ... device looses driver after module unload - nothing happens. ... BUS_PROBE_NOMATCHfor devices detached due to driver unload? ... alternative driver wouldn't detach when we kldload the new one. ...
      (freebsd-arch)