freenode
Kernel & Low-Level

Deadline scheduler bandwidth bugs can crash the kernel

Mathieu Desnoyers posted fixes for 33 SCHED_DEADLINE accounting errors, three of which take the machine down.

Linux's deadline scheduler has been keeping bad books on how much CPU time it has already promised. Mathieu Desnoyers has posted fixes for 33 bugs in SCHED_DEADLINE, most of them in the bandwidth accounting that decides whether a new real-time task can be admitted. Three of the bugs crash the kernel. Another can leave the cpuset lock held.

SCHED_DEADLINE reserves a slice of runtime inside a period and refuses extra work when the CPUs in a root domain cannot guarantee it. When the running totals are wrong, that check either lets deadline tasks in beyond what the CPUs can run, or turns every new one away. The errors show up around CPU hotplug, cpuset moves, priority-inheritance boosts, and parameter changes: a root domain's total bandwidth, or a runqueue's own share, no longer matches the tasks actually running there.

One crash is a divide by the number of active CPUs in a root domain when that number is zero. Another refills a priority-inheritance boost from a runtime of zero and locks up the owner's CPU. A separate fix takes the cpuset mutex for a deadline policy change only when priority inheritance is involved, so a sysrq nice adjustment cannot leave the lock held.

The bugfixes are ordered so stable kernels can take them without the new tests. Desnoyers also exposes each runqueue's deadline bandwidth in the scheduler debug output and adds three selftests of the accounting.

Earlier urgent fixes from deadline maintainer Juri Lelli did not land. Ingo Molnar dropped them after the first one crashed a CPU hotplug test run by Marek Szyprowski. Reworked versions are included here. Desnoyers wrote that Szyprowski found an earlier revision fixed on the board that crashed. One change, from Andrea Parri, is carried unchanged: an affinity flag and a check next to the admission path.