What steps to follow to regain bus child devices after surprise removal?

As part of Windows 2016 HLK certification tests, I ran the Surprise removal test on the “Bus driver”. In the log I saw the message that “surprise removal has been processed as expected”. However, after this test I lost all of the child devices of the selected bus, for example, the mouse, keyboard, network adapters.

These drivers are written for a virtual machines.

Please help me with the steps to follow to regain bus child nodes after the surprise removal.

From the logs, I found that, after the surprise removal step, the PnP manager calls RestartDevice() targetting the selected bus driver and then RescanParentDevice().

Not sure how to address these function calls either and what am I supposed to do in these two calls.

Any help is highly appreciated. Feeling stuck after trying as much I could for almost a month now.

If you own the bus driver you need to report the devices as present on the
next enumeration.

Mark Roddy

On Fri, Sep 15, 2017 at 6:20 AM, xxxxx@gmx.com
wrote:

> As part of Windows 2016 HLK certification tests, I ran the Surprise
> removal test on the “Bus driver”. In the log I saw the message that
> “surprise removal has been processed as expected”. However, after this test
> I lost all of the child devices of the selected bus, for example, the
> mouse, keyboard, network adapters.
>
> These drivers are written for a virtual machines.
>
> Please help me with the steps to follow to regain bus child nodes after
> the surprise removal.
>
> From the logs, I found that, after the surprise removal step, the PnP
> manager calls RestartDevice() targetting the selected bus driver and then
> RescanParentDevice().
>
> Not sure how to address these function calls either and what am I supposed
> to do in these two calls.
>
>
> Any help is highly appreciated. Feeling stuck after trying as much I could
> for almost a month now.
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:> showlists.cfm?list=ntdev>
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and
> software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at <
> http://www.osronline.com/page.cfm?name=ListServer&gt;
></http:></http:>

Hi Mark,

Thanks for replying and helping me out. I was also planning for the same. However, I am not sure how to report that the devices are present. Which IRPs I need to handle to achieve it?

I saw in the test logs that both of the child nodes objects (mouse and keyboard) of bus got destroyed when the bus received a RestartDevice() call.

Pardon me if my doubts are very basic, I am very new to driver development.

Thanks.

xxxxx@gmx.com wrote:

As part of Windows 2016 HLK certification tests, I ran the Surprise removal test on the “Bus driver”. In the log I saw the message that “surprise removal has been processed as expected”. However, after this test I lost all of the child devices of the selected bus, for example, the mouse, keyboard, network adapters.

These drivers are written for a virtual machines.

Please help me with the steps to follow to regain bus child nodes after the surprise removal.

How did they come into being in the first place?  Presumably, your
virtual bus has a list of all the virtual devices it is supposed to
expose.  You converted that list to PDOs when your bus initialized, and
you’ll need to do the exact same thing when you’re asked to rescan after
removal.  You need to have code that brings your PDO list “up to date”
at any time.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

It really depends on what type of driver you have. Also the surprise remove
test is sort of a hack. In the real world a device is removed and then a
device arrives and your driver just has to handle the removal and arrival
and nothing more. That is why I asked if you were a bus driver, as only a
bus driver that enumerates child devices need be concerned with “what to do
after surprise removal finishes”. If you aren’t a bus driver you likely
do not need to do anything. Your devices have been artificially removed by
the test and that is the end of it.

Mark Roddy

On Fri, Sep 15, 2017 at 2:10 PM, xxxxx@gmx.com
wrote:

> Hi Mark,
>
>
> Thanks for replying and helping me out. I was also planning for the same.
> However, I am not sure how to report that the devices are present. Which
> IRPs I need to handle to achieve it?
>
> I saw in the test logs that both of the child nodes objects (mouse and
> keyboard) of bus got destroyed when the bus received a RestartDevice() call.
>
> Pardon me if my doubts are very basic, I am very new to driver development.
>
>
> Thanks.
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:> showlists.cfm?list=ntdev>
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and
> software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at <
> http://www.osronline.com/page.cfm?name=ListServer&gt;
></http:></http:>

xxxxx@gmx.com wrote:

Thanks for replying and helping me out. I was also planning for the same. However, I am not sure how to report that the devices are present. Which IRPs I need to handle to achieve it?

You get a PnP request, IRP_MN_QUERY_DEVICE_RELATIONS of type
BusRelations.  That’s where you report your children.  When your bus is
restarted after the surprise removal, you may need to call
IoInvalidateDeviceRelations to tell the system that your device list has
changed.  That triggers the device relations request.

 

I saw in the test logs that both of the child nodes objects (mouse and keyboard) of bus got destroyed when the bus received a RestartDevice() call.

Pardon me if my doubts are very basic, I am very new to driver development.

Is this a KMDF driver?  KMDF makes bus drivers pretty easy, because it
handles a lot of the relations management.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Tim,

Bus driver is probably a WDM driver derived from the toaster bus template. It is an old driver, so most of the IRPs are not handled in the virtual bus code.

When you said to call IoInvalidateDeviceRelations(), did you meant to call when I receive IRP_MN_QUERY_DEVICE_RELATIONS IRP from the PnP manager after the surprise removal?

xxxxx@gmx.com wrote:

Bus driver is probably a WDM driver derived from the toaster bus template. It is an old driver, so most of the IRPs are not handled in the virtual bus code.

When you said to call IoInvalidateDeviceRelations(), did you meant to call when I receive IRP_MN_QUERY_DEVICE_RELATIONS IRP from the PnP manager after the surprise removal?

No.  The call to IoInvalidateDeviceRelations just asks the system to
send you an IRP_MN_QUERY_DEVICE_RELATIONS.  You need to do that if your
bus is aware of changes in your child list that the operating system
doesn’t know about.

If you are getting an IRP_MN_QUERY_DEVICE_RELATIONS after you have come
back from the surprise removal, that’s the place where you need to tell
him your child PDOs.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

When a surprise removal test is trying to simulate your child device PDO removed behind your back, it’s kind of a hack.

In the true case of surprise removal, you don’t report a PDO on QUERY_DEVICE_RELATIONS after you detected the device is gone. Your PDO can receive SURPRISE_REMOVAL. You delete the PDO on REMOVE_DEVICE.

In the simulated case, the PDO gets deleted from the list by the bus filter, not by you.

The only thing you can do is to mark the PDO for pending removal when you get an unexpected SURPRISE_REMOVAL, remove it on REMOVE_DEVICE and immediately create and report a new PDO for this devnode. Don’t know if it’s kosher, though.

I don’t think the surprise removal test is a bus filter. I think it is a device filter that after start, sets the pnp state to failed and this what sends the surprise remove. The bus driver must not delete the pdo on surprise remove and remove if it is hasn’t reported the pdo as missing. If a rescan or disable/enable are done, the stack will start again with the same pdo.

Bent from my phone


From: xxxxx@lists.osr.com on behalf of xxxxx@broadcom.com
Sent: Saturday, September 16, 2017 1:32:54 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] What steps to follow to regain bus child devices after surprise removal?

When a surprise removal test is trying to simulate your child device PDO removed behind your back, it’s kind of a hack.

In the true case of surprise removal, you don’t report a PDO on QUERY_DEVICE_RELATIONS after you detected the device is gone. Your PDO can receive SURPRISE_REMOVAL. You delete the PDO on REMOVE_DEVICE.

In the simulated case, the PDO gets deleted from the list by the bus filter, not by you.

The only thing you can do is to mark the PDO for pending removal when you get an unexpected SURPRISE_REMOVAL, remove it on REMOVE_DEVICE and immediately create and report a new PDO for this devnode. Don’t know if it’s kosher, though.


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

Doron, I didn’t get what exactly are you trying to convey. I have to explicitly select the bus driver in the HLK studio and then I get this Surprise Removal Test listed under tests tab and then ran the test. So, I think the Surprise removal test in this case removes the bus driver itself.

Ofcourse, there were Surprise removal test for individual devices as well. But those tests went successfully.

I was correcting the last reply. In your case the filter surprise removed your parent bus device in the same way (marked it as failed) and the entire tree was removed. To get it back it should be as simple as a rescan or disable/enable of the !ed out device in device manager.

d

Bent from my phone


From: xxxxx@lists.osr.com on behalf of xxxxx@gmx.com
Sent: Saturday, September 16, 2017 2:40:54 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] What steps to follow to regain bus child devices after surprise removal?

Doron, I didn’t get what exactly are you trying to convey. I have to explicitly select the bus driver in the HLK studio and then I get this Surprise Removal Test listed under tests tab and then ran the test. So, I think the Surprise removal test in this case removes the bus driver itself.

Ofcourse, there were Surprise removal test for individual devices as well. But those tests went successfully.


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>