From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796204602; b=RQbd+HwHXVaWa+FV0HHfnWZ2dqV0IJCRnFqTN6FYgVjubP3m5P9+eru7ahsO8cL4Y2yz W7pYgCuci+GuHefKPYVoaUXybRI5+MnYfUVEd/N98XvXisJCQj/yP8KwX89/06cZBHPNF fxGNZCT+25X/Rm7zQJ48H4BpoYzxcOgzim+lqqE5JcDHd84P7ArtVIXD0ZsjS18gV5jMT sb2FWHnbqGfFhUXX3faXCgE7nhRESWdfAOrIYK5O//Kp50UtZbW4KcRrDopb1f5Yh85jn 2Mrkh0JXjSfw0odCL8XrfdGh+Icm/gWo6eiZpyNhnae2TI8w3Wj+Cr/ftxjn43VZE2w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796204602; 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=eJabkEFpXJIbmhmqEczc4VKJcwZGbQ1fLd7MmdjBTLht+9Ed5GXoY/bvgLaikf2VA+r9 cCtp/A5dMc7xUWDAY/9DrUVkeVck8CRlhIV2wCcqzzaHBpLrInHQwjYWy/k2tx/fPinAg kU6JNNM9jnver7HuTwXQJTczAvC5C968m4Ym+9u61Tfy4SFO+i/4qSm0ditgTyFEr/6dn OdqsQu6Iti02McCQU6KEZz+50n3kWZsDjTMj8f64LIkjdAFsrjoTjVGcjkBpNyL1TmmGO AOnkbYA/3OOdvHxyhKts6MDm/W4ReoMWcTF+4CoEHT/lxZL6YlJh1EtFPJ3nDHm7qxw== 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="Tteti/yH"; 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 9B9EA606A338 for ; Wed, 2 Dec 2026 09:43:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9B9EA606A338 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=Tteti/yH; 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=1796204600; 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=Tteti/yHf/HrybssGNRWpty6Nl7cfklrtdM8zDoGh/5dJ2lb4A9Ovv8F7MvCmDYwkY0xoG 4IwXTk4y5Cuqqfilum0MPHklr/3ibIUkZ7gFTFwJMsXwqJSzclBf9HwWfgagdaitDeC922 HB+RMQuHsz/3idg1fGwse1jzECWiGk4= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-jf130KehMDWQPmYmPFQekg-1; Wed, 2 Dec 2026 09:43:19 +0000 X-MC-Unique: jf130KehMDWQPmYmPFQekg-1 X-Mimecast-MFC-AGG-ID: jf130KehMDWQPmYmPFQekg_1796204598 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-48e00f3929bso7122835f8f.0 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=qjhYHgA/lMeLUwx/rJ92192NTfZZumdixUpaKAc6Jt8=; b=eNYJCY3vGZyDZkrF/cjeAPKwGSwEXcZMz4jkJZpkXVW/fcnm9uA79g5poz8ldbsNdx At3KpPLKkYz1MTsbM1hEyQHSG5gKQ/9flzdMRB9ssjMSS1epGIzt3RKhsun7CbchjbXj O5miSvYJCFac0+JrJYwF2Hd3YDJ2nOMFC7iDtnTqwusni9HpDH7yRINup+zCK9EvX3LG wAVByPISnBkabhgU/NKU3MjYxqKIjO1KD3l4Xb1RikXJcjnAaaLgmrlihHUEqP6tXNfL EmI6J8PJcpxt+aZiVf2b5ZVbUqxpljc8MajTL2th2jMJPh1H46DhAp0kpec5DB8FzVSq GRfQ== X-Forwarded-Encrypted: i=1; AL+hErFJYE6/pmri41Sjk3y+9IAIefFvggKpJ7JI3IlTbsv+nI++upgJRMMPOEAYuvlcSrXfcBXNGzH515VYwps=@vger.kernel.org X-Gm-Message-State: APuU4Z+uwobbbTYufMUEuD3VEY8P1zsO+TUS6JiDePujdkPLN6gXZ99Z N0YQzUzeE6Fpc1RVxTu0p7vG8wQYiWs6NxdyStlbqp9V8sIrX8Q5/w9JmvypTe/vhXBCdSVTR9L fxCywroGr8//23MIh8yELyIC4wXKfGFuA9sHE54yjnuwSa4amUQrNwgQitthT+HJoYQ== X-Gm-Gg: AZFdTZdo2+p5SG91kIN3M975RFgzTiwbfjpl2rlGbQMahdE0cMN/GLOlpskgiXZDC9x 67Ame93gL08c3EtxfEJGuHPesCTvj1X5AOM88fOhj7bSp5kArd0ecpkHvmmmpocJ7qFgW5qGqoF roMz18TbgAuFz1lPqgmPK+ww2E64h+b+H10ZUXzahlbFWUHvWnqrzxYYZiNHgddoWHg513l8DGO z7xQtRyLLfr1A1HeaxNgikzOzCHDcSEYXSNzT8fTXxepS3NlY1EsoXOMdFzOLW9HPJDkehHPR6X mBr9bNxrL9QYhg47Yr+wdER/H0k5v0pERk/0lXTGPZ0dPYrTsJLyDu9jzWTVAzByJ051w7Alra7 ZecheLxCBkEG3ONZj3J8Q84RnBUvARfZ2I2EkS0CiYbmSCHW69L4BvUtFnNZzMzUEtrzqqoK5ZA fBGqE= X-Received: by 2002:a05:600c:848a:b0:4a2:1960:6fa with SMTP id 5b1f17b1804b1-4bb887fb678mr729847365e9.4.1796204597510; 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: linux-kernel@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