Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3897379pxv; Mon, 19 Jul 2021 11:25:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhd5Re0rTvJcoRUwXMg5VEIKcUnLcxkwySzoiLPsaaK2HcEmADQEu7jWrJcAeoPmSkOkqu X-Received: by 2002:a92:c549:: with SMTP id a9mr17868088ilj.248.1626719112645; Mon, 19 Jul 2021 11:25:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626719112; cv=none; d=google.com; s=arc-20160816; b=KVRdzorxmejfMgWuF3sYlIxFfSvUgZK5L5wASxqPVkbuetmZsSdiaFYoxW4Hl7g32V hElY9F+/vveBS6ozxuT2q0c6ZmjYkjAhKEX+66EjRqX/RBCghgor3h/HGnsqL9zk43Y1 PRQNlKNxD47Yk6xS9YuekSEne8MTaLhJeJebc4GVXevlXFDFY7mELnn/1cDMYkqJR1lB rNpBWqJzgiIIwwdYN4GnvqTz1/8qv6oJcM3rquVUC4T0tKCnk2wxCfJiEmSiudVtrti5 jwJN3CThugmgRyY/5JzEOjpf0fgkCxiLyVVVA5SXt00E80nRSLkqcEaIAjDB1hYezhS9 bS0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XUZr2hU6tKX2OiMjFdoT7dqT/WED/x1iTt7px72qhrg=; b=pH7Rh3dHC3eFdlj/JNGPM0OJMw3KD0WHQKmmV0dzThKQDVXNTFV456kF6CqS1Uu9Ek 7Qo+09c4cEIiyps5INgOEetrlCdAnSZrn4NuHrU5t/WfyZFM70x6UIVE1N++SkTD7EXg QcElEkL7vRAlAfm4+KrVxeE5XAwZspJw+Xvq1+r7qAhNc+thfc1l4bOlBNXaJ9fSOt7Q 7JJbk95wYD7CiTUIWoV76Ebh3pIKoWi94eAggcJZ8TPxmExGRHxz7GGU/KCsPhnbMLuR VUtGx90WBXQQmI9K7B2RlHPsdeKWiDwXVRGDFIt79BXADNy7xCKT8XRy73Ob7K7r8DIR /YOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ghwIxZRA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t10si8991432jal.117.2021.07.19.11.24.59; Mon, 19 Jul 2021 11:25:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ghwIxZRA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376409AbhGSRfL (ORCPT + 99 others); Mon, 19 Jul 2021 13:35:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:49362 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350523AbhGSPvI (ORCPT ); Mon, 19 Jul 2021 11:51:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8F0FD61264; Mon, 19 Jul 2021 16:29:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626712195; bh=v7pWGtxDohJ7VY2sfL19nblJLcEcVeGV8U2O2jdQST8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ghwIxZRACQ8WV6CGcTPTzIe5yarKqddUJdfdb+FT5wtfo29SIfUTDkNTouAmXHlWF 64DRyKZ+xHqKHkbVftbgZ/v2Snf0gs8hy0gnyt9Tgs3jYYYqHVDulLsiYIjRjpWJTZ ziUkDcqmGsf3do4HoYospEpCuSrNpy1li55bA3t4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kajol Jain , Nageswara R Sastry , Athira Jajeev , Jiri Olsa , Madhavan Srinivasan , Paul Clarke , Ravi Bangoria , linuxppc-dev@lists.ozlabs.org, Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.12 286/292] perf script python: Fix buffer size to report iregs in perf script Date: Mon, 19 Jul 2021 16:55:48 +0200 Message-Id: <20210719144952.322441606@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144942.514164272@linuxfoundation.org> References: <20210719144942.514164272@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kajol Jain [ Upstream commit dea8cfcc33695f70f56023b416cf88ae44c8a45a ] Commit 48a1f565261d2ab1 ("perf script python: Add more PMU fields to event handler dict") added functionality to report fields like weight, iregs, uregs etc via perf report. That commit predefined buffer size to 512 bytes to print those fields. But in PowerPC, since we added extended regs support in: 068aeea3773a6f4c ("perf powerpc: Support exposing Performance Monitor Counter SPRs as part of extended regs") d735599a069f6936 ("powerpc/perf: Add extended regs support for power10 platform") Now iregs can carry more bytes of data and this predefined buffer size can result to data loss in perf script output. This patch resolves this issue by making the buffer size dynamic, based on the number of registers needed to print. It also changes the regs_map() return type from int to void, as it is not being used by the set_regs_in_dict(), its only caller. Fixes: 068aeea3773a6f4c ("perf powerpc: Support exposing Performance Monitor Counter SPRs as part of extended regs") Signed-off-by: Kajol Jain Tested-by: Nageswara R Sastry Cc: Athira Jajeev Cc: Jiri Olsa Cc: Madhavan Srinivasan Cc: Paul Clarke Cc: Ravi Bangoria Cc: linuxppc-dev@lists.ozlabs.org Link: http://lore.kernel.org/lkml/20210628062341.155839-1-kjain@linux.ibm.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- .../util/scripting-engines/trace-event-python.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 23dc5014e711..a61be9c07565 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -687,7 +687,7 @@ static void set_sample_datasrc_in_dict(PyObject *dict, _PyUnicode_FromString(decode)); } -static int regs_map(struct regs_dump *regs, uint64_t mask, char *bf, int size) +static void regs_map(struct regs_dump *regs, uint64_t mask, char *bf, int size) { unsigned int i = 0, r; int printed = 0; @@ -695,7 +695,7 @@ static int regs_map(struct regs_dump *regs, uint64_t mask, char *bf, int size) bf[0] = 0; if (!regs || !regs->regs) - return 0; + return; for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) { u64 val = regs->regs[i++]; @@ -704,8 +704,6 @@ static int regs_map(struct regs_dump *regs, uint64_t mask, char *bf, int size) "%5s:0x%" PRIx64 " ", perf_reg_name(r), val); } - - return printed; } static void set_regs_in_dict(PyObject *dict, @@ -713,7 +711,16 @@ static void set_regs_in_dict(PyObject *dict, struct evsel *evsel) { struct perf_event_attr *attr = &evsel->core.attr; - char bf[512]; + + /* + * Here value 28 is a constant size which can be used to print + * one register value and its corresponds to: + * 16 chars is to specify 64 bit register in hexadecimal. + * 2 chars is for appending "0x" to the hexadecimal value and + * 10 chars is for register name. + */ + int size = __sw_hweight64(attr->sample_regs_intr) * 28; + char bf[size]; regs_map(&sample->intr_regs, attr->sample_regs_intr, bf, sizeof(bf)); -- 2.30.2