Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1356441pxk; Fri, 18 Sep 2020 10:13:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDXCs2oPkdZ6oQ0isqO7uWRKsFAzto6yzyNsHFUHHQPRxXa4PMR72zhVmirYe5MvwagE1a X-Received: by 2002:a17:906:cf9b:: with SMTP id um27mr37246765ejb.66.1600449232571; Fri, 18 Sep 2020 10:13:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600449232; cv=none; d=google.com; s=arc-20160816; b=pVc7QdW8AgbdXO5i0dq3cXFFNbxMxxBraAORENlVJZKrXLOQeDKEd/w3ylKJX6BG2r 443vsYA+DB0vWf6d4cIBWx6ggQOsEGM+kJOpAd3WU2KEB0wCbOnEecWhfBKTGGvhi2od Nle+20yctRsh1EDu9TV47GA0fx1fkFGoOs1M5NaREVDyotUfvx/UtHzqBtG8UkhYK186 stayf8mf3zxe8yAxGCH8CKPJz7mCNnc4R0sYnbIVwipE9qitQdYE/UbmmOD+CqPasWE+ GFElZp/8Tr1nK+ogrzbugn1gHn7OPocthpWQJkPZOHwXHXgMbpdIcreIIb5klTrSVxZj IhKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=4G1WegF8gq5vdcSogj9DwYdH7NFVLqcYGXn/5t9DVWY=; b=LtNuGbnGuE0qZBD2p8vJzbT3e/6YmtckwGN+6Y5PJNgjkWHhDkrno6LrlNrGZkrADp NMl8LKyzbWlzULaoSmLp0MALEOZpeVI9NeohRi1aBOsJDYvI7U1OUDkzopsAQ5IhmGTK UhD0ebf/spU3cUQ5hHTRlHe3vH2oJnLkgOdMr3yk5I9mxz8ymouVWg/eRg5GuP6C4kQK ogHfogV8lATllDUBfBMXtfhgR9MM+fQlRUTG401aYWn33NSaWgyKQh7gHnQfYB7DE9Fr BBP35qH+tEllUdIGitUoa2LhOvwy2rePQwZDRHm4+0KHU4Zh5jzCvCEpsZoGRsO7japE v0HQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o15si2639623ejb.225.2020.09.18.10.13.28; Fri, 18 Sep 2020 10:13:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726159AbgIRRME (ORCPT + 99 others); Fri, 18 Sep 2020 13:12:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:33494 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725941AbgIRRME (ORCPT ); Fri, 18 Sep 2020 13:12:04 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 24ED2206A2; Fri, 18 Sep 2020 17:12:03 +0000 (UTC) Date: Fri, 18 Sep 2020 13:12:01 -0400 From: Steven Rostedt To: Oleg Nesterov Cc: Davidlohr Bueso , mingo@kernel.org, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: Re: [PATCH] fgraph: Convert ret_stack tasklist scanning to rcu Message-ID: <20200918131201.53b894b4@gandalf.local.home> In-Reply-To: <20200907114301.GA31050@redhat.com> References: <20200907013326.9870-1-dave@stgolabs.net> <20200907114301.GA31050@redhat.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Back from my PTO and still digging out emails ] On Mon, 7 Sep 2020 13:43:02 +0200 Oleg Nesterov wrote: > On 09/06, Davidlohr Bueso wrote: > > > > Here tasklist_lock does not protect anything other than the list > > against concurrent fork/exit. And considering that the whole thing > > is capped by FTRACE_RETSTACK_ALLOC_SIZE (32), it should not be a > > problem to have a pontentially stale, yet stable, list. The task cannot > > go away either, so we don't risk racing with ftrace_graph_exit_task() > > which clears the retstack. > > I don't understand this code but I think you right, tasklist_lock buys > nothing. When I first wrote this code, I didn't want to take tasklist_lock, but there was questions if rcu_read_lock() was enough. And since this code is far from a fast path, I decided it was better to be safe than sorry, and took the tasklist_lock as a paranoid measure. > > Afaics, with or without this change alloc_retstack_tasklist() can race > with copy_process() and miss the new child; ftrace_graph_init_task() > can't help, ftrace_graph_active can be set right after the check and > for_each_process_thread() can't see the new process yet. There's a call in copy_process(): ftrace_graph_init_task() that initializes a new tasks ret_stack, and this loop will ignore it because it first checks to see if the task has a ret_stack before adding one to it. And the child gets one before being added to the list. > > This can't race with ftrace_graph_exit_task(), it is called after the > full gp pass. But this function looks very confusing to me, I don't > understand the barrier and the "NULL must become visible to IRQs before > we free it" comment. Probably not needed, but again, being very paranoid, as to not crash anything. If this is called on a task that is running, and an interrupt comes in after it is freed, but before the ret_stack variable is set to NULL, then it will try to use it. I don't think this is possible, but it may have been in the past. > > Looks like, ftrace_graph_exit_task() was called by the exiting task > in the past? Indeed, see 65afa5e603d50 ("tracing/function-return-tracer: > free the return stack on free_task()"). I think it makes sense to > simplify this function now, it can simply do kfree(t->ret_stack) and > nothing more. Ah, yeah, then you are right. If it can't be called on a running task then it can be simplified. Probably need a: WARN_ON_ONCE(t->on_rq); just to make sure this never happens. > > ACK, but ... > > > @@ -387,8 +387,8 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list) > > } > > } > > > > - read_lock(&tasklist_lock); > > then you should probably rename alloc_retstack_tasklist() ? > tasklist, process thead? Is there a difference? Thanks for reviewing this! -- Steve