Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8124698imu; Tue, 4 Dec 2018 03:25:50 -0800 (PST) X-Google-Smtp-Source: AFSGD/UaKlSmUd9bpPBVCj4IMInUGp++yLZvnSjE62jAoMaSwj4rb0rG+i1KaG0utWwy35ZW+WQL X-Received: by 2002:a63:5b48:: with SMTP id l8mr16592183pgm.80.1543922750761; Tue, 04 Dec 2018 03:25:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543922750; cv=none; d=google.com; s=arc-20160816; b=mqbnaApozY3Z2EmOQl6PheeHaOISaWHKSqiGa6RJYZvC5KhkNaGC6fOEWIaB8P4pMH I4vm+OGEANzVi3HOtxShB2/ay4B1Abv2JSpncoHLNC3E7Pn0qx9ZnDS23L5rj5DIWNv0 XZY9SeiOWmrI3vZxYLOu0pAWEHoMK4iL5xMVJRg8Q6hO04KiKo/ZF32VlrF+z4mfxfZe ZVGCiKA2rOm61hIRRxXungNjK/NlYCzHIMyZpQe617GGDxz+DaPeupUfN3d2pEMaBCHR aDvyFHggqvgbRH0A/EeUHXzBMBnP12CGJ9h9p1s/p/aFs1T/E60+lovkQRW+gAqogURC PxuA== 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=eZTII1R0ImLPNkxRk7vpg2GJcYtO/mBWk8N27mzL/KE=; b=T5NYe26evbwSbIJitEGaB6lZp63O1OLtKEMSF1UJUV0dzoNHCiX+6btki8J5cSalSP tXQukvSWxXLgoW9G2vHBqDstRwn1A8HMz//Gk9d+azd0muZQK4Xrjn9Ofbvi3LIZvrF8 lleQ7P7t0/BU+uJHFba4+r96qBa9i2LShNj6M1yVNpIvV020qFPyAkqSLLTXcbD9rYBK gdtoV+SOf/pM1n7l5daNl/iXe/6UpSB/HdLGB/+p6yOC9JWQ6PgCzqQlgp079cAJpqTb 9PkjQawYD5dAfHSH/7/7pXFB6wY1grDkJdnxmh4OgWdbUp91CVQEzHXlNSKhhQkhMY2Q B8Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rYRX2EjT; 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 g21si16336579plo.435.2018.12.04.03.25.35; Tue, 04 Dec 2018 03:25:50 -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=rYRX2EjT; 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 S1727022AbeLDLZA (ORCPT + 99 others); Tue, 4 Dec 2018 06:25:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:46296 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727000AbeLDLAz (ORCPT ); Tue, 4 Dec 2018 06:00:55 -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 F1D49214DA; Tue, 4 Dec 2018 11:00:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921254; bh=CLhMEYKS/c3Vm4RCRhIOOGXfyDFPMmrmnE662oN1uIM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rYRX2EjToPY5/uZLdmQMLTR4PVmOrnLVg8kNr9xo25HbiACeSz6zAOXFFsghanW50 mr4SMqs4Kt03CQT34Nhnf4GLf9J6d5yRxjYmAzhey1F9ATq4eV5QbgUstp8EFyvcuw Di1PGvzhtz2bfukgDtc+DA1tcFmdUMI+FjBhMCuk= 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 114/139] function_graph: Move return callback before update of curr_ret_stack Date: Tue, 4 Dec 2018 11:49:55 +0100 Message-Id: <20181204103655.307040607@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 552701dd0fa7c3d448142e87210590ba424694a0 upstream. In the past, curr_ret_stack had two functions. One was to denote the depth of the call graph, the other is to keep track of where on the ret_stack the data is used. Although they may be slightly related, there are two cases where they need to be used differently. The one case is that it keeps the ret_stack data from being corrupted by an interrupt coming in and overwriting the data still in use. The other is just to know where the depth of the stack currently is. The function profiler uses the ret_stack to save a "subtime" variable that is part of the data on the ret_stack. If curr_ret_stack is modified too early, then this variable can be corrupted. The "max_depth" option, when set to 1, will record the first functions going into the kernel. To see all top functions (when dealing with timings), the depth variable needs to be lowered before calling the return hook. But by lowering the curr_ret_stack, it makes the data on the ret_stack still being used by the return hook susceptible to being overwritten. Now that there's two variables to handle both cases (curr_ret_depth), we can move them to the locations where they can handle both cases. 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 | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c @@ -261,7 +261,13 @@ ftrace_pop_return_trace(struct ftrace_gr trace->func = current->ret_stack[index].func; trace->calltime = current->ret_stack[index].calltime; trace->overrun = atomic_read(¤t->trace_overrun); - trace->depth = current->curr_ret_depth; + trace->depth = current->curr_ret_depth--; + /* + * We still want to trace interrupts coming in if + * max_depth is set to 1. Make sure the decrement is + * seen before ftrace_graph_return. + */ + barrier(); } /* @@ -275,9 +281,14 @@ unsigned long ftrace_return_to_handler(u ftrace_pop_return_trace(&trace, &ret, frame_pointer); trace.rettime = trace_clock_local(); + ftrace_graph_return(&trace); + /* + * The ftrace_graph_return() may still access the current + * ret_stack structure, we need to make sure the update of + * curr_ret_stack is after that. + */ barrier(); current->curr_ret_stack--; - current->curr_ret_depth--; /* * The curr_ret_stack can be less than -1 only if it was * filtered out and it's about to return from the function. @@ -288,13 +299,6 @@ unsigned long ftrace_return_to_handler(u return ret; } - /* - * The trace should run after decrementing the ret counter - * in case an interrupt were to come in. We don't want to - * lose the interrupt if max_depth is set. - */ - ftrace_graph_return(&trace); - if (unlikely(!ret)) { ftrace_graph_stop(); WARN_ON(1);