Default Queue is being called at Dispatch_Level

I have IoControlCodes in my IoQueue that need to be executed at Passive Level for successful operation. I turned on DriverVerifier for my driver and ran it through its paces and immediatley failed on a Kernel API call in my EvtIoDeviceControl that was called at DispatchLevel. Argh!!! I thought I prevented that from happening when I initialized the IoQueue at AddDevice in my WDF driver.

    //
// Create Default Queue for the LDTPITDevice's LDTPITDeviceControlIO Routine.
//
WDF_OBJECT_ATTRIBUTES_INIT(&LDTPITQueAttributes);
LDTPITQueAttributes.ExecutionLevel = WdfExecutionLevelPassive;
LDTPITQueAttributes.SynchronizationScope = WdfSynchronizationScopeNone;
LDTPITQueAttributes.ParentObject = LDTPITDevice;

WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&LDTPITQueueConfig, WdfIoQueueDispatchParallel);
LDTPITQueueConfig.EvtIoDeviceControl = LDTPITDeviceControlIO;
LDTPITQueueConfig.PowerManaged = WdfTrue;
LDTPITQueueConfig.AllowZeroLengthRequests = WdfFalse;
Status = WdfIoQueueCreate(LDTPITDevice, &LDTPITQueueConfig, &LDTPITQueAttributes, &pLDTPITDevExt->LDTPITQueue);
if (!NT_SUCCESS(Status))
{
	goto End;
}

Does anyone have any idea why the WDF Framework is calling my EvtIoDeviceControl at DISPATCH_LEVEL? Can this be controlled to only call me at PASSIVE_LEVEL. BTW, I tried WdfIoQueueDispatchSequential for the Queue Dispatch Type as well. I still get called at DISPATCH_LEVEL.

Thanks In Advance for the help,
Joe

BTW, I’m using Visual Studio 2017 (version 15.9.4) and Windows Driver Kit (version 1809). These are released versions and not experimental test builds, Right?

Driver Verifier is on Windows 10 build 15063.

I think the issue is understanding the execution levels that the framework may call your callback functions at. Please see here:
https://docs.microsoft.com/en-us/windows-hardware/drivers/wdf/using-automatic-synchronization

Specifically,

  • If a driver uses automatic synchronization, its queue and file object callback functions are called at IRQL = DISPATCH_LEVEL unless the driver asks the framework to call its callback functions at IRQL = PASSIVE_LEVEL.
  • If a driver is not using automatic synchronization and does not specify an execution level, the driver’s queue and file object callback functions can be called at IRQL <= DISPATCH_LEVEL.

Try specifying the SynchronizationScope. You can refer here for a good write-up about it’s usage:
https://www.osr.com/nt-insider/2014-issue3/understanding-sync-scope-wdf-drivers/

Hi Shane,

Thank you for the response. I continue my debugging efforts yesterday and realized the WDF Framework was indeed calling me at PASSIVE_LEVEL. My problem was related to acquiring a Fast Mutex, which when acquired, raised my IRQ_LEVEL to APC. I changed the Fast Mutex to a Semaphore Object and things are good now.

Oh the joys of driver development :slight_smile:

Regards,
Joe

A WDFWAITLOCK is the wdf abstraction for a lock that leaves you running at passive level after acquisition.

d

Bent from my phone


From: Joe_Moriarty
Sent: Wednesday, December 19, 2018 6:28:11 AM
To: Doron Holan
Subject: Re: [NTDEV] Default Queue is being called at Dispatch_Level

OSR https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcommunity.osr.com%2F&amp;data=02|01|doron.holan%40microsoft.com|0736498cf9444c198a1e08d665be34ce|72f988bf86f141af91ab2d7cd011db47|1|1|636808264950291816&amp;sdata=JygxOdC%2B5QErbKWlvIzxRocBS1W1CLsmK0RxHdMXKeQ%3D&amp;reserved=0
Joe_Moriarty commented on Default Queue is being called at Dispatch_Level

Hi Shane,

Thank you for the response. I continue my debugging efforts yesterday and realized the WDF Framework was indeed calling me at PASSIVE_LEVEL. My problem was related to acquiring a Fast Mutex, which when acquired, raised my IRQ_LEVEL to APC. I changed the Fast Mutex to a Semaphore Object and things are good now.

Oh the joys of driver development :slight_smile:

Regards,

Joe

Thanks Doron,

I need to stop calling the old kernel APIs and instead use the WDF abstractions as you suggest doing here. I’ll implement the WDFWAITLOCK object and swap it in for the Semaphore I am currently using.

Regards,
Joe

@Doron_Holan said:
A WDFWAITLOCK is the wdf abstraction for a lock that leaves you running at passive level after acquisition.

d

Bent from my phone


From: Joe_Moriarty
Sent: Wednesday, December 19, 2018 6:28:11 AM
To: Doron Holan
Subject: Re: [NTDEV] Default Queue is being called at Dispatch_Level

OSR https://nam06.safelinks.protection.outlook.com/?url=https://community.osr.com/&data=02|01|doron.holan@microsoft.com|0736498cf9444c198a1e08d665be34ce|72f988bf86f141af91ab2d7cd011db47|1|1|636808264950291816&sdata=JygxOdC+5QErbKWlvIzxRocBS1W1CLsmK0RxHdMXKeQ=&reserved=0
Joe_Moriarty commented on Default Queue is being called at Dispatch_Level

Hi Shane,

Thank you for the response. I continue my debugging efforts yesterday and realized the WDF Framework was indeed calling me at PASSIVE_LEVEL. My problem was related to acquiring a Fast Mutex, which when acquired, raised my IRQ_LEVEL to APC. I changed the Fast Mutex to a Semaphore Object and things are good now.

Oh the joys of driver development :slight_smile:

Regards,

Joe