System Thread Hangs in KeWaitforSingleObject

Hi,

I merge CancelSafe exampe in my volume filter. When I get an Write IRP I put into CSQ, and Remove IRP to read the cluster before this IRP writes.
So I put the segment code in my CsampRemoveIrp below. But it hangs while at KeWaitforSingleObject, it seems no event happens to release it.

I put the same seqment code in my IRP_MJ_WRITE dispatch function and it works fine.

//COW Processing the IRP
irpStack = IoGetCurrentIrpStackLocation(Irp);
dwStartSec = irpStack->Parameters.Write.ByteOffset.QuadPart;
lpBuffer = ExAllocatePool(NonPagedPool, irpStack->Parameters.Write.Length);
ulBufferSize = irpStack->Parameters.Write.Length/512;

liStartSec.QuadPart = dwStartSec;

KeInitializeEvent(&event, NotificationEvent, FALSE);

NewIrp = IoBuildSynchronousFsdRequest(IRP_MJ_READ, devExtension->TargetDeviceObject,
lpBuffer, irpStack->Parameters.Write.Length, &liStartSec,&event, &iosb);
if (!NewIrp)
{
DbgPrint(“IRPCOW Build IRP Fail\n”);
return ;
}

status = IoCallDriver(devExtension->TargetDeviceObject, NewIrp);

if (status == STATUS_PENDING)
{
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
status = iosb.Status;
}

if (!NT_SUCCESS(status))
return;

Some issues with this code …

  1. your IRP_MJ_WRITE handler can be invoked at IRQL > PASSIVE in which
    case you can not wait on event. Your test worked because all the IO came
    in at passive level.
  2. COW technique itself is expensive. In addition to that, synchronously
    reading original data in the Write handler would impact the performance
    in a big way. Your handler should put queue the request and return
    status_pending asap so that IO manager can give you more IO. Process
    that Q in a separate context (thread or workitem).

Harish

-----Original Message-----
From: xxxxx@gmail.com [mailto:xxxxx@gmail.com]
Sent: Tuesday, November 18, 2008 11:02
To: Windows System Software Devs Interest List
Subject: [ntdev] System Thread Hangs in KeWaitforSingleObject

Hi,

I merge CancelSafe exampe in my volume filter. When I get an Write IRP I
put into CSQ, and Remove IRP to read the cluster before this IRP writes.
So I put the segment code in my CsampRemoveIrp below. But it hangs while
at KeWaitforSingleObject, it seems no event happens to release it.

I put the same seqment code in my IRP_MJ_WRITE dispatch function and it
works fine.

//COW Processing the IRP
irpStack = IoGetCurrentIrpStackLocation(Irp);
dwStartSec = irpStack->Parameters.Write.ByteOffset.QuadPart;
lpBuffer = ExAllocatePool(NonPagedPool,
irpStack->Parameters.Write.Length);
ulBufferSize = irpStack->Parameters.Write.Length/512;

liStartSec.QuadPart = dwStartSec;

KeInitializeEvent(&event, NotificationEvent, FALSE);

NewIrp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
devExtension->TargetDeviceObject,
lpBuffer, irpStack->Parameters.Write.Length, &liStartSec,&event,
&iosb);
if (!NewIrp)
{
DbgPrint(“IRPCOW Build IRP Fail\n”);
return ;
}

status = IoCallDriver(devExtension->TargetDeviceObject, NewIrp);

if (status == STATUS_PENDING)
{
KeWaitForSingleObject(&event, Executive, KernelMode,
FALSE, NULL);
status = iosb.Status;
}

if (!NT_SUCCESS(status))
return;


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

Hi Harish,
Thank you for promopt answer.

Your handler should put queue the request and return
status_pending asap so that IO manager can give you more IO.

>Yes, I did. I try to capture all write IRP and put it in CSQ. Start a system tread to remove the IRP and process it. This code segment is to process the removed IRP, but hanged without any event notified.

Harish,thank you again. I locate and fix the issue already.