From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758758AbbCDU2f (ORCPT ); Wed, 4 Mar 2015 15:28:35 -0500 Received: from mail-wi0-f182.google.com ([209.85.212.182]:36875 "EHLO mail-wi0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755135AbbCDU2d (ORCPT ); Wed, 4 Mar 2015 15:28:33 -0500 Date: Wed, 4 Mar 2015 21:28:28 +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: <20150304202828.GB6915@gmail.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> <37D7C6CF3E00A74B8858931C1DB2F077017119BD@SHSMSX103.ccr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <37D7C6CF3E00A74B8858931C1DB2F077017119BD@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: > > * 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)) > > > > return -EINVAL; > > > > > > > > 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. Oh, indeed, and I clearly cannot read code: your original argument and the revert is correct, sorry about the confusion! Thanks, Ingo