From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758264AbbCDOGK (ORCPT ); Wed, 4 Mar 2015 09:06:10 -0500 Received: from mga11.intel.com ([192.55.52.93]:48957 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754549AbbCDOGI convert rfc822-to-8bit (ORCPT ); Wed, 4 Mar 2015 09:06:08 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,687,1418112000"; d="scan'208";a="462406563" From: "Liang, Kan" To: Ingo Molnar CC: "hpa@zytor.com" , "ak@linux.intel.com" , "acme@redhat.com" , "a.p.zijlstra@chello.nl" , "linux-kernel@vger.kernel.org" , "xiakaixu@huawei.com" , "tglx@linutronix.de" , "linux-tip-commits@vger.kernel.org" Subject: RE: [tip:perf/core] Revert "perf: Remove the extra validity check on nr_pages" Thread-Topic: [tip:perf/core] Revert "perf: Remove the extra validity check on nr_pages" Thread-Index: AQHQVY5HqWbmRIhiykqnU5Lr/CQ1I50LLQnwgAAONwCAASG+0A== Date: Wed, 4 Mar 2015 14:06:01 +0000 Message-ID: <37D7C6CF3E00A74B8858931C1DB2F077017119BD@SHSMSX103.ccr.corp.intel.com> References: <1425280466-7830-1-git-send-email-kan.liang@intel.com> <20150303084407.GA1448@gmail.com> <37D7C6CF3E00A74B8858931C1DB2F0770170D43A@SHSMSX103.ccr.corp.intel.com> <20150304044654.GA5061@gmail.com> In-Reply-To: <20150304044654.GA5061@gmail.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: 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 > > > * Liang, Kan wrote: > > > > * tip-bot for Kan Liang wrote: > > > > > > > --- a/kernel/events/core.c > > > > +++ b/kernel/events/core.c > > > > @@ -4446,7 +4446,7 @@ static int perf_mmap(struct file *file, struct > > > vm_area_struct *vma) > > > > * If we have rb pages ensure they're a power-of-two number, so > > > we > > > > * can do bitmasks instead of modulo. > > > > */ > > > > - if (!is_power_of_2(nr_pages)) > > > > + if (nr_pages != 0 && !is_power_of_2(nr_pages)) > > > > return -EINVAL; > > > > > > Hm, what does is_power_of_2(0) return? It should return 0, because 0 > is > > > not a power of 2! > > > > > > and if it's fixed to return 0, then the check should properly be > something > > > like: > > > > > > if (!nr_pages || !is_power_of_2(nr_pages)) > > > > > > or so? > > > > nr_pages == 0 is valid, we cannot return -EINVAL. Because > > vma_size = vma->vm_end - vma->vm_start; > > nr_pages = (vma_size / PAGE_SIZE) - 1; > > > > So here we only want to check is_power_of_2 > > when the pages > 1 (or nr_pages > 0). > > I don't think you answered my first question, on which my later > comments rely: > > > > Hm, what does is_power_of_2(0) return? It should return 0, because 0 > is > > > not a power of 2! Yes, is_power_of_2(0) returns 0. Thanks, Kan > > Thanks, > > Ingo