Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3982854pxb; Mon, 4 Oct 2021 14:23:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYHYx7qKDtkan453mIVZPrFWy+NyIphzSatt/WXG4eFQuJqjfdohN+THCAx9SiTu1NmjvK X-Received: by 2002:a17:90a:47:: with SMTP id 7mr33027185pjb.46.1633382601741; Mon, 04 Oct 2021 14:23:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633382601; cv=none; d=google.com; s=arc-20160816; b=ZRtLMY7bXIr8OZ9hn1fsYXjoZPQzxV4q16vzMTG56F2SkvhZqCuCqii9GbgOQhrYUl y//LcsCVXXeAs4h8aGzFzA+W8kh7EDeMUxnQaeVzquF4qzGEEtNQzvRJbEEieOmZEk/r 780g9R832jaiP3WTg8KVDcZCh1M9UQS2coFea9WN0FEHWnouigSKKAxYFaW1EG99nEnQ wv/Cj7gNsp4Hu16anjCwiQtGNKQ+lu2nH6yeXtZ5XBrRowOFCHSJq66qa2l40fNFwHIS f3fBAZ3+GkrQDaKLDrapOIjtXmiJQ1LVoNyrrWloHczN4n4xj6YJRq0fdsG8QF4TofAi Jnbg== 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=3eybG2hhfdEw98zU8K2cjToOyazZeJfEJDzTjzfqDNg=; b=XSFg6Pysl/updDl2h7eDAVmFik+8HCtE+Zssfew2/w48nGZB1Y9rNrULDgYm40lBFh Ekw7RJNP4MQvRlopFBoOfb8ZtG9cs9NrAFQV58q2gml6KG9I2fGyGCJf0sPvgrtHJOGR I+24iKKu+6sKePRxnhT6c7D4RCHPK9ToTJzBgf8SLeY+ZWdj5SRJLg2I2PiBIgW6D/Ad weqEnp7UcepIyqBqyw5MQpCvQvIIhLInLFeF/jE7PTj8hu5HLHv1IShXwTdgPL2qV9cu CJIEZay3aou/q/+6NX1A2EdPT7Um1VcnTBc7secCEz03mB+O7CnFMSf4CsWw3nPK8iOB HD0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GmHhHmDr; 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 a3si21263461pls.163.2021.10.04.14.23.08; Mon, 04 Oct 2021 14:23:21 -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=GmHhHmDr; 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 S237092AbhJDNcP (ORCPT + 99 others); Mon, 4 Oct 2021 09:32:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:43492 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237735AbhJDNaW (ORCPT ); Mon, 4 Oct 2021 09:30:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1315361B3E; Mon, 4 Oct 2021 13:13:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353220; bh=a4zoJc5uapeK376WmBaJPS7Dvv8GZptPeFqhDydmTFw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GmHhHmDr6ouJIQq4pG2gOi5Lbdpl94PVLcYdH2BGF0UqIoooBSP9TE8ief8s6V6D5 0OuHrAsWe4cyjpvo1UmD0+Vjm9d0TCFwIiRowDCvVTYe0ePitGbhYrI9YjHUhNuTmW Sjm1IKt/80/Kaz0ZJB7kNhqbbZOJ+dcGSz0qa80o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Like Xu , Alexander Antonov , Alexander Shishkin , Ian Rogers , Jiri Olsa , Mark Rutland , Namhyung Kim , Peter Zijlstra , Stephane Eranian , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.14 025/172] perf iostat: Fix Segmentation fault from NULL struct perf_counts_values * Date: Mon, 4 Oct 2021 14:51:15 +0200 Message-Id: <20211004125045.781798191@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@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: Like Xu [ Upstream commit 4da8b121884d84476f3d50d46a471471af1aa9df ] If the 'perf iostat' user specifies two or more iio_root_ports and also specifies the cpu(s) by -C which is not *connected to all* the above iio ports, the iostat_print_metric() will run into trouble: For example: $ perf iostat list S0-uncore_iio_0<0000:16> S1-uncore_iio_0<0000:97> # <--- CPU 1 is located in the socket S0 $ perf iostat 0000:16,0000:97 -C 1 -- ls port Inbound Read(MB) Inbound Write(MB) Outbound Read(MB) Outbound Write(MB) ../perf-iostat: line 12: 104418 Segmentation fault (core dumped) perf stat --iostat$DELIMITER$* The core-dump stack says, in the above corner case, the returned (struct perf_counts_values *) count will be NULL, and the caller iostat_print_metric() apparently doesn't not handle this case. 433 struct perf_counts_values *count = perf_counts(evsel->counts, die, 0); 434 435 if (count->run && count->ena) { (gdb) p count $1 = (struct perf_counts_values *) 0x0 The deeper reason is that there are actually no statistics from the user specified pair "iostat 0000:X, -C (disconnected) Y ", but let's fix it with minimum cost by adding a NULL check in the user space. Fixes: f9ed693e8bc0e7de ("perf stat: Enable iostat mode for x86 platforms") Signed-off-by: Like Xu Cc: Alexander Antonov Cc: Alexander Shishkin Cc: Ian Rogers Cc: Jiri Olsa Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lore.kernel.org/lkml/20210927081115.39568-2-likexu@tencent.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/arch/x86/util/iostat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/arch/x86/util/iostat.c b/tools/perf/arch/x86/util/iostat.c index eeafe97b8105..792cd75ade33 100644 --- a/tools/perf/arch/x86/util/iostat.c +++ b/tools/perf/arch/x86/util/iostat.c @@ -432,7 +432,7 @@ void iostat_print_metric(struct perf_stat_config *config, struct evsel *evsel, u8 die = ((struct iio_root_port *)evsel->priv)->die; struct perf_counts_values *count = perf_counts(evsel->counts, die, 0); - if (count->run && count->ena) { + if (count && count->run && count->ena) { if (evsel->prev_raw_counts && !out->force_header) { struct perf_counts_values *prev_count = perf_counts(evsel->prev_raw_counts, die, 0); -- 2.33.0