Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 685E8C05027 for ; Mon, 23 Jan 2023 16:31:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232516AbjAWQbS (ORCPT ); Mon, 23 Jan 2023 11:31:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231724AbjAWQbP (ORCPT ); Mon, 23 Jan 2023 11:31:15 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0264265BF for ; Mon, 23 Jan 2023 08:30:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674491418; 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=C4WFf0qCjoISjlbl9oDJUT+rYiaHBgzm+Nne34laQe4=; b=Og1MInjk0PHZMwjERiJmR9v4eUmuTzjjNtxgLQ5khxeErNrc2az+uqQXwv4cSnp25ZUpXA C7H0ArvSMCjiJvnz0jcoAGKNviV/gUTmvIODmytn8IbV4BpQXGjoRBXyA0T8Ldp1EqPSzx kR/G6MRUokGlMrHVtN+zh7DijUJpCEU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-361-aSyTRqDuNSmd_Tw2901ykQ-1; Mon, 23 Jan 2023 11:30:13 -0500 X-MC-Unique: aSyTRqDuNSmd_Tw2901ykQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AA7CC857A85; Mon, 23 Jan 2023 16:30:11 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (ovpn-192-224.brq.redhat.com [10.40.192.224]) by smtp.corp.redhat.com (Postfix) with SMTP id 91C201121333; Mon, 23 Jan 2023 16:30:06 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Mon, 23 Jan 2023 17:30:09 +0100 (CET) Date: Mon, 23 Jan 2023 17:30:03 +0100 From: Oleg Nesterov To: Wander Lairson Costa Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , "Eric W. Biederman" , Stafford Horne , Kefeng Wang , Andrew Morton , Thomas Gleixner , Sebastian Andrzej Siewior , Andy Lutomirski , "Liam R. Howlett" , Fenghua Yu , Andrei Vagin , open list , Paul McKenney Subject: Re: [PATCH v2 1/4] sched/task: Add the put_task_struct_atomic_safe function Message-ID: <20230123163002.GB6268@redhat.com> References: <20230120150246.20797-1-wander@redhat.com> <20230120150246.20797-2-wander@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230120150246.20797-2-wander@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/20, Wander Lairson Costa wrote: > > +static inline void put_task_struct_atomic_safe(struct task_struct *task) > +{ > + if (IS_ENABLED(CONFIG_PREEMPT_RT)) { > + /* > + * Decrement the refcount explicitly to avoid unnecessarily > + * calling call_rcu. > + */ > + if (refcount_dec_and_test(&task->usage)) > + /* > + * under PREEMPT_RT, we can't call put_task_struct > + * in atomic context because it will indirectly > + * acquire sleeping locks. > + */ > + call_rcu(&task->rcu, __delayed_put_task_struct); ^^^^^^^^^ I am not sure the usage of task->rcu is safe... Suppose that, before __delayed_put_task_struct() is called by RCU, this task does the last schedule and calls put_task_struct_rcu_user(). And, can't we simply turn put_task_struct() into something like put_task_struct(struct task_struct *t) { if (refcount_dec_and_test(&t->usage)) { if (IS_ENABLED(CONFIG_PREEMPT_RT) && (in_atomic() || irqs_disabled())) call_rcu(...); else __put_task_struct(t); } } ? Oleg.