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=1796048742; b=2rXSbXGVdZZjtarbVx41FpXdbJ3ix8mnusCQkEEkulvq8HyqWlHfgbemrVU1/Qai8G0O 0czCbLgtsgLdUPsYcoBClOBPkQaqGfQPD52SFuRNDfTAnF1TthnOTVZWZIC60gw79Yp+4 gPufN9twY8EU46T8jyReCGogMoO25etWV/xIFymUbx2NfPLJ6UJq2mL9ti9S9ghymupl4 l6RCx1ZNcPlK5IZn34c1hVomEO6roRgabop6pj53++pxFtyh2VKEzC2eFgfYTJ7E4taO8 gMeGf6VTA2yK8NrFD8daHzelM+Nbs25mihtT1c5ZJLFJYUhuVSsBWnv/Mcyn63BQ6DQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796048742; 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=FMf351nM2gIPUvwCOJjyK7PP0QuWrCnUNFMYF0yK629RgiU07ozfBljWUb9FjOtrDR/V M/WsLch4fepzCWf69oPL1mXW8WRofnuXwto54Aa2H0LfCrPL8x43Nowo2BFqbMDzraWvQ 6gq438Nu8TsqsupSoRNL6wsfT2MCuWZc75Xk6fjnZz1/VnEmqNQ89OOTItbYY8EalsCVO mPOW4Ex4+3xQ7EAZw5+VVX0iaNQpTRXggSUnyA1gDard9ycRMisazqXx5sctGbAdQDjMz miUmQCodOm1x5GXfM9dVQERZ0L0luwvQKsDYT3MVAUWOVNaPpfmL9dxFEvWUiXr0pUg== 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 1F914606A32D for ; Mon, 30 Nov 2026 14:25:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1F914606A32D 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-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-137-fZckh2x5MSGATa50PCobuA-1; Mon, 30 Nov 2026 14:25:39 +0000 X-MC-Unique: fZckh2x5MSGATa50PCobuA-1 X-Mimecast-MFC-AGG-ID: fZckh2x5MSGATa50PCobuA_1796048738 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4ba01393800so28666005e9.1 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=adLt/KeaBavpp6KaV70o+yqlVcOYrtAudeQ39Uw9g/pAMDgKyI1dpcOPtls3uzPGw5 U8N9aQoT493+uZngmJ7ZaruegqFDTcoKTrGi6uHV/+cCiyajWoIcMr+s2vMmN3vCaReE QEs9/y2lkOIy7BhV0MAYLD2L7WfEzYBIsnolfa4t5nR6WZbpAETx915s5xT+f28LiLKp ciOw8cbehLX0HZO3CVJUo1dqDnvEp9nWX334J7cxrvE2R9DNCBah2LAO+OzaMI8qMf25 PtEh3nmT3zxMWHslDLqOeu26REUT6YX88FvfwQIOkNkM00+R+tnnMsK3wf/SuUjn+xMA hvyw== X-Forwarded-Encrypted: i=1; AL+hErE2ghfd2tfEI20ta83TReSYEqXC8FS9tpa+h/A7qE/IPXJc/7W43KbJ/j4oJr0hqTpzMAn3C5Sd@vger.kernel.org X-Gm-Message-State: APuU4Z/xEyZ/Me3ll1jo1s6IYGDJty1iXVzvACe+5UpqvMBDnssqVpyb YHRACMzvm8+6FdTjkRKOXDKkOlLuhWCEPahuaKmnGAHDl1CglaryKgM7Cv1lBEsy2mthgxzIAd7 51lj8OxbDOkaejhosa2K1fKj+ccVwu6IfaW5d3+6u1ucyrYmprEjnWOasa2c= X-Gm-Gg: AZFdTZc4N/oJNksN6JARjtw+gWLSHFZe/BqCx4ETygCxJjiekvFgrJApRb70maczQN1 kea7VBXOrQlLAki785So235a8D9X7UJHnKbcx9WArAnUeBNoPYfvvu1L0O9Ro9A2sShXPZqbMvy Cxtg7liBo3QhCdoY5hmbWtczWpnLlAYdIWUQ9jHlYIwT51DPTClq3RDObv7bi2e7S5Iu0Mi5po6 jyqHOJkAT2BKjJI27fsTHTVzQ3WAPTfjFv38XVyOOK9KbwfFIlbkzt91kOrVgBRUcXbmgxM7jsZ 2nsBksAIGEP2vBFTS2LVF6uYouOLGL3offSlAfGOUxW0u1JvHRbUYM9/Do5XnXYDUWBey7vBbjI 39UESUYjWj2/ZHCWqIJgSbLJEunpNgemSzRIwhIqgAfI2cbpQHdIp+XJFST6HsGUBBNHwJMzvlw c5drXG X-Received: by 2002:a05:600c:3547:b0:4a2:a6e:80f5 with SMTP id 5b1f17b1804b1-4bb888098bfmr685936575e9.11.1796048738026; Mon, 30 Nov 2026 06:25:38 -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: 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: 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