linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] Revert "perf: Remove the extra validity check on nr_pages"
@ 2015-03-02  7:14 kan.liang
  2015-03-02 21:03 ` Arnaldo Carvalho de Melo
  2015-03-03  6:26 ` [tip:perf/core] " tip-bot for Kan Liang
  0 siblings, 2 replies; 8+ messages in thread
From: kan.liang @ 2015-03-02  7:14 UTC (permalink / raw)
  To: acme; +Cc: linux-kernel, xiakaixu, a.p.zijlstra, ak, Kan Liang

From: Kan Liang <kan.liang@intel.com>

This reverts commit 74390aa55678 ("perf: Remove the extra validity check
on nr_pages")

nr_pages equals to number of pages - 1 in perf_mmap. So nr_pages = 0 is
valide. So the nr_pages != 0 && !is_power_of_2(nr_pages) are all
needed for checking. Otherwise, for example, perf test 6 failed.
perf test 6
 6: x86 rdpmc test                                         :Error:
mmap() syscall returned with (Invalid argument)
 FAILED!

Signed-off-by: Kan Liang <kan.liang@intel.com>
---
 kernel/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 89f0f16..a83581c 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -4423,7 +4423,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;
 
 	if (vma_size != PAGE_SIZE * (1 + nr_pages))
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/1] Revert "perf: Remove the extra validity check on nr_pages"
  2015-03-02  7:14 [PATCH 1/1] Revert "perf: Remove the extra validity check on nr_pages" kan.liang
@ 2015-03-02 21:03 ` Arnaldo Carvalho de Melo
  2015-03-03  6:26 ` [tip:perf/core] " tip-bot for Kan Liang
  1 sibling, 0 replies; 8+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-03-02 21:03 UTC (permalink / raw)
  To: kan.liang; +Cc: Ingo Molnar, linux-kernel, xiakaixu, a.p.zijlstra, ak

Em Mon, Mar 02, 2015 at 02:14:26AM -0500, kan.liang@intel.com escreveu:
> From: Kan Liang <kan.liang@intel.com>
> 
> This reverts commit 74390aa55678 ("perf: Remove the extra validity check
> on nr_pages")
> 
> nr_pages equals to number of pages - 1 in perf_mmap. So nr_pages = 0 is
> valide. So the nr_pages != 0 && !is_power_of_2(nr_pages) are all
> needed for checking. Otherwise, for example, perf test 6 failed.
> perf test 6
>  6: x86 rdpmc test                                         :Error:
> mmap() syscall returned with (Invalid argument)
>  FAILED!

Yeah, my bad, we need to revert this, its just on tip/perf/core, will
put the revert in my next pull request, thanks for spotting this!

- Arnaldo
 
> Signed-off-by: Kan Liang <kan.liang@intel.com>
> ---
>  kernel/events/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 89f0f16..a83581c 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -4423,7 +4423,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;
>  
>  	if (vma_size != PAGE_SIZE * (1 + nr_pages))
> -- 
> 1.8.3.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [tip:perf/core] Revert "perf: Remove the extra validity check on nr_pages"
  2015-03-02  7:14 [PATCH 1/1] Revert "perf: Remove the extra validity check on nr_pages" kan.liang
  2015-03-02 21:03 ` Arnaldo Carvalho de Melo
@ 2015-03-03  6:26 ` tip-bot for Kan Liang
  2015-03-03  8:44   ` Ingo Molnar
  1 sibling, 1 reply; 8+ messages in thread
From: tip-bot for Kan Liang @ 2015-03-03  6:26 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: ak, acme, a.p.zijlstra, kan.liang, hpa, mingo, tglx,
	linux-kernel, xiakaixu

Commit-ID:  2ed11312eb19506c027e7cac039994ad42a9cb2c
Gitweb:     http://git.kernel.org/tip/2ed11312eb19506c027e7cac039994ad42a9cb2c
Author:     Kan Liang <kan.liang@intel.com>
AuthorDate: Mon, 2 Mar 2015 02:14:26 -0500
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 2 Mar 2015 18:25:38 -0300

Revert "perf: Remove the extra validity check on nr_pages"

This reverts commit 74390aa55678 ("perf: Remove the extra validity check
on nr_pages")

nr_pages equals to number of pages - 1 in perf_mmap. So nr_pages = 0 is
valid.

So the nr_pages != 0 && !is_power_of_2(nr_pages) are all
needed for checking. Otherwise, for example, perf test 6 failed.

 # perf test 6
  6: x86 rdpmc test                                         :Error:
 mmap() syscall returned with (Invalid argument)
 FAILED!

Signed-off-by: Kan Liang <kan.liang@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Kaixu Xia <xiakaixu@huawei.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1425280466-7830-1-git-send-email-kan.liang@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 kernel/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index af924bc..8bb20cc 100644
--- 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;
 
 	if (vma_size != PAGE_SIZE * (1 + nr_pages))

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [tip:perf/core] Revert "perf: Remove the extra validity check on nr_pages"
  2015-03-03  6:26 ` [tip:perf/core] " tip-bot for Kan Liang
@ 2015-03-03  8:44   ` Ingo Molnar
  2015-03-03 20:04     ` Liang, Kan
  0 siblings, 1 reply; 8+ messages in thread
From: Ingo Molnar @ 2015-03-03  8:44 UTC (permalink / raw)
  To: hpa, ak, acme, kan.liang, a.p.zijlstra, linux-kernel, xiakaixu, tglx
  Cc: linux-tip-commits


* 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?

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [tip:perf/core] Revert "perf: Remove the extra validity check on nr_pages"
  2015-03-03  8:44   ` Ingo Molnar
@ 2015-03-03 20:04     ` Liang, Kan
  2015-03-04  4:46       ` Ingo Molnar
  0 siblings, 1 reply; 8+ messages in thread
From: Liang, Kan @ 2015-03-03 20:04 UTC (permalink / raw)
  To: Ingo Molnar, hpa, ak, acme, a.p.zijlstra, linux-kernel, xiakaixu, tglx
  Cc: linux-tip-commits



> 
> 
> * 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).

Thanks,
Kan

> 
> Thanks,
> 
> 	Ingo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [tip:perf/core] Revert "perf: Remove the extra validity check on nr_pages"
  2015-03-03 20:04     ` Liang, Kan
@ 2015-03-04  4:46       ` Ingo Molnar
  2015-03-04 14:06         ` Liang, Kan
  0 siblings, 1 reply; 8+ messages in thread
From: Ingo Molnar @ 2015-03-04  4:46 UTC (permalink / raw)
  To: Liang, Kan
  Cc: hpa, ak, acme, a.p.zijlstra, linux-kernel, xiakaixu, tglx,
	linux-tip-commits


* 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!

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [tip:perf/core] Revert "perf: Remove the extra validity check on nr_pages"
  2015-03-04  4:46       ` Ingo Molnar
@ 2015-03-04 14:06         ` Liang, Kan
  2015-03-04 20:28           ` Ingo Molnar
  0 siblings, 1 reply; 8+ messages in thread
From: Liang, Kan @ 2015-03-04 14:06 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: hpa, ak, acme, a.p.zijlstra, linux-kernel, xiakaixu, tglx,
	linux-tip-commits



> 
> 
> * 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [tip:perf/core] Revert "perf: Remove the extra validity check on nr_pages"
  2015-03-04 14:06         ` Liang, Kan
@ 2015-03-04 20:28           ` Ingo Molnar
  0 siblings, 0 replies; 8+ messages in thread
From: Ingo Molnar @ 2015-03-04 20:28 UTC (permalink / raw)
  To: Liang, Kan
  Cc: hpa, ak, acme, a.p.zijlstra, linux-kernel, xiakaixu, tglx,
	linux-tip-commits


* Liang, Kan <kan.liang@intel.com> wrote:

> > * 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))
> > > >  		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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-03-04 20:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-02  7:14 [PATCH 1/1] Revert "perf: Remove the extra validity check on nr_pages" kan.liang
2015-03-02 21:03 ` Arnaldo Carvalho de Melo
2015-03-03  6:26 ` [tip:perf/core] " tip-bot for Kan Liang
2015-03-03  8:44   ` Ingo Molnar
2015-03-03 20:04     ` Liang, Kan
2015-03-04  4:46       ` Ingo Molnar
2015-03-04 14:06         ` Liang, Kan
2015-03-04 20:28           ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).