Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp226499rwr; Thu, 4 May 2023 01:56:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Ra+O4wAPkZjzyDITrFsrz8DJk2yrgeOgzPy3BbQVtsVxg/ItvIut6NHO5LTXbmtYYldwU X-Received: by 2002:a17:90b:230e:b0:246:5f9e:e4cf with SMTP id mt14-20020a17090b230e00b002465f9ee4cfmr1354426pjb.43.1683190609294; Thu, 04 May 2023 01:56:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683190609; cv=none; d=google.com; s=arc-20160816; b=EcDsua27akuziT7zD7Snit5ZRd1y6A6h5WEoGzn6vCOCXZKb06j6fcKlCqYB81Yzuj /3iu0d8/+S9hNc8EvEuIG8V0IaexI816BVPp3hCblOU2w8l3VHMxfTMsAYb4SavwY4JW bLg9k5VtCX9BX0+8703XttvHquLXX24bYl+0Qq4+2OZ3QfrrzVVjQHkfIEn3YsXMdTA8 eK48N5xhpYn9vmanxo+vOxcgcj4ImZqaxZgHejNCTKRmWUIhnQudfVwvCps7j8LB+67B WLJfRJP3wPIJ83lIlcVUlW1zIigsQFpt0el6N4hPdrZG6643+3f5+vihtxpDlHtQPEGe CC8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=A7O/KcuuPv1NDPSd7/lkTSPyE9V7WRyc8ePThK7wq/A=; b=iwwwZ1r2L0xS6sUFbtfJH+uc6vWn80rVYjz+ZPS1axJW9j60y0r9M4srCuSOmGzFEm e0K+fHj0hxbagn4qd5KB4Y0W2aN7Khf04B2UFZsA5BYbQCMDW1roRXdwSDOYXf+IoToe JNnk9NOyEkQrNxTtaVeja9zgiBovFBKHUPPu1TvjChkDlVq2sQ/XeRYH8957jyGLSyH2 mnk8PAa7DkjvVLxpYnBSaPpyNBKypDpARsrF8OzhLfsVii9oKQaxB57kjuo3o0XGChXJ IomuHsBIVRfme54Z1d3FsuvLzL1cjvPsbshsmE5P6KVMSVavjHlDDmR4LHwTfSgWP/bw BB5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=mxyKF1Pr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q35-20020a631f63000000b0052c22753de4si9015044pgm.662.2023.05.04.01.56.37; Thu, 04 May 2023 01:56:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=mxyKF1Pr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229940AbjEDIna (ORCPT + 99 others); Thu, 4 May 2023 04:43:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229675AbjEDIn3 (ORCPT ); Thu, 4 May 2023 04:43:29 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FBEB90; Thu, 4 May 2023 01:43:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=A7O/KcuuPv1NDPSd7/lkTSPyE9V7WRyc8ePThK7wq/A=; b=mxyKF1PrnMqIYWnEYkfWMTJPXp r8MXIoM6sdXuPMgydTjDpjke6rYEHM8LJxSeRTx+YyrRZnNez/rA1wfqBo/1nVcChGRqTCUQsaOKC c0JZS9Cl0L6VtL2ZWxLyqAd+UltHjaIdNo8HnDibOL7ga6KBqyhE7YTGvphdikQeqeE5ZnJGjzWUe 2+ClryzP5Uhi4E7z4HP/UdPMfjPZAfIrDojqgiSJGHpmU9oKkIlJPttZ8C6kGVYyu82v++v8VDhVp DiovOrXuJQWZyAavjxj2M4UNcQcrolh1NWUuJ7CCbgHvjAQZMNRAV3J4KjktdhvFL1OUR2WQkMhM4 hN4UGwLA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1puUXq-00APp4-6q; Thu, 04 May 2023 08:42:34 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id DE43A302DAA; Thu, 4 May 2023 10:42:29 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 9C4312111BE00; Thu, 4 May 2023 10:42:29 +0200 (CEST) Date: Thu, 4 May 2023 10:42:29 +0200 From: Peter Zijlstra To: Wander Lairson Costa Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Will Deacon , Waiman Long , Boqun Feng , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , "Eric W. Biederman" , Oleg Nesterov , Brian Cain , Kefeng Wang , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Christian Brauner , Andrei Vagin , Shakeel Butt , open list , "open list:PERFORMANCE EVENTS SUBSYSTEM" , Hu Chunyu , Paul McKenney , Thomas Gleixner Subject: Re: [PATCH v7 2/3] sched/task: Add the put_task_struct_atomic_safe() function Message-ID: <20230504084229.GI1734100@hirez.programming.kicks-ass.net> References: <20230425114307.36889-1-wander@redhat.com> <20230425114307.36889-3-wander@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230425114307.36889-3-wander@redhat.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 25, 2023 at 08:43:02AM -0300, Wander Lairson Costa wrote: > diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h > index b597b97b1f8f..cf774b83b2ec 100644 > --- a/include/linux/sched/task.h > +++ b/include/linux/sched/task.h > @@ -141,6 +141,41 @@ static inline void put_task_struct_many(struct task_struct *t, int nr) > > void put_task_struct_rcu_user(struct task_struct *task); > > +extern void __delayed_put_task_struct(struct rcu_head *rhp); > + > +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() will schedule __delayed_put_task_struct() > + * to be called in process context. > + * > + * __put_task_struct() is called when > + * refcount_dec_and_test(&t->usage) succeeds. > + * > + * This means that it can't conflict with > + * put_task_struct_rcu_user() which abuses ->rcu the same > + * way; rcu_users has a reference so task->usage can't be > + * zero after rcu_users 1 -> 0 transition. > + * > + * 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(). > + */ > + call_rcu(&task->rcu, __delayed_put_task_struct); > + } else { > + put_task_struct(task); > + } > +} Urgh.. that's plenty horrible. And I'm sure everybody plus kitchen sink has already asked why can't we just rcu free the thing unconditionally. Google only found me an earlier version of this same patch set, but I'm sure we've had that discussion many times over the past several years. The above and your follow up patch is just horrible. It requires users to know the RT specific context and gives them no help what so ever for !RT builds.