Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2327382imm; Mon, 28 May 2018 06:08:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrHIdxxxojkjQnoKhtE9T5xtmfgoVrMUkbGTb2kMvJMg6+YkNGmCPtOlwM1FKoU9PPdBN2j X-Received: by 2002:a63:8c4f:: with SMTP id q15-v6mr10904701pgn.236.1527512905968; Mon, 28 May 2018 06:08:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527512905; cv=none; d=google.com; s=arc-20160816; b=tNcbHK77rHEMLix0Efv0DGXWOrT/C5ZiQavwK2lIUHOsLCW3bXvwE6xAl01mZ+66Tp olViej8CTdLS27OmT+5uqm+w89Q4Gaxfa+0PM1uA8jdjmCsNZZcUPU2U4WQZEODmciid RgFUAlnZZ7dJVrNYJo75uGKebphGrJxFajLVW9HHhVIGaFnH30JbwyDwY7T80hqoxEuP Sq9aF2ljd9RZGnbGoTFyOHneCmAMTN7A/b9V7QFtpMfJtSeMs8oSNM3BXdZZRoP2nPSC DYBbtooN5g53l5p49ESLkxHZuUwLw6KG3U+da7MZT5MPf9z6w1opTCKw+o1OAKHqd9Gg gmdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=8HSmKrFbZNTEv4UGNziXbxd6qx3IkuyEXnvb8FA/jsk=; b=wADUKN97Y2E1vaaps5Vfa3K9TF8BRLGJEPsDYy4/VgNPlce4Fx8/6PtBw3GA5nNHFb srSL0nLgq3nD4V+6vQPv6auiN7rYFAhYgRxPICX1svA66Sch4E3dqeFWpvniHCHYRCnd hYCUMVk/mUbMjiz9xapGkAv71ImmJU1VVxUZa5PGBi6Nf8EBQBkCNSSaSaolZ8L0Gc8b 35+MbuM8NtT8WKlJW1zI7vsPW3KWILxp+UzFjOXaoxLfrvoWfLEBInK0aGzz3z4DJ1+B 0CCj5saQO9D7SV3vuNUyM/K483MmdfPurHcAFRRugqWykNoyeduQpslkmsF2RVSgoUCL 1Y0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WuPVOCts; 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 k6-v6si23521562pgq.85.2018.05.28.06.08.07; Mon, 28 May 2018 06:08:25 -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; dkim=pass header.i=@kernel.org header.s=default header.b=WuPVOCts; 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 S1165190AbeE1NGJ (ORCPT + 99 others); Mon, 28 May 2018 09:06:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:41724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1163789AbeE1Kw0 (ORCPT ); Mon, 28 May 2018 06:52:26 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C91B5204EE; Mon, 28 May 2018 10:52:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527504745; bh=fm1JAbcy8jfnwoIzhV88J57UC9oO63vlEnhzuV3329k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WuPVOCtsX4VcTKmjKSHd6qzQ8dYYBcc4aqVXuWzSHxpS3vVzxXY4ZtxduDEjVe2Wa WsiN39X3ZsKHhAMRE3mvzg2PX1nOHKQGwLNhoEY9o89q2KxO8S6SohPbb2TQ1lKsiV TPsp0a1cAa3KaOY01s4ZMd+4Ure0c/SUk0y8JtD0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Olsa , Alexander Shishkin , David Ahern , Namhyung Kim , Peter Zijlstra , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.14 216/496] perf record: Fix crash in pipe mode Date: Mon, 28 May 2018 12:00:01 +0200 Message-Id: <20180528100329.030788184@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100319.498712256@linuxfoundation.org> References: <20180528100319.498712256@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiri Olsa [ Upstream commit ad46e48c65fa1f204fa29eaff1b91174d314a94b ] Currently we can crash perf record when running in pipe mode, like: $ perf record ls | perf report # To display the perf.data header info, please use --header/--header-only options. # perf: Segmentation fault Error: The - file has no samples! The callstack of the crash is: 0x0000000000515242 in perf_event__synthesize_event_update_name 3513 ev = event_update_event__new(len + 1, PERF_EVENT_UPDATE__NAME, evsel->id[0]); (gdb) bt #0 0x0000000000515242 in perf_event__synthesize_event_update_name #1 0x00000000005158a4 in perf_event__synthesize_extra_attr #2 0x0000000000443347 in record__synthesize #3 0x00000000004438e3 in __cmd_record #4 0x000000000044514e in cmd_record #5 0x00000000004cbc95 in run_builtin #6 0x00000000004cbf02 in handle_internal_command #7 0x00000000004cc054 in run_argv #8 0x00000000004cc422 in main The reason of the crash is that the evsel does not have ids array allocated and the pipe's synthesize code tries to access it. We don't force evsel ids allocation when we have single event, because it's not needed. However we need it when we are in pipe mode even for single event as a key for evsel update event. Fixing this by forcing evsel ids allocation event for single event, when we are in pipe mode. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20180302161354.30192-1-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- tools/perf/builtin-record.c | 9 +++++++++ tools/perf/perf.h | 1 + tools/perf/util/record.c | 8 ++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -926,6 +926,15 @@ static int __cmd_record(struct record *r } } + /* + * If we have just single event and are sending data + * through pipe, we need to force the ids allocation, + * because we synthesize event name through the pipe + * and need the id for that. + */ + if (data->is_pipe && rec->evlist->nr_entries == 1) + rec->opts.sample_id = true; + if (record__open(rec) != 0) { err = -1; goto out_child; --- a/tools/perf/perf.h +++ b/tools/perf/perf.h @@ -61,6 +61,7 @@ struct record_opts { bool tail_synthesize; bool overwrite; bool ignore_missing_thread; + bool sample_id; unsigned int freq; unsigned int mmap_pages; unsigned int auxtrace_mmap_pages; --- a/tools/perf/util/record.c +++ b/tools/perf/util/record.c @@ -137,6 +137,7 @@ void perf_evlist__config(struct perf_evl struct perf_evsel *evsel; bool use_sample_identifier = false; bool use_comm_exec; + bool sample_id = opts->sample_id; /* * Set the evsel leader links before we configure attributes, @@ -163,8 +164,7 @@ void perf_evlist__config(struct perf_evl * match the id. */ use_sample_identifier = perf_can_sample_identifier(); - evlist__for_each_entry(evlist, evsel) - perf_evsel__set_sample_id(evsel, use_sample_identifier); + sample_id = true; } else if (evlist->nr_entries > 1) { struct perf_evsel *first = perf_evlist__first(evlist); @@ -174,6 +174,10 @@ void perf_evlist__config(struct perf_evl use_sample_identifier = perf_can_sample_identifier(); break; } + sample_id = true; + } + + if (sample_id) { evlist__for_each_entry(evlist, evsel) perf_evsel__set_sample_id(evsel, use_sample_identifier); }