[PW_SID:1088339] lib: rework bitreverse#1851
Conversation
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>
|
Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32" |
|
Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32" |
|
Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32" |
|
Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32" |
|
Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32" |
|
Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32" |
|
Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32" |
|
Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32" |
|
Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32" |
|
Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32" |
|
Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32" |
|
Patch 1: "[1/6] lib: include crc32.h conditionally on CONFIG_CRC32" |
|
Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig" |
|
Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig" |
|
Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig" |
|
Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig" |
|
Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig" |
|
Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig" |
|
Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig" |
|
Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig" |
|
Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig" |
|
Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig" |
|
Patch 2: "[2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig" |
|
Patch 4: "[4/6] arch/riscv: Add bitrev.h file to support rev8 and brev8" |
|
Patch 4: "[4/6] arch/riscv: Add bitrev.h file to support rev8 and brev8" |
|
Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE" |
94a07a2 to
f190ec6
Compare
|
Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE" |
|
Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE" |
|
Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE" |
|
Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE" |
|
Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE" |
|
Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE" |
|
Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE" |
|
Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE" |
|
Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE" |
|
Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE" |
|
Patch 5: "[5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE" |
|
Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]" |
|
Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]" |
|
Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]" |
|
Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]" |
|
Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]" |
|
Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]" |
|
Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]" |
|
Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]" |
|
Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]" |
|
Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]" |
|
Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]" |
|
Patch 6: "[6/6] MAINTAINERS: BITOPS: include bitrev.[ch]" |
f190ec6 to
2c3b264
Compare
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