powerpc/pseries: Fix numa FORM2 parsing fallback code
Nicholas Piggin
reviewerPATCH 1/1 powerpc/pseries: Fix numa FORM2 parsing fallback code
In case the FORM2 distance table from firmware is not the expected size, there is fallback code that just populates the lookup table as local vs remote.
However it then continues on to use the distance table. Fix.
--- arch/powerpc/mm/numa.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)
arch/powerpc/mm/numa.c +13 -16
@@ -380,6 +380,7 @@ static void initialize_form2_numa_distance_lookup_table(void)const __be32 *numa_lookup_index;int numa_dist_table_length;int max_numa_index, distance_index; +bool good = true;if (firmware_has_feature (FW_FEATURE_OPAL )) root =of_find_node_by_path ("/ibm,opal" );
@@ -407,30 +408,26 @@ static void initialize_form2_numa_distance_lookup_table(void)if (numa_dist_table_length != max_numa_index * max_numa_index) {WARN (1 ,"Wrong NUMA distance information\n" ); -/* consider everybody else just remote. */ -for (i =0 ; i < max_numa_index; i++) { -for (j =0 ; j < max_numa_index; j++) { -int nodeA = numa_id_index_table[i]; -int nodeB = numa_id_index_table[j]; - -if (nodeA == nodeB) - numa_distance_table[nodeA][nodeB] =LOCAL_DISTANCE ; -else - numa_distance_table[nodeA][nodeB] =REMOTE_DISTANCE ; - } - } + good = false; } - distance_index =0 ;for (i =0 ; i < max_numa_index; i++) {for (j =0 ; j < max_numa_index; j++) {int nodeA = numa_id_index_table[i];int nodeB = numa_id_index_table[j]; - - numa_distance_table[nodeA][nodeB] = numa_dist_table[distance_index++]; -pr_debug ("dist[%d][%d]=%d " , nodeA, nodeB, numa_distance_table[nodeA][nodeB]); +int dist; + +if (good) + dist = numa_dist_table[distance_index++]; +else if (nodeA == nodeB) + dist =LOCAL_DISTANCE ; +else + dist =REMOTE_DISTANCE ; + numa_distance_table[nodeA][nodeB] = dist; +pr_debug ("dist[%d][%d]=%d " , nodeA, nodeB, dist); } } +of_node_put (root); }
Signature · 1 line
2.23.0
Quoted 6 lines · Nicholas Piggin
In case the FORM2 distance table from firmware is not the expected size, there is fallback code that just populates the lookup table as local vs remote.
However it then continues on to use the distance table. Fix.
Quoted 64 lines
Cc Aneesh Kumar K.V <[email protected]>Fixes 1c6b5a7e7405 ("powerpc/pseries: Add support for FORM2 associativity")Signed-off-by Nicholas Piggin <[email protected]>--- arch/powerpc/mm/numa.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)arch/powerpc/mm/numa.c +13
-16@@ -380,6 +380,7 @@ static void initialize_form2_numa_distance_lookup_table(void)const __be32 *numa_lookup_index;int numa_dist_table_length;int max_numa_index, distance_index; +bool good = true;if (firmware_has_feature (FW_FEATURE_OPAL )) root =of_find_node_by_path ("/ibm,opal" );@@ -407,30 +408,26 @@ static void initialize_form2_numa_distance_lookup_table(void)if (numa_dist_table_length != max_numa_index * max_numa_index) {WARN (1 ,"Wrong NUMA distance information\n" ); -/* consider everybody else just remote. */ -for (i =0 ; i < max_numa_index; i++) { -for (j =0 ; j < max_numa_index; j++) { -int nodeA = numa_id_index_table[i]; -int nodeB = numa_id_index_table[j]; - -if (nodeA == nodeB) - numa_distance_table[nodeA][nodeB] =LOCAL_DISTANCE ; -else - numa_distance_table[nodeA][nodeB] =REMOTE_DISTANCE ; - } - } + good = false; } - distance_index =0 ;for (i =0 ; i < max_numa_index; i++) {for (j =0 ; j < max_numa_index; j++) {int nodeA = numa_id_index_table[i];int nodeB = numa_id_index_table[j]; - - numa_distance_table[nodeA][nodeB] = numa_dist_table[distance_index++]; -pr_debug ("dist[%d][%d]=%d " , nodeA, nodeB, numa_distance_table[nodeA][nodeB]); +int dist; + +if (good) + dist = numa_dist_table[distance_index++]; +else if (nodeA == nodeB) + dist =LOCAL_DISTANCE ; +else + dist =REMOTE_DISTANCE ; + numa_distance_table[nodeA][nodeB] = dist; +pr_debug ("dist[%d][%d]=%d " , nodeA, nodeB, dist); } } +of_node_put (root); }Signature · 1 line
2.23.0
Michael Ellerman
reviewerQuoted 18 lines · Nicholas Piggin
In case the FORM2 distance table from firmware is not the expected size, there is fallback code that just populates the lookup table as local vs remote.
However it then continues on to use the distance table. Fix.
Cc Aneesh Kumar K.V <[email protected]>Fixes 1c6b5a7e7405 ("powerpc/pseries: Add support for FORM2 associativity")Signed-off-by Nicholas Piggin <[email protected]>--- arch/powerpc/mm/numa.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)arch/powerpc/mm/numa.c +0
-0
arch/powerpc/mm/numa.c static void initialize_form2_numa_distance_lookup_table(void) · line 383
Quoted 4 lines
arch/powerpc/mm/numa.c +1
-0@@ -380,6 +380,7 @@ static void initialize_form2_numa_distance_lookup_table(void)const __be32 *numa_lookup_index;int numa_dist_table_length;int max_numa_index, distance_index; +bool good = true;
numa_dist_table is a pointer, so couldn't we just set it to NULL if the info it's pointing at is invalid?
Quoted 10 lines
arch/powerpc/mm/numa.c +0
-3if (firmware_has_feature (FW_FEATURE_OPAL )) root =of_find_node_by_path ("/ibm,opal" );@@ -407,30 +408,26 @@ static void initialize_form2_numa_distance_lookup_table(void)if (numa_dist_table_length != max_numa_index * max_numa_index) {WARN (1 ,"Wrong NUMA distance information\n" ); -/* consider everybody else just remote. */ -for (i =0 ; i < max_numa_index; i++) { -for (j =0 ; j < max_numa_index; j++) {
arch/powerpc/mm/numa.c static void initialize_form2_numa_distance_lookup_table(void) · line 411
Quoted 10 lines
arch/powerpc/mm/numa.c +1
-9-int nodeA = numa_id_index_table[i]; -int nodeB = numa_id_index_table[j]; - -if (nodeA == nodeB) - numa_distance_table[nodeA][nodeB] =LOCAL_DISTANCE ; -else - numa_distance_table[nodeA][nodeB] =REMOTE_DISTANCE ; - } - } + good = false;
ie. numa_dist_table = NULL;
arch/powerpc/mm/numa.c static void initialize_form2_numa_distance_lookup_table(void) · line 420
Quoted 13 lines
arch/powerpc/mm/numa.c +3
-4} - distance_index =0 ;for (i =0 ; i < max_numa_index; i++) {for (j =0 ; j < max_numa_index; j++) {int nodeA = numa_id_index_table[i];int nodeB = numa_id_index_table[j]; - - numa_distance_table[nodeA][nodeB] = numa_dist_table[distance_index++]; -pr_debug ("dist[%d][%d]=%d " , nodeA, nodeB, numa_distance_table[nodeA][nodeB]); +int dist; + +if (good)
if (numa_dist_table)
arch/powerpc/mm/numa.c static void initialize_form2_numa_distance_lookup_table(void) · line 432
Quoted 12 lines
arch/powerpc/mm/numa.c +8
-0+ dist = numa_dist_table[distance_index++]; + else if (nodeA == nodeB) + dist =LOCAL_DISTANCE ; + else + dist =REMOTE_DISTANCE ; + numa_distance_table[nodeA][nodeB] = dist; +pr_debug ("dist[%d][%d]=%d " , nodeA, nodeB, dist); } } +of_node_put (root); }
But maybe before we do that we can rename it, because it is really easy to confuse numa_dist_table and numa_distance_table if you don't look closely.
cheers
Nicholas Piggin
reviewerExcerpts from Michael Ellerman's message of November 8, 2021 3:20 pm:
Quoted 14 lines
Quoted 13 lines · Nicholas Piggin
In case the FORM2 distance table from firmware is not the expected size, there is fallback code that just populates the lookup table as local vs remote.
However it then continues on to use the distance table. Fix.
Cc Aneesh Kumar K.V <[email protected]>Fixes 1c6b5a7e7405 ("powerpc/pseries: Add support for FORM2 associativity")Signed-off-by Nicholas Piggin <[email protected]>--- arch/powerpc/mm/numa.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)
Quoted 12 lines
arch/powerpc/mm/numa.c static void initialize_form2_numa_distance_lookup_table(void) · line 383
Quoted 9 lines
arch/powerpc/mm/numa.c +1
-0@@ -380,6 +380,7 @@ static void initialize_form2_numa_distance_lookup_table(void)const __be32 *numa_lookup_index;int numa_dist_table_length;int max_numa_index, distance_index; +bool good = true;
numa_dist_tableis a pointer, so couldn't we just set it to NULL if the info it's pointing at is invalid?
Yeah probably could just do that.
Quoted 49 lines
Quoted 11 lines
arch/powerpc/mm/numa.c +0
-3if (firmware_has_feature (FW_FEATURE_OPAL )) root =of_find_node_by_path ("/ibm,opal" );@@ -407,30 +408,26 @@ static void initialize_form2_numa_distance_lookup_table(void)if (numa_dist_table_length != max_numa_index * max_numa_index) {WARN (1 ,"Wrong NUMA distance information\n" ); -/* consider everybody else just remote. */ -for (i =0 ; i < max_numa_index; i++) { -for (j =0 ; j < max_numa_index; j++) {arch/powerpc/mm/numa.c static void initialize_form2_numa_distance_lookup_table(void) · line 411
Quoted 10 lines
arch/powerpc/mm/numa.c +1
-9-int nodeA = numa_id_index_table[i]; -int nodeB = numa_id_index_table[j]; - -if (nodeA == nodeB) - numa_distance_table[nodeA][nodeB] =LOCAL_DISTANCE ; -else - numa_distance_table[nodeA][nodeB] =REMOTE_DISTANCE ; - } - } + good = false;ie.
numa_dist_table= NULL;arch/powerpc/mm/numa.c static void initialize_form2_numa_distance_lookup_table(void) · line 420
Quoted 13 lines
arch/powerpc/mm/numa.c +3
-4} - distance_index =0 ;for (i =0 ; i < max_numa_index; i++) {for (j =0 ; j < max_numa_index; j++) {int nodeA = numa_id_index_table[i];int nodeB = numa_id_index_table[j]; - - numa_distance_table[nodeA][nodeB] = numa_dist_table[distance_index++]; -pr_debug ("dist[%d][%d]=%d " , nodeA, nodeB, numa_distance_table[nodeA][nodeB]); +int dist; + +if (good)if (
numa_dist_table)Quoted 9 lines
arch/powerpc/mm/numa.c +7
-0+ dist = numa_dist_table[distance_index++]; + else if (nodeA == nodeB) + dist =LOCAL_DISTANCE ; + else + dist =REMOTE_DISTANCE ; + numa_distance_table[nodeA][nodeB] = dist; +pr_debug ("dist[%d][%d]=%d " , nodeA, nodeB, dist); } }
Quoted 8 lines
arch/powerpc/mm/numa.c static void initialize_form2_numa_distance_lookup_table(void) · line 432
Quoted 3 lines
arch/powerpc/mm/numa.c +1
-0+of_node_put (root); }But maybe before we do that we can rename it, because it is really easy to confuse
numa_dist_tableandnuma_distance_tableif you don't look closely.
Maybe dt_form2_distances?
Thanks,
Nick
Michael Ellerman
reviewerQuoted 88 lines · Nicholas Piggin
Excerpts from Michael Ellerman's message of November 8, 2021 3:20 pm:
Quoted 14 lines
Quoted 13 lines · Nicholas Piggin
In case the FORM2 distance table from firmware is not the expected size, there is fallback code that just populates the lookup table as local vs remote.
However it then continues on to use the distance table. Fix.
Cc Aneesh Kumar K.V <[email protected]>Fixes 1c6b5a7e7405 ("powerpc/pseries: Add support for FORM2 associativity")Signed-off-by Nicholas Piggin <[email protected]>--- arch/powerpc/mm/numa.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)Quoted 12 lines
arch/powerpc/mm/numa.c static void initialize_form2_numa_distance_lookup_table(void) · line 383
Quoted 9 lines
arch/powerpc/mm/numa.c +1
-0@@ -380,6 +380,7 @@ static void initialize_form2_numa_distance_lookup_table(void)const __be32 *numa_lookup_index;int numa_dist_table_length;int max_numa_index, distance_index; +bool good = true;
numa_dist_tableis a pointer, so couldn't we just set it to NULL if the info it's pointing at is invalid?Yeah probably could just do that.
Quoted 49 lines
Quoted 11 lines
arch/powerpc/mm/numa.c +0
-3if (firmware_has_feature (FW_FEATURE_OPAL )) root =of_find_node_by_path ("/ibm,opal" );@@ -407,30 +408,26 @@ static void initialize_form2_numa_distance_lookup_table(void)if (numa_dist_table_length != max_numa_index * max_numa_index) {WARN (1 ,"Wrong NUMA distance information\n" ); -/* consider everybody else just remote. */ -for (i =0 ; i < max_numa_index; i++) { -for (j =0 ; j < max_numa_index; j++) {arch/powerpc/mm/numa.c static void initialize_form2_numa_distance_lookup_table(void) · line 411
Quoted 10 lines
arch/powerpc/mm/numa.c +1
-9-int nodeA = numa_id_index_table[i]; -int nodeB = numa_id_index_table[j]; - -if (nodeA == nodeB) - numa_distance_table[nodeA][nodeB] =LOCAL_DISTANCE ; -else - numa_distance_table[nodeA][nodeB] =REMOTE_DISTANCE ; - } - } + good = false;ie.
numa_dist_table= NULL;arch/powerpc/mm/numa.c static void initialize_form2_numa_distance_lookup_table(void) · line 420
Quoted 13 lines
arch/powerpc/mm/numa.c +3
-4} - distance_index =0 ;for (i =0 ; i < max_numa_index; i++) {for (j =0 ; j < max_numa_index; j++) {int nodeA = numa_id_index_table[i];int nodeB = numa_id_index_table[j]; - - numa_distance_table[nodeA][nodeB] = numa_dist_table[distance_index++]; -pr_debug ("dist[%d][%d]=%d " , nodeA, nodeB, numa_distance_table[nodeA][nodeB]); +int dist; + +if (good)if (
numa_dist_table)Quoted 9 lines
arch/powerpc/mm/numa.c +7
-0+ dist = numa_dist_table[distance_index++]; + else if (nodeA == nodeB) + dist =LOCAL_DISTANCE ; + else + dist =REMOTE_DISTANCE ; + numa_distance_table[nodeA][nodeB] = dist; +pr_debug ("dist[%d][%d]=%d " , nodeA, nodeB, dist); } }Quoted 8 lines
arch/powerpc/mm/numa.c static void initialize_form2_numa_distance_lookup_table(void) · line 432
Quoted 3 lines
arch/powerpc/mm/numa.c +1
-0+of_node_put (root); }But maybe before we do that we can rename it, because it is really easy to confuse
numa_dist_tableandnuma_distance_tableif you don't look closely.
Quoted 1 line
Maybe
dt_form2_distances?
Or just "form2_distances", it's only a local so the fact that it's from the dt is clear enough I think.
cheers