Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5580006yba; Thu, 11 Apr 2019 00:53:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqy6kBTB9RgT9jh5u+1/1T4Bpr8XVUa3tcRYnmDVV0ssAQRwn/xbkTHU2h7NYTVu4SuUJ+Z7 X-Received: by 2002:a63:fd49:: with SMTP id m9mr45932907pgj.16.1554969217804; Thu, 11 Apr 2019 00:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554969217; cv=none; d=google.com; s=arc-20160816; b=HWzAwz1vmiZFL22QSZHWu2kPwNq636QVsVXGGp4BYGM7U8O1GTBqPhg7ghB1/I5R67 ve5fhK6mh5qPztSqkBeU9ijce2r/RbPDF1GGy++mYUOcDFvTjsZYv9LeKx7jaSrEFDXb JwuPAb9+I3gE98b1PHZmAowwPavS795Ndy+2CICCb3O6n99W8K1A9T6aBcFNlXVsacqe /hDRVOyEWSTN8xQOW9fc9pvJmifKYZ0QgWO2T4iCNhWO8lEJT+bYK2Syob/K3pn8mYTf CrBFFwnIjWkAqt+ZwwuDoKuCnCD7DHE9xX4zluR5WKZCBIRXoKKrtfwW0rE0yMzrqm89 2Olg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from; bh=cCllNop/L/q9eAB6bypEInoHW4lQRHuOdRaHPpkH6ik=; b=lbQX1EKtyh3nMaN9K4cjRYYFLt+v9suoqCtB8x2k/QE/UVH8ou8TG/5SlP67aq7Z6n 0vO4fomXP9P83vUTDC+tfwzrym9r8R6f65+BJTv2O8P5j2OISw76BzyfHmjMM+DR1JO7 Khg4kCTdsrhw/BvqEughJzqB/qfjO2DUm1KlbNUJYnvYZAWu1p+aViKXvVPjMmAej218 r62uAW3dognNQPNOAyVq4iZ9AaNsVaRjCYKgq07IqqJmhhnE5iFzhpajzBfOiVC2CaUx 6Tqp9ozfyLv6Gy2pOFwhKakTQk4gNgBekzZDAial7QJO5GuTsW1lwAmR/037lOdkA14v 61XA== 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 m7si10167352pls.114.2019.04.11.00.53.21; Thu, 11 Apr 2019 00:53:37 -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 S1726872AbfDKHwp (ORCPT + 99 others); Thu, 11 Apr 2019 03:52:45 -0400 Received: from smtp2200-217.mail.aliyun.com ([121.197.200.217]:41914 "EHLO smtp2200-217.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726145AbfDKHwl (ORCPT ); Thu, 11 Apr 2019 03:52:41 -0400 X-Alimail-AntiSpam: AC=CONTINUE;BC=0.07437655|-1;CH=green;DM=CONTINUE|CONTINUE|true|0.389576-0.0133998-0.597024;FP=0|0|0|0|0|-1|-1|-1;HT=e02c03306;MF=han_mao@c-sky.com;NM=1;PH=DS;RN=9;RT=9;SR=0;TI=SMTPD_---.EJoSU-3_1554969157; Received: from localhost(mailfrom:han_mao@c-sky.com fp:SMTPD_---.EJoSU-3_1554969157) by smtp.aliyun-inc.com(10.147.41.187); Thu, 11 Apr 2019 15:52:37 +0800 From: Mao Han To: linux-kernel@vger.kernel.org Cc: Mao Han , Adrian Hunter , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Peter Zijlstra , Stephane Eranian , Arnaldo Carvalho de Melo Subject: [PATCH v4 1/3] perf evsel: Use hweight64() instead of hweight_long(attr.sample_regs_user) Date: Thu, 11 Apr 2019 15:44:59 +0800 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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") : 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 66d066f..9663608 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 { -- 2.7.4