Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9084996pxu; Mon, 28 Dec 2020 06:16:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJx3pBdylaJoSjHdWy8AktegUXyk1a1iDCK9h8agCfvunyxY1KYyEwHIZgRyUyobTUIpZcvl X-Received: by 2002:a17:906:af75:: with SMTP id os21mr42365449ejb.330.1609164974247; Mon, 28 Dec 2020 06:16:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609164974; cv=none; d=google.com; s=arc-20160816; b=WQ/kZKv06ynpRTrU8Dd772HYeVMSbb1IkxeyzGKnb3t5gMi1JapW4hGVJ+00hYaw/i 1lJtlhITh2cEG4LHDQ6ux84tGCd+JYuJBe46ASwEPXAGchNxbCAt9NCBzyfb6+mCalZU ggyryvP7xd5wObPyjBFtmPC+ZLb0GitASF5Bs8IBKu7VnHVSrEZ1ZdvZCSHrhmb4sp4m eQs0LW01wRjKooR67Gdx3kuH3Lw85WmKpxV5SLl1tfHs0Eftb2UORsQRZ2xAx/WDUgjX AhIsHfEPoVd+P3qkt2q3XXab4kT0xVS/hYsZh9XiqYdFim9uXGL41nFOAHanQlQc8jzs oA1g== 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=M1F+rXFyZWsbzdpRKeiaJxp4LrzNtzRlkrOWIfQBfn4=; b=AmLcKFTB7J5VOlK5DNc4LMwQFV31/3njsBairNYoIEYLGmfepmAKzsOQLXbPtgo7hU Z/1MRcbrSljZV1wWp4arkrNQYidB5AhlYRwgwzHDeTy/QolJuzC4NNcD0xoEDTZHdS9D /zWcryMgIp/olJ81UOTMtyQQcOwb6khueBItxs7gad3jmmzPOMRVOoz2RMSziHNx2hJC IhAFN0uwjmSHBQP7Mcp1vNl/dNjTNXFdJt3gmsf9WBur/M+Prl40rUqoiG52NVkhK4A+ /ghSbIYa6Q9eKAhJsckdnK/azSed36/s+QIdkbzZPXp2RUvslyNtF8AYu/2uUKqBZFZo C97w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gfuiLxSh; 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 h26si18764407ejq.399.2020.12.28.06.15.51; Mon, 28 Dec 2020 06:16:14 -0800 (PST) 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=gfuiLxSh; 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 S2440292AbgL1ON6 (ORCPT + 99 others); Mon, 28 Dec 2020 09:13:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:48566 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2440283AbgL1ONz (ORCPT ); Mon, 28 Dec 2020 09:13:55 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 652BB20791; Mon, 28 Dec 2020 14:13:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609164819; bh=LuCfF+Xzrjs1dNnQyLjcvWfeaoI+MMU+/dYfWKcA+Ro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gfuiLxSh6W0oyF7QVC7TnPONrr66SucbcxQzfJdkXbu/e0mby0MS0Qaa4x5YhjG4n nMbFipGSa/vrdNxdSPbAbTwUTFPoPh00wKWYN0H/+WD/naXel0tf9RSBcBizR38fqC x0d62IxW7JDjj9qIne1nxYOieFtLdPa/btr5QLBk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sachin Sant , Athira Rajeev , Michael Ellerman , Sasha Levin Subject: [PATCH 5.10 279/717] powerpc/perf: Fix crash with is_sier_available when pmu is not set Date: Mon, 28 Dec 2020 13:44:37 +0100 Message-Id: <20201228125034.387934879@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@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: Athira Rajeev [ Upstream commit f75e7d73bdf73f07b0701a6d21c111ef5d9021dd ] On systems without any specific PMU driver support registered, running 'perf record' with —intr-regs will crash ( perf record -I ). The relevant portion from crash logs and Call Trace: Unable to handle kernel paging request for data at address 0x00000068 Faulting instruction address: 0xc00000000013eb18 Oops: Kernel access of bad area, sig: 11 [#1] CPU: 2 PID: 13435 Comm: kill Kdump: loaded Not tainted 4.18.0-193.el8.ppc64le #1 NIP: c00000000013eb18 LR: c000000000139f2c CTR: c000000000393d80 REGS: c0000004a07ab4f0 TRAP: 0300 Not tainted (4.18.0-193.el8.ppc64le) NIP [c00000000013eb18] is_sier_available+0x18/0x30 LR [c000000000139f2c] perf_reg_value+0x6c/0xb0 Call Trace: [c0000004a07ab770] [c0000004a07ab7c8] 0xc0000004a07ab7c8 (unreliable) [c0000004a07ab7a0] [c0000000003aa77c] perf_output_sample+0x60c/0xac0 [c0000004a07ab840] [c0000000003ab3f0] perf_event_output_forward+0x70/0xb0 [c0000004a07ab8c0] [c00000000039e208] __perf_event_overflow+0x88/0x1a0 [c0000004a07ab910] [c00000000039e42c] perf_swevent_hrtimer+0x10c/0x1d0 [c0000004a07abc50] [c000000000228b9c] __hrtimer_run_queues+0x17c/0x480 [c0000004a07abcf0] [c00000000022aaf4] hrtimer_interrupt+0x144/0x520 [c0000004a07abdd0] [c00000000002a864] timer_interrupt+0x104/0x2f0 [c0000004a07abe30] [c0000000000091c4] decrementer_common+0x114/0x120 When perf record session is started with "-I" option, capturing registers on each sample calls is_sier_available() to check for the SIER (Sample Instruction Event Register) availability in the platform. This function in core-book3s accesses 'ppmu->flags'. If a platform specific PMU driver is not registered, ppmu is set to NULL and accessing its members results in a crash. Fix the crash by returning false in is_sier_available() if ppmu is not set. Fixes: 333804dc3b7a ("powerpc/perf: Update perf_regs structure to include SIER") Reported-by: Sachin Sant Signed-off-by: Athira Rajeev Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/1606185640-1720-1-git-send-email-atrajeev@linux.vnet.ibm.com Signed-off-by: Sasha Levin --- arch/powerpc/perf/core-book3s.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c index 08643cba14948..1de4770c2194b 100644 --- a/arch/powerpc/perf/core-book3s.c +++ b/arch/powerpc/perf/core-book3s.c @@ -137,6 +137,9 @@ static void pmao_restore_workaround(bool ebb) { } bool is_sier_available(void) { + if (!ppmu) + return false; + if (ppmu->flags & PPMU_HAS_SIER) return true; -- 2.27.0