From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <JBeulich@suse.com>, xen-devel@lists.xen.org
Cc: Huaitong Han <huaitong.han@intel.com>
Subject: Re: [PATCH v2] x86/cpuidle: prevent out of bounds array access
Date: Fri, 22 May 2015 15:01:30 +0100 [thread overview]
Message-ID: <555F36BA.6000608@citrix.com> (raw)
In-Reply-To: <555F5177020000780007D510@mail.emea.novell.com>
On 22/05/15 14:55, Jan Beulich wrote:
> ... resulting from fbeef5570c ("x86/cpuidle: get accurate C0 value with
> xenpm tool"). For consistency also no longer account an unknown state
> to C0 in pmstat_get_cx_stat().
>
> Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
Looks plausible. Reviewed-by: Andrew Cooper <andrew.cooper3@citirx.com>
>
> --- a/xen/arch/x86/acpi/cpu_idle.c
> +++ b/xen/arch/x86/acpi/cpu_idle.c
> @@ -279,7 +279,7 @@ static void print_acpi_power(
> uint64_t usage[ACPI_PROCESSOR_MAX_POWER] = { 0 };
> uint64_t res_tick[ACPI_PROCESSOR_MAX_POWER] = { 0 };
> unsigned int i;
> - u8 last_state_idx;
> + signed int last_state_idx;
>
> printk("==cpu%d==\n", cpu);
> last_state_idx = power->last_state ? power->last_state->idx : -1;
> @@ -298,8 +298,12 @@ static void print_acpi_power(
> last_state_update_tick = power->last_state_update_tick;
> spin_unlock_irq(&power->stat_lock);
>
> - res_tick[last_state_idx] += ticks_elapsed(last_state_update_tick, current_tick);
> - usage[last_state_idx]++;
> + if ( last_state_idx >= 0 )
> + {
> + res_tick[last_state_idx] += ticks_elapsed(last_state_update_tick,
> + current_tick);
> + usage[last_state_idx]++;
> + }
>
> for ( i = 1; i < power->count; i++ )
> {
> @@ -1233,6 +1237,7 @@ int pmstat_get_cx_stat(uint32_t
> else
> {
> struct hw_residencies hw_res;
> + signed int last_state_idx;
>
> stat->nr = power->count;
>
> @@ -1245,11 +1250,18 @@ int pmstat_get_cx_stat(uint32_t
> res[i] = power->states[i].time;
> }
> last_state_update_tick = power->last_state_update_tick;
> - stat->last = power->last_state ? power->last_state->idx : 0;
> + last_state_idx = power->last_state ? power->last_state->idx : -1;
> spin_unlock_irq(&power->stat_lock);
>
> - usage[stat->last]++;
> - res[stat->last] += ticks_elapsed(last_state_update_tick, current_tick);
> + if ( last_state_idx >= 0 )
> + {
> + usage[last_state_idx]++;
> + res[last_state_idx] += ticks_elapsed(last_state_update_tick,
> + current_tick);
> + stat->last = last_state_idx;
> + }
> + else
> + stat->last = 0;
>
> for ( i = 1; i < nr; i++ )
> {
>
>
>
prev parent reply other threads:[~2015-05-22 14:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-21 9:39 [V7] x86/cpuidle: get accurate C0 value with xenpm tool Huaitong Han
2015-05-22 12:28 ` Andrew Cooper
2015-05-22 12:48 ` [PATCH] x86/cpuidle: prevent out of bounds array access Jan Beulich
2015-05-22 12:57 ` Andrew Cooper
2015-05-22 13:48 ` Jan Beulich
2015-05-22 13:55 ` [PATCH v2] " Jan Beulich
2015-05-22 14:01 ` Andrew Cooper [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=555F36BA.6000608@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=huaitong.han@intel.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.