Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8124536imu; Tue, 4 Dec 2018 03:25:38 -0800 (PST) X-Google-Smtp-Source: AFSGD/XP2RD0gCKoVMLgEiW2NzPwxrhO0InDoOJHt2vxgE7/Zu6C6Nm5jBMAapwTrjmXs7Q1LfG7 X-Received: by 2002:a62:26c7:: with SMTP id m190mr20043890pfm.79.1543922738604; Tue, 04 Dec 2018 03:25:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543922738; cv=none; d=google.com; s=arc-20160816; b=Vji08RIphhIuq1RByrAn3UfQnc/Ji5qKlJddjAj+yPY6go79Zc1O/V5oQu0aXzWT/k 5HuvGiUIeZ1vploY9FU5Z0SRdL5ouBv81lvgZcECAj5pIrXCe5HjWQuepuU7qO+ruDjB zh+4oRUhG6bQ83kXd87Nv9rHLR2dLPkWvRGXZYDwfATwgWNMUjZn+xoixpjXM/jcJ4Gz RK4rAlcsPVHsVfwcfEdmnzzN8HqSgtHXMXATq4wYqus5HSBCD9B31zDHAvuoHClXb5Er i72IzVJ5hbpAcydrIbRMWuIxpXa2cz4GcMPizqldM/suGPOJGvgvofby8PEm01e/MLfL 3thA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BZvcKqwhtlA1UJk4VUvzMrpOF4hs63UQK9Ml/2lvMpw=; b=a4Iks9+FFmzZYgrMFSoxwOl+6d2/lJ7tnPMNQWpu/pxFgQVjIpiS7U78AbaZu0U0Y3 FOnjL4LG25tzIymlJFjKCgSnsyOSdCtjubG29V7DdvU5JqaopmvQVsMzijJ79wubdsM1 go7uSx6XDMwImc2kzX52mnrU1hcg7BnWkV29Pyw0uAqFG2L9xqrRampEajc1uK4rLMTv uf8YzQq7AEhYpcaQtWPAgYorgOVXT+9oKgIu+pLTbU4LkK1pZUB/7mNmi4RIC7lbuSEN +1fmHur3K5KV57JdlI2oY4YZivYek/gZ/VZeiVcQJGP07IxpdCm4gdVxB/lGBDbJTyIl C0Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SolievR+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a195si19126648pfd.143.2018.12.04.03.25.23; Tue, 04 Dec 2018 03:25:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SolievR+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727408AbeLDLA7 (ORCPT + 99 others); Tue, 4 Dec 2018 06:00:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:46332 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727029AbeLDLA5 (ORCPT ); Tue, 4 Dec 2018 06:00:57 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 8EB4C214C1; Tue, 4 Dec 2018 11:00:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921257; bh=kiKN8juHzsOtpLvErzq1OqBEv5xMBxqSuBMzf0v/XLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SolievR+Yb0kpxVZHGkcRUi2enxgIWb2uJi57mv9434KbAAZ181u3Smw8VyHaHjE5 ik9ECp09bsg3sQMJtgVdpI8XvsZ320YFL2yOHn+6JuTZy7cj6V9BtACTT45KUr6JsY prCeRr2QuI/dysikP4GuvWCGJEudJT8XmBURAfGU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Masami Hiramatsu , "Steven Rostedt (VMware)" Subject: [PATCH 4.19 115/139] function_graph: Reverse the order of pushing the ret_stack and the callback Date: Tue, 4 Dec 2018 11:49:56 +0100 Message-Id: <20181204103655.349825042@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204103649.950154335@linuxfoundation.org> References: <20181204103649.950154335@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Steven Rostedt (VMware) commit 7c6ea35ef50810aa12ab26f21cb858d980881576 upstream. The function graph profiler uses the ret_stack to store the "subtime" and reuse it by nested functions and also on the return. But the current logic has the profiler callback called before the ret_stack is updated, and it is just modifying the ret_stack that will later be allocated (it's just lucky that the "subtime" is not touched when it is allocated). This could also cause a crash if we are at the end of the ret_stack when this happens. By reversing the order of the allocating the ret_stack and then calling the callbacks attached to a function being traced, the ret_stack entry is no longer used before it is allocated. Cc: stable@kernel.org Fixes: 03274a3ffb449 ("tracing/fgraph: Adjust fgraph depth before calling trace return callback") Reviewed-by: Masami Hiramatsu Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace_functions_graph.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c @@ -188,15 +188,17 @@ int function_graph_enter(unsigned long r trace.func = func; trace.depth = ++current->curr_ret_depth; - /* Only trace if the calling function expects to */ - if (!ftrace_graph_entry(&trace)) - goto out; - if (ftrace_push_return_trace(ret, func, frame_pointer, retp)) goto out; + /* Only trace if the calling function expects to */ + if (!ftrace_graph_entry(&trace)) + goto out_ret; + return 0; + out_ret: + current->curr_ret_stack--; out: current->curr_ret_depth--; return -EBUSY;