From: "Jan Beulich" Subject: Re: [PATCH] XENPF_set_processor_pminfo XEN_PM_CX overflows states array Date: Wed, 07 Mar 2012 15:07:55 +0000 Message-ID: <4F5787DB0200007800076EC8@nat28.tlf.novell.com> References: <20120307140721.GB22674@eric.cam.xci-test.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20120307140721.GB22674@eric.cam.xci-test.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Eric Chanudet Cc: julian.pidancet@eu.citrix.com, xen-devel List-Id: xen-devel@lists.xenproject.org >>> On 07.03.12 at 15:07, eric wrote: > Calling XENPF_set_processor_pminfo with XEN_PM_CX could cause states > array in "struct acpi_processor_power" to exceed its limit. > > The array used to be reset (by function cpuidle_init_cpu()) for each > hypercall. The patch puts it back that way and adds an assertion to make > it clear in case that happens again. > > Signed-off-by: Eric Chanudet > > diff --git a/xen/arch/x86/acpi/cpu_idle.c b/xen/arch/x86/acpi/cpu_idle.c > --- a/xen/arch/x86/acpi/cpu_idle.c > +++ b/xen/arch/x86/acpi/cpu_idle.c > @@ -622,19 +622,19 @@ static int cpuidle_init_cpu(int cpu) > > for ( i = 0; i < ACPI_PROCESSOR_MAX_POWER; i++ ) > acpi_power->states[i].idx = i; > - > - acpi_power->states[ACPI_STATE_C1].type = ACPI_STATE_C1; > - acpi_power->states[ACPI_STATE_C1].entry_method = ACPI_CSTATE_EM_HALT; > - > - acpi_power->states[ACPI_STATE_C0].valid = 1; > - acpi_power->states[ACPI_STATE_C1].valid = 1; > - > - acpi_power->count = 2; > - acpi_power->safe_state = &acpi_power->states[ACPI_STATE_C1]; > - acpi_power->cpu = cpu; > processor_powers[cpu] = acpi_power; > } > > + acpi_power->states[ACPI_STATE_C1].type = ACPI_STATE_C1; > + acpi_power->states[ACPI_STATE_C1].entry_method = ACPI_CSTATE_EM_HALT; > + > + acpi_power->states[ACPI_STATE_C0].valid = 1; > + acpi_power->states[ACPI_STATE_C1].valid = 1; > + > + acpi_power->count = 2; > + acpi_power->safe_state = &acpi_power->states[ACPI_STATE_C1]; > + acpi_power->cpu = cpu; Is there any reason to move all of these assignments, rather than just the assignment of ->count and maybe ->states[ACPI_STATE_C1]? Everything else should not get modified anywhere else. > + > if ( cpu == 0 ) > { > if ( boot_cpu_has(X86_FEATURE_NONSTOP_TSC) ) > @@ -870,11 +870,10 @@ static void set_cx( > > if ( xen_cx->type == ACPI_STATE_C1 ) > cx = &acpi_power->states[1]; > - else > - cx = &acpi_power->states[acpi_power->count]; > - > - if ( !cx->valid ) > - acpi_power->count++; > + else { Please put the brace on a new line. > + ASSERT(acpi_power->count < ACPI_PROCESSOR_MAX_POWER); > + cx = &acpi_power->states[acpi_power->count++]; > + } To be on the safe side, you should probably also check for ACPI_STATE_C0 (and ignore its data), otherwise (other than before your patch) ->count would get incremented for this too. So I'd suggest converting the if() here to a switch(). Jan > > cx->valid = 1; > cx->type = xen_cx->type; > > -- > Eric Chanudet > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xen.org > http://lists.xen.org/xen-devel