From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 748FB245022 for ; Mon, 12 May 2025 18:48:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747075727; cv=none; b=BetPZe0kZCGn8toAn8ErLT7wE56CNr7s1DJeDy78kDclHVGbiDgTnmLXdfGOjzjK2yHoS7vLXvc6bDKEYXEV64RIRbCjtIeaPGZKMtdlERi4154MoBh/yseCov5XI8Zbv3g25Rc40K1x3wFE3rYBuJTdXnSZyVuRK5PmEtcZcDs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747075727; c=relaxed/simple; bh=mI5i/GImq1ZnUQr2ekI8bE0fqAimP+Wb8ALeMzLg/18=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nTkPMVTHlfdzAP/kkDQHIvtNx3gTQwhrokh1r4WDrnu8NBMvyxmrpbfhjoe+xBxmnNh8Jg8UsCXicZvgs2TTyRIDA3npAgQVmKigfppwsFf7F5wcIMj91M8hkEbtk8LPug0T+Psn5MNJWOb9M8B1pyfQPL9mIqb8D68pIdyuYPM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=doW6AABL; arc=none smtp.client-ip=170.10.133.124 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.b="doW6AABL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747075724; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Fe+TIk6WVks6ABD04kvwmyFaFFWKImSpZeKv17rlzew=; b=doW6AABL3/76+/zpbqROKNf6rrwbZgCSQvpBxnksNb1CWvUVrNEW3D+I2ppMXPrP/PjBe6 LQkcApLI+MmUA3h+eQ10N7U1l4Wm62CZec8QJgyl8jzWoeVtIModYaNO3fUarAp8J5XQTb TVeKZ/N8Dbf+hIWLus5e+EUcQtDppq8= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-500-bYtFZULYN7OX6-Mi1X5-dg-1; Mon, 12 May 2025 14:48:39 -0400 X-MC-Unique: bYtFZULYN7OX6-Mi1X5-dg-1 X-Mimecast-MFC-AGG-ID: bYtFZULYN7OX6-Mi1X5-dg_1747075716 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4846C1955BED; Mon, 12 May 2025 18:48:36 +0000 (UTC) Received: from localhost (unknown [10.22.80.42]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F3D7918001DA; Mon, 12 May 2025 18:48:34 +0000 (UTC) Date: Mon, 12 May 2025 15:48:33 -0300 From: "Luis Claudio R. Goncalves" To: Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Tejun Heo , David Vernet , Barret Rhoden , Josh Don , Crystal Wood , linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, Juri Lelli , Ben Segall , Dietmar Eggemann , Ingo Molnar , Mel Gorman , Peter Zijlstra , Valentin Schneider , Vincent Guittot , Thomas Gleixner Subject: Re: [PATCH v4] sched: do not call __put_task_struct() on rt if pi_blocked_on is set Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 On Thu, Apr 10, 2025 at 03:19:28PM -0300, Luis Claudio R. Goncalves wrote: > With PREEMPT_RT enabled, some of the calls to put_task_struct() coming > from rt_mutex_adjust_prio_chain() could happen in preemptible context and > with a mutex enqueued. That could lead to this sequence: > > rt_mutex_adjust_prio_chain() > put_task_struct() > __put_task_struct() > sched_ext_free() > spin_lock_irqsave() > rtlock_lock() ---> TRIGGERS > lockdep_assert(!current->pi_blocked_on); > > Fix that by unconditionally resorting to the deferred call to > __put_task_struct() if PREEMPT_RT is enabled. Peter, Sebastian, Is this patch acceptable as is or do you think I should rework something? Best regards, Luis > Suggested-by: Crystal Wood > Signed-off-by: Luis Claudio R. Goncalves > --- > > v2: (Rostedt) remove the #ifdef from put_task_struct() and create > tsk_is_pi_blocked_on() in sched.h to make the change cleaner. > v3: (Sebastian, PeterZ) always call the deferred __put_task_struct() on RT. > v4: Fix the implementation of what was requested on v3. > > include/linux/sched/task.h | 17 ++++++++--------- > 1 file changed, 8 insertions(+), 9 deletions(-) > > diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h > index 0f2aeb37bbb04..51678a541477a 100644 > --- a/include/linux/sched/task.h > +++ b/include/linux/sched/task.h > @@ -134,11 +134,8 @@ static inline void put_task_struct(struct task_struct *t) > if (!refcount_dec_and_test(&t->usage)) > return; > > - /* > - * In !RT, it is always safe to call __put_task_struct(). > - * Under RT, we can only call it in preemptible context. > - */ > - if (!IS_ENABLED(CONFIG_PREEMPT_RT) || preemptible()) { > + /* In !RT, it is always safe to call __put_task_struct(). */ > + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) { > static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_SLEEP); > > lock_map_acquire_try(&put_task_map); > @@ -148,11 +145,13 @@ static inline void put_task_struct(struct task_struct *t) > } > > /* > - * under PREEMPT_RT, we can't call put_task_struct > + * Under PREEMPT_RT, we can't call __put_task_struct > * in atomic context because it will indirectly > - * acquire sleeping locks. > + * acquire sleeping locks. The same is true if the > + * current process has a mutex enqueued (blocked on > + * a PI chain). > * > - * call_rcu() will schedule delayed_put_task_struct_rcu() > + * call_rcu() will schedule __put_task_struct_rcu_cb() > * to be called in process context. > * > * __put_task_struct() is called when > @@ -165,7 +164,7 @@ static inline void put_task_struct(struct task_struct *t) > * > * delayed_free_task() also uses ->rcu, but it is only called > * when it fails to fork a process. Therefore, there is no > - * way it can conflict with put_task_struct(). > + * way it can conflict with __put_task_struct(). > */ > call_rcu(&t->rcu, __put_task_struct_rcu_cb); > } > ---end quoted text---