lkml.org 
[lkml]   [2015]   [Mar]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [tip:perf/core] Revert "perf: Remove the extra validity check on nr_pages"
Date


>
>
> * Liang, Kan <kan.liang@intel.com> wrote:
>
> > > * tip-bot for Kan Liang <tipbot@zytor.com> 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


\
 
 \ /
  Last update: 2015-03-04 15:21    [W:0.162 / U:0.068 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site