Received: by 10.192.165.156 with SMTP id m28csp73883imm; Tue, 10 Apr 2018 16:43:50 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+f6h5rLSFCQkNUE8BO4E/Kcc9QOUPAZvT8dmQLYg5jG8XrignvHd67oIK7BS5WwvXuTTnq X-Received: by 2002:a17:902:1025:: with SMTP id b34-v6mr2449168pla.324.1523403830399; Tue, 10 Apr 2018 16:43:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523403830; cv=none; d=google.com; s=arc-20160816; b=BQQ+NTG4Pbx9WndtFRtp5HOY94hARguQFL12Ru1aySSEuycfMu99YaijMwVUt21OWv xAVlsht/3AUyPZwzaY09AT/XRjCcw/JY6Hai/egOfsh0lACcuQlHtP0p9+E/VN1JfQ1z aDZ2DIMvAZnXG0OIZBBO3sO0xI8QqiMjFxQVFi/DtBCbklWSrZCOdGSbJxOa7DzDO0rS +NdyHrGlAFSB9ppMyaI2z50OWW9oU6qQZ2ZCIc9v/4KnE4QLDr9WsSo3mjLkTl20A+57 H9NMAy0v8Q0CGMK5VXfSkKJj/oNqB8ptGnUnJJ5L5cNc/q5N31+a/z6tDRpgaeYJtImi Tr8g== 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=NIHCMqcoSl3v7WmrxS6bL/iKpQl18cE951zDsGPc+6A=; b=QH6QRibNYnqonwLDwjfSl/EwYFXfBNzbOxG+MeRiRCdu5FfX1zwN+eKFfv73uA+0bs asJlNlN9e4Ze8bxPkadskaIkOEfROA0AzLE2pcp+oKwEEhjSZlBtpOMY2PcK4MkG+IZa OnRQKgW9VDSAhGs74osLXt7MKj6K4A8yH94BJAXak7/BIK1FvFrMWj1XjWULUUyWEGPj ERqcFpvZZoCCYpHuhVk/UW7XAbtjMER5rx5tmeICFm1No2q0ATdDecA6sZhlzzH7+l0r UwGfr7CS7ejo1iTiybN5M5MMP/qfPzXCfroG4ihCBquTd4/GplPXLDYae7PXgXZqu6lU ONrA== 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 n6-v6si3223333plp.194.2018.04.10.16.43.13; Tue, 10 Apr 2018 16:43:50 -0700 (PDT) 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 S1753391AbeDJW1B (ORCPT + 99 others); Tue, 10 Apr 2018 18:27:01 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37668 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753241AbeDJW07 (ORCPT ); Tue, 10 Apr 2018 18:26:59 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5A3AECDA; Tue, 10 Apr 2018 22:26:58 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Olsa , David Ahern , Namhyung Kim , Peter Zijlstra , Steven Rostedt , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.15 011/168] perf evsel: Fix swap for samples with raw data Date: Wed, 11 Apr 2018 00:22:33 +0200 Message-Id: <20180410212800.697659051@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180410212800.144079021@linuxfoundation.org> References: <20180410212800.144079021@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiri Olsa [ Upstream commit f9d8adb345d7adbb2d3431eea73beb89c8d6d612 ] When we detect a different endianity we swap event before processing. It's tricky for samples because we have no idea what's inside. We treat it as an array of u64s, swap them and later on we swap back parts which are different. We mangle this way also the tracepoint raw data, which ends up in report showing wrong data: 1.95% comm=Q^B pid=29285 prio=16777216 target_cpu=000 1.67% comm=l^B pid=0 prio=16777216 target_cpu=000 Luckily the traceevent library handles the endianity by itself (thank you Steven!), so we can pass the RAW data directly in the other endianity. 2.51% comm=beah-rhts-task pid=1175 prio=120 target_cpu=002 2.23% comm=kworker/0:0 pid=11566 prio=120 target_cpu=000 The fix is basically to swap back the raw data if different endianity is detected. Signed-off-by: Jiri Olsa Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Steven Rostedt Link: http://lkml.kernel.org/r/20171129184346.3656-1-jolsa@kernel.org [ Add util/memswap.c to python-ext-sources to link missing mem_bswap_64() ] Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/evsel.c | 20 +++++++++++++++++--- tools/perf/util/python-ext-sources | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -36,6 +36,7 @@ #include "debug.h" #include "trace-event.h" #include "stat.h" +#include "memswap.h" #include "util/parse-branch-options.h" #include "sane_ctype.h" @@ -2120,14 +2121,27 @@ int perf_evsel__parse_sample(struct perf if (type & PERF_SAMPLE_RAW) { OVERFLOW_CHECK_u64(array); u.val64 = *array; - if (WARN_ONCE(swapped, - "Endianness of raw data not corrected!\n")) { - /* undo swap of u64, then swap on individual u32s */ + + /* + * Undo swap of u64, then swap on individual u32s, + * get the size of the raw area and undo all of the + * swap. The pevent interface handles endianity by + * itself. + */ + if (swapped) { u.val64 = bswap_64(u.val64); u.val32[0] = bswap_32(u.val32[0]); u.val32[1] = bswap_32(u.val32[1]); } data->raw_size = u.val32[0]; + + /* + * The raw data is aligned on 64bits including the + * u32 size, so it's safe to use mem_bswap_64. + */ + if (swapped) + mem_bswap_64((void *) array, data->raw_size); + array = (void *)array + sizeof(u32); OVERFLOW_CHECK(array, data->raw_size, max_size); --- a/tools/perf/util/python-ext-sources +++ b/tools/perf/util/python-ext-sources @@ -10,6 +10,7 @@ util/ctype.c util/evlist.c util/evsel.c util/cpumap.c +util/memswap.c util/mmap.c util/namespaces.c ../lib/bitmap.c