From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757435AbbCCUFK (ORCPT ); Tue, 3 Mar 2015 15:05:10 -0500 Received: from mga03.intel.com ([134.134.136.65]:10359 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756394AbbCCUFI convert rfc822-to-8bit (ORCPT ); Tue, 3 Mar 2015 15:05:08 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,683,1418112000"; d="scan'208";a="462032772" From: "Liang, Kan" To: Ingo Molnar , "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" CC: "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/CQ1I50LLQnw Date: Tue, 3 Mar 2015 20:04:42 +0000 Message-ID: <37D7C6CF3E00A74B8858931C1DB2F0770170D43A@SHSMSX103.ccr.corp.intel.com> References: <1425280466-7830-1-git-send-email-kan.liang@intel.com> <20150303084407.GA1448@gmail.com> In-Reply-To: <20150303084407.GA1448@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 > > > * 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). Thanks, Kan > > Thanks, > > Ingo