microsoft / usersim

MIT License
73 stars 22 forks source link

KeSetTimer doesn't fire when there is a heavy DPC load #189

Open Alan-Jowett opened 6 months ago

Alan-Jowett commented 6 months ago

Emulated DPC threads running at thread priority time critical which starves the thread pool timer threads resulting in the timers not firing.

This breaks the eBPF for Windows epoch cleanup code which requires a timer to initiate.

mtfriesen commented 6 months ago

Yeah, I remember worrying about this when elevating the thread priority.

Maybe KeShouldYieldProcessor should periodically (randomly?) return TRUE to require threads/DPCs cooperate to lower IRQL, allowing the timer threadpool to fire.

This would be subtly different from kernel mode, where timers fire at IRQL > dispatch and queue a DPC, but we should be able to detect broken code in user mode by requiring the yields.

mtfriesen commented 6 months ago

We may also want to put a Sleep(0) into KeLowerIrql while in a ShouldYieldProcessor window. Sleep(0) is the equivalent of sched_yield on Linux, and would prod the scheduler to let the ready thread in the timer threadpool run.