No IRP_MN_REMOVE_DEVICE after IRP_MN_SURPRISE_REMOVAL

I have written a WDM driver for a PCI device and am testing the surprise removal handling for it.

I believe that I’m following the DDK rules for surprise removal correctly, but I never get a IRP_MN_REMOVE_DEVICE notification after the surprise removal.

I’m also sure that there is no application with an open handle to the device. I’m doing this testing without accessing the device from any application.

Other then open handles, is there any other reason for a missing remove device IRP after a surprise device removal?

I’m running on XP. I’ve been generating the surprise removal events in two different ways with the same results; by using the PNPDTEST utility that came with the DDK, and also by plugging my PCI card into a cardbus <-> PCI bridge and popping the bridge out without stopping it.

Any thoughts?

Thanks,
Steve

Run !locks and see what thread is actively holding the pnp tree lock
(.thread xxx for the owning thread). Also, !devnode might give you a
clue. What does your code look like for handling surprise remove? are
you just sending the irp down the stack?

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@embeddedintelligence.com
Sent: Friday, July 21, 2006 4:35 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] No IRP_MN_REMOVE_DEVICE after IRP_MN_SURPRISE_REMOVAL

I have written a WDM driver for a PCI device and am testing the surprise
removal handling for it.

I believe that I’m following the DDK rules for surprise removal
correctly, but I never get a IRP_MN_REMOVE_DEVICE notification after the
surprise removal.

I’m also sure that there is no application with an open handle to the
device. I’m doing this testing without accessing the device from any
application.

Other then open handles, is there any other reason for a missing remove
device IRP after a surprise device removal?

I’m running on XP. I’ve been generating the surprise removal events in
two different ways with the same results; by using the PNPDTEST utility
that came with the DDK, and also by plugging my PCI card into a cardbus
<-> PCI bridge and popping the bridge out without stopping it.

Any thoughts?

Thanks,
Steve


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Hi Doron, thanks for the quick response.

My surprise remove code follows these steps:

  1. Abort any pending IRPS (I’m using Walter Oney’s DevQueue for IRP handling)
  2. release all mapped memory and interrupts
  3. Disable the interface using IoSetDeviceInterfaceState()
  4. Disable a symbolic link to my driver
  5. Set the IRP status to success
  6. IoSkipCurrentIrpStackLocation()
  7. IoCallDriver( next in stack )
  8. Return result of IoCallDriver (which is success - 0)

I’m afraid I’m a novice as far as windbg goes, but the !locks command returned exactly the same result when run at three different times:

  1. before I plugged in my device
  2. while device was plugged in and started
  3. after the surprise remove.

In all cases !locks reported two locks held: MnSystemWsLock and one just displayed in hex.

I’m trying to decypher the output from !devnodes now.

Thanks,
Steve

For what it’s worth, here’s the output of !devnode for my device after the surprise removal.

At this point I have not seen a remove PNP message unless I’m missing it somehow.

lkd> !devnode 85575630
DevNode 0x85575630 for PDO 0x850a3a58
Parent 0000000000 Sibling 0000000000 Child 0000000000
InstancePath is “PCI\VEN_10EE&DEV_D154&SUBSYS_D15410EE&REV_00\6&2b8c85f2&0&20200050”
ServiceName is “copleycan”
State = DeviceNodeDeleted (0x314)
Previous State = DeviceNodeDeletePendingCloses (0x313)
StateHistory[12] = DeviceNodeDeletePendingCloses (0x313)
StateHistory[11] = DeviceNodeRemovePendingCloses (0x311)
StateHistory[10] = DeviceNodeStarted (0x308)
StateHistory[09] = DeviceNodeAwaitingQueuedDeletion (0x30e)
StateHistory[08] = DeviceNodeStarted (0x308)
StateHistory[07] = DeviceNodeEnumerateCompletion (0x30d)
StateHistory[06] = DeviceNodeStarted (0x308)
StateHistory[05] = DeviceNodeStartPostWork (0x307)
StateHistory[04] = DeviceNodeStartCompletion (0x306)
StateHistory[03] = DeviceNodeResourcesAssigned (0x304)
StateHistory[02] = DeviceNodeDriversAdded (0x303)
StateHistory[01] = DeviceNodeInitialized (0x302)
StateHistory[00] = DeviceNodeUninitialized (0x301)
StateHistory[19] = Unknown State (0x0)
StateHistory[18] = Unknown State (0x0)
StateHistory[17] = Unknown State (0x0)
StateHistory[16] = Unknown State (0x0)
StateHistory[15] = Unknown State (0x0)
StateHistory[14] = Unknown State (0x0)
StateHistory[13] = Unknown State (0x0)
Flags (0x00002020) DNF_IDS_QUERIED, DNF_HAS_PROBLEM
Problem = CM_PROB_DEVICE_NOT_THERE

Is there a driver above yours (!devstack ) will tell you
that. Also, does !devhandles show anything?

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@embeddedintelligence.com
Sent: Friday, July 21, 2006 6:56 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] No IRP_MN_REMOVE_DEVICE after
IRP_MN_SURPRISE_REMOVAL

For what it’s worth, here’s the output of !devnode for my device after
the surprise removal.

At this point I have not seen a remove PNP message unless I’m missing it
somehow.

lkd> !devnode 85575630
DevNode 0x85575630 for PDO 0x850a3a58
Parent 0000000000 Sibling 0000000000 Child 0000000000
InstancePath is
“PCI\VEN_10EE&DEV_D154&SUBSYS_D15410EE&REV_00\6&2b8c85f2&0&20200050”
ServiceName is “copleycan”
State = DeviceNodeDeleted (0x314)
Previous State = DeviceNodeDeletePendingCloses (0x313)
StateHistory[12] = DeviceNodeDeletePendingCloses (0x313)
StateHistory[11] = DeviceNodeRemovePendingCloses (0x311)
StateHistory[10] = DeviceNodeStarted (0x308)
StateHistory[09] = DeviceNodeAwaitingQueuedDeletion (0x30e)
StateHistory[08] = DeviceNodeStarted (0x308)
StateHistory[07] = DeviceNodeEnumerateCompletion (0x30d)
StateHistory[06] = DeviceNodeStarted (0x308)
StateHistory[05] = DeviceNodeStartPostWork (0x307)
StateHistory[04] = DeviceNodeStartCompletion (0x306)
StateHistory[03] = DeviceNodeResourcesAssigned (0x304)
StateHistory[02] = DeviceNodeDriversAdded (0x303)
StateHistory[01] = DeviceNodeInitialized (0x302)
StateHistory[00] = DeviceNodeUninitialized (0x301)
StateHistory[19] = Unknown State (0x0)
StateHistory[18] = Unknown State (0x0)
StateHistory[17] = Unknown State (0x0)
StateHistory[16] = Unknown State (0x0)
StateHistory[15] = Unknown State (0x0)
StateHistory[14] = Unknown State (0x0)
StateHistory[13] = Unknown State (0x0)
Flags (0x00002020) DNF_IDS_QUERIED, DNF_HAS_PROBLEM
Problem = CM_PROB_DEVICE_NOT_THERE


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Hi Doron;

!devstack shows no device above mine in the stack, but there is a device just below mine between my device and the pci device. This is \Device\mrtcb which is the device for the cardbus <-> PCI bridge that I’m using.

After I pop the PCI bridge out (and thereby get my surprise removal), the !devstack just shows these two devices in the stack. The lowest PCI device is gone.

!devhandles doesn’t seem to show any open handles, but I’m having trouble finding any documentation on this command to help me decypher it’s output.

Thanks,
Steve

The device below is presumably also in pending remove state. In all cases
I’ve seen where pending remove is stuck there is either an IRP that is not
fully completed or a process that has an open handle to the device.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@embeddedintelligence.com
Sent: Saturday, July 22, 2006 7:54 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] No IRP_MN_REMOVE_DEVICE after
IRP_MN_SURPRISE_REMOVAL

Hi Doron;

!devstack shows no device above mine in the stack, but there
is a device just below mine between my device and the pci
device. This is \Device\mrtcb which is the device for the
cardbus <-> PCI bridge that I’m using.

After I pop the PCI bridge out (and thereby get my surprise
removal), the !devstack just shows these two devices in the
stack. The lowest PCI device is gone.

!devhandles doesn’t seem to show any open handles, but I’m
having trouble finding any documentation on this command to
help me decypher it’s output.

Thanks,
Steve


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online
at http://www.osronline.com/page.cfm?name=ListServer

I would start taking a step backwards from the situation and try to
isolate what is going on. For instance, do not have any app open the
device and then surprise remove the device. Does it then get a remove?
If not, start removing other variables from the equation.

One simple case to test is to write a simple KMDF driver that does
nothing at all and then surprise remove the device and see if it gets a
remove (you can tell if EvtObjectCleanup on the FDO WDFDEVICE is
called). If not, there is some other issue at hand, otherwise it is
something you are doing and you should continue down the elimination
path

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Saturday, July 22, 2006 5:13 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] No IRP_MN_REMOVE_DEVICE after
IRP_MN_SURPRISE_REMOVAL

The device below is presumably also in pending remove state. In all
cases
I’ve seen where pending remove is stuck there is either an IRP that is
not
fully completed or a process that has an open handle to the device.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@embeddedintelligence.com
Sent: Saturday, July 22, 2006 7:54 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] No IRP_MN_REMOVE_DEVICE after
IRP_MN_SURPRISE_REMOVAL

Hi Doron;

!devstack shows no device above mine in the stack, but there
is a device just below mine between my device and the pci
device. This is \Device\mrtcb which is the device for the
cardbus <-> PCI bridge that I’m using.

After I pop the PCI bridge out (and thereby get my surprise
removal), the !devstack just shows these two devices in the
stack. The lowest PCI device is gone.

!devhandles doesn’t seem to show any open handles, but I’m
having trouble finding any documentation on this command to
help me decypher it’s output.

Thanks,
Steve


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online
at http://www.osronline.com/page.cfm?name=ListServer


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer