Skip to content

[PW_SID:1088339] lib: rework bitreverse#1851

Closed
linux-riscv-bot wants to merge 7 commits into
workflow__riscv__fixesfrom
pw1088339
Closed

[PW_SID:1088339] lib: rework bitreverse#1851
linux-riscv-bot wants to merge 7 commits into
workflow__riscv__fixesfrom
pw1088339

Conversation

@linux-riscv-bot
Copy link
Copy Markdown

PR for series 1088339 applied to workflow__riscv__fixes

Name: lib: rework bitreverse
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1088339
Version: 1

Linux RISC-V bot and others added 7 commits April 30, 2026 05:50
Currently, bitreverse API is either declared based on
CONFIG_HAVE_ARCH_BITREVERSE, wired to arch implementation, or if the
arch has no bitreverse, based on generic implementation.

So, regardless of CONFIG_BITREVERSE=n, the corresponding API is always
declared. If that happens, the functions become declared but not
implemented, which is an error.

The following patches of the series make it possible to have bitreverse
API undeclared if CONFIG_BITREVERSE=n, thus spotting the problem when
building the tinyconfig:

   $ make -skj"$(nproc)" ARCH=s390 CROSS_COMPILE=s390-linux- mrproper tinyconfig fs/select.o
   In file included from include/linux/crc32.h:6,
                    from include/linux/etherdevice.h:23,
                    from include/linux/if_vlan.h:11,
                    from include/linux/filter.h:21,
                    from include/net/xdp.h:10,
                    from include/net/busy_poll.h:19,
                    from fs/select.c:33:
   include/linux/etherdevice.h: In function 'eth_hw_addr_crc':
   include/linux/bitrev.h:16:20: error: implicit declaration of function 'generic___bitrev32' [-Wimplicit-function-declaration]
      16 | #define __bitrev32 generic___bitrev32
         |                    ^~~~~~~~~~~~~~~~~~
   include/linux/bitrev.h:67:9: note: in expansion of macro '__bitrev32'
      67 |         __bitrev32(__x);                                \
         |         ^~~~~~~~~~
   include/linux/crc32.h:107:36: note: in expansion of macro 'bitrev32'
     107 | #define ether_crc(length, data)    bitrev32(crc32_le(~0, data, length))
         |                                    ^~~~~~~~
   include/linux/etherdevice.h:292:16: note: in expansion of macro 'ether_crc'
     292 |         return ether_crc(ETH_ALEN, ha->addr);
         |                ^~~~~~~~~
   make[5]: *** [scripts/Makefile.build:289: fs/select.o] Error 1
   ...

The current unconditionally enabled codebase doesn't use CRC32, neither
bitrev functionality, and if generic___bitrev32 prototype is provided,
the compilation and linkage phases are passed OK.

The only header requiring the crc32 and bitreverse prototypes is
include/linux/etherdevice.h. Thus, protect inclusion of corresponding
headers in the etherdevice with CONFIG_CRC32, together with the only
function depending on it.

Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Yury Norov <ynorov@nvidia.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Currently, the bit reversal lookup table is controlled by
!HAVE_ARCH_BITREVERSE. This makes it difficult for architectures to
provide a hardware-accelerated implementation while still falling
back to the generic table for specific configurations.

Introduce CONFIG_GENERIC_BITREVERSE to explicitly manage the generic
lookup table implementation. By using 'def_bool !HAVE_ARCH_BITREVERSE'
with a dependency on 'BITREVERSE', we ensure that:

1. The table is only compiled when needed.
2. The .config is not polluted with useless options when BITREVERSE
   is disabled.
3. Avoids bloating the .data section for architectures that have
   full hardware bit-reverse support and don't need the table.

Update lib/bitrev.c to use CONFIG_GENERIC_BITREVERSE instead of
checking the absence of HAVE_ARCH_BITREVERSE. This provides a
cleaner interface for architectures like RISC-V that may want to
selectively use the generic implementation as a fallback.

Suggested-by: David Laight <David.Laight@ACULAB.COM>
Suggested-by: Yury Norov <ynorov@nvidia.com>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Signed-off-by: Yury Norov <ynorov@nvidia.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Define generic __bitrev8/16/32 using the implementation
in <linux/bitrev.h>, so they can be reused in <asm/bitrev.h>,
such as RISCV.

Reviewed-by: Yury Norov <ynorov@nvidia.com>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Signed-off-by: Yury Norov <ynorov@nvidia.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
The RISC-V Bit-manipulation Extension for Cryptography (Zbkb) provides
the 'brev8' instruction, which reverses the bits within each byte.
Combined with the 'rev8' instruction (from Zbb or Zbkb), which reverses
the byte order of a register, we can efficiently implement 16-bit,
32-bit, and (on RV64) 64-bit bit reversal.

This is significantly faster than the default software table-lookup
implementation in lib/bitrev.c, as it replaces memory accesses and
multiple arithmetic operations with just two or three hardware
instructions.

Select HAVE_ARCH_BITREVERSE as well as GENERIC_BITREVERSE,
and provide <asm/bitrev.h> to utilize these instructions when
the Zbkb extension is available at runtime via the alternatives
mechanism.

Link: https://docs.riscv.org/reference/isa/unpriv/b-st-ext.html
Suggested-by: David Laight <david.laight.linux@gmail.com>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Signed-off-by: Yury Norov <ynorov@nvidia.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
The file is compiled based on CONFIG_BITREVERSE=y, but everything inside
is protected with CONFIG_GENERIC_BITREVERSE.

Make it simpler by switching the Makefile to compile lib/bitrev.c based
on the proper config.

Signed-off-by: Yury Norov <ynorov@nvidia.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Arch bitrev API is covered in MAINTAINERS under the BITOPS entry,
while generic bitrev is unmaintained. Move it under BITOPS too.

Signed-off-by: Yury Norov <ynorov@nvidia.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 140.70 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1299.48 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1933.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 25.74 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 27.03 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 1.73 seconds
Result: WARNING
Output:

WARNING: Reported-by: should be immediately followed by Closes: with a URL to the report
#51: 
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Yury Norov <ynorov@nvidia.com>

total: 0 errors, 1 warnings, 0 checks, 23 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

Commit b5f7b74e0736 ("lib: include crc32.h conditionally on CONFIG_CRC32") has style problems, please review.

NOTE: Ignored message types: ALLOC_SIZEOF_STRUCT CAMELCASE COMMIT_LOG_LONG_LINE GIT_COMMIT_ID MACRO_ARG_REUSE NO_AUTHOR_SIGN_OFF

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.
total: 0 errors, 1 warnings, 0 checks, 23 lines checked
WARNING: Reported-by: should be immediately followed by Closes: with a URL to the report


@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 87.31 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.25 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32"
kdoc
Desc: Detects for kdoc errors
Duration: 0.86 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32"
module-param
Desc: Detect module_param changes
Duration: 0.26 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.32 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 140.36 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1146.12 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1695.01 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 25.98 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 27.15 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 1.42 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 86.94 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.26 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig"
kdoc
Desc: Detects for kdoc errors
Duration: 0.92 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig"
module-param
Desc: Detect module_param changes
Duration: 0.81 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.85 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 4: "[4/6] arch/riscv: Add bitrev.h file to support rev8 and brev8"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.25 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 4: "[4/6] arch/riscv: Add bitrev.h file to support rev8 and brev8"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.32 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 139.63 seconds
Result: PASS

@linux-riscv-bot linux-riscv-bot force-pushed the workflow__riscv__fixes branch from 94a07a2 to f190ec6 Compare May 1, 2026 02:14
@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1123.92 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1672.26 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 25.74 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 27.09 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.92 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 88.61 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE"
kdoc
Desc: Detects for kdoc errors
Duration: 0.92 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE"
module-param
Desc: Detect module_param changes
Duration: 0.27 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.31 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 138.88 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1013.27 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1375.64 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 25.85 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 27.26 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.73 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 87.78 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]"
kdoc
Desc: Detects for kdoc errors
Duration: 0.97 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]"
module-param
Desc: Detect module_param changes
Duration: 0.33 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.31 seconds
Result: PASS

@linux-riscv-bot linux-riscv-bot force-pushed the workflow__riscv__fixes branch from f190ec6 to 2c3b264 Compare May 2, 2026 08:13
@linux-riscv-bot linux-riscv-bot deleted the pw1088339 branch May 8, 2026 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants