Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795625831; b=GIDpK7aTzz771fYptkjrkFyP394L/y8TWLozqlFqrGgc+wT7IvaR6iqV7fjGeDnQ5oE4 qyQaedwL3HdHiIUGfkho1HhvQGbgUCA3mZ7Tk6juZrm1daYVCYlbHjJUFeV+d4OMhpm2b ECqeu/rYPlEuijVKojsO8U3ukecurO2uFNApp5gdrMibfiQOVsOeLr1bc2w0s93/yHH92 pioslGetQbSbOqAOjS+zEbz0PO8DG3WPViAogtbstNuPt5a2N6SmmjH4xAzbyjsV68ru3 0trQsRB9hZ6v2v9cyCF2xD3SLYo2zE3VXhFNbo1/Kdc3jWN+Zs7+T69hMNvuksCJt3A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795625831; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=x1OArG7IkxfWsHYt5SLtroZgvnh8X1QNr1Gq+dr/sjw=; b=0/ttObjsA0UFwTMJb6pq+1T0MxLwyF0yjJD/5EY5qe8vrEIntByHjpxwiASA6FFWWBGJ Ez59d46DwKp+JGb8gQ29uEtFKCyOB+9hye/k6ALGKYNUDywDie0EYw/qKBtw91OOuWA1+ /9kEC66WQOQD8vFQSOYpgW32791/up6Bv6rhIsy2gfMa3WkSyv8iLRXFt9BEVBtni00K2 iOGgZA1uVYSVuWZneIYYcUSqmUlX2JP1+eW6HNAx9WGbAi+SsHx2pqPuBzNiODjrfMJS7 Jcl2gyCjPLKjVxoHpLTHizPnac08K/kQ0gGHjmKyquyCgeIz28v905nRA0JtqnsZCFw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="hcsZX/G3"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5685606A331; Wed, 25 Nov 2026 16:57:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=hcsZX/G3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6145C1F000D1; Wed, 25 Nov 2026 16:57:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795625830; bh=x1OArG7IkxfWsHYt5SLtroZgvnh8X1QNr1Gq+dr/sjw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hcsZX/G3Pc7yxLWxV3qgmN/XX7rMc71n9YoJ6dgK1vTn7yLzQLcKu9tfjMiUHJ3N3 pp5BsJctZiNH4/EXiDDxEr9VZC8HX5KNcXMBvPeKznsRURE/RYraAHaFy6d+EtbJbv 0EBHM4kYVkol+uqVXQUtrQiVNElt2TboK2SoVz90= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Andrea Parri , "Peter Zijlstra (Intel)" , Ingo Molnar , Sebastian Andrzej Siewior , Juri Lelli Subject: [PATCH 6.12 644/816] sched/deadline: Fix spurious -EPERM for migration-disabled tasks Date: Wed, 25 Nov 2026 15:36:32 +0100 Message-ID: <20261125143904.091807227@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125143849.205329330@linuxfoundation.org> References: <20261125143849.205329330@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrea Parri commit 6616bffa9b52da1338cf8bff9882404e02b9e361 upstream. sched_setattr() can refuse to make a task SCHED_DEADLINE with -EPERM, even though the task's affinity covers the whole root domain. A retry can succeed, but the error blames an affinity the task does not have. __sched_setscheduler() tests p->cpus_ptr, which is not always the task's affinity. When a task is scheduled out inside a migrate_disable() section, migrate_disable_switch() points p->cpus_ptr at the current CPU until migrate_enable(). On PREEMPT_RT every spinlock_t holder is in such a section, so ordinary kernel work opens the window. Elsewhere, seccomp filters run in one. Test p->cpus_mask instead, which keeps the task's affinity and is what sched_getaffinity() reports. This should be safe because an admitted task's cpus_mask covers the root domain, so set_cpus_allowed_dl() moves no bandwidth when migrate_enable() restores p->cpus_ptr. The following program, run as root, had 553679, 453720 and 424623 of its 1000000 requests refused on three boots of a 4-CPU PREEMPT_RT guest, and 236182, 217174 and 237183 without PREEMPT_RT. With this applied the count is 0, also with lockdep, and a task pinned to one CPU is still refused: #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #define REQUESTS 1000000 #define INSNS 300 struct attr { uint32_t size, policy; uint64_t flags; int32_t nice; uint32_t prio; uint64_t runtime, deadline, period; }; static volatile int stop; static volatile pid_t target; static long set(struct attr a) { a.size = sizeof(a); return syscall(SYS_sched_setattr, target, &a, 0); } static void *worker(void *arg) { struct sock_filter f[INSNS + 1]; struct sock_fprog prog = { .len = INSNS + 1, .filter = f }; int i; /* Reading the arguments keeps seccomp from caching the result */ for (i = 0; i < INSNS; i++) f[i] = (struct sock_filter) BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args)); f[INSNS] = (struct sock_filter) BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW); syscall(SYS_seccomp, SECCOMP_SET_MODE_FILTER, 0, &prog); target = syscall(SYS_gettid); while (!stop) syscall(SYS_getppid); return arg; } static void *hog(void *arg) { while (!stop) ; return arg; } int main(void) { pthread_t t[9]; long refused = 0; int i; pthread_create(&t[0], NULL, worker, NULL); while (!target) usleep(100); for (i = 1; i < 9; i++) pthread_create(&t[i], NULL, hog, NULL); for (i = 0; i < REQUESTS; i++) { /* SCHED_DEADLINE, 2us every 1s */ if (set((struct attr){ .policy = 6, .runtime = 2000, .deadline = 1000000000, .period = 1000000000 }) && errno == EPERM) refused++; set((struct attr){ .policy = 0 }); /* SCHED_OTHER */ } stop = 1; for (i = 0; i < 9; i++) pthread_join(t[i], NULL); printf("%ld of %d requests refused\n", refused, REQUESTS); return 0; } An LLM helped find this bug and write this patch and its test. Fixes: af449901b84c ("sched: Add migrate_disable()") Signed-off-by: Andrea Parri Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Reviewed-by: Sebastian Andrzej Siewior Acked-by: Juri Lelli Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261102135420.244745-1-parri.andrea@gmail.com Signed-off-by: Greg Kroah-Hartman --- kernel/sched/syscalls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/kernel/sched/syscalls.c +++ b/kernel/sched/syscalls.c @@ -631,7 +631,7 @@ change: * the entire root_domain to become SCHED_DEADLINE. We * will also fail if there's no bandwidth available. */ - if (!cpumask_subset(span, p->cpus_ptr) || + if (!cpumask_subset(span, &p->cpus_mask) || rq->rd->dl_bw.bw == 0) { retval = -EPERM; goto unlock;