freenode
Kernel & Low-Level

Deadline scheduler bandwidth bugs can over-admit tasks or miss deadlines

Mathieu Desnoyers's fixes cover accounting, cpuset moves, and parameter changes that let SCHED_DEADLINE tasks exceed their reservations.

A large set of fixes from Mathieu Desnoyers repairs long-standing holes in the Linux kernel's SCHED_DEADLINE bandwidth accounting, the mechanism that is supposed to refuse real-time tasks the CPU cannot guarantee. When the totals are wrong, a root domain can admit deadline tasks beyond its capacity, or refuse tasks that would fit. Other bugs hand a task more runtime than its reservation, so deadline tasks can miss their deadlines.

Most of the defects leave the bandwidth recorded for a root domain, or for a runqueue, out of date. Three worse outcomes were found by reading the code rather than by reproduction: a domain rebuild that hits a kernel bug check, an rt_mutex owner that keeps an exited task as its deadline donor and then reads freed memory on the next refill, and a task that never runs again. Desnoyers wrote that the first fixes, which include those priority-inheritance cases, stand alone. Further priority-inheritance work was split into a follow-on series at the request of deadline maintainer Juri Lelli.

Cpuset changes are part of the problem. Moving a task into another cpuset asks the destination domain for room. Weaker checks on other cpuset updates do not. With isolated CPUs, or with load balancing turned off on cgroup v1, a cpuset can hold CPUs from two root domains. A write to the CPU mask, growth of a partition root, or housekeeping CPUs handed back by an isolated partition can then leave a deadline task running in a domain that never admitted it. The series refuses those changes, or marks the partition invalid, when they would strand a deadline task with no CPU in the domain that counts it.

Parameter changes have a similar effect. sched_setattr() has long left the period already in progress alone, on the view that applying new parameters at once would let user space circumvent the scheduler's bandwidth guarantees. Admission control still counts the new, smaller reservation immediately. Desnoyers cites a construction from Tang, Anderson and Abeni in which two tasks pass a large runtime back and forth: admission control sees about 71 percent of a CPU, while the tasks consume nearly all of it. Lelli also found that a task can leave the deadline class and return runnable with a smaller runtime, yet keep running on the old one. The fixes fit the period in progress to the new parameters and apply the wakeup rule when a runnable task re-enters the class.

Rebuilds of root-domain accounting can drop bandwidth for tasks that leave the class, die, or are reaped in a narrow window, or fail to restore it when priority inheritance boosts a departed task back in. New cases in the deadline bandwidth selftest cover hotplug, cpusets, and parameter changes. Several of the fixes are marked for stable kernels.