* [PATCH] perf: fix bug mismatch with -c option definition
@ 2010-05-17 10:04 Stephane Eranian
2010-05-17 11:29 ` Frederic Weisbecker
2010-05-17 14:19 ` Arnaldo Carvalho de Melo
0 siblings, 2 replies; 4+ messages in thread
From: Stephane Eranian @ 2010-05-17 10:04 UTC (permalink / raw)
To: linux-kernel
Cc: peterz, mingo, paulus, davem, fweisbec, acme, perfmon2-devel,
eranian, eranian
The -c option defines the user requested sampling period. It was implemented
using an unsigned int variable but the type of the option was OPT_LONG. Thus,
the option parser was overwriting memory belonging to other variables, namely
the mmap_pages leading to a zero page sampling buffer. The bug was exposed
only when compiling at -O0, probably because the compiler was padding
variables at higher optimization levels.
This patch fixes this problem by declaring user_interval as u64. This also
avoids wrap-around issues for large period on 32-bit systems.
Signed-off-by: Stephane Eranian <eranian@google.com>
--
tools/perf/builtin-record.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 0f467cf..78f64cc 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -33,8 +33,8 @@ enum write_mode_t {
static int *fd[MAX_NR_CPUS][MAX_COUNTERS];
-static unsigned int user_interval = UINT_MAX;
-static long default_interval = 0;
+static u64 user_interval = ULLONG_MAX;
+static u64 default_interval = 0;
static int nr_cpus = 0;
static unsigned int page_size;
@@ -268,7 +268,7 @@ static void create_counter(int counter, int cpu)
* it a weak assumption overridable by the user.
*/
if (!attr->sample_period || (user_freq != UINT_MAX &&
- user_interval != UINT_MAX)) {
+ user_interval != ULLONG_MAX)) {
if (freq) {
attr->sample_type |= PERF_SAMPLE_PERIOD;
attr->freq = 1;
@@ -901,7 +901,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
if (!event_array)
return -ENOMEM;
- if (user_interval != UINT_MAX)
+ if (user_interval != ULLONG_MAX)
default_interval = user_interval;
if (user_freq != UINT_MAX)
freq = user_freq;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] perf: fix bug mismatch with -c option definition
2010-05-17 10:04 [PATCH] perf: fix bug mismatch with -c option definition Stephane Eranian
@ 2010-05-17 11:29 ` Frederic Weisbecker
2010-05-17 14:19 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 4+ messages in thread
From: Frederic Weisbecker @ 2010-05-17 11:29 UTC (permalink / raw)
To: Stephane Eranian
Cc: linux-kernel, peterz, mingo, paulus, davem, acme, perfmon2-devel,
eranian
On Mon, May 17, 2010 at 12:04:01PM +0200, Stephane Eranian wrote:
> The -c option defines the user requested sampling period. It was implemented
> using an unsigned int variable but the type of the option was OPT_LONG. Thus,
> the option parser was overwriting memory belonging to other variables, namely
> the mmap_pages leading to a zero page sampling buffer. The bug was exposed
> only when compiling at -O0, probably because the compiler was padding
> variables at higher optimization levels.
>
> This patch fixes this problem by declaring user_interval as u64. This also
> avoids wrap-around issues for large period on 32-bit systems.
>
> Signed-off-by: Stephane Eranian <eranian@google.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Small detail: could you avoid the spaces in the beginning of
your changelog lines?
May be that's because you use git-show to dump your patches?
In which case I suggest you to use git-format-patch instead.
Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] perf: fix bug mismatch with -c option definition
2010-05-17 10:04 [PATCH] perf: fix bug mismatch with -c option definition Stephane Eranian
2010-05-17 11:29 ` Frederic Weisbecker
@ 2010-05-17 14:19 ` Arnaldo Carvalho de Melo
2010-05-17 15:39 ` Stephane Eranian
1 sibling, 1 reply; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-05-17 14:19 UTC (permalink / raw)
To: Stephane Eranian
Cc: linux-kernel, peterz, mingo, paulus, davem, fweisbec,
perfmon2-devel, eranian
Em Mon, May 17, 2010 at 12:04:01PM +0200, Stephane Eranian escreveu:
> The -c option defines the user requested sampling period. It was implemented
> using an unsigned int variable but the type of the option was OPT_LONG. Thus,
> the option parser was overwriting memory belonging to other variables, namely
> the mmap_pages leading to a zero page sampling buffer. The bug was exposed
> only when compiling at -O0, probably because the compiler was padding
> variables at higher optimization levels.
Well spotted!
> This patch fixes this problem by declaring user_interval as u64. This also
> avoids wrap-around issues for large period on 32-bit systems.
>
> Signed-off-by: Stephane Eranian <eranian@google.com>
> --
> tools/perf/builtin-record.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index 0f467cf..78f64cc 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -33,8 +33,8 @@ enum write_mode_t {
>
> static int *fd[MAX_NR_CPUS][MAX_COUNTERS];
>
> -static unsigned int user_interval = UINT_MAX;
> -static long default_interval = 0;
> +static u64 user_interval = ULLONG_MAX;
> +static u64 default_interval = 0;
The parsing code uses this for OPT_LONG:
case OPTION_LONG:
if (unset) {
*(long *)opt->value = 0;
return 0;
}
if (opt->flags & PARSE_OPT_OPTARG && !p->opt) {
*(long *)opt->value = opt->defval;
return 0;
}
if (get_arg(p, opt, flags, &arg))
return -1;
*(long *)opt->value = strtol(arg, (char **)&s, 10);
So I think we should augment the parsing code to have OPTION_ULONG, and,
for handling u64, OPTION_ULLONG.
I'll add that and then modify your patch to use it.
- Arnaldo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] perf: fix bug mismatch with -c option definition
2010-05-17 14:19 ` Arnaldo Carvalho de Melo
@ 2010-05-17 15:39 ` Stephane Eranian
0 siblings, 0 replies; 4+ messages in thread
From: Stephane Eranian @ 2010-05-17 15:39 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: linux-kernel, peterz, mingo, paulus, davem, fweisbec,
perfmon2-devel, eranian
On Mon, May 17, 2010 at 4:19 PM, Arnaldo Carvalho de Melo
<acme@infradead.org> wrote:
> Em Mon, May 17, 2010 at 12:04:01PM +0200, Stephane Eranian escreveu:
>> The -c option defines the user requested sampling period. It was implemented
>> using an unsigned int variable but the type of the option was OPT_LONG. Thus,
>> the option parser was overwriting memory belonging to other variables, namely
>> the mmap_pages leading to a zero page sampling buffer. The bug was exposed
>> only when compiling at -O0, probably because the compiler was padding
>> variables at higher optimization levels.
>
> Well spotted!
As you can imagine, it was not so trivial to find ;->
>
>> This patch fixes this problem by declaring user_interval as u64. This also
>> avoids wrap-around issues for large period on 32-bit systems.
>>
>> Signed-off-by: Stephane Eranian <eranian@google.com>
>> --
>> tools/perf/builtin-record.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
>> index 0f467cf..78f64cc 100644
>> --- a/tools/perf/builtin-record.c
>> +++ b/tools/perf/builtin-record.c
>> @@ -33,8 +33,8 @@ enum write_mode_t {
>>
>> static int *fd[MAX_NR_CPUS][MAX_COUNTERS];
>>
>> -static unsigned int user_interval = UINT_MAX;
>> -static long default_interval = 0;
>> +static u64 user_interval = ULLONG_MAX;
>> +static u64 default_interval = 0;
>
> The parsing code uses this for OPT_LONG:
>
> case OPTION_LONG:
> if (unset) {
> *(long *)opt->value = 0;
> return 0;
> }
> if (opt->flags & PARSE_OPT_OPTARG && !p->opt) {
> *(long *)opt->value = opt->defval;
> return 0;
> }
> if (get_arg(p, opt, flags, &arg))
> return -1;
> *(long *)opt->value = strtol(arg, (char **)&s, 10);
>
> So I think we should augment the parsing code to have OPTION_ULONG, and,
> for handling u64, OPTION_ULLONG.
>
> I'll add that and then modify your patch to use it.
>
That's fine too.
Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-05-17 15:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-17 10:04 [PATCH] perf: fix bug mismatch with -c option definition Stephane Eranian
2010-05-17 11:29 ` Frederic Weisbecker
2010-05-17 14:19 ` Arnaldo Carvalho de Melo
2010-05-17 15:39 ` Stephane Eranian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox