Why is Windows "restarting" my device

I have a Bus driver for a virtual device. One operation that happens
frequently is the currently enumerated devices are replaced with new
devices. The new devices are reported when I receive
IRP_MJ_PNP/IRN_MN_DEVICE_RELATIONS(BusRelations) and the old ones are
not. The old devices receive IRP_MJ_PNP/IRN_MN_SURPRISE_REMOVAL
notifications . This operation is triggered by an IOCTL from my config
app. The driver handles all this, and it all works quite nicely…

Except, sometimes (maybe even always) the new devices are “restarted”.
Shortly after I get the START_DEVICE notification I receive an
IRP_MN_REMOVE_DEVICE, followed by a bunch of IRP_MN_QUERY…s, and
another IRP_MN_START_DEVICE.

Before I could only speculate that the devices were being restarted,
but this was sort of confirmed when I set a break point and saw
PiRestartDevice in the stack.

So, some questions:

  1. Why would my device be restarted?
  2. How can I prevent my device from being restarted?
  3. What’s to stop my device from being restarted a third time (or more
    times)?
  4. Or, is it safe to assume that my devices will always be started then
    restarted?

The reason I ask this is because I am tracking down a couple bugs in my
driver and they seem to be related to accessing the device before I get
the second start message. Sometimes everything works fine other times I
see some weird behavior. The last thing that the IOCTL from my config
app does, is it wait for all the devices to be started (the device
extension has an event that I wait on). But, waiting on this event is
useless. It’s really the second START_DEVICE message that I want to
wait for.

(As I was typing this email I modified the driver to wait for the
second start message. Ever thing seems to work ok and my problems go
away, but it just doesn’t sit right with me. It really doesn’t seem
like the right thing to do.)

I’ve seen the side effect of this issue on Win2k (SP4) and WinXP (SP1
SP2) but I’ve only poked around with a debugger on WinXP.

Cliff

  1. are your children marked as raw? If so, they will be started and
    then pnp will try to find a match, resulting in another start

  2. what are you returing for the device state in handling
    IRP_MN_QUERY_PNP_DEVICE_STATE? If the right bits are set, this can
    cause a restart, but that is usually start->stop->start

  3. relying on the pdo to start should not be a part of your device.
    There are so many things that can fail in the interim, including pnp not
    install a dirver for the pdo. If the pdo is marked as raw, the pnp
    install part is less of a problem. Things that can fail: failure to
    allocate a device object, failure to allocate a device relations,
    failure to allocate and return an set of hw IDs asked for, failure to
    allocate a devnode in the kernel, etc etc. I have written a stack like
    this and attempted to do the wait for start thing, it doesn’t work in
    the end. Instead, have the PDO you enumerate register a device
    interface. You can be notified of the interface arrival if the device
    is successfully started. To differentiate between different interfaces,
    you can set a property when you ask for enumeration and then ask for
    that property when the interface arrives (or look for it in the devnode
    (which the driver wrote to)).

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Cliff Russell
Sent: Wednesday, January 19, 2005 9:15 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Why is Windows “restarting” my device

I have a Bus driver for a virtual device. One operation that happens
frequently is the currently enumerated devices are replaced with new
devices. The new devices are reported when I receive
IRP_MJ_PNP/IRN_MN_DEVICE_RELATIONS(BusRelations) and the old ones are
not. The old devices receive IRP_MJ_PNP/IRN_MN_SURPRISE_REMOVAL
notifications . This operation is triggered by an IOCTL from my config
app. The driver handles all this, and it all works quite nicely…

Except, sometimes (maybe even always) the new devices are “restarted”.
Shortly after I get the START_DEVICE notification I receive an
IRP_MN_REMOVE_DEVICE, followed by a bunch of IRP_MN_QUERY…s, and
another IRP_MN_START_DEVICE.

Before I could only speculate that the devices were being restarted,
but this was sort of confirmed when I set a break point and saw
PiRestartDevice in the stack.

So, some questions:

  1. Why would my device be restarted?
  2. How can I prevent my device from being restarted?
  3. What’s to stop my device from being restarted a third time (or more
    times)?
  4. Or, is it safe to assume that my devices will always be started then
    restarted?

The reason I ask this is because I am tracking down a couple bugs in my
driver and they seem to be related to accessing the device before I get
the second start message. Sometimes everything works fine other times I
see some weird behavior. The last thing that the IOCTL from my config
app does, is it wait for all the devices to be started (the device
extension has an event that I wait on). But, waiting on this event is
useless. It’s really the second START_DEVICE message that I want to
wait for.

(As I was typing this email I modified the driver to wait for the
second start message. Ever thing seems to work ok and my problems go
away, but it just doesn’t sit right with me. It really doesn’t seem
like the right thing to do.)

I’ve seen the side effect of this issue on Win2k (SP4) and WinXP (SP1
SP2) but I’ve only poked around with a debugger on WinXP.

Cliff


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

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

In general, you should write your code so that arbitrary stops and
starts won’t cause problems, because there are legitimate reasons why
users or other software might do this, and there’s no good reason to
@#$#@ off your customers.

Don’t know whether this could be relevant to your situation, but I also
have a vague memory of an anti-virus or debugging app (don’t remember
which) that would get PnP notifications of device arrival, and force a
rebuild of the stack so it could wedge itself in as a filter. This would
look like a stop/restart cycle.

Cliff Russell wrote:

I have a Bus driver for a virtual device. One operation that happens
frequently is the currently enumerated devices are replaced with new
devices. The new devices are reported when I receive
IRP_MJ_PNP/IRN_MN_DEVICE_RELATIONS(BusRelations) and the old ones are
not. The old devices receive IRP_MJ_PNP/IRN_MN_SURPRISE_REMOVAL
notifications . This operation is triggered by an IOCTL from my config
app. The driver handles all this, and it all works quite nicely…

Except, sometimes (maybe even always) the new devices are “restarted”.
Shortly after I get the START_DEVICE notification I receive an
IRP_MN_REMOVE_DEVICE, followed by a bunch of IRP_MN_QUERY…s, and
another IRP_MN_START_DEVICE.

Before I could only speculate that the devices were being restarted, but
this was sort of confirmed when I set a break point and saw
PiRestartDevice in the stack.

So, some questions:

  1. Why would my device be restarted?
  2. How can I prevent my device from being restarted?
  3. What’s to stop my device from being restarted a third time (or more
    times)?
  4. Or, is it safe to assume that my devices will always be started then
    restarted?

The reason I ask this is because I am tracking down a couple bugs in my
driver and they seem to be related to accessing the device before I get
the second start message. Sometimes everything works fine other times I
see some weird behavior. The last thing that the IOCTL from my config
app does, is it wait for all the devices to be started (the device
extension has an event that I wait on). But, waiting on this event is
useless. It’s really the second START_DEVICE message that I want to wait
for.

(As I was typing this email I modified the driver to wait for the second
start message. Ever thing seems to work ok and my problems go away, but
it just doesn’t sit right with me. It really doesn’t seem like the right
thing to do.)

I’ve seen the side effect of this issue on Win2k (SP4) and WinXP (SP1
SP2) but I’ve only poked around with a debugger on WinXP.


…/ray..

Please remove “.spamblock” from my email address if you need to contact
me outside the newsgroup.

On 19-Jan-05, at 11:13 PM, Doron Holan wrote:

  1. are your children marked as raw? If so, they will be started and
    then pnp will try to find a match, resulting in another start

Bingo…that’s it!

  1. what are you returing for the device state in handling
    IRP_MN_QUERY_PNP_DEVICE_STATE? If the right bits are set, this can
    cause a restart, but that is usually start->stop->start

Which bits for IRP_MN_QUERY_PNP_DEVICE_STATE would cause the
start->stop->start cycle (or other other restart cycles)?

  1. relying on the pdo to start should not be a part of your device.
    There are so many things that can fail in the interim, including pnp
    not
    install a dirver for the pdo. If the pdo is marked as raw, the pnp
    install part is less of a problem. Things that can fail: failure to
    allocate a device object, failure to allocate a device relations,
    failure to allocate and return an set of hw IDs asked for, failure to
    allocate a devnode in the kernel, etc etc. I have written a stack like
    this and attempted to do the wait for start thing, it doesn’t work in
    the end. Instead, have the PDO you enumerate register a device
    interface. You can be notified of the interface arrival if the device
    is successfully started. To differentiate between different
    interfaces,
    you can set a property when you ask for enumeration and then ask for
    that property when the interface arrives (or look for it in the devnode
    (which the driver wrote to)).

You raise a good point there…I think that bit of code in my driver is
a little “optimistic”

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Cliff Russell
Sent: Wednesday, January 19, 2005 9:15 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Why is Windows “restarting” my device

I have a Bus driver for a virtual device. One operation that happens
frequently is the currently enumerated devices are replaced with new
devices. The new devices are reported when I receive
IRP_MJ_PNP/IRN_MN_DEVICE_RELATIONS(BusRelations) and the old ones are
not. The old devices receive IRP_MJ_PNP/IRN_MN_SURPRISE_REMOVAL
notifications . This operation is triggered by an IOCTL from my config
app. The driver handles all this, and it all works quite nicely…

Except, sometimes (maybe even always) the new devices are “restarted”.
Shortly after I get the START_DEVICE notification I receive an
IRP_MN_REMOVE_DEVICE, followed by a bunch of IRP_MN_QUERY…s, and
another IRP_MN_START_DEVICE.

Before I could only speculate that the devices were being restarted,
but this was sort of confirmed when I set a break point and saw
PiRestartDevice in the stack.

So, some questions:

  1. Why would my device be restarted?
  2. How can I prevent my device from being restarted?
  3. What’s to stop my device from being restarted a third time (or more
    times)?
  4. Or, is it safe to assume that my devices will always be started then
    restarted?

The reason I ask this is because I am tracking down a couple bugs in my
driver and they seem to be related to accessing the device before I get
the second start message. Sometimes everything works fine other times I
see some weird behavior. The last thing that the IOCTL from my config
app does, is it wait for all the devices to be started (the device
extension has an event that I wait on). But, waiting on this event is
useless. It’s really the second START_DEVICE message that I want to
wait for.

(As I was typing this email I modified the driver to wait for the
second start message. Ever thing seems to work ok and my problems go
away, but it just doesn’t sit right with me. It really doesn’t seem
like the right thing to do.)

I’ve seen the side effect of this issue on Win2k (SP4) and WinXP (SP1
SP2) but I’ve only poked around with a debugger on WinXP.

Cliff


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

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


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

You are currently subscribed to ntdev as: unknown lmsubst tag
argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/kmarch/
hh/kmarch/k112_de83a2be-0948-448d-bc52-b69ded97706c.xml.asp

beware of wrap.

Also, in the device caps, you might want to report SilentInstall = TRUE;

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Cliff Russell
Sent: Thursday, January 20, 2005 11:18 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Why is Windows “restarting” my device

On 19-Jan-05, at 11:13 PM, Doron Holan wrote:

  1. are your children marked as raw? If so, they will be started and
    then pnp will try to find a match, resulting in another start

Bingo…that’s it!

  1. what are you returing for the device state in handling
    IRP_MN_QUERY_PNP_DEVICE_STATE? If the right bits are set, this can
    cause a restart, but that is usually start->stop->start

Which bits for IRP_MN_QUERY_PNP_DEVICE_STATE would cause the
start->stop->start cycle (or other other restart cycles)?

  1. relying on the pdo to start should not be a part of your device.
    There are so many things that can fail in the interim, including pnp
    not
    install a dirver for the pdo. If the pdo is marked as raw, the pnp
    install part is less of a problem. Things that can fail: failure to
    allocate a device object, failure to allocate a device relations,
    failure to allocate and return an set of hw IDs asked for, failure to
    allocate a devnode in the kernel, etc etc. I have written a stack
    like
    this and attempted to do the wait for start thing, it doesn’t work in
    the end. Instead, have the PDO you enumerate register a device
    interface. You can be notified of the interface arrival if the device
    is successfully started. To differentiate between different
    interfaces,
    you can set a property when you ask for enumeration and then ask for
    that property when the interface arrives (or look for it in the
    devnode
    (which the driver wrote to)).

You raise a good point there…I think that bit of code in my driver is
a little “optimistic”

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Cliff Russell
Sent: Wednesday, January 19, 2005 9:15 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Why is Windows “restarting” my device

I have a Bus driver for a virtual device. One operation that happens
frequently is the currently enumerated devices are replaced with new
devices. The new devices are reported when I receive
IRP_MJ_PNP/IRN_MN_DEVICE_RELATIONS(BusRelations) and the old ones are
not. The old devices receive IRP_MJ_PNP/IRN_MN_SURPRISE_REMOVAL
notifications . This operation is triggered by an IOCTL from my config
app. The driver handles all this, and it all works quite nicely…

Except, sometimes (maybe even always) the new devices are “restarted”.
Shortly after I get the START_DEVICE notification I receive an
IRP_MN_REMOVE_DEVICE, followed by a bunch of IRP_MN_QUERY…s, and
another IRP_MN_START_DEVICE.

Before I could only speculate that the devices were being restarted,
but this was sort of confirmed when I set a break point and saw
PiRestartDevice in the stack.

So, some questions:

  1. Why would my device be restarted?
  2. How can I prevent my device from being restarted?
  3. What’s to stop my device from being restarted a third time (or more
    times)?
  4. Or, is it safe to assume that my devices will always be started
    then
    restarted?

The reason I ask this is because I am tracking down a couple bugs in
my
driver and they seem to be related to accessing the device before I
get
the second start message. Sometimes everything works fine other times
I
see some weird behavior. The last thing that the IOCTL from my config
app does, is it wait for all the devices to be started (the device
extension has an event that I wait on). But, waiting on this event is
useless. It’s really the second START_DEVICE message that I want to
wait for.

(As I was typing this email I modified the driver to wait for the
second start message. Ever thing seems to work ok and my problems go
away, but it just doesn’t sit right with me. It really doesn’t seem
like the right thing to do.)

I’ve seen the side effect of this issue on Win2k (SP4) and WinXP (SP1
SP2) but I’ve only poked around with a debugger on WinXP.

Cliff


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

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


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

You are currently subscribed to ntdev as: unknown lmsubst tag
argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


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

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

More for the archives than for Cliff (since it was #1 below for him),
another cause could be the device’s coinstaller (esp. if it’s one built
into windows) requesting a restart of the device. This is very common
the first time a storage device is seen by the system.

.

-----Original Message-----
From: Doron Holan
Sent: Wednesday, January 19, 2005 11:14 PM
Subject: RE: Why is Windows “restarting” my device

  1. are your children marked as raw? If so, they will be started and
    then pnp will try to find a match, resulting in another start

  2. what are you returing for the device state in handling
    IRP_MN_QUERY_PNP_DEVICE_STATE? If the right bits are set, this can
    cause a restart, but that is usually start->stop->start

  3. relying on the pdo to start should not be a part of your device.
    There are so many things that can fail in the interim, including pnp not
    install a dirver for the pdo. If the pdo is marked as raw, the pnp
    install part is less of a problem. Things that can fail: failure to
    allocate a device object, failure to allocate a device relations,
    failure to allocate and return an set of hw IDs asked for, failure to
    allocate a devnode in the kernel, etc etc. I have written a stack like
    this and attempted to do the wait for start thing, it doesn’t work in
    the end. Instead, have the PDO you enumerate register a device
    interface. You can be notified of the interface arrival if the device
    is successfully started. To differentiate between different interfaces,
    you can set a property when you ask for enumeration and then ask for
    that property when the interface arrives (or look for it in the devnode
    (which the driver wrote to)).

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Cliff Russell
Sent: Wednesday, January 19, 2005 9:15 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Why is Windows “restarting” my device

I have a Bus driver for a virtual device. One operation that happens
frequently is the currently enumerated devices are replaced with new
devices. The new devices are reported when I receive
IRP_MJ_PNP/IRN_MN_DEVICE_RELATIONS(BusRelations) and the old ones are
not. The old devices receive IRP_MJ_PNP/IRN_MN_SURPRISE_REMOVAL
notifications . This operation is triggered by an IOCTL from my config
app. The driver handles all this, and it all works quite nicely…

Except, sometimes (maybe even always) the new devices are “restarted”.
Shortly after I get the START_DEVICE notification I receive an
IRP_MN_REMOVE_DEVICE, followed by a bunch of IRP_MN_QUERY…s, and
another IRP_MN_START_DEVICE.

Before I could only speculate that the devices were being restarted, but
this was sort of confirmed when I set a break point and saw
PiRestartDevice in the stack.

So, some questions:

  1. Why would my device be restarted?
  2. How can I prevent my device from being restarted?
  3. What’s to stop my device from being restarted a third time (or more
    times)?
  4. Or, is it safe to assume that my devices will always be started then
    restarted?

The reason I ask this is because I am tracking down a couple bugs in my
driver and they seem to be related to accessing the device before I get
the second start message. Sometimes everything works fine other times I
see some weird behavior. The last thing that the IOCTL from my config
app does, is it wait for all the devices to be started (the device
extension has an event that I wait on). But, waiting on this event is
useless. It’s really the second START_DEVICE message that I want to wait
for.

(As I was typing this email I modified the driver to wait for the second
start message. Ever thing seems to work ok and my problems go away, but
it just doesn’t sit right with me. It really doesn’t seem like the right
thing to do.)

I’ve seen the side effect of this issue on Win2k (SP4) and WinXP (SP1
SP2) but I’ve only poked around with a debugger on WinXP.

Cliff


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

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com