From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755020AbbCDErB (ORCPT ); Tue, 3 Mar 2015 23:47:01 -0500 Received: from mail-wi0-f178.google.com ([209.85.212.178]:39336 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752105AbbCDEq7 (ORCPT ); Tue, 3 Mar 2015 23:46:59 -0500 Date: Wed, 4 Mar 2015 05:46:54 +0100 From: Ingo Molnar To: "Liang, Kan" 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" Message-ID: <20150304044654.GA5061@gmail.com> References: <1425280466-7830-1-git-send-email-kan.liang@intel.com> <20150303084407.GA1448@gmail.com> <37D7C6CF3E00A74B8858931C1DB2F0770170D43A@SHSMSX103.ccr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <37D7C6CF3E00A74B8858931C1DB2F0770170D43A@SHSMSX103.ccr.corp.intel.com> User-Agent: Mutt/1.5.23 (2014-03-12) 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! Thanks, Ingo