Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2083681ybp; Thu, 10 Oct 2019 01:54:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqy5PLn9yGHsbiHH8B1DPfgG0W0Y874jjyhGA9Lx/fRWDtuPvDQSD2iUj64pqQEQk+Ib3Ojo X-Received: by 2002:a05:6402:134e:: with SMTP id y14mr7279635edw.55.1570697665104; Thu, 10 Oct 2019 01:54:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570697665; cv=none; d=google.com; s=arc-20160816; b=SUozGawbS5f2YKD5pvuK1dRR/ox+dn0S9alJ7HMryNB/EANvLYWeS1DcubyO6OvBB7 Dq3dy6JNIltS08bxCW5loirGz1AajyuuiAza/pN5ixkzC7QCyM2qJTz1YdHYcOxIOmBu zpTnbNmh2IKoCOhgL7fldSA65p0TLWpYRo2TKdZpXgg+R+ELWlOgUY8Svf+GnPdH9xmi 7Ee0EbWXHsc3hf1yGA+/2MpqtoEt/dh443Pjhs+xAg4U/ThXBbqHcQACCK7uH5+Q+0dL 9kMxl8x3/v8jCYLhgQcOeWhNcTJ/KOU/Y8wDaJLx8jadZPryu2GImjBpChrH+sff9yS5 WquA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7w1vskuY+40kGTpSWp//3kk5ZqTmDX+0qmm3Ga2vxeE=; b=tgov+MPw9hmVXZC4x2UxtULMKh8pLzVlcSf4S6s9aZPWj57LEYC7vIqEeHYcRKWOSF rz8iIvBHgNvI+JBHcNGWlBt0etpxLLxjpz1BPj9VQqXefK6WB1O+cSpjK0fROBp067ap d+WWulPwriEA0/bUQHTKAkBQ59WR0WlO7nKBtIM0esWaQD2WyfEffGRKz69ET7wEEIM4 DysMwRlNAyVyLGS3ukRdl4XvsgKzlVgjTnW3iCwcu12STctbuV1Fg8n2WX6kj3Nrwe9t AsIeYUBxo5RqxY6PYPUTIZKq/F0clizC7kyK+cB1FcR51Z3tV7JzMaiobHMBmfQ2klpd QSdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=R0L2w0Tt; 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 k6si2691841ejc.399.2019.10.10.01.54.01; Thu, 10 Oct 2019 01:54: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=R0L2w0Tt; 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 S2388860AbfJJIv6 (ORCPT + 99 others); Thu, 10 Oct 2019 04:51:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:59582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389331AbfJJIvx (ORCPT ); Thu, 10 Oct 2019 04:51:53 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 ADAD22064A; Thu, 10 Oct 2019 08:51:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570697512; bh=QzZUIKgGeYlbpmGf0NnBsRvUqyBwNvPwsxQAVxza750=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R0L2w0TtOjZCoJU39zStT5g7pt1TFHINdOCkHUlKMm8bkfRQtYSkh/f2UfV5/R+l9 eZQFfiHGw40J9nEhPzEbe9kZBcfQecBVoUN4Y2Phn2Be1aaR0YwGNsMa+YFxpQiaBO mIsVgXUUdwjQ+r050XTx+MVmo8gFRXMuk/7hmGrU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Srikar Dronamraju , Jiri Olsa , Arnaldo Carvalho de Melo , Ravi Bangoria , Namhyung Kim , "Naveen N. Rao" , Sasha Levin Subject: [PATCH 4.14 53/61] perf stat: Fix a segmentation fault when using repeat forever Date: Thu, 10 Oct 2019 10:37:18 +0200 Message-Id: <20191010083523.076799160@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083449.500442342@linuxfoundation.org> References: <20191010083449.500442342@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Srikar Dronamraju [ Upstream commit 443f2d5ba13d65ccfd879460f77941875159d154 ] Observe a segmentation fault when 'perf stat' is asked to repeat forever with the interval option. Without fix: # perf stat -r 0 -I 5000 -e cycles -a sleep 10 # time counts unit events 5.000211692 3,13,89,82,34,157 cycles 10.000380119 1,53,98,52,22,294 cycles 10.040467280 17,16,79,265 cycles Segmentation fault This problem was only observed when we use forever option aka -r 0 and works with limited repeats. Calling print_counter with ts being set to NULL, is not a correct option when interval is set. Hence avoid print_counter(NULL,..) if interval is set. With fix: # perf stat -r 0 -I 5000 -e cycles -a sleep 10 # time counts unit events 5.019866622 3,15,14,43,08,697 cycles 10.039865756 3,15,16,31,95,261 cycles 10.059950628 1,26,05,47,158 cycles 5.009902655 3,14,52,62,33,932 cycles 10.019880228 3,14,52,22,89,154 cycles 10.030543876 66,90,18,333 cycles 5.009848281 3,14,51,98,25,437 cycles 10.029854402 3,15,14,93,04,918 cycles 5.009834177 3,14,51,95,92,316 cycles Committer notes: Did the 'git bisect' to find the cset introducing the problem to add the Fixes tag below, and at that time the problem reproduced as: (gdb) run stat -r0 -I500 sleep 1 Program received signal SIGSEGV, Segmentation fault. print_interval (prefix=prefix@entry=0x7fffffffc8d0 "", ts=ts@entry=0x0) at builtin-stat.c:866 866 sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, csv_sep); (gdb) bt #0 print_interval (prefix=prefix@entry=0x7fffffffc8d0 "", ts=ts@entry=0x0) at builtin-stat.c:866 #1 0x000000000041860a in print_counters (ts=ts@entry=0x0, argc=argc@entry=2, argv=argv@entry=0x7fffffffd640) at builtin-stat.c:938 #2 0x0000000000419a7f in cmd_stat (argc=2, argv=0x7fffffffd640, prefix=) at builtin-stat.c:1411 #3 0x000000000045c65a in run_builtin (p=p@entry=0x6291b8 , argc=argc@entry=5, argv=argv@entry=0x7fffffffd640) at perf.c:370 #4 0x000000000045c893 in handle_internal_command (argc=5, argv=0x7fffffffd640) at perf.c:429 #5 0x000000000045c8f1 in run_argv (argcp=argcp@entry=0x7fffffffd4ac, argv=argv@entry=0x7fffffffd4a0) at perf.c:473 #6 0x000000000045cac9 in main (argc=, argv=) at perf.c:588 (gdb) Mostly the same as just before this patch: Program received signal SIGSEGV, Segmentation fault. 0x00000000005874a7 in print_interval (config=0xa1f2a0 , evlist=0xbc9b90, prefix=0x7fffffffd1c0 "`", ts=0x0) at util/stat-display.c:964 964 sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, config->csv_sep); (gdb) bt #0 0x00000000005874a7 in print_interval (config=0xa1f2a0 , evlist=0xbc9b90, prefix=0x7fffffffd1c0 "`", ts=0x0) at util/stat-display.c:964 #1 0x0000000000588047 in perf_evlist__print_counters (evlist=0xbc9b90, config=0xa1f2a0 , _target=0xa1f0c0 , ts=0x0, argc=2, argv=0x7fffffffd670) at util/stat-display.c:1172 #2 0x000000000045390f in print_counters (ts=0x0, argc=2, argv=0x7fffffffd670) at builtin-stat.c:656 #3 0x0000000000456bb5 in cmd_stat (argc=2, argv=0x7fffffffd670) at builtin-stat.c:1960 #4 0x00000000004dd2e0 in run_builtin (p=0xa30e00 , argc=5, argv=0x7fffffffd670) at perf.c:310 #5 0x00000000004dd54d in handle_internal_command (argc=5, argv=0x7fffffffd670) at perf.c:362 #6 0x00000000004dd694 in run_argv (argcp=0x7fffffffd4cc, argv=0x7fffffffd4c0) at perf.c:406 #7 0x00000000004dda11 in main (argc=5, argv=0x7fffffffd670) at perf.c:531 (gdb) Fixes: d4f63a4741a8 ("perf stat: Introduce print_counters function") Signed-off-by: Srikar Dronamraju Acked-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Tested-by: Ravi Bangoria Cc: Namhyung Kim Cc: Naveen N. Rao Cc: stable@vger.kernel.org # v4.2+ Link: http://lore.kernel.org/lkml/20190904094738.9558-3-srikar@linux.vnet.ibm.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/builtin-stat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 52486c90ab936..b6c1c9939c2f1 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2770,7 +2770,7 @@ int cmd_stat(int argc, const char **argv) run_idx + 1); status = run_perf_stat(argc, argv); - if (forever && status != -1) { + if (forever && status != -1 && !interval) { print_counters(NULL, argc, argv); perf_stat__reset_stats(); } -- 2.20.1