From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796048743; b=aL94EFAHnqFxXJu6kvbanW6u7eMF5I4lBKVXMTlulh3dEC1UP0Dy6SPLURYCU4ajvaQa HRTACp+EE5KRWc7jNz/Nas3is+DM/6O1B1lFv3DllnRLvoebw+VVMDnQ/Rp9Rzc4ti7kK FUBIzKuHaW22aQdB2ubDAl5Fto5ua1J5mz6d8DPf5PpOFWtet9hywpf5HApVanhJs8eZa 0nVLLIxWU5gvbDRKls1U+xnrqKJYYnHH9JERlUJU3qBEu7Fk1JFsDP3LRkrCKwg4sfvlg lv1B84iMZV/r0+dkxP38ZQAWyvHcMNdNuwinWehRbgA4bKbodh45VPSMS1Ima5ukLhQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796048743; 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=KrZf9GRZmwp570DiRDKnN4DzQosDGKLC6zkZw7L+484=; b=5AlkGIjTa8KwlJtderT78BS0GWbnPz7wo0HMfbHVBn4aAC30YRbZlnqaPZA9sU3xbn+K oM2QQLb+FqMCrJlmplFPCOVk6JdzKpMiSmZtWivIYnXv4aU5j4xmgoibuHA1IP59gdqfB XwhI+61JChzJazXOfZstrw5HzqjiX6EpysYXAgyN4z5Yx1PYbHD3CT+XBnG9BGVH1rHPQ KEQcjRdLTg3KdgMyBDmAYiQtIAegZohPx0yZFji/x396nIMqmYmdSAzshuoV24PmOzGY1 Z8Jo29asN1DOXw+6N1AZJZKpLmybcCD9lCD/RKouMmPbWp+11Ek3Dz+g1pfdFbtnn4A== 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=e3P2DTaH; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=S7KHEBEB; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 B5901606A331 for ; Mon, 30 Nov 2026 14:25:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B5901606A331 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=e3P2DTaH; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=S7KHEBEB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796048741; 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=KrZf9GRZmwp570DiRDKnN4DzQosDGKLC6zkZw7L+484=; b=e3P2DTaHu5z93RwJasOJhHj5REgtqHrmCeSpogWFu7fAY6XoUtqeARG2kS0QnfO8Bnn06H qD7xEIY+lr+5vI/wonR7RiNop9ccDN4DVQ3lvrghDDx8pQbkktCyQ6O05tQDqlDdHeYWpT ss3SsyZHu7s/feGE1hcVium1aFkpd/k= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-311-geWTEvRlMQKUKTQxOR_eOA-1; Mon, 30 Nov 2026 14:25:39 +0000 X-MC-Unique: geWTEvRlMQKUKTQxOR_eOA-1 X-Mimecast-MFC-AGG-ID: geWTEvRlMQKUKTQxOR_eOA_1796048738 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4a17741243eso22392665e9.0 for ; Mon, 30 Nov 2026 06:25:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1796048738; x=1796653538; 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=KrZf9GRZmwp570DiRDKnN4DzQosDGKLC6zkZw7L+484=; b=S7KHEBEB+BHb4Xo2ru49QO79JFGocgQCNiw3qVg1zRLXEBQyUNlmEAiPrn1Aq88w41 JcFpbP5Rs3mI/fjj0mCt/Eg13AzCmmgD67EGnFlWO+ZgdswPh/Y6Dab1u0zWd+gFizmk N02ljdEBcuUkHH3NlwOCvCGanZAKkoNbwb3PMYQ1cK80W4dre+F+j3TNRqbebcp2Xq3l UB5uJ/Bm0zhd60Yxaf5rNWcZE1Gzii3kn+EYAzPJdZu8NE+V/NWLcHv9dcZFpNXOucPE TcnKlJsHzTunIg/ER6o+FvloaqMVNhaJw/xwPdxt0VChYzTaenbaju7SycN/2U+4LCTL uNPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796048738; x=1796653538; 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=KrZf9GRZmwp570DiRDKnN4DzQosDGKLC6zkZw7L+484=; b=Zn8MAi/eSJIBpgkwmcshZTyLrzJ1y+woSkJnvWqdsNBQLwP92c6mARp6r6AHTCpbqC e4MJJvBBi0BMXqw55+phujYSHv1/2Hq7q9p6bMIFjyNO6YNYvOn8IQ4zlM5CQYghmifm LLnjHUIaixucfQOlo+UWSOqTqkPbFTqVQfq2qMwrq92E3He8qCAb8UJELwfbM9cjyFtk WVEl+qNqfRfpUySmjFkYBREbUqv4c6aW5kBdjqePS88jl6WTkPYOFidHbB5il3NkhcV5 7W9DgtDHFZ394SXj5CqUgdUuJzVhO5eFqcIdO52A31B+HzmR+8ZiQIgpcepVVlliaOmY b80A== X-Forwarded-Encrypted: i=1; AL+hErGHWxEswG+emOUfB17rs2hELzcjwl23PL0ZjxkldyWdcfrgcdcwCPa/nHMl8xNrZENxGRsygq2qCFiWnjg=@vger.kernel.org X-Gm-Message-State: APuU4Z9q5TAl5UUBvafj0ehoS3NvzI6GPd1HE99w4m+JfJ165yJL+XHV tkvQqSs96KhhlfQfAouQePRT6QG7qasTGYx3U1AhZG9XYAmyezppxl11F5Wg6rWy9Ivt4i8iAMS cfWLy4fI+wyn1UEDy4ffRSHGdcINfaQtzqY6Y/omljTdjLO4pw7MiD9flDk3b6x26pA== X-Gm-Gg: AZFdTZcE5mHVDbkbEvjLaQbSe7OKf4W8Jc9a4YSf9/3IX333Qd0RQGcNbdxXzxCd/he btw5B+qy6J2zm9acJ69zsboHzhnSWC83nmyASxRKpTxFKiB1QHB+iwbxpTm12Zn1jHNey8xrKOL 3Xq3CdGq1av3/mP75gE8lbkDvqEDCGT04oWTBhQQ4t7SBj3D0ajxS6mP7nIp20In17F7UMwYARf CcVZGkj0qUQBm/7hDQuJMFt+oSEftJwRx5ra1m07jy4QQKvzbKdeP9mKMxZdxizx1hYUz9k/R0T aalTuqAWSe1g9ALCJHzqnjkt11nEyXMgcR8Ie1hFW449GtD8LzLndpmMjxI/UtNYkBlHqiEtwkE 2Lvr8T9NpJN26v60t/qLEj4CXGur8b1D+M6FqHv/gpUh22C2TLQa4Gz7Kh3x4dGgrMQd6oTCpqA JTP1Ig X-Received: by 2002:a05:600c:3547:b0:4a2:a6e:80f5 with SMTP id 5b1f17b1804b1-4bb888098bfmr685936355e9.11.1796048737969; Mon, 30 Nov 2026 06:25:37 -0800 (PST) X-Received: by 2002:a05:600c:3547:b0:4a2:a6e:80f5 with SMTP id 5b1f17b1804b1-4bb888098bfmr685935685e9.11.1796048737478; Mon, 30 Nov 2026 06:25:37 -0800 (PST) Received: from jlelli-thinkpadt14gen4.remote.csb ([151.29.146.153]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb884b39b6sm867667115e9.12.2026.11.30.06.25.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 06:25:36 -0800 (PST) Date: Mon, 30 Nov 2026 15:25:34 +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, stable@vger.kernel.org Subject: Re: [PATCH v12 23/43] sched/deadline: Hold a reference on the deadline donor of a boosted task Message-ID: References: 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: Hello, On 27/11/26 09:35, Mathieu Desnoyers wrote: ... > 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. Thanks for implementing this. As far as I can see it covers all the writers of pi_se, and it closes the use after free without needing the two rtmutex patches before it. ... > Cc: stable@vger.kernel.org # 6.16.x and older: 8671bad873eb: sched: Do not call __put_task_struct() on rt if pi_blocked_on is set > Cc: stable@vger.kernel.org Nit: the second line looks redundant. Also, tryget_task_struct() is only there since v6.12, so older trees need something else on top of 8671bad873eb. ... > +static inline void dl_set_donor(struct sched_dl_entity *dl_se, > + struct task_struct *pi_task) > +{ > + struct sched_dl_entity *pi_se; > + > + for (;;) { > + 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))) > + break; > + /* Pairs with the ordering of refcount_dec_and_test(). */ > + smp_rmb(); > + } > + dl_replace_donor(dl_se, pi_se); > +} I convinced myself that this terminates: tryget can only fail once the last reference on the donor is gone, which means the waiter dropped its own. The waiter does that only in dl_replace_donor(), after storing the new donor in its pi_se, so the re-read after the smp_rmb() finds a newer pointer. And the rq lock keeps the old task_struct from being freed meanwhile. Still, this is an open-ended loop with the rq lock and the pi_lock held and interrupts disabled, and it ends only as long as every writer of pi_se that points it at another task holds a reference on that task. We have a few of them already and later patches rework this code. If one of them ever gets it wrong we spin here forever, with nothing telling us why. Would it make sense to give up after a few tries, warn, and fall back to the top waiter itself? It is blocked, so it cannot go away, and a waiter with no parameters of its own is what "sched/deadline: Do not replenish a boost from cleared parameters" already handles. The boost is then less accurate in a case that should never happen, which looks better to me than a silent lockup. Giving up also puts a hard limit on the time spent here with interrupts off. One more thing. Since this fixes a use after free and seems to stand on its own, can we move it ahead of the rest of the series? Thanks, Juri