Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp599758yba; Fri, 12 Apr 2019 09:43:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqyRpX4rrxMNsTE+orqiwM735IvA+3dbYbSbp7ihKnP0NFQLVpjZAjPIqA8aMRJ7hWDXeg5u X-Received: by 2002:a17:902:2b87:: with SMTP id l7mr58796996plb.38.1555087425758; Fri, 12 Apr 2019 09:43:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555087425; cv=none; d=google.com; s=arc-20160816; b=dAv7ABAp1QI/X213k8hUrBpulIcJq4t1WEILFeAQUDkRIIJtCSzqHCgYqLDrt7slas fPjBlCyq1zZMqDVLuABEvvme+4n5PwHlzJVBu6DaHDcSmFEXE0oXAsSZgT3ycuh0lJeC XxqU1xmUoLW1IFAogSCY8OTQVCxH840SAiVuxeMPMTUekI+IXQpfkMByz8ycrRpykjPY h5RxIq+tGf4jeZoE4SthB4o1Ekf6S8pQDBHRQp7qexG+cHAm5E8P8zpj5vBLQo/Q9tfS LcsOO0kOiXZwDLSm6H1Fan8lKmoS8Ep2taSymDK8cHNsuX/yCp3XpxTHzXKJqBE5zwZN ducQ== 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=QPUdsWzhfVQ9JT2YA1RAWG8RzxTIFpL8tUMk19J7HOU=; b=hKjIRL2PYpmoAacWwaPx9n6SbgoKbDc49ZKlBYYgSN60XidTdrWvBpU3Ge4cxapeS4 7svhewtbuUmYt1Yr5Mb3LRU0TVgnVJ7wMsu0lgc50PuM5fpFWsvPUqlNtjbPAi+2R3bZ sU2XbedPpH7qHJQKcpKAWZirePh/bqz6nkvyDjMwgKxGX5BbdLSZ40VmLlSyUmarlhSI ko93CNCg2HvA/qGCUoIk77tbDuD9qnFd5xsB86PdQzC4eruOlWHqv+IELeAU8LreHGLn vy7IhGFExCtt+XZQoC6fat4zUlFncXRbcLrn7scX+znfwxF+qd2yZIBr9dlLa/whvL8S MJ9Q== 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 b10si37313400plr.131.2019.04.12.09.43.29; Fri, 12 Apr 2019 09:43:45 -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 S1726952AbfDLQmC (ORCPT + 99 others); Fri, 12 Apr 2019 12:42:02 -0400 Received: from terminus.zytor.com ([198.137.202.136]:44881 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726765AbfDLQmC (ORCPT ); Fri, 12 Apr 2019 12:42:02 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x3CGeT201753340 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 12 Apr 2019 09:40:29 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x3CGeSWv1753337; Fri, 12 Apr 2019 09:40:28 -0700 Date: Fri, 12 Apr 2019 09:40:28 -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: acme@redhat.com, adrian.hunter@intel.com, peterz@infradead.org, namhyung@kernel.org, tglx@linutronix.de, han_mao@c-sky.com, alexander.shishkin@linux.intel.com, hpa@zytor.com, eranian@google.com, mingo@kernel.org, jolsa@redhat.com, linux-kernel@vger.kernel.org Reply-To: jolsa@redhat.com, linux-kernel@vger.kernel.org, alexander.shishkin@linux.intel.com, hpa@zytor.com, mingo@kernel.org, eranian@google.com, namhyung@kernel.org, tglx@linutronix.de, han_mao@c-sky.com, acme@redhat.com, peterz@infradead.org, adrian.hunter@intel.com 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: 21e6dfe04861c2c1b529f2759850bc62a80ca050 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=0.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_03_06 autolearn=no 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: 21e6dfe04861c2c1b529f2759850bc62a80ca050 Gitweb: https://git.kernel.org/tip/21e6dfe04861c2c1b529f2759850bc62a80ca050 Author: Mao Han AuthorDate: Wed, 10 Apr 2019 16:16:43 +0800 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 10 Apr 2019 10:25:28 -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 {