From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=90.155.92.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796405218; b=dkUBDpZUoUMa+2WH/ZP4hU6Akm5uOr2+zVMYhCghXnc3vL/68VqYcFVVXlEgV+y08x3d T39PIc519cpIyxtoWe9DqvtBwW4CiEnFkPGwbyKVdSpSupZYEQGOcUpLQxm8UiKIaW9lm 9niRXmT5J2RabF8y+n2qp4kZqus+dVEoRGtsLG+8hjNJIRSC1ptOVaDkofS3kKUwNVFXB 2GKrhPAo6sOLwGeOkvORsZv4+2s+MLo9G/3TTCIosCOR6SDK36827laYD0CSeYLRp3SR8 JZBQ/mlvm7ZE5vRuxb+i2SyDN7ccLDBWkDqAK1BtahCgvQmK6jh5Xs18c4qwssC1bwQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796405218; h=DMARC-Filter:DKIM-Signature:Received:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=Ty5jLbtYal5Uz/h1pVnlkSEcTV/f2n1quS8FKsKaS2M=; b=H5O+F9rItG1HJEQHBycN9ndGLJZodzhHgm1R4FHlNm0a0vcVnGcPtPDMrSS7zEdT8mYS ULwpPbe8XMXpGs6KIWvRq+egR0GUy18vuYHm1qjPnszQdGl27XmZg7cCVCHTrm/LKtCwp xc23Ckk5tSnDZSWTHmcHnYM6cl5ETpVDHvWNQ9bRdCY8HmbK0yFaHyNYORH1OlaYOKj/8 q2SGslOM/DCelb80GcAkdWfeepqb6vURe9Zdcpu+I+7FiOTOo/TpnVClHvcSmy1NypbWN VapQ57s+NKxBwPOu0K9Q6+HCcgVVEEtwOOgrfXR0PD9gcDaDQoMMAAydwBOaNoqixEw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b="DtP/wwLu"; arc=none smtp.remote-ip=90.155.92.199 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 7A1B4606A322; Fri, 4 Dec 2026 17:26:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7A1B4606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=DtP/wwLu DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Ty5jLbtYal5Uz/h1pVnlkSEcTV/f2n1quS8FKsKaS2M=; b=DtP/wwLuERM+JjzsX9LLzUjSTM Wzom+CUNVo5WD/D3gEySIufw/mC7oxQ46Xy0/Xj8dcR4SltXcsA8Nb2QEIf9KJL3H8LpC+oj182Nk dHAkJjTt9gIiLJrpCoP4Q7nEZuACeTieuALOxc9szwPyzRa7EnSgx5Z73FBg/dq2DwradQl3XhefZ 8dNKKbBNuVmXrgaUWj6xtg0TxIYZID5QW5ZRp5gXXA7h8jyvDoB0yDHm+S3R9R7+IyaTmkUt6+MMJ KY7BlEacfaRpLdDQxXOJoWPMq0IytIYnhIve8TWS84q7QKauN8Ai6ixMWNgphT5pCwQWGtSdxm1Wj RRXQAQeQ==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZX3a-0000000Ed8b-2t2G; Fri, 04 Dec 2026 17:26:50 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 8B1753006DD; Fri, 04 Dec 2026 18:26:48 +0100 (CET) Date: Fri, 4 Dec 2026 18:26:48 +0100 From: Peter Zijlstra To: Mathieu Desnoyers Cc: juri.lelli@redhat.com, mingo@redhat.com, vincent.guittot@linaro.org, tglx@kernel.org, anna-maria@linutronix.de, frederic@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 v14 01/39] sched/deadline: Hold a reference on the deadline donor of a boosted task Message-ID: <20261204172648.GY2668804@noisy.programming.kicks-ass.net> References: <22d46c764dc269349e9d1cbb90c880d349974d2a.1796296313.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: <22d46c764dc269349e9d1cbb90c880d349974d2a.1796296313.git.mathieu.desnoyers@efficios.com> On Thu, Dec 03, 2026 at 09:58:15AM -0500, Mathieu Desnoyers wrote: > +#ifdef CONFIG_RT_MUTEXES > +/* > + * Make @pi_se the deadline donor of @dl_se. The caller holds a reference > + * on the task of @pi_se, unless @pi_se is @dl_se. Put the reference on > + * the old donor. > + */ > +static inline void dl_replace_donor(struct sched_dl_entity *dl_se, > + struct sched_dl_entity *pi_se) > +{ > + struct sched_dl_entity *old = dl_se->pi_se; > + > + WRITE_ONCE(dl_se->pi_se, pi_se); > + if (old != dl_se) > + put_task_struct(container_of(old, struct task_struct, dl)); > +} > + > +/* 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); *groan*, so it feels like this WARN is something that could be constructed to trigger, which would be bad. All this takes is for a high frequency pthread_cancel() or somesuch, no? Create a ton of high prio tasks, get them involved in a boost chain and cancel them. Or am I missing soemthing? > + 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); > +} > + > +/* Make @dl_se its own donor. The caller holds the rq lock of its task. */ > +static inline void dl_clear_donor(struct sched_dl_entity *dl_se) > +{ > + dl_replace_donor(dl_se, dl_se); > +} > +#endif