Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3956988ybi; Mon, 15 Jul 2019 01:32:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+5CQHur85rnCU7iyyI4VnTpJS9J5v4x0qZNvx2hUyHmkWT4aOtGgb61RlhMon7IL8cd71 X-Received: by 2002:a17:90a:338b:: with SMTP id n11mr27553643pjb.21.1563179530646; Mon, 15 Jul 2019 01:32:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563179530; cv=none; d=google.com; s=arc-20160816; b=Z3+JpEf7bBm0LEk8WZR0XsLIR+jK2lGk5KROBRiOQbhsSZ9BrwdKG/zk0LuJCZbee8 wxL5z9oDQIOcbiQS94YfwNw/ec/tBR4s3Qk2ObQOaoCLhVqmrJ5ql8hFLzayMiRpp+gZ VlD4lBxUML7gJLdFild+iFS2J82Cf6vX36FhbU0LLOejbLidHYPtqyNSmkVEQVE5cDSl K6jay8ANsJ5Zfn+n3cyNsPwhXMao7n/52+0k33cWe4CdCinLoltfVoCvQLrw5D/3EP3D SVy70EzAwBCFEoLJZjXZVaZQIoRUhqXBPl6jLu53l7Cu03TjM2CCnfxYCVot9gmMWxUC +SbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=6MzG6U4525ZvtBCyZ+2RXiHz3mkuQQYc2DWDawNv0aQ=; b=WYfg/HRo9UujhvkpUmCnzvqcy88SC2OIpaEIhXkZ0kRs9oYbjLg7EfJDKW63zLLahd rwoAtkbs9LJ73ZPCqlny3wtVfkhuL5Xq7u6PgxRoc+Ltqb8w5KnJ7coAP+dtukpT4v+/ E7BtP3ROBBY/MR2FN+fsR5tsOd7gIiuDkMP7rz5pDc64uDKRdLzS8f9VNWpoYFRC1VCL 3AbGfPqQXhr4RsIr3GMyJK0jLpesbUia7sCyYKr1ki07xcWn568mHDCl3AVHe7NONofD 04po2izOl7cdE940c7uSkreoowSsSvQ+TZTGDD6ozewSpgLC5oRc1FbGXxIUZCSElMpa Te0g== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t17si14885276pjw.99.2019.07.15.01.31.51; Mon, 15 Jul 2019 01:32:10 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729551AbfGOIbJ (ORCPT + 99 others); Mon, 15 Jul 2019 04:31:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43384 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729442AbfGOIbJ (ORCPT ); Mon, 15 Jul 2019 04:31:09 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 05C1085A03; Mon, 15 Jul 2019 08:31:09 +0000 (UTC) Received: from krava (unknown [10.40.205.8]) by smtp.corp.redhat.com (Postfix) with SMTP id 803EB5D9D6; Mon, 15 Jul 2019 08:31:06 +0000 (UTC) Date: Mon, 15 Jul 2019 10:31:05 +0200 From: Jiri Olsa To: Stephane Eranian Cc: Numfor Mbiziwo-Tiapo , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Namhyung Kim , Song Liu , mbd@fb.com, LKML , Ian Rogers Subject: Re: [PATCH] Fix perf stat repeat segfault Message-ID: <20190715083105.GB2821@krava> References: <20190710204540.176495-1-nums@google.com> <20190714204432.GA8120@krava> <20190714205505.GB8120@krava> <20190715075912.GA2821@krava> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.0 (2019-05-25) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 15 Jul 2019 08:31:09 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 15, 2019 at 01:14:59AM -0700, Stephane Eranian wrote: > On Mon, Jul 15, 2019 at 12:59 AM Jiri Olsa wrote: > > > > On Sun, Jul 14, 2019 at 02:36:42PM -0700, Stephane Eranian wrote: > > > On Sun, Jul 14, 2019 at 1:55 PM Jiri Olsa wrote: > > > > > > > > On Sun, Jul 14, 2019 at 10:44:36PM +0200, Jiri Olsa wrote: > > > > > On Wed, Jul 10, 2019 at 01:45:40PM -0700, Numfor Mbiziwo-Tiapo wrote: > > > > > > When perf stat is called with event groups and the repeat option, > > > > > > a segfault occurs because the cpu ids are stored on each iteration > > > > > > of the repeat, when they should only be stored on the first iteration, > > > > > > which causes a buffer overflow. > > > > > > > > > > > > This can be replicated by running (from the tip directory): > > > > > > > > > > > > make -C tools/perf > > > > > > > > > > > > then running: > > > > > > > > > > > > tools/perf/perf stat -e '{cycles,instructions}' -r 10 ls > > > > > > > > > > > > Since run_idx keeps track of the current iteration of the repeat, > > > > > > only storing the cpu ids on the first iteration (when run_idx < 1) > > > > > > fixes this issue. > > > > > > > > > > > > Signed-off-by: Numfor Mbiziwo-Tiapo > > > > > > --- > > > > > > tools/perf/builtin-stat.c | 7 ++++--- > > > > > > 1 file changed, 4 insertions(+), 3 deletions(-) > > > > > > > > > > > > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > > > > > > index 63a3afc7f32b..92d6694367e4 100644 > > > > > > --- a/tools/perf/builtin-stat.c > > > > > > +++ b/tools/perf/builtin-stat.c > > > > > > @@ -378,9 +378,10 @@ static void workload_exec_failed_signal(int signo __maybe_unused, siginfo_t *inf > > > > > > workload_exec_errno = info->si_value.sival_int; > > > > > > } > > > > > > > > > > > > -static bool perf_evsel__should_store_id(struct perf_evsel *counter) > > > > > > +static bool perf_evsel__should_store_id(struct perf_evsel *counter, int run_idx) > > > > > > { > > > > > > - return STAT_RECORD || counter->attr.read_format & PERF_FORMAT_ID; > > > > > > + return STAT_RECORD || counter->attr.read_format & PERF_FORMAT_ID > > > > > > + && run_idx < 1; > > > > > > > > > > we create counters for every iteration, so this can't be > > > > > based on iteration > > > > > > > > > > I think that's just a workaround for memory corruption, > > > > > that's happening for repeating groupped events stats, > > > > > I'll check on this > > > > > > > > how about something like this? we did not cleanup > > > > ids on evlist close, so it kept on raising and > > > > causing corruption in next iterations > > > > > > > not sure, that would realloc on each iteration of the repeats. > > > > well, we need new ids, because we create new events every iteration > > > If you recreate them, then agreed. > It is not clear to me why you need ids when not running is STAT_RECORD mode. it's for faster reading of group events, see: 82bf311e15d2 perf stat: Use group read for event groups jirka