Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp462918rwr; Thu, 4 May 2023 05:46:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5MIrbvpQ4x00io3D4/sKBe6fCo5yVEGrXSZTi8ue6ElDpyPph0IN2VZLQEYT1M+qHX/T+T X-Received: by 2002:a05:6a20:918e:b0:ee:cc76:5023 with SMTP id v14-20020a056a20918e00b000eecc765023mr2307120pzd.22.1683204379888; Thu, 04 May 2023 05:46:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683204379; cv=none; d=google.com; s=arc-20160816; b=oBm1n0jYaYI+RG5zVDw76IYEOvtTit3YEFRsRd+N8y66JvlY5GEEmbMRSsuDndvTeB 6tq8gcpLW5b/zgqMrnteQKZG7ldFPtZyZr/7LJG4pUjurgjheqnAT1I4Ni3AxTWK1IsC lNn+i+uW8bsnkxEhR3aJ9uxfdM5is+1uV/d4ROoLMtQeKH2b0T33idfr7Y7LvmTfteYb M6gpOZ+wT/ySAbYL6fCwkftXouKHluVH5q2qkAAlnc8dSw1tQ6iY7bSC2OtaX0CKkexU g7fcEMSqB5Cw7sEb15vyV17x7QRV7/12zr7JkV9YuYKj1NVjE5mS2jGiDUkKwHA+wXgJ e4Ig== 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=cg/S6CffV/7p1WGKv2Maqy/rp1ZtmP3xYGneohx7AsI=; b=KEuVTuNDRcGE7PcUZYbGf6U5EioXc2ZJYV/W3D2g/hkxD4zK0aaFSglWnA9cMVOa1X E7SPbV167byc5BeG+qMNG0nYmYHvADQj6WOz0/r8tlUAa221XxQ0UrFyhtKtc50ks6D5 1dx7M+i0RQd7cUgXZrj5zdZYHxGh67SlL77HOUlp83Mvb9dEQuz5r3c5BCuNinzNZZ46 TZqewO1tDZFBfqan2kHdA1csANUv9fpru7PVy7WmRLKpSHfLVU/1A68jS5qbarm8BgFm qI1PdL1fWSNluOUE7mADNK+yACzv913iyxXD8iNDG9Beonk3uxtETDEIUXz989Azoesg YOjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XIARPh7g; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e20-20020aa79814000000b0064378bea76dsi2078526pfl.239.2023.05.04.05.46.06; Thu, 04 May 2023 05:46:19 -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=@redhat.com header.s=mimecast20190719 header.b=XIARPh7g; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230374AbjEDM0B (ORCPT + 99 others); Thu, 4 May 2023 08:26:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229606AbjEDM0A (ORCPT ); Thu, 4 May 2023 08:26:00 -0400 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 5171F5FFF for ; Thu, 4 May 2023 05:25:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683203113; 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=cg/S6CffV/7p1WGKv2Maqy/rp1ZtmP3xYGneohx7AsI=; b=XIARPh7geotbXY238UC+SDO0ySDleFPZTKu9tYqWDAOEh5mdb+9ZX+tUuES07AMhqhn9E+ G5i07qROZPu/QS15uM64GrlDfJLk5JmklFh//R7JtjUQVtoKXQAoUoJB3aJTYD/vvbUlJW F4mcdUP9EjUT/FZNC5AhL5tuzQeDLe4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-357-JdZLXvfJM6CqF1HsOnyd9Q-1; Thu, 04 May 2023 08:25:09 -0400 X-MC-Unique: JdZLXvfJM6CqF1HsOnyd9Q-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B06003C0D856; Thu, 4 May 2023 12:25:07 +0000 (UTC) Received: from fedora (unknown [10.22.9.13]) by smtp.corp.redhat.com (Postfix) with SMTP id 6B28C2026D16; Thu, 4 May 2023 12:25:00 +0000 (UTC) Date: Thu, 4 May 2023 09:24:59 -0300 From: Wander Lairson Costa To: Valentin Schneider Cc: Peter Zijlstra , 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 , "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: References: <20230425114307.36889-1-wander@redhat.com> <20230425114307.36889-3-wander@redhat.com> <20230504084229.GI1734100@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Thu, May 04, 2023 at 10:32:31AM +0100, Valentin Schneider wrote: > On 04/05/23 10:42, Peter Zijlstra wrote: > > 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. > > > > So on v3/v4 we got to doing that unconditionally for PREEMPT_RT, but per > [1] Wander went back to hand-fixing the problematic callsites. > > Now that I'm looking at it again, I couldn't find a concrete argument from > Oleg against doing this unconditionally - as Wander is pointing out in the > changelog and comments, reusing task_struct.rcu for that purpose is safe > (although not necessarily obviously so). > > Is this just miscommunication, or is there a genuine issue with doing this > unconditionally? As argued before, I'd also much rather have this be an > unconditional call_rcu() (regardless of context or PREEMPT_RT). > Yeah, I think it was a misunderstanding of mine.