Received: by 10.213.65.68 with SMTP id h4csp1866822imn; Mon, 19 Mar 2018 15:43:53 -0700 (PDT) X-Google-Smtp-Source: AG47ELvsWQO0imvr9iPXfb9T1VaTAzt2Tr8opiV8RGjD7ZUrO0yo2M2Y4atq5lC6WbS6+BbYfIlF X-Received: by 10.101.97.15 with SMTP id z15mr8439621pgu.393.1521499433337; Mon, 19 Mar 2018 15:43:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521499433; cv=none; d=google.com; s=arc-20160816; b=h5NTPcjf/M2Z5epwj2nvOPNHR4fD0qeuNpUDF0lNSvJDW1ceBoI9U3vWpxXCrzH9oO D5fXRLJOWuoS/Eo1XdL62lKbc1kDeTP9VvepXiZuIieOmOe39P5UYrdYZcUFSlLuXDpa iIMnyRXwGqlbZVykJbuOIgLffMOzWlXXfSA+xGTdFhXW2BLYwIkPI+NwxqM/uIFZLatS ox2sIESsBTSfO3Tsnuu4+Bsalty3BmYLVAj6Bd3MG0Ju5jS6h0gtvQ4RB9VzvS3p7BMF 3jv0XWnVWUOpNbzwKaoPzfR4kadCWgn/1HglIhnkhuxJMsAkhdtTLrzI7r0q0GNwFXZ2 LZaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=SdPATOJCWCiuhQcv7wGgo+67G6sG7M7a0gmwVdWYg88=; b=QEqIdCdvgHYeC4dGKva3KSSPcW3VUbcNcFNd5ops5YC8L0NaictNFnvTdDaCTNQLY2 63h8pOoNV4P15Kga2pQU3QwrTKYubxuMfXLx2L5h238LOsKi00Ykcvz9xtHMzNtkC586 u6BAIDFH8DdtxSbZYa4ZhJELqGahaWJrbG6XZ8hX/Gg5kEnevCcU2Y/YRxPe9nvEiFYO NeyjTKGaB8ilW/XhZ34x+ZS9qMnDKqTIO+9Afqy2VoHFH5yAoE+gxZocdpwkL5roKjyX M8E5t2JhUj7khu7n0ozsSSNPXaa1gPtz1EnpXVT2/R/RQOvAAuukDkoN+LF0KAwH9umD bI7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=bl/XpYBW; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p13-v6si210835pll.416.2018.03.19.15.43.39; Mon, 19 Mar 2018 15:43:53 -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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=bl/XpYBW; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936835AbeCSWl7 (ORCPT + 99 others); Mon, 19 Mar 2018 18:41:59 -0400 Received: from mail-by2nam01on0103.outbound.protection.outlook.com ([104.47.34.103]:19764 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756009AbeCSPrQ (ORCPT ); Mon, 19 Mar 2018 11:47:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=SdPATOJCWCiuhQcv7wGgo+67G6sG7M7a0gmwVdWYg88=; b=bl/XpYBWVbUTMPu6ibwPBotvQdXvhv0unZmrJll6vf9z8Qm6i839x3G1b9wNc3DwPURBAbxBu7r0RP5WDlnWxW7SjgIzOu0rue6OK/Pp3Q2nbQ68SyU8NEWIekScptEMywdDAVyeToz0IC+Ndy4mmId7E5indn/RkI/SyKRQPMo= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1013.namprd21.prod.outlook.com (52.132.133.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.631.0; Mon, 19 Mar 2018 15:47:09 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 15:47:09 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Jiri Olsa , David Ahern , Namhyung Kim , Peter Zijlstra , Steven Rostedt , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 011/124] perf evsel: Fix swap for samples with raw data Thread-Topic: [PATCH AUTOSEL for 4.15 011/124] perf evsel: Fix swap for samples with raw data Thread-Index: AQHTv5mJ2gyOdvKb0UOu6Gkryg2HTA== Date: Mon, 19 Mar 2018 15:47:09 +0000 Message-ID: <20180319154645.11350-11-alexander.levin@microsoft.com> References: <20180319154645.11350-1-alexander.levin@microsoft.com> In-Reply-To: <20180319154645.11350-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1013;7:DdZrRUx0R1PwG9DIjMvsFf74FbhPUcou+6f4+UVzi1RxIFHWoTUSNqKROEDcRXGcTJVB11SeDO9kVYajHyHufZn/LxumCRUl14KsJaZV5Vh22nz4ywrZeTrC6S+ja5ZSUC3dNrgqUvphabimvc7N/wqcq5U7dddbSsVNyjvblWoytvCDGwNAwLR3KBKUqJ+/Xh2Oh+Dny686lMZOFFJeZqaFibJshUL2PUNrOildesOZ6yGMjiNilsTeL2ZT/DGZ;20:T7WhJPcnBHHIwGto2viNCvdFJeI3CtQl3mo9FPc5K+NQwoIb01gZ+aSYef15+6udYdWWP3fRlJYU10uqGZte8Rcpipi2cnP5VFyViysM7zQd1Ttr4eHRxppqHURgH4bDw+A/GPsS+aM8u/Mw6UY7boQmyhYawHl6DrnO6FqI4GU= x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 53904acd-657f-457f-32e7-08d58db0acc8 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1013; x-ms-traffictypediagnostic: DM5PR2101MB1013: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(85827821059158)(42068640409301); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3231221)(944501300)(52105095)(3002001)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB1013;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1013; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(396003)(39860400002)(346002)(376002)(39380400002)(189003)(199004)(86612001)(316002)(26005)(72206003)(4326008)(25786009)(110136005)(10290500003)(966005)(86362001)(575784001)(59450400001)(54906003)(53936002)(36756003)(107886003)(3280700002)(39060400002)(14454004)(22452003)(6506007)(5660300001)(68736007)(99286004)(186003)(478600001)(76176011)(2950100002)(10090500001)(102836004)(6116002)(5250100002)(2501003)(97736004)(3660700001)(106356001)(81156014)(81166006)(8676002)(8936002)(7736002)(305945005)(2900100001)(105586002)(3846002)(1076002)(66066001)(6436002)(2906002)(6306002)(6512007)(6486002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1013;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: eqFxSI4Zz6dPfo56H/9cA8kcFikZWaDuENjXeKmiea69/cPF9UqaPCaShJgL6BvYFcUhbj+B+3fcGVgXzUTdstiQOswQNmPvbiCFxh8yMQEEWV/W6YnsMZMdJLRsMMI35zJx+GBfG8t0rkTG6xFchHXj3WH3Y2t6jsE0jxl9SwlpAzxDIPzJjAEPuEtpeLYpMUv3WHHeEXKAndBjtLWBIUYnqWYO4vWmVWCxWbeB7g1yKnXoB+2nKHDnLQFI7VlILh7aVz8RUY+Q5mZBB3XEoov4VZ7hiSEM76jW7W7fn3MALMgvM65pFV0i/XU75gqSpGVkzFcGXsrSf7fxaqEfIA== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 53904acd-657f-457f-32e7-08d58db0acc8 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 15:47:09.0211 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1013 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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=3DQ^B pid=3D29285 prio=3D16777216 target_cpu=3D000 1.67% comm=3Dl^B pid=3D0 prio=3D16777216 target_cpu=3D000 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=3Dbeah-rhts-task pid=3D1175 prio=3D120 target_cpu=3D002 2.23% comm=3Dkworker/0:0 pid=3D11566 prio=3D120 target_cpu=3D000 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 --- tools/perf/util/evsel.c | 20 +++++++++++++++++--- tools/perf/util/python-ext-sources | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index d5fbcf8c7aa7..111b924f0a17 100644 --- 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" =20 #include "sane_ctype.h" @@ -2120,14 +2121,27 @@ int perf_evsel__parse_sample(struct perf_evsel *evs= el, union perf_event *event, if (type & PERF_SAMPLE_RAW) { OVERFLOW_CHECK_u64(array); u.val64 =3D *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 =3D bswap_64(u.val64); u.val32[0] =3D bswap_32(u.val32[0]); u.val32[1] =3D bswap_32(u.val32[1]); } data->raw_size =3D 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 =3D (void *)array + sizeof(u32); =20 OVERFLOW_CHECK(array, data->raw_size, max_size); diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ex= t-sources index b4f2f06722a7..7aa0ea64544e 100644 --- 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 --=20 2.14.1