Cell OProfile: Incorrect local array size in activate spu profiling function
PATCH 1/1 Cell OProfile: Incorrect local array size in activate spu profiling function
The size of the pm_signal_local array should be equal to the number of SPUs being configured in the call. Currently, the array is of size 4 (NR_PHYS_CTRS) but being indexed by a for loop from 0 to 7 (NUM_SPUS_PER_NODE).
arch/powerpc/oprofile/op_model_cell.c +1 -1
@@ -830,7 +830,7 @@ static int calculate_lfsr(int n)static int pm_rtas_activate_spu_profiling (u32 node) {int ret, i; -struct pm_signal pm_signal_local[NR_PHYS_CTRS ]; +struct pm_signal pm_signal_local[NUM_SPUS_PER_NODE ];/* * Set up the rtas call to configure the debug bus to
Quoted 4 lines · Carl Love
The size of the
pm_signal_localarray should be equal to the number of SPUs being configured in the call. Currently, the array is of size 4 (NR_PHYS_CTRS) but being indexed by a for loop from 0 to 7 (NUM_SPUS_PER_NODE).
While you're at it you should change to using ARRAY_SIZE() in the for loop, and use sizeof in the rtas call - that way you'll only have the size in one place.
I notice pm_rtas_activate_signals() also allocates a pm_signal_local on the stack and iterates over it. I take it something guarantees that count in that routine will not exceed NR_PHYS_CTRS ?
cheers
Signature · 8 lines
Michael Ellerman OzLabs, IBM Australia Development Lab wwweb: http://michael.ellerman.id.au phone: +61 2 6212 1183 (tie line 70 21183) We do not inherit the earth from our ancestors, we borrow it from our children. - S.M.A.R.T Person
PATCH 1/1 Cell OProfile: Incorrect local array size in activate spu profiling function
Updated the patch to address comments by Michael Ellerman. Specifically, changed upper limit in for loop to ARRAY_SIZE() macro and added a check to make sure the number of events specified by the user, which is used as the max for indexing various arrays, is no bigger then the declared size of the arrays.
The size of the pm_signal_local array should be equal to the number of SPUs being configured in the array. Currently, the array is of size 4 (NR_PHYS_CTRS) but being indexed by a for loop from 0 to 7 (NUM_SPUS_PER_NODE).
arch/powerpc/oprofile/op_model_cell.c +9 -2
@@ -582,6 +582,13 @@ static int cell_reg_setup(struct op_coun num_counters = num_ctrs; +if (unlikely (num_ctrs >NR_PHYS_CTRS )) { +printk (KERN_ERR +"%s: Oprofile, number of specified events " \ +"exceeds number of physical counters\n" , + __func__); +return -EIO ; + } pm_regs.group_control =0 ; pm_regs.debug_bus_control =0 ;
@@ -830,13 +837,13 @@ static int calculate_lfsr(int n)static int pm_rtas_activate_spu_profiling (u32 node) {int ret, i; -struct pm_signal pm_signal_local[NR_PHYS_CTRS ]; +struct pm_signal pm_signal_local[NUM_SPUS_PER_NODE ];/* * Set up the rtas call to configure the debug bus to * route the SPU PCs. Setup the pm_signal for each SPU */ -for (i =0 ; i <NUM_SPUS_PER_NODE ; i++) { +for (i =0 ; i <ARRAY_SIZE (pm_signal_local); i++) { pm_signal_local[i].cpu = node; pm_signal_local[i].signal_group =41 ;/* spu i on word (i/2) */
Quoted 20 lines · Carl Love
Updated the patch to address comments by Michael Ellerman. Specifically, changed upper limit in for loop to
ARRAY_SIZE()macro and added a check to make sure the number of events specified by the user, which is used as the max for indexing various arrays, is no bigger then the declared size of the arrays.The size of the
pm_signal_localarray should be equal to the number of SPUs being configured in the array. Currently, the array is of size 4 (NR_PHYS_CTRS) but being indexed by a for loop from 0 to 7 (NUM_SPUS_PER_NODE).Signed-off-by Carl Love <[email protected]>Index:
Cell_kernel_10_24_2008/arch/powerpc/oprofile/op_model_cell.c
===================================================================
arch/powerpc/oprofile/op_model_cell.c static int cell_reg_setup(struct op_coun · line 591
Quoted 10 lines
arch/powerpc/oprofile/op_model_cell.c +7
-0@@ -582,6 +582,13 @@ static int cell_reg_setup(struct op_coun num_counters = num_ctrs; +if (unlikely (num_ctrs >NR_PHYS_CTRS )) { +printk (KERN_ERR +"%s: Oprofile, number of specified events " \ +"exceeds number of physical counters\n" , + __func__); +return -EIO ; + }
I wouldn't bother with the unlikely, but whatever, looks good.
Quoted 9 lines
arch/powerpc/oprofile/op_model_cell.c +1
-1pm_regs.group_control =0 ; pm_regs.debug_bus_control =0 ;@@ -830,13 +837,13 @@ static int calculate_lfsr(int n)static int pm_rtas_activate_spu_profiling (u32 node) {int ret, i; -struct pm_signal pm_signal_local[NR_PHYS_CTRS ]; +struct pm_signal pm_signal_local[NUM_SPUS_PER_NODE ];
arch/powerpc/oprofile/op_model_cell.c static int calculate_lfsr(int n) · line 849
Quoted 10 lines
arch/powerpc/oprofile/op_model_cell.c +1
-1/* * Set up the rtas call to configure the debug bus to * route the SPU PCs. Setup the pm_signal for each SPU */ -for (i =0 ; i <NUM_SPUS_PER_NODE ; i++) { +for (i =0 ; i <ARRAY_SIZE (pm_signal_local); i++) { pm_signal_local[i].cpu = node; pm_signal_local[i].signal_group =41 ;/* spu i on word (i/2) */
Looks good, but ..
You should patch the call to rtas_ibm_cbe_perftools() as well, like:
ret = rtas_ibm_cbe_perftools(SUBFUNC_ACTIVATE,
PASSTHRU_ENABLE, pm_signal_local, sizeof(pm_signal_local));
cheers
Signature · 8 lines
Michael Ellerman OzLabs, IBM Australia Development Lab wwweb: http://michael.ellerman.id.au phone: +61 2 6212 1183 (tie line 70 21183) We do not inherit the earth from our ancestors, we borrow it from our children. - S.M.A.R.T Person
Updated the patch to address comments by Michael Ellerman. Specifically, changed upper limit in for loop to ARRAY_SIZE() macro and added a check to make sure the number of events specified by the user, which is used as the max for indexing various arrays, is no bigger then the declared size of the arrays.
The size of the pm_signal_local array should be equal to the number of SPUs being configured in the array. Currently, the array is of size 4 (NR_PHYS_CTRS) but being indexed by a for loop from 0 to 7 (NUM_SPUS_PER_NODE).
arch/powerpc/oprofile/op_model_cell.c +10 -3
@@ -582,6 +582,13 @@ static int cell_reg_setup(struct op_coun num_counters = num_ctrs; +if (unlikely (num_ctrs >NR_PHYS_CTRS )) { +printk (KERN_ERR +"%s: Oprofile, number of specified events " \ +"exceeds number of physical counters\n" , + __func__); +return -EIO ; + } pm_regs.group_control =0 ; pm_regs.debug_bus_control =0 ;
@@ -830,13 +837,13 @@ static int calculate_lfsr(int n)static int pm_rtas_activate_spu_profiling (u32 node) {int ret, i; -struct pm_signal pm_signal_local[NR_PHYS_CTRS ]; +struct pm_signal pm_signal_local[NUM_SPUS_PER_NODE ];/* * Set up the rtas call to configure the debug bus to * route the SPU PCs. Setup the pm_signal for each SPU */ -for (i =0 ; i <NUM_SPUS_PER_NODE ; i++) { +for (i =0 ; i <ARRAY_SIZE (pm_signal_local); i++) { pm_signal_local[i].cpu = node; pm_signal_local[i].signal_group =41 ;/* spu i on word (i/2) */
@@ -848,7 +855,7 @@ static int pm_rtas_activate_spu_profilin ret =rtas_ibm_cbe_perftools (SUBFUNC_ACTIVATE ,PASSTHRU_ENABLE , pm_signal_local, - (NUM_SPUS_PER_NODE + (ARRAY_SIZE (pm_signal_local) *sizeof (struct pm_signal )));if (unlikely (ret)) {
Robert Richter
AppliedQuoted 7 lines · Carl Love
Updated the patch to address comments by Michael Ellerman. Specifically, changed upper limit in for loop to
ARRAY_SIZE()macro and added a check to make sure the number of events specified by the user, which is used as the max for indexing various arrays, is no bigger then the declared size of the arrays.
Quoted 6 lines
The size of the
pm_signal_localarray should be equal to the number of SPUs being configured in the array. Currently, the array is of size 4 (NR_PHYS_CTRS) but being indexed by a for loop from 0 to 7 (NUM_SPUS_PER_NODE).Signed-off-by Carl Love <[email protected]>
I applied your patch to oprofile/oprofile-for-tip. Thanks Carl.
-Robert
Signature · 3 lines
Advanced Micro Devices, Inc. Operating System Research Center email: [email protected]
Robert Richter
AppliedQuoted 7 lines · Carl Love
The size of the
pm_signal_localarray should be equal to the number of SPUs being configured in the call. Currently, the array is of size 4 (NR_PHYS_CTRS) but being indexed by a for loop from 0 to 7 (NUM_SPUS_PER_NODE).Signed-off-by Carl Love <[email protected]>
I applied your patch to oprofile/oprofile-for-tip. Thanks Carl.
-Robert
Signature · 3 lines
Advanced Micro Devices, Inc. Operating System Research Center email: [email protected]