How check PDEVICE_OBJECT is valid

No, you got a remove. At remove you free up resources and state. How can you reliably even begin to process io, even just to fail it, if you have no state left? It is up to the caller to synchronize sending io with the target’s state. This can be done directly (as is the case with the notification callback) or indirectly (no registering a callback and preventing the state change). The complexity has to live somewhere. It is a bit more deterministic that this complexity live in the client b/c the client can have client specific logic and test cases, if it lived in the target device it would have to be quite generic and would be difficult if not impossible to test for all scenarios

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, November 11, 2008 12:08 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How check PDEVICE_OBJECT is valid

OK but it’d be more complicated for caller anyway. Am I right BSOD is a bug in target driver even if caller doesn’t care about removal notification (failed request is expected)?

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.comhttp:</http:>]


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Tuesday, November 11, 2008 9:04 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How check PDEVICE_OBJECT is valid
No race should exist. The notification callback is synchonously called before the remove and a properly written callback will put up the right barriers to synchronously drain existing io as well as preventing new io from being sent before returning from the callback

d

Sent from my phone with no t9, all spilling mistakes are not intentional.


From: Michal Vodicka
Sent: Tuesday, November 11, 2008 11:44 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How check PDEVICE_OBJECT is valid
________________________________
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Tuesday, November 11, 2008 7:18 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How check PDEVICE_OBJECT is valid

1) An Ob ref on the device object alone is not enough. It will keep the device object pointer valid, but it will not maintain state for you. A pnp remove can come in while you are holding the ref on the device and sending io after the pnp remove will probably lead to a bluescreen, or just a !NT_SUCESS if you are lucky

If it leads to BSOD, it’d mean a bug in target driver. It has to gracefully handle device removal and all IO requests coming later. Otherwise there are unresolvable race conditions even if device removal notification is used. Am I wrong?

I’d probably use simpler approach. Reference target device for any request and dereference it immediatelly. At least I’d start this way and measure if there isn’t performance bottleneck.

(if the message is badly formatted, it is because Outlook is too smart to allow me format the message as I want…)

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.comhttp:</http:>]


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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

Ah, I understand. I missed the part about not preventing remove by
keeping reference and had in mind what you call preventing state change.
What is necessary to do it in kernel mode? User mode handle is enough so
should caller open a handle instead of using pointer reference?

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com http:</http:>]


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Tuesday, November 11, 2008 10:06 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How check PDEVICE_OBJECT is valid

No, you got a remove. At remove you free up resources and
state. How can you reliably even begin to process io, even just to fail
it, if you have no state left? It is up to the caller to synchronize
sending io with the target’s state. This can be done directly (as is
the case with the notification callback) or indirectly (no registering a
callback and preventing the state change). The complexity has to live
somewhere. It is a bit more deterministic that this complexity live in
the client b/c the client can have client specific logic and test cases,
if it lived in the target device it would have to be quite generic and
would be difficult if not impossible to test for all scenarios

d

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, November 11, 2008 12:08 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How check PDEVICE_OBJECT is valid

OK but it’d be more complicated for caller anyway. Am I right
BSOD is a bug in target driver even if caller doesn’t care about removal
notification (failed request is expected)?

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com
http:</http:> ]


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Tuesday, November 11, 2008 9:04 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How check PDEVICE_OBJECT is valid

No race should exist. The notification callback is
synchonously called before the remove and a properly written callback
will put up the right barriers to synchronously drain existing io as
well as preventing new io from being sent before returning from the
callback

d

Sent from my phone with no t9, all spilling mistakes are
not intentional.


From: Michal Vodicka
Sent: Tuesday, November 11, 2008 11:44 AM
To: Windows System Software Devs Interest List

Subject: RE: [ntdev] How check PDEVICE_OBJECT is valid

________________________________

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Tuesday, November 11, 2008 7:18 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How check PDEVICE_OBJECT is
valid

1) An Ob ref on the device object alone is
not enough. It will keep the device object pointer valid, but it will
not maintain state for you. A pnp remove can come in while you are
holding the ref on the device and sending io after the pnp remove will
probably lead to a bluescreen, or just a !NT_SUCESS if you are lucky

If it leads to BSOD, it’d mean a bug in target driver.
It has to gracefully handle device removal and all IO requests coming
later. Otherwise there are unresolvable race conditions even if device
removal notification is used. Am I wrong?

I’d probably use simpler approach. Reference target
device for any request and dereference it immediatelly. At least I’d
start this way and measure if there isn’t performance bottleneck.

(if the message is badly formatted, it is because
Outlook is too smart to allow me format the message as I want…)

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com
http:</http:>]


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other
seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other
seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars
visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars
visit:
http://www.osr.com/seminars

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

A user mode handle is basically the equivalent of the PFILE_OBJECT returned by IoGetDeviceObjectPointer

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, November 11, 2008 1:22 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How check PDEVICE_OBJECT is valid

Ah, I understand. I missed the part about not preventing remove by keeping reference and had in mind what you call preventing state change. What is necessary to do it in kernel mode? User mode handle is enough so should caller open a handle instead of using pointer reference?

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.comhttp:</http:>]


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Tuesday, November 11, 2008 10:06 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How check PDEVICE_OBJECT is valid
No, you got a remove. At remove you free up resources and state. How can you reliably even begin to process io, even just to fail it, if you have no state left? It is up to the caller to synchronize sending io with the target’s state. This can be done directly (as is the case with the notification callback) or indirectly (no registering a callback and preventing the state change). The complexity has to live somewhere. It is a bit more deterministic that this complexity live in the client b/c the client can have client specific logic and test cases, if it lived in the target device it would have to be quite generic and would be difficult if not impossible to test for all scenarios

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, November 11, 2008 12:08 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How check PDEVICE_OBJECT is valid

OK but it’d be more complicated for caller anyway. Am I right BSOD is a bug in target driver even if caller doesn’t care about removal notification (failed request is expected)?

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.comhttp:</http:>]


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Tuesday, November 11, 2008 9:04 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How check PDEVICE_OBJECT is valid
No race should exist. The notification callback is synchonously called before the remove and a properly written callback will put up the right barriers to synchronously drain existing io as well as preventing new io from being sent before returning from the callback

d

Sent from my phone with no t9, all spilling mistakes are not intentional.


From: Michal Vodicka
Sent: Tuesday, November 11, 2008 11:44 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How check PDEVICE_OBJECT is valid
________________________________
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Tuesday, November 11, 2008 7:18 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How check PDEVICE_OBJECT is valid

1) An Ob ref on the device object alone is not enough. It will keep the device object pointer valid, but it will not maintain state for you. A pnp remove can come in while you are holding the ref on the device and sending io after the pnp remove will probably lead to a bluescreen, or just a !NT_SUCESS if you are lucky

If it leads to BSOD, it’d mean a bug in target driver. It has to gracefully handle device removal and all IO requests coming later. Otherwise there are unresolvable race conditions even if device removal notification is used. Am I wrong?

I’d probably use simpler approach. Reference target device for any request and dereference it immediatelly. At least I’d start this way and measure if there isn’t performance bottleneck.

(if the message is badly formatted, it is because Outlook is too smart to allow me format the message as I want…)

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.comhttp:</http:>]


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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