JustKernel

Ray Of Hope

Deadlock scenario while handling System/Device Power states.

Recently ran into a deadlock condition where in my USB driver was waiting for reference count to be decremented and the completion routine which decrements the reference count has returned STATUS PENDING.
The scenario goes like this:
I keep a reference count which is incremented when a request is received (Dispatched ) and is decremented in the completion routine when the request has been serviced.

So what I had implemented was that – During the system power state handler I received as SYSTEM IRP_MN_QUERY_POWER so I incremented the reference count. Now in its handler, I called PoRequestPowerIrp for the device . In response to the call to PoRequestPowerIrp, the power manager allocates a power IRP and sends it to the top of the device stack for the device. So again my dispatcher got called and I incremented the reference count .So now reference count stood as 2.

Now in the handler of Device Power IRP, I had a while loop where in I compared the reference count to 1 assuming that only 1 request was pending at that instant.

Thus I have this while loop which is running endlessly comparing reference count to 1 leading to a complete system bog down. And on other hand I had my completion routine waiting for control to signal completion of irp and decrement reference count to 1.

Putting the wait loop (while loop) in a separate thread solved the issue, but it was not correct solution as I was comparing reference count to an incorrect value. The reference count should be compared to 2 as there are two requests pending at that moment.

Originally Posted On: 2012-11-07 14:02:12

Anshul Makkar

anshul_makkar@justkernel.com

Tags: ,


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.