Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2903752pxk; Sun, 6 Sep 2020 18:51:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK6bhwTZ01gMNL+UCatxxitD8xmGkieuruPR56dF/A/uO7zed/IwpCKE8Hxb6av8OY71e6 X-Received: by 2002:a17:906:fb8c:: with SMTP id lr12mr19954834ejb.9.1599443479862; Sun, 06 Sep 2020 18:51:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599443479; cv=none; d=google.com; s=arc-20160816; b=hcDkM0rh5edMQMLqHuBephR9oFLhnvaKBteHDdJ7K/ZYFDNonM2OU4MX9KK1a8MHdZ NPQRvjCcLeCJew3nBifNqXUrVuS0eAinqV89CU57UUeWxs2gJvd1HkIj/sbBsLeWjoUT KwKJMaEdnmUC2qKlUIapKv1nVnIJ+6fbTybjLQp/leJfc6WSENwKGnz/cFkg+8ahZheA XMcxsdzL9CJVSd74hJlpO9y30FoVfHS8TBuJeHlsKCZfmKqVzFpQyDdPINyc64fHEGeH Qj42jMPJn/HGI2CrOOEQrMCuF9puZRidq2r8OnPxGzU5zZJVZJrCPRfJ2wnE+/Zrv4fh DDvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=mGi/uEdwDsCEuKB8FRl/hlRZ1fj5tWz9+I1E4TWwnCU=; b=BkhlI8mTQckdibnP9+ZYL5Xow2mApS+R3da6zJ3B4XDsWVn6BViPBayrflzk2Yg0Mn Hj6erStzjNDuBn+wawJRUK/kAvL8+Spch7BIFV9rZ3PBhQPFmbL8Ifx07qTqVLHLzmhe MJt0pUNkxCvvuGl0Jj44xC/AIDNMQyzIKf8+cl/4agIZe+9MBXfarH5oAcL7hi9ZhemR E2S25z/SSNVLrvT+NYuq13AE7HokV9gEWDg/YUGxdrTdYKQxz2z29chn8UT7U85PfT+r 5LZMMf48hp3hVOSnl6yKbIvr8XYdzkhNbNrnM9Xo+H0dfJlDXWUYCU5dNJC4wNuSTqAG wgNQ== 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 t27si7268082edc.436.2020.09.06.18.50.57; Sun, 06 Sep 2020 18:51:19 -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 S1726314AbgIGBtY (ORCPT + 99 others); Sun, 6 Sep 2020 21:49:24 -0400 Received: from mx2.suse.de ([195.135.220.15]:51400 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725773AbgIGBtY (ORCPT ); Sun, 6 Sep 2020 21:49:24 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D978CAB91; Mon, 7 Sep 2020 01:49:22 +0000 (UTC) From: Davidlohr Bueso To: rostedt@goodmis.org Cc: mingo@kernel.org, oleg@redhat.com, linux-kernel@vger.kernel.org, dave@stgolabs.net, Davidlohr Bueso Subject: [PATCH] fgraph: Convert ret_stack tasklist scanning to rcu Date: Sun, 6 Sep 2020 18:33:26 -0700 Message-Id: <20200907013326.9870-1-dave@stgolabs.net> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It seems that alloc_retstack_tasklist() can also take a lockless approach for scanning the tasklist, instead of using the big global tasklist_lock. For this we also kill another deprecated and rcu-unsafe tsk->thread_group user replacing it with for_each_process_thread(), maintaining semantics. 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. The tsk->ret_stack management is not protected by tasklist_lock, being serialized with the corresponding publish/subscribe barriers against concurrent ftrace_push_return_trace(). In addition this plays nicer with cachelines by avoiding two atomic ops in the uncontended case. Signed-off-by: Davidlohr Bueso --- kernel/trace/fgraph.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index 1af321dec0f1..5658f13037b3 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -387,8 +387,8 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list) } } - read_lock(&tasklist_lock); - do_each_thread(g, t) { + rcu_read_lock(); + for_each_process_thread(g, t) { if (start == end) { ret = -EAGAIN; goto unlock; @@ -403,10 +403,10 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list) smp_wmb(); t->ret_stack = ret_stack_list[start++]; } - } while_each_thread(g, t); + } unlock: - read_unlock(&tasklist_lock); + rcu_read_unlock(); free: for (i = start; i < end; i++) kfree(ret_stack_list[i]); -- 2.26.2