Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796204604; b=fx66fsg7rupssDdCoM5DpplE9S0RO4f4veCIXWfAEX0hj/6Y+EE28YbvnjlvddC/jVnI wf91Dz7N9LjimWA7XO6aL+7UngdNYgAtLwL6gyI48tD5UzIHJv5YREFRRxyRXrDj9e36G jJsiJQa2fAHDC9ujyuWsYy/xeTrwb4ZnqFLbg5BIfjx+yGJsn4IJ/0ErkGVswNAerYa9b YUg0/9bqr966bMvvfp9da6YQVUoh3TiWemcr8Vb521ABLClM4h+/VzqhLkgsM31RSu8R7 BzLp9SIBCn/GL476PhylQkSdWnZItpXc6zIasFkpl9OAv2Dckg8o6G13cJB0xM4b2Og== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796204604; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received: X-Received:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=qjhYHgA/lMeLUwx/rJ92192NTfZZumdixUpaKAc6Jt8=; b=t2FGBZJebC6UXTdBIsQqVElyD9wfYi+jDaBoWH442h52fwLyZgS+aVVzGj4QO//rEgW0 6imq4CUMWnP3TDXFsXldaqFI23mAFFgVhWkm7Vx8poEE4pxrVsNQqRDNo8OgMtxXlfe6b xKb/ipCGJ/SUYu+E1jneKHXVy2Ho0yTboNelZqNQ4wagb9ty0ChBtd0wD+Y7gd1/h7D+D ToDTH5WFl49nSVmtz30bzcZyoc9t7xaEjv1pqlxypqsAvnTJXcuRouVjpTsakkja2kh0U XdsX/Ff48jWchQXuLJYlNmuSiodHKS6EKDPptmvjRUVBk2au6vVhzqQ4LwWBK/CzIkQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MfrRnD8N; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b="lc/6MJLb"; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 D61D8606A691 for ; Wed, 2 Dec 2026 09:43:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D61D8606A691 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MfrRnD8N; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=lc/6MJLb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796204601; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=qjhYHgA/lMeLUwx/rJ92192NTfZZumdixUpaKAc6Jt8=; b=MfrRnD8NiGOf2ZxIKs2eGSXKJujXSPZsMzKr4ucacLcRmhIizot8zfFGpNG1k4SeNsxHFX W5ZyUEA2pKkX3y8aydcr3zGTwSOXG/QJgNXHcgpw62+jSqBjUWEksfYt7BFBA6PiFdxRC2 aiZyGJ00xPzOVzaY16XU8JYAmVAo9oU= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-AA3yUWovOFS4uSvMQuMukg-1; Wed, 2 Dec 2026 09:43:19 +0000 X-MC-Unique: AA3yUWovOFS4uSvMQuMukg-1 X-Mimecast-MFC-AGG-ID: AA3yUWovOFS4uSvMQuMukg_1796204598 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4bba5f21b85so40382675e9.1 for ; Wed, 02 Dec 2026 01:43:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1796204598; x=1796809398; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=qjhYHgA/lMeLUwx/rJ92192NTfZZumdixUpaKAc6Jt8=; b=lc/6MJLbQidwETlVAnbFpFkE+OCYd5bw8br5hWU83IjVmis1OagCirHJXFj9PS88Hk XAae+YsD9LDfFq4/+Grd4au8O96YJ/iM0VWz6MqjEJ1BrExgoEVrFWeDt8tPakMWGK6N 8VEHdS9LLOWbzzZpT8WD2y0m4mmfnSSPI++wsscu4geGm1tqHdh7T0g2/CnZly+qx10q F3WiR997hIuF0axGAUqhIhuT9y4yrzqp7K7MPCbHLMJerJ/AGf3iHE4G36xaF4qgs2UQ KSbje3LuJWAO7MSmZkhcIr53wjmJPf9CnbSkcgwiyBKA/KK56MLo8eHJw6Kx+sfLDUlG TG/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796204598; x=1796809398; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=qjhYHg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bE7M5eWqndXg yc/DrFMOgyopCE4W1BWSIB7NBfuG1vvKUI7FsvKAuz+mRF2IJqrQ439gSc+sNqlmXdVDrcfbc1H 2R7K4= X-Received: by 2002:a05:600c:848a:b0:4a2:1960:6fa with SMTP id 5b1f17b1804b1-4bb887fb678mr729847205e9.4.1796204597478; Wed, 02 Dec 2026 01:43:17 -0800 (PST) X-Received: by 2002:a05:600c:848a:b0:4a2:1960:6fa with SMTP id 5b1f17b1804b1-4bb887fb678mr729846675e9.4.1796204596629; Wed, 02 Dec 2026 01:43:16 -0800 (PST) Received: from jlelli-thinkpadt14gen4.remote.csb ([151.29.146.153]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb884ab091sm1467475275e9.11.2026.12.02.01.43.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 01:43:15 -0800 (PST) Date: Wed, 2 Dec 2026 10:43:11 +0100 From: Juri Lelli To: Mathieu Desnoyers Cc: peterz@infradead.org, mingo@redhat.com, vincent.guittot@linaro.org, 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, stable@vger.kernel.org Subject: Re: [PATCH v13 01/36] sched/deadline: Hold a reference on the deadline donor of a boosted task Message-ID: References: <1fe992bb3b14c04df8e9d2e58fd9ad794e6f806f.1796146461.git.mathieu.desnoyers@efficios.com> X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1fe992bb3b14c04df8e9d2e58fd9ad794e6f806f.1796146461.git.mathieu.desnoyers@efficios.com> Hello, On 01/12/26 12:43, Mathieu Desnoyers wrote: > A task boosted by a SCHED_DEADLINE waiter runs on the parameters of a > donor, dl.pi_se. Since commit 2279f540ea7d ("sched/deadline: Fix > priority inheritance with multiple scheduling classes"), > rt_mutex_setprio() copies the donor of the top waiter to the owner. So > each owner along a chain points at the deadline task at its head. > > rt_mutex_setprio() keeps the top waiter, pi_top_task, as a plain > pointer. The top waiter is blocked, so it cannot exit. The donor further > up the chain has no such guarantee. When it stops waiting, the owners > below it are fixed by chain walks. A walk can be preempted, and it runs > in the context of the task that started it, not the donor's. So the > donor can exit before the walk reaches the last owner. > > M, O and P are SCHED_OTHER tasks. W is a SCHED_DEADLINE task: > > P O M W > > locks L3 locks L2 locks L1 > blocks on L3 > blocks on L2 > blocks on L1 > M, O, P get W's parameters > times out on L2 > O deboosted > walk from O: preempted > times out on L1 > M not blocked: no walk > exits > runs out of runtime > refill reads P->dl.pi_se: > W's freed task_struct > > P would run on parameters read from freed memory, until M's walk > reaches it. Setting up the deadline task needs CAP_SYS_NICE. The > timeout of a FUTEX_LOCK_PI needs no privilege. This was found by > reading. > > Fix this by holding a reference on the donor's task, for each task whose > donor is another task. dl_set_donor() gives a task the donor of its top > waiter. dl_clear_donor() ends the boost. Both move the reference. A > late walk can still leave P on the parameters of an exited donor for a > while. P now reads them from valid memory. ... > +/* Reads of the donor of a waiter before the lookup falls back. */ > +#define DL_DONOR_TRIES 8 > + > +/* > + * Make the deadline donor of the waiter @pi_task the donor of @dl_se. A > + * boosted entity holds a reference on the task of its donor. The donor > + * is the deadline task at the head of the chain. It can stop waiting > + * and exit before the chain walk reaches @dl_se: that walk can be > + * preempted. > + * > + * The donor of @pi_task is read without the locks of @pi_task. Another > + * CPU can change it meanwhile, and put the last reference on the old > + * donor. That CPU stores the new donor first: read it again then. The > + * old task_struct stays readable while the rq lock is held: > + * put_task_struct() frees it through call_rcu(), and the rq lock holds > + * off the grace period. > + * > + * Each failed tryget_task_struct() means that another CPU stored a newer > + * donor. This holds as long as every writer of pi_se holds a reference > + * on the new donor. A writer that breaks this rule could leave a dead > + * donor in pi_se, and every read would fail on it. So stop after > + * DL_DONOR_TRIES reads, rather than spin forever with interrupts off. > + * Warn, and fall back to @pi_task itself. It waits on a lock, so it > + * cannot exit. If it has no parameters of its own, > + * replenish_dl_entity() handles it as a donor that left the class. > + * > + * The caller holds the rq lock and the pi_lock of the task of @dl_se. > + */ > +static inline void dl_set_donor(struct sched_dl_entity *dl_se, > + struct task_struct *pi_task) > +{ > + struct sched_dl_entity *pi_se; > + int tries; > + > + for (tries = 0; tries < DL_DONOR_TRIES; tries++) { > + pi_se = READ_ONCE(pi_task->dl.pi_se); > + if (pi_se == dl_se->pi_se) > + return; > + if (pi_se == dl_se || > + tryget_task_struct(container_of(pi_se, struct task_struct, dl))) > + goto set; > + /* Pairs with the ordering of refcount_dec_and_test(). */ > + smp_rmb(); > + } > + WARN_ON_ONCE(1); > + pi_se = &pi_task->dl; > + if (pi_se == dl_se->pi_se) > + return; > + if (pi_se != dl_se) > + get_task_struct(pi_task); > +set: > + dl_replace_donor(dl_se, pi_se); > +} This is what I had in mind, and the patch looks OK to me. Wonder what Peter/others think of it, but I can give Reviewed-by: Juri Lelli Thanks, Juri