Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1408245imu; Sat, 26 Jan 2019 02:09:31 -0800 (PST) X-Google-Smtp-Source: ALg8bN62kv7No43jFZ/hd6wo2djQIMNgaNSNBA86LNPlsHDnLWXziLS8Y7jUNkL2CkJfqNdoX19R X-Received: by 2002:a62:6f88:: with SMTP id k130mr14354821pfc.234.1548497371748; Sat, 26 Jan 2019 02:09:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548497371; cv=none; d=google.com; s=arc-20160816; b=C1A02ejkgSEh3VlIwHB1l0XpHhTt70HrBHOr45BMTLIH5JBYl1ceNKYe0bTjtfE/Sj rt64scQ5mdv3ii8J/DXxx+LrYu1q1ddHAuty/u9qrNuQodntlh1EXrD1vbuZvEh0rHK/ X1go8NQOIN3YviVbxVQKNr7ghhQGg8+wMQ/NcUFx85tpke0NFnHcvMbyh3S93fMFBt6B X5a6kiY6iEi4pXuSFnL1VZh5jaBwJn4Nx7tr0N+jo2T0WrLsxjLJ8usGZcKhcRCVg9zy E0l0e+YbRz3VICr4CmM/CE+ksHjJ1h0cnAKgV24z3Iv8aELLwDvnH6GmvO4CkVWRKt3G bqmA== 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=5BUHo/yc7Si4Wp0nFplH+zuh4szUU85GqYN2D/a/U4k=; b=hM42h5lf5gIMqeuzTmUxWKTtiVPvzlyVJA7Q3N97fjCZi6bKKlVsCA6U92k73zfB7Q 5QUSLh4ZcPqKJv9vBF6yP2q76uvovXS3tk/ZhKYuOsP9DT54x/tJCb675GfN/FDBHp3F +PZQYGZuUbqtFP8Y2dw2xCnq6zDNzUVZpXDmm2y934CEhlxfAQ55MHHH3t/znAOVIVO+ zFwhEhSQIJ90Do/Ambnb7MmhfMVvHKfYw+sI40q2rRDhTqXUELwFMHRcgdKWWtuTc9LJ JCW62+Tj9nJAeJJ71CJAIMyML6nkFiewbZ4rWmh+ED9hGxkIT5IS0in5M1RWEyPNEz0R nroA== 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 z9si7730331pgf.54.2019.01.26.02.09.16; Sat, 26 Jan 2019 02:09:31 -0800 (PST) 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 S1729791AbfAZKHQ (ORCPT + 99 others); Sat, 26 Jan 2019 05:07:16 -0500 Received: from terminus.zytor.com ([198.137.202.136]:38733 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726143AbfAZKHP (ORCPT ); Sat, 26 Jan 2019 05:07:15 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x0QA76dp513316 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sat, 26 Jan 2019 02:07:06 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x0QA75RY513313; Sat, 26 Jan 2019 02:07:05 -0800 Date: Sat, 26 Jan 2019 02:07:05 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Tony Jones Message-ID: Cc: tglx@linutronix.de, linux-kernel@vger.kernel.org, tonyj@suse.de, s1seetee@linux.vnet.ibm.com, mingo@kernel.org, corbet@lwn.net, hpa@zytor.com, ravi.bangoria@linux.ibm.com, jolsa@kernel.org, jskarvad@redhat.com, acme@redhat.com Reply-To: hpa@zytor.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, tonyj@suse.de, mingo@kernel.org, s1seetee@linux.vnet.ibm.com, corbet@lwn.net, acme@redhat.com, jskarvad@redhat.com, ravi.bangoria@linux.ibm.com, jolsa@kernel.org In-Reply-To: <20190124005229.16146-3-tonyj@suse.de> References: <20190124005229.16146-3-tonyj@suse.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf script python: Use PyBytes for attr in trace-event-python Git-Commit-ID: 72e0b15cb24a497d7d0d4707cf51ff40c185ae8c 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.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_24_48 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: 72e0b15cb24a497d7d0d4707cf51ff40c185ae8c Gitweb: https://git.kernel.org/tip/72e0b15cb24a497d7d0d4707cf51ff40c185ae8c Author: Tony Jones AuthorDate: Wed, 23 Jan 2019 16:52:25 -0800 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 25 Jan 2019 15:12:10 +0100 perf script python: Use PyBytes for attr in trace-event-python With Python3. PyUnicode_FromStringAndSize is unsafe to call on attr and will return NULL. Use _PyBytes_FromStringAndSize (as with raw_buf). Below is the observed behavior without the fix. Note it is first necessary to apply the prior fix (Add trace_context extension module to sys,modules): # ldd /usr/bin/perf | grep -i python libpython3.6m.so.1.0 => /usr/lib64/libpython3.6m.so.1.0 (0x00007f8e1dfb2000) # perf record -e raw_syscalls:sys_enter /bin/false [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.018 MB perf.data (21 samples) ] # perf script -g python | cat generated Python script: perf-script.py # perf script -s ./perf-script.py in trace_begin Segmentation fault (core dumped) Signed-off-by: Tony Jones Acked-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: Jaroslav Škarvada Cc: Jonathan Corbet Cc: Ravi Bangoria Cc: Seeteena Thoufeek Fixes: 66dfdff03d19 ("perf tools: Add Python 3 support") Link: http://lkml.kernel.org/r/20190124005229.16146-3-tonyj@suse.de Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/scripting-engines/trace-event-python.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 315905c748fa..7059d1be2d09 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -733,8 +733,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, Py_FatalError("couldn't create Python dictionary"); pydict_set_item_string_decref(dict, "ev_name", _PyUnicode_FromString(perf_evsel__name(evsel))); - pydict_set_item_string_decref(dict, "attr", _PyUnicode_FromStringAndSize( - (const char *)&evsel->attr, sizeof(evsel->attr))); + pydict_set_item_string_decref(dict, "attr", _PyBytes_FromStringAndSize((const char *)&evsel->attr, sizeof(evsel->attr))); pydict_set_item_string_decref(dict_sample, "pid", _PyLong_FromLong(sample->pid));