Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751162AbdLAFGG (ORCPT ); Fri, 1 Dec 2017 00:06:06 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:33568 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750859AbdLAFGF (ORCPT ); Fri, 1 Dec 2017 00:06:05 -0500 Subject: Re: [PATCH] powerpc/perf: Fix oops when grouping different pmu events To: Ravi Bangoria , mpe@ellerman.id.au Cc: benh@kernel.crashing.org, paulus@samba.org, tglx@linutronix.de, kan.liang@intel.com, sukadev@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org References: <20171130083322.31206-1-ravi.bangoria@linux.vnet.ibm.com> From: Madhavan Srinivasan Date: Fri, 1 Dec 2017 10:35:56 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171130083322.31206-1-ravi.bangoria@linux.vnet.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 17120105-0008-0000-0000-000004B1AA9F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17120105-0009-0000-0000-00001E44926D Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-12-01_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712010059 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2098 Lines: 54 On Thursday 30 November 2017 02:03 PM, Ravi Bangoria wrote: > When user tries to group imc (In-Memory Collections) event with > normal event, (sometime) kernel crashes with following log: > > Faulting instruction address: 0x00000000 > [link register ] c00000000010ce88 power_check_constraints+0x128/0x980 > ... > c00000000010e238 power_pmu_event_init+0x268/0x6f0 > c0000000002dc60c perf_try_init_event+0xdc/0x1a0 > c0000000002dce88 perf_event_alloc+0x7b8/0xac0 > c0000000002e92e0 SyS_perf_event_open+0x530/0xda0 > c00000000000b004 system_call+0x38/0xe0 > > 'event_base' field of 'struct hw_perf_event' is used as flags for > normal hw events and used as memory address for imc events. While > grouping these two types of events, collect_events() tries to > interpret imc 'event_base' as a flag, which causes a corruption > resulting in a crash. > > Consider only those events which belongs to 'perf_hw_context' in > collect_events(). Reviewed-By: Madhavan Srinivasan > > Signed-off-by: Ravi Bangoria > --- > arch/powerpc/perf/core-book3s.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c > index 9e3da16..1538129 100644 > --- a/arch/powerpc/perf/core-book3s.c > +++ b/arch/powerpc/perf/core-book3s.c > @@ -1415,7 +1415,7 @@ static int collect_events(struct perf_event *group, int max_count, > int n = 0; > struct perf_event *event; > > - if (!is_software_event(group)) { > + if (group->pmu->task_ctx_nr == perf_hw_context) { > if (n >= max_count) > return -1; > ctrs[n] = group; > @@ -1423,7 +1423,7 @@ static int collect_events(struct perf_event *group, int max_count, > events[n++] = group->hw.config; > } > list_for_each_entry(event, &group->sibling_list, group_entry) { > - if (!is_software_event(event) && > + if (event->pmu->task_ctx_nr == perf_hw_context && > event->state != PERF_EVENT_STATE_OFF) { > if (n >= max_count) > return -1;