Skip to content

-Wattribute-warning in drivers/base/arch_numa.c on RISC-V with CONFIG_NR_CPUS > 64 #2174

Description

@nathanchance

Debian recently bumped CONFIG_NR_CPUS from 64 to 128, which causes an instance of -Wattribute-warning from the fortify routines when CONFIG_UBSAN_BOUNDS is enabled. I have reduced this down to:

$ cat arch/riscv/configs/repro.config
CONFIG_FORTIFY_SOURCE=y
CONFIG_NR_CPUS=128
CONFIG_NUMA=y
CONFIG_UBSAN=y

$ make -skj"$(nproc)" ARCH=riscv LLVM=1 mrproper defconfig repro.config drivers/base/arch_numa.o
In file included from drivers/base/arch_numa.c:11:
In file included from include/linux/acpi.h:14:
In file included from include/linux/resource_ext.h:11:
In file included from include/linux/slab.h:17:
In file included from include/linux/gfp.h:7:
In file included from include/linux/mmzone.h:8:
In file included from include/linux/spinlock.h:63:
In file included from include/linux/lockdep.h:14:
In file included from include/linux/smp.h:13:
In file included from include/linux/cpumask.h:11:
In file included from include/linux/bitmap.h:13:
In file included from include/linux/string.h:383:
include/linux/fortify-string.h:430:4: warning: call to '__write_overflow_field' declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Wattribute-warning]
  430 |                         __write_overflow_field(p_size_field, size);
      |                         ^
include/linux/fortify-string.h:430:4: note: called by function 'fortify_memset_chk(unsigned long, unsigned long, unsigned long)'
include/linux/bitmap.h:245:3: note: inlined by function 'cpumask_clear'
  245 |                 memset(dst, 0, len);
      |                 ^
include/linux/fortify-string.h:462:25: note: expanded from macro 'memset'
  462 | #define memset(p, c, s) __fortify_memset_chk(p, c, s,                   \
      |                         ^
include/linux/fortify-string.h:453:2: note: expanded from macro '__fortify_memset_chk'
  453 |         fortify_memset_chk(__fortify_size, p_size, p_size_field),       \
      |         ^
drivers/base/arch_numa.c:111:3: note: inlined by function 'setup_node_to_cpumask_map'
  111 |                 cpumask_clear(node_to_cpumask_map[node]);
      |                 ^
include/linux/fortify-string.h:430:4: note: use '-gline-directives-only' (implied by '-g1') or higher for more accurate inlining chain locations
  430 |                         __write_overflow_field(p_size_field, size);
      |                         ^
1 warning generated.

It reproduces with CONFIG_NR_CPUS=65, so 64 seems to be the limit where there is no warning. I do not see this warning with GCC 16.1.0, even with adding -Warray-bounds via CFLAGS_arch_numa.o.

I have tried to follow through the code to see what is going on here but I have not had much luck at this point so I'll double back later unless someone else beats me to it.

cc @kees

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions