Received: by 10.223.176.46 with SMTP id f43csp2675217wra; Mon, 22 Jan 2018 01:21:55 -0800 (PST) X-Google-Smtp-Source: AH8x2278O0zmTulk+P5RyTCnza0kQ3XakOR8qPwbkrSLvqshE7WooaIKVpeWbDvQLUFbU8iv4L2T X-Received: by 2002:a17:902:1e5:: with SMTP id b92-v6mr2832634plb.144.1516612915826; Mon, 22 Jan 2018 01:21:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516612915; cv=none; d=google.com; s=arc-20160816; b=teBNxysiRtE6khqIfW4yEVDI8+II1nIPwYpazl57V1fzgiUehXJaipvxnn7EU0v5WT wdGqjJhkLQXw2WvcQTJGSD5R3qiAHXppmrEpTe+JNNV8JIuQfiKqhwzhC+vQwFJ4LmTS fUniilF/mkTfLm+GGf4o1OBAVJFvF/BZRF9LZKsWY98hcbxENJUYnJMEGEwW+qgiExjW 7ktnlSWqQhZX9Mj7WVuX3RazxzO+A5oyAK4xwnwPR7bhiDgo/v5Gq8S+oqGvf2wMeKEl whdFATZcXvPdLIhF9FGn8h82TXEc8emM6QU6pi/usZ6u5q2YqEQRWq2W0RyWzkbB/Mg+ 4URw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=7HOkd4hrtFdQ/Li/iq+aolURBnwL6zJcZfJ7pVGUwDo=; b=DyKeBDLuqIMtmkDli8KHt6zWuYYJdc9y4r3SWqVBYQNDPerH3LP3D0lEf6z8oj3o9D 8CDkYbQqH0rDyponLOnEmapt6QlXe30F5jz/nksfTmWaffR7moq9Y7kB/T0o1PFNPaIF RKZnADvP3xMZagNYuHn1O/WtyNWO6JqCN29wTLqF1LtiYSHDabcVjsn+wR+eNs/V2EdF ZPY5SL18gjY0bIWsi+mGdGOzwg5oSqy7cVheloWmq8dc41TWrFzSp+CoDPxqgw9j81qb a4aIM3k+RXTprFtxt3p0vnyfq2BfRnZx/jTCryn24+H5/DB11S1h5e+nKnr+kj9pgjlk Lu/g== ARC-Authentication-Results: i=1; mx.google.com; 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 p71si14994836pfi.105.2018.01.22.01.21.41; Mon, 22 Jan 2018 01:21:55 -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; 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 S1751851AbeAVIuP (ORCPT + 99 others); Mon, 22 Jan 2018 03:50:15 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:60870 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751091AbeAVIuN (ORCPT ); Mon, 22 Jan 2018 03:50:13 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id EDE0C8F5; Mon, 22 Jan 2018 08:50:12 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chuck Lever , "Steven Rostedt (VMware)" Subject: [PATCH 4.9 28/47] tracing: Fix converting enums from the map in trace_event_eval_update() Date: Mon, 22 Jan 2018 09:45:39 +0100 Message-Id: <20180122083927.664966699@linuxfoundation.org> X-Mailer: git-send-email 2.16.0 In-Reply-To: <20180122083925.568134913@linuxfoundation.org> References: <20180122083925.568134913@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Steven Rostedt (VMware) commit 1ebe1eaf2f02784921759992ae1fde1a9bec8fd0 upstream. Since enums do not get converted by the TRACE_EVENT macro into their values, the event format displaces the enum name and not the value. This breaks tools like perf and trace-cmd that need to interpret the raw binary data. To solve this, an enum map was created to convert these enums into their actual numbers on boot up. This is done by TRACE_EVENTS() adding a TRACE_DEFINE_ENUM() macro. Some enums were not being converted. This was caused by an optization that had a bug in it. All calls get checked against this enum map to see if it should be converted or not, and it compares the call's system to the system that the enum map was created under. If they match, then they call is processed. To cut down on the number of iterations needed to find the maps with a matching system, since calls and maps are grouped by system, when a match is made, the index into the map array is saved, so that the next call, if it belongs to the same system as the previous call, could start right at that array index and not have to scan all the previous arrays. The problem was, the saved index was used as the variable to know if this is a call in a new system or not. If the index was zero, it was assumed that the call is in a new system and would keep incrementing the saved index until it found a matching system. The issue arises when the first matching system was at index zero. The next map, if it belonged to the same system, would then think it was the first match and increment the index to one. If the next call belong to the same system, it would begin its search of the maps off by one, and miss the first enum that should be converted. This left a single enum not converted properly. Also add a comment to describe exactly what that index was for. It took me a bit too long to figure out what I was thinking when debugging this issue. Link: http://lkml.kernel.org/r/717BE572-2070-4C1E-9902-9F2E0FEDA4F8@oracle.com Fixes: 0c564a538aa93 ("tracing: Add TRACE_DEFINE_ENUM() macro to map enums to their values") Reported-by: Chuck Lever Teste-by: Chuck Lever Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace_events.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -2200,6 +2200,7 @@ void trace_event_enum_update(struct trac { struct trace_event_call *call, *p; const char *last_system = NULL; + bool first = false; int last_i; int i; @@ -2207,15 +2208,28 @@ void trace_event_enum_update(struct trac list_for_each_entry_safe(call, p, &ftrace_events, list) { /* events are usually grouped together with systems */ if (!last_system || call->class->system != last_system) { + first = true; last_i = 0; last_system = call->class->system; } + /* + * Since calls are grouped by systems, the likelyhood that the + * next call in the iteration belongs to the same system as the + * previous call is high. As an optimization, we skip seaching + * for a map[] that matches the call's system if the last call + * was from the same system. That's what last_i is for. If the + * call has the same system as the previous call, then last_i + * will be the index of the first map[] that has a matching + * system. + */ for (i = last_i; i < len; i++) { if (call->class->system == map[i]->system) { /* Save the first system if need be */ - if (!last_i) + if (first) { last_i = i; + first = false; + } update_event_printk(call, map[i]); } }