# git rev-parse -q --verify 8ca09d5fa3549d142c2080a72a4c70ce389163cd^{commit} 8ca09d5fa3549d142c2080a72a4c70ce389163cd already have revision, skipping fetch # git checkout -q -f -B kisskb 8ca09d5fa3549d142c2080a72a4c70ce389163cd # git clean -qxdf # < git log -1 # commit 8ca09d5fa3549d142c2080a72a4c70ce389163cd # Author: Linus Torvalds # Date: Mon Mar 6 12:15:13 2023 -0800 # # cpumask: fix incorrect cpumask scanning result checks # # It turns out that commit 596ff4a09b89 ("cpumask: re-introduce # constant-sized cpumask optimizations") exposed a number of cases of # drivers not checking the result of "cpumask_next()" and friends # correctly. # # The documented correct check for "no more cpus in the cpumask" is to # check for the result being equal or larger than the number of possible # CPU ids, exactly _because_ we've always done those constant-sized # cpumask scans using a widened type before. So the return value of a # cpumask scan should be checked with # # if (cpu >= nr_cpu_ids) # ... # # because the cpumask scan did not necessarily stop exactly *at* that # maximum CPU id. # # But a few cases ended up instead using checks like # # if (cpu == nr_cpumask_bits) # ... # # which used that internal "widened" number of bits. And that used to # work pretty much by accident (ok, in this case "by accident" is simply # because it matched the historical internal implementation of the cpumask # scanning, so it was more of a "intentionally using implementation # details rather than an accident"). # # But the extended constant-sized optimizations then did that internal # implementation differently, and now that code that did things wrong but # matched the old implementation no longer worked at all. # # Which then causes subsequent odd problems due to using what ends up # being an invalid CPU ID. # # Most of these cases require either unusual hardware or special uses to # hit, but the random.c one triggers quite easily. # # All you really need is to have a sufficiently small CONFIG_NR_CPUS value # for the bit scanning optimization to be triggered, but not enough CPUs # to then actually fill that widened cpumask. At that point, the cpumask # scanning will return the NR_CPUS constant, which is _not_ the same as # nr_cpumask_bits. # # This just does the mindless fix with # # sed -i 's/== nr_cpumask_bits/>= nr_cpu_ids/' # # to fix the incorrect uses. # # The ones in the SCSI lpfc driver in particular could probably be fixed # more cleanly by just removing that repeated pattern entirely, but I am # not emptionally invested enough in that driver to care. # # Reported-and-tested-by: Guenter Roeck # Link: https://lore.kernel.org/lkml/481b19b5-83a0-4793-b4fd-194ad7b978c3@roeck-us.net/ # Reported-and-tested-by: Geert Uytterhoeven # Link: https://lore.kernel.org/lkml/CAMuHMdUKo_Sf7TjKzcNDa8Ve+6QrK+P8nSQrSQ=6LTRmcBKNww@mail.gmail.com/ # Reported-by: Vernon Yang # Link: https://lore.kernel.org/lkml/20230306160651.2016767-1-vernon2gm@gmail.com/ # Cc: Yury Norov # Cc: Jason A. Donenfeld # Signed-off-by: Linus Torvalds # < /opt/cross/kisskb/x86-64--glibc--bleeding-edge-2022.08-1/bin/x86_64-linux-gcc --version # < /opt/cross/kisskb/x86-64--glibc--bleeding-edge-2022.08-1/bin/x86_64-linux-ld --version # < git log --format=%s --max-count=1 8ca09d5fa3549d142c2080a72a4c70ce389163cd # < make -s -j 24 ARCH=um O=/kisskb/build/linus_um-allmodconfig_um-x86_64-gcc12 CROSS_COMPILE=/opt/cross/kisskb/x86-64--glibc--bleeding-edge-2022.08-1/bin/x86_64-linux- SUBARCH=x86_64 allmodconfig # Added to kconfig CONFIG_STANDALONE=y # Added to kconfig CONFIG_KCOV=n # Added to kconfig CONFIG_GCC_PLUGINS=n # Added to kconfig CONFIG_GCC_PLUGIN_CYC_COMPLEXITY=n # Added to kconfig CONFIG_GCC_PLUGIN_SANCOV=n # Added to kconfig CONFIG_GCC_PLUGIN_LATENT_ENTROPY=n # Added to kconfig CONFIG_GCC_PLUGIN_STRUCTLEAK=n # Added to kconfig CONFIG_GCC_PLUGIN_RANDSTRUCT=n # Added to kconfig CONFIG_UML_NET=n # Added to kconfig CONFIG_UML_NET_ETHERTAP=n # Added to kconfig CONFIG_UML_NET_TUNTAP=n # Added to kconfig CONFIG_UML_NET_SLIP=n # Added to kconfig CONFIG_UML_NET_DAEMON=n # Added to kconfig CONFIG_UML_NET_VDE=n # Added to kconfig CONFIG_UML_NET_MCAST=n # Added to kconfig CONFIG_UML_NET_PCAP=n # Added to kconfig CONFIG_UML_NET_SLIRP=n # Added to kconfig CONFIG_GCOV_KERNEL=n # Added to kconfig CONFIG_DEBUG_INFO_BTF=n # Added to kconfig CONFIG_BPF_PRELOAD=n # < make -s -j 24 ARCH=um O=/kisskb/build/linus_um-allmodconfig_um-x86_64-gcc12 CROSS_COMPILE=/opt/cross/kisskb/x86-64--glibc--bleeding-edge-2022.08-1/bin/x86_64-linux- SUBARCH=x86_64 help # make -s -j 24 ARCH=um O=/kisskb/build/linus_um-allmodconfig_um-x86_64-gcc12 CROSS_COMPILE=/opt/cross/kisskb/x86-64--glibc--bleeding-edge-2022.08-1/bin/x86_64-linux- SUBARCH=x86_64 olddefconfig .config:12728:warning: override: reassigning to symbol GCC_PLUGIN_LATENT_ENTROPY .config:12732:warning: override: reassigning to symbol UML_NET_ETHERTAP .config:12734:warning: override: reassigning to symbol UML_NET_SLIP .config:12739:warning: override: reassigning to symbol UML_NET_SLIRP # make -s -j 24 ARCH=um O=/kisskb/build/linus_um-allmodconfig_um-x86_64-gcc12 CROSS_COMPILE=/opt/cross/kisskb/x86-64--glibc--bleeding-edge-2022.08-1/bin/x86_64-linux- SUBARCH=x86_64 /kisskb/src/drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.c: In function 'kfd_cpumask_to_apic_id': /kisskb/src/drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.c:2157:48: error: 'struct cpuinfo_um' has no member named 'apicid' 2157 | return cpu_data(first_cpu_of_numa_node).apicid; | ^ /kisskb/src/drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.c:2161:1: error: control reaches end of non-void function [-Werror=return-type] 2161 | } | ^ cc1: all warnings being treated as errors make[6]: *** [/kisskb/src/scripts/Makefile.build:252: drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.o] Error 1 make[6]: *** Waiting for unfinished jobs.... make[5]: *** [/kisskb/src/scripts/Makefile.build:494: drivers/gpu/drm/amd/amdgpu] Error 2 make[5]: *** Waiting for unfinished jobs.... make[4]: *** [/kisskb/src/scripts/Makefile.build:494: drivers/gpu/drm] Error 2 make[3]: *** [/kisskb/src/scripts/Makefile.build:494: drivers/gpu] Error 2 make[3]: *** Waiting for unfinished jobs.... make[2]: *** [/kisskb/src/scripts/Makefile.build:494: drivers] Error 2 make[1]: *** [/kisskb/src/Makefile:2028: .] Error 2 make: *** [Makefile:226: __sub-make] Error 2 Command 'make -s -j 24 ARCH=um O=/kisskb/build/linus_um-allmodconfig_um-x86_64-gcc12 CROSS_COMPILE=/opt/cross/kisskb/x86-64--glibc--bleeding-edge-2022.08-1/bin/x86_64-linux- SUBARCH=x86_64 ' returned non-zero exit status 2 # rm -rf /kisskb/build/linus_um-allmodconfig_um-x86_64-gcc12 # Build took: 0:31:54.670471