Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3297397yba; Tue, 16 Apr 2019 08:32:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQHBMnKBXfGapBjp614QH533anmjDG6fuZwn0UYXch7r6Jn4c2xEmchFlXriWNmiych6Rd X-Received: by 2002:a63:b64:: with SMTP id a36mr78122886pgl.58.1555428749776; Tue, 16 Apr 2019 08:32:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555428749; cv=none; d=google.com; s=arc-20160816; b=aIfLyJNXflTBo4i/q1BwAEjwd+VJCz1rfoup6Et5VTtNHDf6VKsElmxhQDBvnKdj7y mR2ZPOYwK/huygMZnFj+g3/1B++5pJ5i4jpuz3HW4XGpwRggVHK7qqN+ez+oBlnO9CDm XOQrdA9d62/BjSR5A7PAzNYlQWHdv5isSY4zu6lDZEUBAtH+cNmyqUn0D3FMv4SA0q8Y o/y3ThtczTNqr5B5hPK9EBfWnG/z5uSFI4u6TSKfF7VnHz45jCU3oqr9SecQc/72PfAp cAplOO26eEycAGc3z8Lhl4yK1WSFTGPJMnhSMndqga2iZdg0ribOekZLiAyhwFrnSQ+Q s+ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=+4pBmzaNAUBZvyePz1VD/OauP9AbaoqLjUCe2RZ+a5A=; b=t1iACZs6rCXinTYAi6iBl0GYJSx+TOvZaVWU2HCXSy8tIUdYngayYdT5BnMOXu4tiv eAsSB4j6+Q5xROaoqOpNBMUClH+po62D9EfQqz9AhCsoBJlz1fUbhblP20guZjw/V31c H4MRvewGPp43oBoXs2+1+d/Q0HA5nkBBlTBs1Xo6wRpe0cZR7hAZo6w75C0mEf1FkiJw sP+k45ZEJD+NLOr5J5xUZFtKPtixMN5tzPnhfM/tTxoq0IPCcrJjxndCg9txzn36LQvo YF5eWNU/9HuZZiX8ELuFc2gnBPy991ey5vye7esM5UAKPAuHJd5pgu+p7+d27JzNhsi+ j/eQ== 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 t14si31384718pfh.87.2019.04.16.08.32.13; Tue, 16 Apr 2019 08:32:29 -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 S1729333AbfDPPbT (ORCPT + 99 others); Tue, 16 Apr 2019 11:31:19 -0400 Received: from terminus.zytor.com ([198.137.202.136]:53597 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbfDPPbT (ORCPT ); Tue, 16 Apr 2019 11:31:19 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x3GFUmEV3495018 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 16 Apr 2019 08:30:48 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x3GFUl4V3495015; Tue, 16 Apr 2019 08:30:47 -0700 Date: Tue, 16 Apr 2019 08:30:47 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Mao Han Message-ID: Cc: jolsa@redhat.com, eranian@google.com, tglx@linutronix.de, han_mao@c-sky.com, adrian.hunter@intel.com, alexander.shishkin@linux.intel.com, peterz@infradead.org, hpa@zytor.com, namhyung@kernel.org, mingo@kernel.org, linux-kernel@vger.kernel.org, acme@redhat.com Reply-To: namhyung@kernel.org, hpa@zytor.com, peterz@infradead.org, alexander.shishkin@linux.intel.com, adrian.hunter@intel.com, han_mao@c-sky.com, tglx@linutronix.de, eranian@google.com, jolsa@redhat.com, acme@redhat.com, linux-kernel@vger.kernel.org, mingo@kernel.org In-Reply-To: <29ad7947dc8fd1ff0abd2093a72cc27a2446be9f.1554883878.git.han_mao@c-sky.com> References: <29ad7947dc8fd1ff0abd2093a72cc27a2446be9f.1554883878.git.han_mao@c-sky.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf evsel: Use hweight64() instead of hweight_long(attr.sample_regs_user) Git-Commit-ID: 3a5b64f05d7fe36dea0dde26423e3044fbacd482 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_06_12 autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 3a5b64f05d7fe36dea0dde26423e3044fbacd482 Gitweb: https://git.kernel.org/tip/3a5b64f05d7fe36dea0dde26423e3044fbacd482 Author: Mao Han AuthorDate: Wed, 10 Apr 2019 16:16:43 +0800 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 16 Apr 2019 11:27:53 -0300 perf evsel: Use hweight64() instead of hweight_long(attr.sample_regs_user) On 32-bits platform with more than 32 registers, the 64 bits mask is truncate to the lower 32 bits and the return value of hweight_long will always smaller than 32. When kernel outputs more than 32 registers, but the user perf program only counts 32, there will be a data mismatch result to overflow check fail. Signed-off-by: Mao Han Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Fixes: 6a21c0b5c2ab ("perf tools: Add core support for sampling intr machine state regs") Fixes: d03f2170546d ("perf tools: Expand perf_event__synthesize_sample()") Fixes: 0f6a30150ca2 ("perf tools: Support user regs and stack in sample parsing") Link: http://lkml.kernel.org/r/29ad7947dc8fd1ff0abd2093a72cc27a2446be9f.1554883878.git.han_mao@c-sky.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evsel.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 66d066f18b5b..966360844fff 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2368,7 +2368,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, if (data->user_regs.abi) { u64 mask = evsel->attr.sample_regs_user; - sz = hweight_long(mask) * sizeof(u64); + sz = hweight64(mask) * sizeof(u64); OVERFLOW_CHECK(array, sz, max_size); data->user_regs.mask = mask; data->user_regs.regs = (u64 *)array; @@ -2424,7 +2424,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, if (data->intr_regs.abi != PERF_SAMPLE_REGS_ABI_NONE) { u64 mask = evsel->attr.sample_regs_intr; - sz = hweight_long(mask) * sizeof(u64); + sz = hweight64(mask) * sizeof(u64); OVERFLOW_CHECK(array, sz, max_size); data->intr_regs.mask = mask; data->intr_regs.regs = (u64 *)array; @@ -2552,7 +2552,7 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, if (type & PERF_SAMPLE_REGS_USER) { if (sample->user_regs.abi) { result += sizeof(u64); - sz = hweight_long(sample->user_regs.mask) * sizeof(u64); + sz = hweight64(sample->user_regs.mask) * sizeof(u64); result += sz; } else { result += sizeof(u64); @@ -2580,7 +2580,7 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, if (type & PERF_SAMPLE_REGS_INTR) { if (sample->intr_regs.abi) { result += sizeof(u64); - sz = hweight_long(sample->intr_regs.mask) * sizeof(u64); + sz = hweight64(sample->intr_regs.mask) * sizeof(u64); result += sz; } else { result += sizeof(u64); @@ -2710,7 +2710,7 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, if (type & PERF_SAMPLE_REGS_USER) { if (sample->user_regs.abi) { *array++ = sample->user_regs.abi; - sz = hweight_long(sample->user_regs.mask) * sizeof(u64); + sz = hweight64(sample->user_regs.mask) * sizeof(u64); memcpy(array, sample->user_regs.regs, sz); array = (void *)array + sz; } else { @@ -2746,7 +2746,7 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, if (type & PERF_SAMPLE_REGS_INTR) { if (sample->intr_regs.abi) { *array++ = sample->intr_regs.abi; - sz = hweight_long(sample->intr_regs.mask) * sizeof(u64); + sz = hweight64(sample->intr_regs.mask) * sizeof(u64); memcpy(array, sample->intr_regs.regs, sz); array = (void *)array + sz; } else {