Skip to contentSkip to conversation

Fix Power CI build

PATCH Superseded Shawn Anastasio 3 participants 9 messages Sep 26, 2023

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Fix Power CI build

Hello all,

This series contains a few minor fixes to the CI config and one additional patch to common/ that resolve ppc64-specific CI failures that Jan discovered.

Thanks,

Shawn Anastasio (2):
automation: Change build script to use arch defconfig xen/common: Add NUMA node id bounds check to
page_alloc.c/node_to_scrub

 automation/scripts/build | 7 ++++++-
 xen/common/page_alloc.c  | 8 ++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

--
2.30.2

#5 lore raw

PATCH v2 2/2 xen/common: Add NUMA node id bounds check to page_alloc.c/node_to_scrub

When building for Power with CONFIG_DEBUG unset, a compiler error gets raised inside page_alloc.c's node_to_scrub function:

common/page_alloc.c: In function 'node_to_scrub.part.0':
common/page_alloc.c:1217:29: error: array subscript 1 is above array
bounds of 'long unsigned int[1]' [-Werror=array-bounds]
1217 | if ( node_need_scrub[node] )

It appears that this is a false positive, given that in practice cycle_node should never return a node ID >= MAX_NUMNODES as long as the architecture's node_online_map is properly defined and initialized, so this additional bounds check is only to satisfy GCC.

---
v2: Add comment to explain the bounds check.

 xen/common/page_alloc.c | 8 ++++++++
 1 file changed, 8 insertions(+)
xen/common/page_alloc.c +8 -0
index 35d9a26fa6..c53f917dbc 100644
@@ -1211,6 +1211,14 @@ static unsigned int node_to_scrub(bool get_node)
         } while ( !cpumask_empty(&node_to_cpumask(node)) &&
                   (node != local_node) );
 
+        /*
+         * In practice `node` will always be within MAX_NUMNODES, but GCC can't
+         * always see that, so an explicit check is necessary to avoid tripping
+         * its out-of-bounds array access warning (-Warray-bounds).
+         */
+        if ( node >= MAX_NUMNODES )
+            break;
+
         if ( node == local_node )
             break;
 

--
2.30.2

#1 lore raw

PATCH v2 1/2 automation: Change build script to use arch defconfig

In reply to Shawn Anastasio

Change automation build script to call the make defconfig target before setting CONFIG_DEBUG and extra options. This fixes issues on Power where the build fails without using the ppc64_defconfig.

---
v2: No changes.

 automation/scripts/build | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
automation/scripts/build +6 -1
index b4edcf010e..19dd9e8270 100755
@@ -22,7 +22,12 @@ if [[ "${RANDCONFIG}" == "y" ]]; then
     # RANDCONFIG implies HYPERVISOR_ONLY
     HYPERVISOR_ONLY="y"
 else
-    echo "CONFIG_DEBUG=${debug}" > xen/.config
+    # Start off with arch's defconfig
+    make -C xen defconfig
+
+    # Drop existing CONFIG_DEBUG and replace with value of ${debug}
+    sed -i 's/^CONFIG_DEBUG=[yn]//g' xen/.config
+    echo "CONFIG_DEBUG=${debug}" >> xen/.config
 
     if [[ -n "${EXTRA_XEN_CONFIG}" ]]; then
         echo "${EXTRA_XEN_CONFIG}" >> xen/.config

--
2.30.2

#2 lore raw

Re: [PATCH v2 1/2] automation: Change build script to use arch defconfig

Quoted 5 lines · Shawn Anastasio
automation/scripts/build +0 -0
index b4edcf010e..19dd9e8270 100755

automation/scripts/build if [[ "${RANDCONFIG}" == "y" ]]; then · line 30

Quoted 10 lines
automation/scripts/build +6 -1
@@ -22,7 +22,12 @@ if [[ "${RANDCONFIG}" == "y" ]]; then
     # RANDCONFIG implies HYPERVISOR_ONLY
     HYPERVISOR_ONLY="y"
 else
-    echo "CONFIG_DEBUG=${debug}" > xen/.config
+    # Start off with arch's defconfig
+    make -C xen defconfig
+
+    # Drop existing CONFIG_DEBUG and replace with value of ${debug}
+    sed -i 's/^CONFIG_DEBUG=[yn]//g' xen/.config
+    echo "CONFIG_DEBUG=${debug}" >> xen/.config

Kconfig is latest-takes precedence, which is why we always append for this and the other related options.  There's no need for sed to drop the old value.

~Andrew

#6 lore raw

Re: [PATCH v2 2/2] xen/common: Add NUMA node id bounds check to page_alloc.c/node_to_scrub

In reply to Shawn Anastasio
Quoted 8 lines · Shawn Anastasio

When building for Power with CONFIG_DEBUG unset, a compiler error gets raised inside page_alloc.c's node_to_scrub function:

common/page_alloc.c: In function 'node_to_scrub.part.0':
common/page_alloc.c:1217:29: error: array subscript 1 is above array
bounds of 'long unsigned int[1]' [-Werror=array-bounds]
1217 | if ( node_need_scrub[node] )

Quoted 4 lines

It appears that this is a false positive, given that in practice cycle_node should never return a node ID >= MAX_NUMNODES as long as the architecture's node_online_map is properly defined and initialized, so this additional bounds check is only to satisfy GCC.

If GCC thinks it's got an index of 1 here, then it thinks it's proved that a 1 gets passed.  But the fact that cycle_node() really can return 1 if one variable gets tweaked in memory means that logic derived on this property is broken.

But we've got even more basic problems to fix first.

xen$ git grep -B1 '__read_mostly node_online_map' arch/arm/smpboot.c-45-/* Fake one node for now. See also asm/numa.h */ arch/arm/smpboot.c:46:nodemask_t __read_mostly node_online_map = { { [0] = 1UL } };
arch/ppc/stubs.c-25-
arch/ppc/stubs.c:26:nodemask_t __read_mostly node_online_map = { { [0] = 1UL } };
common/numa.c-44-
common/numa.c:45:nodemask_t __read_mostly node_online_map = { { [0] = 1UL } };

There are 3 identical definitions of node_online_map, one for the architecture which really supports NUMA, and two for the stubs which don't.

And the bug here is that code outside of CONFIG_NUMA assumes NUMA is valid, including several places in page_alloc.c, domain_set_node_affinity(), credit1 and sysctl.  XEN_SYSCTL_numainfo even has a bigger sin of using a static MAX_NUMNODES array when it doesn't need an array in the first place.

It's rude for xen/nodemask.h to short circuit some of the operations on node_online_map based on MAX_NUMNODES but not others.

If nothing else, the fallback for "not really NUMA" needs providing by the common code and not by the arch stubs.  When that is sorted, we might have more consistent behaviour to investigate.

~Andrew

Reviewed-by on v2 2/2
#8 lore raw

Re: [PATCH v2 2/2] xen/common: Add NUMA node id bounds check to page_alloc.c/node_to_scrub

In reply to Shawn Anastasio
Quoted 8 lines · Shawn Anastasio

When building for Power with CONFIG_DEBUG unset, a compiler error gets raised inside page_alloc.c's node_to_scrub function:

common/page_alloc.c: In function 'node_to_scrub.part.0':
common/page_alloc.c:1217:29: error: array subscript 1 is above array
bounds of 'long unsigned int[1]' [-Werror=array-bounds]
1217 | if ( node_need_scrub[node] )

Quoted 6 lines

It appears that this is a false positive, given that in practice cycle_node should never return a node ID >= MAX_NUMNODES as long as the architecture's node_online_map is properly defined and initialized, so this additional bounds check is only to satisfy GCC.

Quoted 28 lines

---
v2: Add comment to explain the bounds check.

 xen/common/page_alloc.c | 8 ++++++++
 1 file changed, 8 insertions(+)
xen/common/page_alloc.c +8 -1
index 35d9a26fa6..c53f917dbc 100644
@@ -1211,6 +1211,14 @@ static unsigned int node_to_scrub(bool get_node)
         } while ( !cpumask_empty(&node_to_cpumask(node)) &&
                   (node != local_node) );
 
+        /*
+         * In practice `node` will always be within MAX_NUMNODES, but GCC can't
+         * always see that, so an explicit check is necessary to avoid tripping
+         * its out-of-bounds array access warning (-Warray-bounds).
+         */
+        if ( node >= MAX_NUMNODES )
+            break;
+
         if ( node == local_node )
             break;
 
--

2.30.2

#3 lore raw

Re: [PATCH v2 1/2] automation: Change build script to use arch defconfig

In reply to Andrew Cooper
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · Shawn Anastasio
automation/scripts/build +2 -1
index b4edcf010e..19dd9e8270 100755
@@ -22,7 +22,12 @@ if [[ "${RANDCONFIG}" == "y" ]]; then
     # RANDCONFIG implies HYPERVISOR_ONLY
     HYPERVISOR_ONLY="y"
 else
-    echo "CONFIG_DEBUG=${debug}" > xen/.config
+    # Start off with arch's defconfig
+    make -C xen defconfig
Quoted 8 lines

automation/scripts/build if [[ "${RANDCONFIG}" == "y" ]]; then · line 30

Quoted 4 lines
automation/scripts/build +4 -0
+
+    # Drop existing CONFIG_DEBUG and replace with value of ${debug}
+    sed -i 's/^CONFIG_DEBUG=[yn]//g' xen/.config
+    echo "CONFIG_DEBUG=${debug}" >> xen/.config

Kconfig is latest-takes precedence, which is why we always append for this and the other related options.  There's no need for sed to drop the old value.

+1

#4 lore raw

Re: [PATCH v2 1/2] automation: Change build script to use arch defconfig

In reply to Andrew Cooper
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · Shawn Anastasio
automation/scripts/build +2 -1
index b4edcf010e..19dd9e8270 100755
@@ -22,7 +22,12 @@ if [[ "${RANDCONFIG}" == "y" ]]; then
     # RANDCONFIG implies HYPERVISOR_ONLY
     HYPERVISOR_ONLY="y"
 else
-    echo "CONFIG_DEBUG=${debug}" > xen/.config
+    # Start off with arch's defconfig
+    make -C xen defconfig
Quoted 9 lines

automation/scripts/build if [[ "${RANDCONFIG}" == "y" ]]; then · line 30

Quoted 4 lines
automation/scripts/build +4 -0
+
+    # Drop existing CONFIG_DEBUG and replace with value of ${debug}
+    sed -i 's/^CONFIG_DEBUG=[yn]//g' xen/.config
+    echo "CONFIG_DEBUG=${debug}" >> xen/.config

Kconfig is latest-takes precedence, which is why we always append for this and the other related options. There's no need for sed to drop the old value.

Thank you for the confirmation. I'll go ahead and drop the sed.

Quoted 1 line

~Andrew

Thanks,
Shawn

#7 lore raw

Re: [PATCH v2 2/2] xen/common: Add NUMA node id bounds check to page_alloc.c/node_to_scrub

In reply to Andrew Cooper
Quoted 32 lines · Andrew Cooper
Quoted 8 lines · Shawn Anastasio

When building for Power with CONFIG_DEBUG unset, a compiler error gets raised inside page_alloc.c's node_to_scrub function:

common/page_alloc.c: In function 'node_to_scrub.part.0':
common/page_alloc.c:1217:29: error: array subscript 1 is above array
bounds of 'long unsigned int[1]' [-Werror=array-bounds]
1217 | if ( node_need_scrub[node] )

Quoted 4 lines

It appears that this is a false positive, given that in practice cycle_node should never return a node ID >= MAX_NUMNODES as long as the architecture's node_online_map is properly defined and initialized, so this additional bounds check is only to satisfy GCC.

If GCC thinks it's got an index of 1 here, then it thinks it's proved that a 1 gets passed. But the fact that cycle_node() really can return 1 if one variable gets tweaked in memory means that logic derived on this property is broken.

But we've got even more basic problems to fix first.

xen$ git grep -B1 '__read_mostly node_online_map' arch/arm/smpboot.c-45-/* Fake one node for now. See also asm/numa.h */ arch/arm/smpboot.c:46:nodemask_t __read_mostly node_online_map = { { [0] = 1UL } };
arch/ppc/stubs.c-25-
arch/ppc/stubs.c:26:nodemask_t __read_mostly node_online_map = { { [0] = 1UL } };
common/numa.c-44-
common/numa.c:45:nodemask_t __read_mostly node_online_map = { { [0] = 1UL } };

Quoted 9 lines

There are 3 identical definitions of node_online_map, one for the architecture which really supports NUMA, and two for the stubs which don't.

And the bug here is that code outside of CONFIG_NUMA assumes NUMA is valid, including several places in page_alloc.c, domain_set_node_affinity(), credit1 and sysctl. XEN_SYSCTL_numainfo even has a bigger sin of using a static MAX_NUMNODES array when it doesn't need an array in the first place.

Agreed. It seems like the current state of affairs resulted from hacks in Arm to work around NUMA assumptions in common instead of properly making common support !CONFIG_NUMA. And now ppc is inheriting some of that baggage.

Quoted 7 lines

It's rude for xen/nodemask.h to short circuit some of the operations on node_online_map based on MAX_NUMNODES but not others.

If nothing else, the fallback for "not really NUMA" needs providing by the common code and not by the arch stubs. When that is sorted, we might have more consistent behaviour to investigate.

I'll leave these more sweeping changes up to someone with a bit more familiarity with this code for now. In the meantime, this patch at should introduce no functional change to the status quo and allows ppc to build in the interim.

Quoted 1 line

~Andrew

Thanks,
Shawn