From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=158.69.130.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796147075; b=WQlSgzB7cKkhoPaf6mr+K0GCtpfpgs30mrRpD6XPqI7hq0YukFoPfOqIqwOVvZzq/iLk 0pGPR3B0is74/KdUne+92StdHbegvpAduqAnHW7Q0+gt4m4v2FlInGaDzUahzaZ07F4Fb TwaTPAyydLU/8UT7PyMVH2OvFOi6lvwV2Ox14inaBRT+Go+vd6am0oN18QxUZaBKTDk5v BKGqNI8lDiO/9cJLfg9m4RvbL1bnjFIMnbWf6hMN/CMzPH6EoldS0LPtkDv/e94JfaNg6 T9ISW08g2H8edqolmt9svt8jOavWhjqVrSCznIOay7nLApFZ0dSwE66TV9EdyhQddEA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796147075; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=bGyeRYkCGpoc3000j6hOUwo1XJvufbVoEihR4/fksoY=; b=m9MFSS0s3n7XxNLN/+nXa+HKy4VJ0GQdNVQlkl6+KIhmmtxvzN9syNpSJ6jVQS9e7VSX nlH4nZ32uHtkfVDbgJ4npdWDNRBQDg9QP442AXdujv8P2ei/uHEOraSowOTPJ9U06oOm1 3UFzKDxBghUO0hp2XnqU+xSl+TYEDK3SbKVKQ6nllu7R31M7rGHHEIjosB+Hhwl+YmX2F P3ElkIz3kp2GAIcNM/3g2dhjVZEFh+J8kLYaRhtANBQF2wEDWQSXBVEm07mx//SnwY/sN gF/HxaAnKHO5AUpPGwYyR4bloTgI8JxuOKLesz5zTvQPEC7P12sUcZaBGC/yZXRkYtw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=smtpout1 header.b=NUxpq1ks; arc=none smtp.remote-ip=158.69.130.18 Received: from smtpout.efficios.com (smtpout.efficios.com [158.69.130.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 707A0606A329; Tue, 1 Dec 2026 17:44:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 707A0606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=smtpout1 header.b=NUxpq1ks DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=smtpout1; t=1796147073; bh=bGyeRYkCGpoc3000j6hOUwo1XJvufbVoEihR4/fksoY=; h=From:To:Cc:Subject:Date:From; b=NUxpq1kskTpoZfDWjXuDucmi5Za9pJ175YUkQi+JtwPHDx6aysZsMy2jL6cAD0Enm S7GxX+VmMcfCCQHCPvgzJdzb8pN0wHJTGEHr3gFmzfV2q0lsYIjgXrJ6Q7FmuYIawj 0IZWnv+u6MSBp/5rUaZhgsO0y5wlZFsI+Iq7Uls+7J4QXmB1Q7BQrdrxNkS68Ckx0+ ZQQpvKIfzedkt8sLAc8HW7ak0Cc8YBLGzdbP/UlF6r+7B/IGnwDpeSwLs55Rjgw5dx NvLm+e78j+kYESUhgNKIF0oBWruGFrkYkQqnaJrg6xVjX8bvKeBzIbLJ/dGWA/hN0L ZJZiJSwhUQWOQ== Received: from thinkos.internal.efficios.com (mtl.efficios.com [216.120.195.104]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4jf7Ys1VyGzYnl; Tue, 01 Dec 2026 12:44:33 -0500 (EST) From: Mathieu Desnoyers To: juri.lelli@redhat.com, peterz@infradead.org, mingo@redhat.com, vincent.guittot@linaro.org Cc: Mathieu Desnoyers , tglx@kernel.org, will@kernel.org, boqun@kernel.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, luca.abeni@santannapisa.it, tommaso.cucinotta@gmail.com, mathieu.poirier@linaro.org, longman@redhat.com, ridong.chen@linux.dev, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com, shuah@kernel.org, bigeasy@linutronix.de, clrkwllms@kernel.org, parri.andrea@gmail.com, m.szyprowski@samsung.com, kayracizmeci@gmail.com, weihengqiuu@gmail.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-rt-devel@lists.linux.dev, oleg@redhat.com, brauner@kernel.org Subject: [PATCH v13 00/36] sched/deadline: bandwidth accounting fixes and selftests Date: Tue, 1 Dec 2026 12:43:54 -0500 Message-ID: X-Mailer: git-send-email 2.47.3 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi Ingo, Juri, This is v13. It fixes bugs of SCHED_DEADLINE in 27 patches. It applies on top of the first series [1], with its updated patch 10 [2]. The largest change since v12: as Juri asked, most changes to priority inheritance moved out into a series of their own. That series applies on top of this one. Patches 31 to 35 are new. They fix how a rebuild counts a task that left the class or died, and add warnings. The other changes are at the end. Most of the bugs are in the bandwidth accounting. They leave total_bw of a root domain, or this_bw of a runqueue, wrong. The root domain then admits deadline tasks beyond its capacity, or refuses tasks that would fit. The other bugs give a task more runtime than its reservation. Deadline tasks can then miss their deadlines. Three worse outcomes were found by reading, not reproduced: - A rebuild would hit its BUG_ON() (patch 18). - An rt_mutex owner can keep a task that has exited as its deadline donor. Its next refill would then read freed memory (patch 1). - A task would never run again (patch 2). As Juri asked, the fixes he named come first, in his order: 1 to 5. They need none of patches 6 to 36, and apply on the first series alone. Patches 1 and 2 fix priority inheritance too. They stay here for the outcomes above, while the other changes to priority inheritance moved out. Patches 4 and 5 also fix a regression of the first series. With its patches 9 and 11, a constrained task can leave the class and come back after its 0-lag time, but before its next period. It then starts a new period at once, and gets more than its bandwidth. So patches 4 and 5 should be merged with the first series, or right after it. The patches also come in groups, one per theme. A group of fixes ends with the test cases of deadline_bw_test for these fixes. Two groups have no test patch: - Patches 1 to 5. Patches 1 to 3 have no test case (see "Testing"). The test cases of patches 4 and 5 are in patch 30, with those of the parameter changes. - Patch 24, which has no test case. Patches 28 and 34 are not fixes. Patch 28 prepares patch 29, and patch 34 adds warnings. Juri, patch 8 replaces your fix 1/4, which Ingo dropped from sched/urgent. It records a CPU of the root domain that counts the bandwidth. Your fix took the first active CPU of the task's mask. The other three fixes are in the first series. The groups ========== The fixes that apply on the first series alone (1-5): 1 Hold a reference on the deadline donor of a boosted task. 2 Replenish a throttled task that a waiter boosts while it sleeps, so that it runs again. 3 Divide a change of total_bw by the number of CPUs on 64 bits: a sum of bandwidths can pass S32_MAX. 4 Count the 0-lag time from the next period, not from the deadline. A constrained task then stays counted until it has paid for what it ran. 5 Keep the bandwidth and the deadline of a constrained task that leaves the class until its next period. The rebuild of the root domains' accounting (6-11): 6 Keep the bandwidth of departing tasks across a root domain rebuild. A departed task left the class, or died, before its 0-lag time. It waits on dl_departed_list until that time. 7 Rebuild the root domains' accounting from the task list. 8 Record the root domain that holds a task's bandwidth. 9 Leave out of a rebuild a dying task that released its bandwidth. 10 Add deadline_rebuild_test. 11 Add the 7 test cases of deadline_bw_test for this group. cpuset attach (12-17): 12 Move a task's bandwidth only where an attach made room for it. 13 Wait for an attach before rebuilding the sched domains. 14 Make a policy or affinity change of a deadline task wait for a cpuset attach in progress. 15 Give back the bandwidth an attach did not move. 16 Reserve an attach's bandwidth in the root domain each task moves to. 17 Add the 24 test cases of deadline_bw_test for this group. The root domain of a task, with partitions and isolcpus=domain (18-23): 18 Make a rebuild count a task in the root domain it runs in. 19 Move a task's bandwidth to the root domain it runs in. 20 Pick a CPU for a task in the root domain that counts its bandwidth, if the task's mask has a CPU there. 21 Refuse to take offline the last CPU a task has in the root domain that counts its bandwidth. Also refuse an offline that makes a partition invalid and so moves a deadline task to another root domain. 22 Refuse a cpuset change that leaves a deadline task no CPU in the root domain that counts its bandwidth. 23 Add the 36 test cases of deadline_bw_test for this group. extra_bw (24): 24 Count only the active CPUs when a change of total_bw is spread over extra_bw, at an offline migration and at a rebuild. Parameter changes (25-30): 25 Cancel the replenishment timer with the parameters. 26 Cap the runtime left of a constrained task at dl_runtime when its parameters change. 27 Check the runtime left of a task that comes back to the class runnable, as a wakeup does. 28 Record the start of the period. No functional change. 29 Apply new parameters to the period in progress, at the change. A task that ran ahead of its reservation keeps that debt, and repays it at the new bandwidth. A task with no period to apply them to gets the check of a wakeup. 30 Add the 24 test cases of deadline_bw_test for this group. Departed tasks across a rebuild (31-35): 31 Count a task that leaves the class or dies during a rebuild, before the walk of the task list reaches it. 32 Count again a departed task whose bandwidth a rebuild dropped, when a boost brings it back into the class. 33 Put a reaped deadline task on the departed list, so that a rebuild still counts it until its last schedule. 34 Warn when a runqueue keeps the bandwidth of a task out of the class, or of a task whose parameters are cleared. 35 Add the 2 test cases of deadline_bw_test for this group. Priority inheritance triggers the bugs of patches 31 and 32: a deboost during a rebuild, or a boost after one. A task that dies during a rebuild also triggers the bug of patch 31. Both fixes are in the accounting, so they stay in this series. Patch 36 moves the helpers that the three deadline selftests share to a header. Backporting =========== The fixes and patch 28 carry Cc: stable. The test patches do not. Some fixes need other commits: - Patch 6 needs patch 5. It puts on the departed list a task that patch 5 leaves to the inactive timer handler. - Patches 6 to 22 go together. Patch 8 records the root domain that counts a task's bandwidth. This record replaces dl_departed_cpu, which patch 6 adds. Patch 9 completes the task list walk of patch 7. Patches 9, 15, 16 and 18 to 22 use the record of patch 8. Patches 15 and 16 rely on the fixes of patches 12 to 14. - Patch 24 changes code that patches 6 to 22 rework, so it comes after them. - Patch 2 relies on patch 1: its refill from the timer reads the donor. - Patch 1 needs commit 8671bad873eb ("sched: Do not call __put_task_struct() on rt if pi_blocked_on is set") on stable trees older than v6.17. Trees older than v6.12 also need tryget_task_struct(). It was added by commit a8532fac7b5d ("sched_ext: TASK_DEAD tasks must be switched into SCX on ops_enable"). Only that helper of the commit is needed. - A backport of these patches of the first series needs patches 4 and 5, for the regression above: - "sched/deadline: Reset the deadline and the runtime with the parameters" (patch 9). - "sched/deadline: Release the bandwidth of a task that leaves the class asleep" (patch 11). Patch 4 needs patch 10 of the first series, which adds dl_time_to_zerolag(). Patch 5 needs patch 1 for its context. - Patch 29 needs patch 28, which records the start of the period. - Patches 31 to 33 change the departed list and the rebuild of patches 6 to 22, so they come after them. Patches 31 and 32 use dl_bw_move_blocked() and dl_bw_skip_gen, which patch 19 adds. Patches 32 and 33 need patch 31. Notes for the reviewers ======================= Peter, I would like your review of the series. Patches 1 and 2 touch priority inheritance. Patch 1 makes a boosted task hold a reference on its donor. dl_set_donor() reads the donor of the top waiter without the waiter's locks. So it takes the reference with tryget_task_struct(). A failed tryget means that another CPU stored a newer donor. dl_set_donor() then reads the donor again. A writer of pi_se that does not hold a reference on the new donor would make every read fail, with interrupts off. So dl_set_donor() stops after 8 reads. It then warns, and uses the top waiter itself as donor. The top waiter is blocked, so it cannot exit. These patches also touch the core scheduler, or the exit path: - 7: without CONFIG_CPUSETS, __sched_setscheduler() takes the new dl_accounting_mutex. - 8: __sched_setscheduler() and dl_task_check_affinity() check a deadline task against the root domain that counts its bandwidth, not that of its runqueue. - 12: the new set_cpus_allowed_bw_reserved() flags a move that reserved bandwidth, with SCA_DL_BW_RESERVED. __set_cpus_allowed_ptr_locked() does not skip such a move when the mask does not change. - 14: __sched_setscheduler() and sched_setaffinity() wait for a cpuset attach in progress. - 15: set_cpus_allowed_bw_reserved() reports the bandwidth it moved. - 16: __set_cpus_allowed_ptr_locked() steers a task to the CPU that an attach reserved. - 20: select_fallback_rq() and __set_cpus_allowed_ptr_locked() keep a deadline task in its root domain. - 29: __setscheduler_params() marks a task that comes back to the deadline policy with the same parameters. Its runtime left is then checked as at a wakeup. - 33: release_task(), in kernel/exit.c, calls the new dl_task_unhash() under tasklist_lock. - 34: set_task_cpu() warns when a task out of the deadline class still counts in the this_bw of a runqueue. Waiman, patches 21 and 22 add refusals, with admission control on: - A CPU offline or a cpuset.cpus write fails with EBUSY if it leaves a deadline task no CPU in the root domain that counts it. This needs a cpuset with CPUs of two root domains. - A write that makes a partition root, or makes it grow, still succeeds in that case. cpuset then makes the partition invalid, and cpuset.cpus.partition reads "root invalid (Deadline task would leave its root domain)". - A write to cpuset.cpus or cpuset.cpus.exclusive can make an isolated partition root give housekeeping CPUs back to a parent that is not isolated. The rebuild then takes these CPUs out of the default root domain. Making the partition invalid would give them back too. So the write fails with EBUSY if a deadline task would then have no CPU left in the default root domain. This holds even if the write also grows the partition. - Patch 21 also refuses an offline that makes a child or a sibling partition invalid, when a deadline task in it would change root domain. An offline can leave a partition with tasks and no CPU of its own. cpuset then makes it invalid, and its tasks count in its parent. Take a parent partition P with no task of its own. Its child partitions hold all its CPUs. An offline takes the last CPU of one of them, C, which has tasks. On a hotplug event, cpuset updates a parent before its children: - It updates P first. The tasks of C do not count in P yet, so P stays valid with no CPU. - It then makes C invalid. The tasks of C now count in P, which has no CPU. - If P has another child partition, cpuset makes the next one that it updates invalid. P takes its CPUs. Else P stays valid with tasks and no CPU, until a later hotplug event. Patch 21 does not model this order. It goes up from the parent while each partition has no CPU of its own. It refuses the offline if a deadline task is under the last of these partitions. The known limits below say what it then refuses, and what it misses. Questions ========= Waiman, two questions on patch 21: - Would you prefer cpuset to offer a dry run of its hotplug update, as a follow-up? It would be exact, but too large for stable. - An offline can leave a partition valid with tasks and no CPU, until the next hotplug event. Is that state intended? Known limits ============ These limits stay open: - Patch 6: a task keeps its bandwidth until its 0-lag time after it leaves the class or dies. A rebuild still drops that bandwidth if the CPU recorded with it is inactive. The root domain that counted it can then no longer be found. total_bw then misses it until that time. Patch 32 counts it again if a boost brings the task back into the class. - Patch 6: a write can put the CPU recorded with a departed task into a new partition root. The rebuild then counts the bandwidth of the task in the new root domain, until its 0-lag time. That root domain can refuse tasks meanwhile. The old root domain of the CPU no longer counts the task, and can admit too much. On v7.4-rc2, the rebuild drops that bandwidth instead. - Patch 6: a task can come back to SCHED_DEADLINE before its 0-lag time. Its old bandwidth is then still counted. sched_dl_overflow() does not subtract it in its check, as on v7.4-rc2. In a full root domain, sched_setattr() can then fail with EBUSY. On success, sched_dl_overflow() adds the new bandwidth, then removes the old one in a second lock section. Both count in between. - Patch 19 moves the bandwidth of a task to the root domain it runs in with no check for room. dl_task_offline_migration() does the same on v7.4-rc2. - Patch 20: a wakeup inside a rebuild of the sched domains can still move a task's bandwidth to another root domain. It moves with no check for room. This was found by reading. - Patches 21 and 22 refuse nothing during a suspend, or with admission control off. - Patch 21 can refuse an offline that keeps each task in its root domain. This needs nested partitions whose parents have no CPU of their own. - Patch 21 does not check a deadline task that enters a partition after an offline left a parent partition valid with tasks and no CPU. The next hotplug event, an online too, can then move it to another root domain with no check for room. - Patch 21 does not see a task that sched_setattr() makes a deadline task during the offline. That task can then run in a root domain that did not admit it. The bandwidth test of dl_bw_deactivate() has the same window. This was found by reading. - Patch 22 accepts a write that grows a partition root and makes a child partition valid. The child takes the CPUs on which the parent's deadline tasks were admitted. Those tasks then run on the CPUs that the parent just got, in a root domain that did not admit them. On v7.4-rc2, a rebuild does the same. - Patch 22 accepts a write of "member" to cpuset.cpus.partition of a partition root that holds a deadline task. Its tasks then count in the root domain of the parent, with no check for room. This is as on v7.4-rc2. A refusal would keep an administrator from removing the partition while its deadline tasks run. - Patch 22 does not check the room for the deadline tasks of a cpuset that a write makes a partition root. The rebuild counts them in the new root domain, as on v7.4-rc2. In a test, that root domain then counted 125% of its capacity. Deadline tasks that use all their runtime would then miss deadlines there. sched_setattr() refuses new deadline tasks there until it has room again. - Patch 22 does not check a write that makes two invalid child partitions valid. Take a write to the CPUs of a partition root with two invalid child partitions. When the first child takes its CPUs, update_sibling_cpumasks() gives the remaining CPUs to the second child and its tasks, with no check. Those tasks would then run in a root domain that did not admit them. This is as on v7.4-rc2, and was found by reading. - Patch 22 can make an isolated partition root invalid when the change is safe. Take a write that makes it take CPUs and give others back to its parent. The check does not count the CPUs given back as CPUs of the root domain of the parent. Until the rebuild, these CPUs are still in the default root domain. Counting them would accept a write that leaves a deadline task of the default root domain with no CPU after the rebuild. An administrator can make the change in two writes: make the partition a member, then an isolated partition root of its new CPUs. - The XXX in dl_bw_capacity(), which Juri pointed at in the v5 thread, stays open. In the default root domain, admission control counts the capacity of all its CPUs, not that of the CPU the task runs on. A deadline task in a cpuset with isolated and housekeeping CPUs is admitted that way. - A cpuset attach frees the bandwidth of a task in the root domain it leaves at once, even before the task's 0-lag time. That root domain can then admit a task up to one period too early [3]. A task moved while runnable also keeps its runtime and deadline in the root domain it arrives in (Example 3 of [4]). Both are as on v7.4-rc2. - Patch 29: admission control releases the old bandwidth at the change. Right after a cut of bandwidth, a task admitted into the released bandwidth would rarely miss a deadline near the change. The simulator below shows it. - Patch 29: two costs fall on the task that changes its parameters. With a constrained deadline, a job that already used the new dl_runtime ends at the change. A task that waits for its next period and changes its constrained dl_deadline back and forth moves that period later at each shorter dl_deadline. - Patch 29 does not apply new parameters to the period of a boosted task. The first enqueue after its deboost checks its runtime left, as a wakeup does. That check can start a new period at once. The task then loses its debt, as on v7.4-rc2. The priority inheritance series also fits the period of a boosted task to new parameters. Testing ======= On top of the first series, the 148 test cases of the three deadline selftests pass wherever they run, with lockdep and no kernel warning. deadline_bw_test has 140 of them. They ran in 20 QEMU guests of 4 to 8 vCPUs: - with proxy execution on and off. - with PREEMPT_RT. - without CONFIG_CPUSETS. - with CONFIG_RT_GROUP_SCHED. - booted with isolcpus=domain on CPUs 1-2, 0-1 or 6-7, some with PREEMPT_RT. The 29 test cases that need isolated CPUs skip in the guests without them. No guest combines isolcpus=domain with a kernel without CONFIG_CPUSETS: such a kernel hits a BUG at boot on v7.4-rc2 [5]. At each test patch, the kernel and the test cases of that patch pass in 12 guests of the same kinds. Three guests with kmemleak ran the whole series: no leak. On top of the first series, the series builds at each of its 36 patches. At each patch, it also builds with tinyconfig, without CONFIG_RT_MUTEXES. At each test patch, the series also builds without CONFIG_CPUSETS, with PREEMPT_RT and with CONFIG_RT_GROUP_SCHED. The selftests build there with no warning. The cpuset selftest test_cpuset_prs.sh passes, with and without PREEMPT_RT. Each fix names the test cases that test it. Each test patch says which of its cases fail, and without which fix. These changes have no test case: - patches 2, 9 and 24: they were found by reading. - patch 3: it needs a machine with more than 2048 CPUs. - patch 1: it needs a chain walk preempted at the right step. - the bound of 8 reads in patch 1: it only acts if a writer of pi_se does not hold a reference on the new donor, or if 8 donors exit during the loop. - patch 25: it has no reproducer. - patch 28: it changes no behaviour. - patch 33: a Spin model found it (see below). Its window, from release_task() to the last schedule of the task, is too short for a test. - patch 34: it adds warnings. They do not fire in any of the runs above. - the change of patch 20 in dl_task_offline_migration(): it needs a timer that fires between a CPU going inactive and the cpuset update. - one change of v11 in each of patches 8, 18 and 21. They were found by reading. - the changes of v12, and those of v13 in patches 5 and 29. They come from the Sashiko reviews of v11 and v12, and a second LLM review of the fixes. The test cases above pass with them. These were not tested: - cgroup v1 cpusets. - threaded cgroups: every move is a write to cgroup.procs. - the sched_ext server. - CPUs of unequal capacity. How this was developed ====================== An LLM coding assistant wrote these patches, their messages and the tests, under my direction and review. I know the concepts behind SCHED_DEADLINE, but not its implementation well. So I ask those who know this code for a careful reading of the fixes. A reproducer that stops failing shows that the symptom goes away. It does not show that the fix is the one you would have written. The bugs came from: - flaky cgroup selftests of a feature I am developing. - the review of Juri's four fixes, and his review of v5. - building deadline_bw_test, and reading the code. - the Sashiko AI reviews of v1 to v12, and of the first series, plus a local run on the patches that changed for v11. Each finding was checked against the code first. - second LLM reads of the fixes and of the harder findings. They found the gaps fixed in patches 1, 20 and 21. - kmemleak, which found a leaked task_struct in an early version of patch 1. - a rare failure of the random_mix case of deadline_bw_test, on top of the priority inheritance series. Reading the accounting code for its cause found the bugs of patches 31 and 32. The likely cause itself was in the test: see the change of patch 30 below. Kernel traces taken with LTTng did not catch the failure. - a Spin model of the bandwidth accounting, which found the bug of patch 33, and the bug of patch 31 again. The rule of patch 29 was first checked in a user-space model of the CBS on one CPU. Two independent LLM reviews of that model found the problem of a task that moves to a constrained deadline, which patch 29 now covers. For v11, the assistant extended that model into a simulator of SCHED_DEADLINE on one CPU. It models these parts: - EDF over several tasks, and the CBS rules. - admission control on total_bw. - class changes, and rt_mutexes with priority inheritance. It has the rules of an earlier version of this series, transcribed by hand from the code. A search over small task sets, random and adversarial, checks two properties: - no task gets more than its bandwidth. - an admitted task meets its deadlines. Without rt_mutexes, those rules show two exceptions only: - the transient after a cut of bandwidth, which the known limits state. - misses in task sets with a density above 1, which admission by bandwidth does not exclude for constrained deadlines. With rt_mutexes, it found cases that the priority inheritance series covers. The search did not run on the rules of v13. The simulator also replays several test cases, and Example 1 of [4]. It is not part of this series. I can share it. For v13, the assistant also wrote a Spin model of the bandwidth accounting. It models this_bw, total_bw, the departed list, the rebuild and the boosts of priority inheritance. It has the rules of v13 with the priority inheritance series on top. It was first checked on a known bug. Without "sched/deadline: Fix this_bw when a task is changed during a remote wakeup", from the first series, it finds that bug again. With patches 31 to 33, it finds no error for two tasks and one root domain, with every CPU active. The model assumes sequential consistency: it does not check memory ordering. It is not part of this series. I can share it. Changes since v12 ================= The series has 36 patches, 7 fewer than v12. In this section, a bare number is that of a v12 patch. These patches moved out: - 21, 24, 28 to 33 and 38 to 41 go to the series on priority inheritance. So do the part of 37 for a boosted task, and the test cases of 42 for priority inheritance. 38 is split in two there. - 22 goes to my rtmutex series, in its next version. It is a chain walk bug that also leaves an owner on an old RT priority, with SCHED_FIFO waiters. As Juri asked, 37 is split in two here: - v13 patch 28 records the start of the period, with no functional change. - v13 patch 29 applies new parameters to the period in progress. It also makes dl_next_period() count from the start of the period. Without the other rules of v13 patch 29, that change alone fails three test cases of v13 patch 30. The patches of v12 have these numbers in v13: - 23, 27, 20, 25 and 26 are now 1 to 5: the order of Juri's list. - 1 to 19 are now 6 to 24. - 34 to 36 are now 25 to 27. - 37 is now 28 and 29. - 42 is now 30, with the test cases of the fixes in this series. - 43 is now 36. v13 patches 31 to 35 are new. Each v12 patch keeps its subject. v13 patch 28, split from 37, has a new one. The changes come from Juri's review of v12, the Sashiko AI review of v12, and a second LLM review of the fixes. Two failures of random_mix led to the change of 30. These patches changed, with their v13 numbers: - 1: as Juri suggested, dl_set_donor() stops after 8 reads of the donor (see the notes for Peter). v12 read it until a tryget succeeded. - 1: its message now says that trees older than v6.12 also need tryget_task_struct(). A duplicate Cc: stable line is gone. The message also gives the right reason for 8671bad873eb: the lockless tryget_task_struct() needs a task_struct freed through call_rcu(). - 2: its message now says that patch 1 keeps the donor readable from the timer. v12 named its patch 21 there, which moved out. Juri's Reviewed-by. - 3: Juri's Reviewed-by. - 4: its message now says why dl_time_to_zerolag() and dl_check_constrained_dl() skip a task with no period yet. The second skip fixes an older bug, so the patch also has "Fixes: df8eac8cafce". A comment in dl_check_constrained_dl() says it too. Juri's Reviewed-by. - 5: task_non_contending() cannot cancel the inactive timer while its handler runs. For a departing task, v12 then released the bandwidth and cleared the deadline at once. So a constrained task still lost them before its next period. A new flag, dl_inactive_pending, tells whether the handler will still act. If it will, task_non_contending() leaves the task to it. Else it goes on as if no timer were armed. A task that blocks in the class is unchanged. - 5: the inactive timer can still be queued when the task comes back to the class. If it fires then, its handler now leaves the task alone while it is contending. On v12, a handler that fired while such a task exited would clear its parameters before its last dequeue. Its bandwidth would then stay in running_bw and this_bw. - 5: it no longer calls dl_task_depart(), so that it applies on the first series alone. - 6: it adds that call of dl_task_depart(), with the departed list. - 22: it now checks an isolated partition root that gives CPUs back to a parent that is not isolated (see the notes for Waiman). v12 counted the housekeeping CPUs given back as CPUs that a task keeps in the default root domain. - 22: a partition root that is not isolated can take CPUs and give others back to its parent in one write. It now stays valid when the tasks of the parent keep a CPU of their root domain. The check counts the CPUs given back as CPUs of the root domain of the parent. v12 made the partition invalid. - 23: the new test cases partition_gives_back_refused, partition_gives_back_only_refused, partition_swap_gives_back_refused and partition_swap_accepted test these two changes. - 23: hotplug_user_mask_refused now allows every isolated CPU at first. It failed with three or more isolated CPUs, as the Sashiko AI review of v12 found. - 25: its message now says that patch 4 puts the 0-lag time of a constrained task after its next period. - 29: without the priority inheritance part, a change of a boosted task is checked at the first enqueue after its deboost (see "Known limits"). - 29: an enqueue now also throttles a task woken with no runtime left, after sched_setattr() left it none. Such a task can then reach the cancel of the replenishment timer at the end of enqueue_dl_entity(), which only servers reached before. That cancel now drops the reference that a queued timer holds on the task. - 30: its test cases for priority inheritance moved out, with those patches. - 30: the cases that use P, a one-CPU partition root, now also wait for this_bw. After each of them, the harness waits until this_bw of the three CPUs that random_mix checks is back to its value before the case. A task that a cpuset attach moves while it sleeps keeps its bandwidth in this_bw of its old CPU until it wakes up. This is the likely cause of two failures of random_mix in 366 runs, on top of the priority inheritance series. - 30: reenter_pi_blocked_in_gap, reenter_asleep_in_gap and reenter_asleep_late_in_gap now wait for the third period of T. T keeps its bandwidth until then, and the probe must run after its release. The Sashiko AI review of v12 found this. Patches 7, 8, 16 and 20 changed only to apply on top of these changes. "Known limits" has six new entries: two for patch 6, and four for patch 22. The first entry for patch 6 no longer lists a task that dies or is deboosted during a rebuild: patch 31 fixes that. The first series is based on tip sched/urgent, ec6f6731538e (v7.4-rc2). [1] https://lore.kernel.org/all/cover.1795115075.git.mathieu.desnoyers@efficios.com/ [2] https://lore.kernel.org/all/d975f317a4f9f79d2300b68ad76664755459ba36.1795181168.git.mathieu.desnoyers@efficios.com/ [3] T. Cucinotta, L. Abeni, "Migrating Constant Bandwidth Servers on Multi-Cores", RTNS 2021, section 4 [4] S. Tang, J. H. Anderson, L. Abeni, "On the Defectiveness of SCHED_DEADLINE w.r.t. Tardiness and Affinities, and a Partial Fix", RTNS 2021, https://doi.org/10.1145/3453417.3453440 [5] https://lore.kernel.org/lkml/20261117144817.265109-1-mathieu.desnoyers@efficios.com/ v12: https://lore.kernel.org/all/cover.1795771147.git.mathieu.desnoyers@efficios.com/ v11: https://lore.kernel.org/all/cover.1795646914.git.mathieu.desnoyers@efficios.com/ v10: https://lore.kernel.org/all/cover.1795207232.git.mathieu.desnoyers@efficios.com/ v9: https://lore.kernel.org/all/cover.1795181240.git.mathieu.desnoyers@efficios.com/ v8: https://lore.kernel.org/all/cover.1795116790.git.mathieu.desnoyers@efficios.com/ v7: https://lore.kernel.org/all/cover.1794922146.git.mathieu.desnoyers@efficios.com/ v6: https://lore.kernel.org/all/20261116190549.230119-1-mathieu.desnoyers@efficios.com/ v5: https://lore.kernel.org/all/20261108185406.1549770-1-mathieu.desnoyers@efficios.com/ v4: https://lore.kernel.org/all/20261107014451.1487825-1-mathieu.desnoyers@efficios.com/ Mathieu Desnoyers (36): sched/deadline: Hold a reference on the deadline donor of a boosted task sched/deadline: Replenish a throttled task boosted while asleep sched/deadline: Do not truncate a bandwidth to 32 bits in __dl_add/sub() sched/deadline: Count the 0-lag time from the next period sched/deadline: Keep a departing constrained task until its next period sched/deadline: Keep departing bandwidth across a root domain rebuild sched/deadline: Rebuild the root domains' accounting from the task list sched/deadline: Record the root domain holding a task's bandwidth sched/deadline: Leave a dying task out of a rebuild of the accounting selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild selftests/sched: Test the root domain rebuild in deadline_bw_test sched/deadline: Move a task's bandwidth only where room was made cgroup/cpuset: Wait for an attach before rebuilding the sched domains sched: Make deadline policy and affinity changes wait for a cpuset attach cgroup/cpuset: Give back the bandwidth an attach did not move cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to selftests/sched: Test cpuset moves in deadline_bw_test sched/deadline: Make a rebuild count a task in the root domain it runs in sched/deadline: Move a task's bandwidth to the root domain it runs in sched/deadline: Keep a task in the root domain that counts its bandwidth sched/deadline: Keep the last CPU a task has in its root domain cgroup/cpuset: Refuse to take a deadline task out of its root domain selftests/sched: Test the root domain of a task in deadline_bw_test sched/deadline: Count only active CPUs when spreading extra_bw sched/deadline: Cancel the replenishment timer with the parameters sched/deadline: Cap the runtime left of a constrained task at dl_runtime sched/deadline: Check the runtime of a task that comes back runnable sched/deadline: Record the start of the period sched/deadline: Keep the debt of a task across a change of parameters selftests/sched: Test parameter changes in deadline_bw_test sched/deadline: Count a task that departs while a rebuild walks the tasks sched/deadline: Count again a departed task that a boost brings back sched/deadline: Keep a reaped deadline task in a rebuild sched/deadline: Warn when a runqueue keeps the bandwidth of a task selftests/sched: Test PI against hotplug and rebuilds in deadline_bw_test selftests/sched: Share the helpers of the deadline tests Documentation/scheduler/sched-deadline.rst | 12 +- include/linux/cpuset.h | 28 +- include/linux/sched.h | 59 + include/linux/sched/deadline.h | 44 +- kernel/cgroup/cgroup.c | 3 - kernel/cgroup/cpuset-internal.h | 15 +- kernel/cgroup/cpuset.c | 891 +- kernel/exit.c | 2 + kernel/sched/core.c | 151 +- kernel/sched/deadline.c | 1945 +++- kernel/sched/sched.h | 89 + kernel/sched/syscalls.c | 124 +- kernel/sched/topology.c | 11 + .../selftests/sched/deadline/.gitignore | 1 + .../testing/selftests/sched/deadline/Makefile | 4 +- .../sched/deadline/deadline_bw_test.c | 8995 ++++++++++++++++- .../sched/deadline/deadline_rebuild_test.c | 501 + .../sched/deadline/deadline_switch_test.c | 36 +- .../selftests/sched/deadline/deadline_util.h | 106 + 19 files changed, 12478 insertions(+), 539 deletions(-) create mode 100644 tools/testing/selftests/sched/deadline/deadline_rebuild_test.c create mode 100644 tools/testing/selftests/sched/deadline/deadline_util.h base-commit: ec6f6731538e0d45872eb279fdeb477bed152d6f prerequisite-patch-id: 5e2478ffdfb7583751bf44bdf87fb930bc23551b prerequisite-patch-id: d5e5ef986ff2d9bc39a87b56e96a2acbd3158687 prerequisite-patch-id: 99e47f80396008ee2b2576157d37842481ce52d2 prerequisite-patch-id: a10824f98c11a4c902dad55cab3ec03b3dbe2c8a prerequisite-patch-id: 8959e5a408641b4fa81bc79737cd17d5f1b03389 prerequisite-patch-id: 16acf1d18f01d20310d6db767dfbec2f072e0372 prerequisite-patch-id: e1946bb015a7b14ed4e2cd0421e5e30b0c7afdda prerequisite-patch-id: 4daf48a89779fbd8c8bc5fc1d7a7d6df9bca2d9d prerequisite-patch-id: 980d8045f9fe8c3757bb3d82c61d68e321cf74bb prerequisite-patch-id: b2d75d7b3eebbda11af43b3917b1c99e0cce2725 prerequisite-patch-id: fb69a0665dc38ca9022cc2bd75234a90e2035b7f prerequisite-patch-id: 7a115ab83ad96ffaf8e833e0eaeb75f859af2e79 prerequisite-patch-id: 8574b50d81a09ec6091e42d65338adcab2986d71 prerequisite-patch-id: 1aa25df96d60d30f549c71fdfba5589cb239928f prerequisite-patch-id: d38384e0b7d043a3556ee02fb09316a6227038da prerequisite-patch-id: 83ded04a76ecf973e2b8c6e04ff83c2b7278915a prerequisite-patch-id: b8f5d9f9146e887050bbd8ad30463fd81cad9411 -- 2.47.3