Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756197AbcCUOTd (ORCPT ); Mon, 21 Mar 2016 10:19:33 -0400 Received: from mga01.intel.com ([192.55.52.88]:33716 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755376AbcCUOTb convert rfc822-to-8bit (ORCPT ); Mon, 21 Mar 2016 10:19:31 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,372,1455004800"; d="scan'208";a="915621501" From: "Liang, Kan" To: Thomas Gleixner , LKML CC: Peter Zijlstra , "x86@kernel.org" , Stephane Eranian , Borislav Petkov , "Andi Kleen (ak@linux.intel.com)" Subject: RE: [patch 2/4] x86/perf/intel/cstate: Sanitize probing Thread-Topic: [patch 2/4] x86/perf/intel/cstate: Sanitize probing Thread-Index: AQHRgtrSKWxUAB1xQkadBOnglt+kv59j7zaw Date: Mon, 21 Mar 2016 14:19:27 +0000 Message-ID: <37D7C6CF3E00A74B8858931C1DB2F077058A7665@SHSMSX103.ccr.corp.intel.com> References: <20160320185527.763205536@linutronix.de> <20160320185623.500381872@linutronix.de> In-Reply-To: <20160320185623.500381872@linutronix.de> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYjBiN2JmMDItNjM4MC00OGY2LWJiM2YtZDIwMTNiMzI3OWVjIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6ImhRM0E3MEhzRk02UFk4aHRzY0szVk92QUpaRGNPMFJaVWxBZTBZalJkS3c9In0= x-ctpclassification: CTP_IC x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1368 Lines: 49 > /* > * Probe the cstate events and insert the available one into sysfs attrs > - * Return false if there is no available events. > + * Return false if there are no available events. > */ > -static bool cstate_probe_msr(struct perf_cstate_msr *msr, > - struct attribute **events_attrs, > - int max_event_nr) > +static bool __init cstate_probe_msr(const unsigned long evmsk, > + struct perf_cstate_msr *msr, > + struct attribute **attrs) > { > - int i, j = 0; > + bool found = false; > + unsigned int bit; > u64 val; > > - /* Probe the cstate events. */ > - for (i = 0; i < max_event_nr; i++) { > - if (!msr[i].test(i) || rdmsrl_safe(msr[i].msr, &val)) > - msr[i].attr = NULL; > - } I think we need to update msr[i].attr as well. Because in cstate_pmu_event_init we still need it to do check. Thanks, Kan > - > - /* List remaining events in the sysfs attrs. */ > - for (i = 0; i < max_event_nr; i++) { > - if (msr[i].attr) > - events_attrs[j++] = &msr[i].attr->attr.attr; > + for_each_set_bit(bit, &evmsk, sizeof(evmsk) * BITS_PER_BYTE) { > + /* Verify whether the MSR is accessible */ > + if (!rdmsrl_safe(msr[bit].msr, &val)) { > + *attrs++ = &msr[bit].attr->attr.attr; > + found = true; > + } > } > - events_attrs[j] = NULL; > - > - return (j > 0) ? true : false; > + *attrs = NULL; > + return found; > } >