* [PATCH v5 0/3] arch/riscv: Add bitrev.h file to support rev8 and brev8
@ 2026-04-21 13:07 Jinjie Ruan
2026-04-21 13:07 ` [PATCH v5 1/3] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig Jinjie Ruan
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Jinjie Ruan @ 2026-04-21 13:07 UTC (permalink / raw)
To: pjw, palmer, aou, alex, yury.norov, linux, arnd, akpm, ruanjinjie,
linux-riscv, linux-kernel, linux-arch, david.laight.linux, nathan,
cp0613
Add bitrev.h file to support rev8 and brev8 for riscv.
Tested functionally on riscv64 QEMU with:
"-M virt,acpi=on,zbkb=true,zbb=true"
Changes in v5:
- Rename NEED_BYTE_REV_TABLE to GENERIC_BITREVERSE.
- Add help text and make GENERIC_BITREVERSE depends on BITREVERSE, and
use def_bool.
- Split into three patches.
- Add suggested-by.
Changes in v4:
- Update the riscv implementation as David suggested.
- Add new config called NEED_BYTE_REV_TABLE as David suggested to avoid
bloating the .data section for architectures that have full hardware
bit-reverse support and don't need the table.
Changes in v3:
- Fix the build issue by remving the CONFIG_HAVE_ARCH_BITREVERSE macro
for byte_rev_table.
- Update the riscv implementation as David suggested.
- Add Reviwed-by.
Changes in v2:
- Define generic __bitrev8/16/32 for reuse in riscv.
Jinjie Ruan (3):
lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig
bitops: Define generic __bitrev8/16/32 for reuse
arch/riscv: Add bitrev.h file to support rev8 and brev8
arch/riscv/Kconfig | 2 ++
arch/riscv/include/asm/bitrev.h | 51 +++++++++++++++++++++++++++
include/asm-generic/bitops/__bitrev.h | 25 +++++++++++++
include/linux/bitrev.h | 20 +++--------
lib/Kconfig | 18 ++++++++++
lib/bitrev.c | 4 +--
6 files changed, 102 insertions(+), 18 deletions(-)
create mode 100644 arch/riscv/include/asm/bitrev.h
create mode 100644 include/asm-generic/bitops/__bitrev.h
--
2.34.1
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH v5 1/3] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig 2026-04-21 13:07 [PATCH v5 0/3] arch/riscv: Add bitrev.h file to support rev8 and brev8 Jinjie Ruan @ 2026-04-21 13:07 ` Jinjie Ruan 2026-04-21 13:07 ` [PATCH v5 2/3] bitops: Define generic __bitrev8/16/32 for reuse Jinjie Ruan ` (2 subsequent siblings) 3 siblings, 0 replies; 10+ messages in thread From: Jinjie Ruan @ 2026-04-21 13:07 UTC (permalink / raw) To: pjw, palmer, aou, alex, yury.norov, linux, arnd, akpm, ruanjinjie, linux-riscv, linux-kernel, linux-arch, david.laight.linux, nathan, cp0613 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> --- lib/Kconfig | 18 ++++++++++++++++++ lib/bitrev.c | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/Kconfig b/lib/Kconfig index 0f2fb9610647..e3f9719a4d6f 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -62,6 +62,24 @@ config HAVE_ARCH_BITREVERSE This option enables the use of hardware bit-reversal instructions on architectures which support such operations. +config GENERIC_BITREVERSE + def_bool !HAVE_ARCH_BITREVERSE + depends on BITREVERSE + help + This option provides the standard software-based bit reversal + implementation using a lookup table. + + Architecture-specific implementations (HAVE_ARCH_BITREVERSE) + and this generic version are not necessarily mutually exclusive + at the configuration level, but selecting this ensures that + the generic `bitrev8/16/32` functions are available when the + CPU does not provide native instructions (like RISC-V's ZBKB + extension). + + If you are an architecture maintainer and your CPU has native + bit-reversal instructions, you should select HAVE_ARCH_BITREVERSE + to skip this table-based implementation. + config ARCH_HAS_STRNCPY_FROM_USER bool diff --git a/lib/bitrev.c b/lib/bitrev.c index 81b56e0a7f32..3a53ff67aeba 100644 --- a/lib/bitrev.c +++ b/lib/bitrev.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only -#ifndef CONFIG_HAVE_ARCH_BITREVERSE +#ifdef CONFIG_GENERIC_BITREVERSE #include <linux/types.h> #include <linux/module.h> #include <linux/bitrev.h> @@ -44,4 +44,4 @@ const u8 byte_rev_table[256] = { }; EXPORT_SYMBOL_GPL(byte_rev_table); -#endif /* CONFIG_HAVE_ARCH_BITREVERSE */ +#endif /* CONFIG_GENERIC_BITREVERSE */ -- 2.34.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v5 2/3] bitops: Define generic __bitrev8/16/32 for reuse 2026-04-21 13:07 [PATCH v5 0/3] arch/riscv: Add bitrev.h file to support rev8 and brev8 Jinjie Ruan 2026-04-21 13:07 ` [PATCH v5 1/3] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig Jinjie Ruan @ 2026-04-21 13:07 ` Jinjie Ruan 2026-04-29 20:29 ` Nathan Chancellor 2026-04-21 13:07 ` [PATCH v5 3/3] arch/riscv: Add bitrev.h file to support rev8 and brev8 Jinjie Ruan 2026-04-27 20:18 ` [PATCH v5 0/3] " Yury Norov 3 siblings, 1 reply; 10+ messages in thread From: Jinjie Ruan @ 2026-04-21 13:07 UTC (permalink / raw) To: pjw, palmer, aou, alex, yury.norov, linux, arnd, akpm, ruanjinjie, linux-riscv, linux-kernel, linux-arch, david.laight.linux, nathan, cp0613 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> --- include/asm-generic/bitops/__bitrev.h | 25 +++++++++++++++++++++++++ include/linux/bitrev.h | 20 ++++---------------- 2 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 include/asm-generic/bitops/__bitrev.h diff --git a/include/asm-generic/bitops/__bitrev.h b/include/asm-generic/bitops/__bitrev.h new file mode 100644 index 000000000000..f06af929678d --- /dev/null +++ b/include/asm-generic/bitops/__bitrev.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS___BITREV_H_ +#define _ASM_GENERIC_BITOPS___BITREV_H_ + +#ifdef CONFIG_GENERIC_BITREVERSE +#include <asm/types.h> + +extern u8 const byte_rev_table[256]; +static __always_inline __attribute_const__ u8 generic___bitrev8(u8 byte) +{ + return byte_rev_table[byte]; +} + +static __always_inline __attribute_const__ u16 generic___bitrev16(u16 x) +{ + return (generic___bitrev8(x & 0xff) << 8) | generic___bitrev8(x >> 8); +} + +static __always_inline __attribute_const__ u32 generic___bitrev32(u32 x) +{ + return (generic___bitrev16(x & 0xffff) << 16) | generic___bitrev16(x >> 16); +} +#endif /* CONFIG_GENERIC_BITREVERSE */ + +#endif /* _ASM_GENERIC_BITOPS___BITREV_H_ */ diff --git a/include/linux/bitrev.h b/include/linux/bitrev.h index d35b8ec1c485..11620a70e776 100644 --- a/include/linux/bitrev.h +++ b/include/linux/bitrev.h @@ -12,22 +12,10 @@ #define __bitrev8 __arch_bitrev8 #else -extern u8 const byte_rev_table[256]; -static inline u8 __bitrev8(u8 byte) -{ - return byte_rev_table[byte]; -} - -static inline u16 __bitrev16(u16 x) -{ - return (__bitrev8(x & 0xff) << 8) | __bitrev8(x >> 8); -} - -static inline u32 __bitrev32(u32 x) -{ - return (__bitrev16(x & 0xffff) << 16) | __bitrev16(x >> 16); -} - +#include <asm-generic/bitops/__bitrev.h> +#define __bitrev32 generic___bitrev32 +#define __bitrev16 generic___bitrev16 +#define __bitrev8 generic___bitrev8 #endif /* CONFIG_HAVE_ARCH_BITREVERSE */ #define __bitrev8x4(x) (__bitrev32(swab32(x))) -- 2.34.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v5 2/3] bitops: Define generic __bitrev8/16/32 for reuse 2026-04-21 13:07 ` [PATCH v5 2/3] bitops: Define generic __bitrev8/16/32 for reuse Jinjie Ruan @ 2026-04-29 20:29 ` Nathan Chancellor 2026-04-30 1:47 ` Yury Norov 0 siblings, 1 reply; 10+ messages in thread From: Nathan Chancellor @ 2026-04-29 20:29 UTC (permalink / raw) To: Jinjie Ruan Cc: pjw, palmer, aou, alex, yury.norov, linux, arnd, akpm, linux-riscv, linux-kernel, linux-arch, david.laight.linux, cp0613 Hi Jinjie, On Tue, Apr 21, 2026 at 09:07:51PM +0800, Jinjie Ruan wrote: > 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> > --- > include/asm-generic/bitops/__bitrev.h | 25 +++++++++++++++++++++++++ > include/linux/bitrev.h | 20 ++++---------------- > 2 files changed, 29 insertions(+), 16 deletions(-) > create mode 100644 include/asm-generic/bitops/__bitrev.h > > diff --git a/include/asm-generic/bitops/__bitrev.h b/include/asm-generic/bitops/__bitrev.h > new file mode 100644 > index 000000000000..f06af929678d > --- /dev/null > +++ b/include/asm-generic/bitops/__bitrev.h > @@ -0,0 +1,25 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_GENERIC_BITOPS___BITREV_H_ > +#define _ASM_GENERIC_BITOPS___BITREV_H_ > + > +#ifdef CONFIG_GENERIC_BITREVERSE The dependencies of this symbol seem insufficient, as I can trigger a build failure on next-20260429 like so: $ 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 ... $ scripts/config -s BITREVERSE undef $ rg BITREVERSE .config > +#include <asm/types.h> > + > +extern u8 const byte_rev_table[256]; > +static __always_inline __attribute_const__ u8 generic___bitrev8(u8 byte) > +{ > + return byte_rev_table[byte]; > +} > + > +static __always_inline __attribute_const__ u16 generic___bitrev16(u16 x) > +{ > + return (generic___bitrev8(x & 0xff) << 8) | generic___bitrev8(x >> 8); > +} > + > +static __always_inline __attribute_const__ u32 generic___bitrev32(u32 x) > +{ > + return (generic___bitrev16(x & 0xffff) << 16) | generic___bitrev16(x >> 16); > +} > +#endif /* CONFIG_GENERIC_BITREVERSE */ > + > +#endif /* _ASM_GENERIC_BITOPS___BITREV_H_ */ > diff --git a/include/linux/bitrev.h b/include/linux/bitrev.h > index d35b8ec1c485..11620a70e776 100644 > --- a/include/linux/bitrev.h > +++ b/include/linux/bitrev.h > @@ -12,22 +12,10 @@ > #define __bitrev8 __arch_bitrev8 > > #else > -extern u8 const byte_rev_table[256]; > -static inline u8 __bitrev8(u8 byte) > -{ > - return byte_rev_table[byte]; > -} > - > -static inline u16 __bitrev16(u16 x) > -{ > - return (__bitrev8(x & 0xff) << 8) | __bitrev8(x >> 8); > -} > - > -static inline u32 __bitrev32(u32 x) > -{ > - return (__bitrev16(x & 0xffff) << 16) | __bitrev16(x >> 16); > -} > - > +#include <asm-generic/bitops/__bitrev.h> > +#define __bitrev32 generic___bitrev32 > +#define __bitrev16 generic___bitrev16 > +#define __bitrev8 generic___bitrev8 > #endif /* CONFIG_HAVE_ARCH_BITREVERSE */ > > #define __bitrev8x4(x) (__bitrev32(swab32(x))) > -- > 2.34.1 > -- Cheers, Nathan ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v5 2/3] bitops: Define generic __bitrev8/16/32 for reuse 2026-04-29 20:29 ` Nathan Chancellor @ 2026-04-30 1:47 ` Yury Norov 2026-04-30 3:59 ` Nathan Chancellor 0 siblings, 1 reply; 10+ messages in thread From: Yury Norov @ 2026-04-30 1:47 UTC (permalink / raw) To: Nathan Chancellor Cc: Jinjie Ruan, pjw, palmer, aou, alex, yury.norov, linux, arnd, akpm, linux-riscv, linux-kernel, linux-arch, david.laight.linux, cp0613, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni + networking maintainers On Wed, Apr 29, 2026 at 01:29:22PM -0700, Nathan Chancellor wrote: > Hi Jinjie, > > On Tue, Apr 21, 2026 at 09:07:51PM +0800, Jinjie Ruan wrote: > > 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> > > --- > > include/asm-generic/bitops/__bitrev.h | 25 +++++++++++++++++++++++++ > > include/linux/bitrev.h | 20 ++++---------------- > > 2 files changed, 29 insertions(+), 16 deletions(-) > > create mode 100644 include/asm-generic/bitops/__bitrev.h > > > > diff --git a/include/asm-generic/bitops/__bitrev.h b/include/asm-generic/bitops/__bitrev.h > > new file mode 100644 > > index 000000000000..f06af929678d > > --- /dev/null > > +++ b/include/asm-generic/bitops/__bitrev.h > > @@ -0,0 +1,25 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +#ifndef _ASM_GENERIC_BITOPS___BITREV_H_ > > +#define _ASM_GENERIC_BITOPS___BITREV_H_ > > + > > +#ifdef CONFIG_GENERIC_BITREVERSE > > The dependencies of this symbol seem insufficient, as I can trigger a > build failure on next-20260429 like so: > > $ 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 > ... > > $ scripts/config -s BITREVERSE > undef > > $ rg BITREVERSE .config Confirm the same for x86 tinyconfig. The problem is that the patch makes generic bitrevXX() conditional on CONFIG_GENERIC_BITREVERSE, while before they were conditional on !CONFIG_HAVE_ARCH_BITREVERSE. So if you don't have arch bitreverse(), and dont' enable BITREVERSE, the generic implementation is not defined now. Luckily, the only user of bitrev() in unconditionally compiled objects is CRC32, and it's not needed if CRC32 is disabled. This is the minimal working fix for me. Please let me know what do you think. I can prepend Jinjie's pathes in my tree with it if it's OK for you. Thanks, Yury diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index df8f88f63a70..245b206dd38b 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -20,7 +20,9 @@ #include <linux/if_ether.h> #include <linux/netdevice.h> #include <linux/random.h> +#ifdef CONFIG_CRCC32 #include <linux/crc32.h> +#endif #include <linux/unaligned.h> #include <asm/bitsperlong.h> @@ -281,6 +283,7 @@ static inline void eth_hw_addr_random(struct net_device *dev) dev->addr_assign_type = NET_ADDR_RANDOM; } +#ifdef CONFIG_CRCC32 /** * eth_hw_addr_crc - Calculate CRC from netdev_hw_addr * @ha: pointer to hardware address @@ -291,6 +294,7 @@ static inline u32 eth_hw_addr_crc(struct netdev_hw_addr *ha) { return ether_crc(ETH_ALEN, ha->addr); } +#endif /** * ether_addr_copy - Copy an Ethernet address ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v5 2/3] bitops: Define generic __bitrev8/16/32 for reuse 2026-04-30 1:47 ` Yury Norov @ 2026-04-30 3:59 ` Nathan Chancellor 2026-04-30 16:41 ` Yury Norov 0 siblings, 1 reply; 10+ messages in thread From: Nathan Chancellor @ 2026-04-30 3:59 UTC (permalink / raw) To: Yury Norov Cc: Jinjie Ruan, pjw, palmer, aou, alex, yury.norov, linux, arnd, akpm, linux-riscv, linux-kernel, linux-arch, david.laight.linux, cp0613, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni On Wed, Apr 29, 2026 at 09:47:12PM -0400, Yury Norov wrote: > + networking maintainers > > On Wed, Apr 29, 2026 at 01:29:22PM -0700, Nathan Chancellor wrote: > > Hi Jinjie, > > > > On Tue, Apr 21, 2026 at 09:07:51PM +0800, Jinjie Ruan wrote: > > > 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> > > > --- > > > include/asm-generic/bitops/__bitrev.h | 25 +++++++++++++++++++++++++ > > > include/linux/bitrev.h | 20 ++++---------------- > > > 2 files changed, 29 insertions(+), 16 deletions(-) > > > create mode 100644 include/asm-generic/bitops/__bitrev.h > > > > > > diff --git a/include/asm-generic/bitops/__bitrev.h b/include/asm-generic/bitops/__bitrev.h > > > new file mode 100644 > > > index 000000000000..f06af929678d > > > --- /dev/null > > > +++ b/include/asm-generic/bitops/__bitrev.h > > > @@ -0,0 +1,25 @@ > > > +/* SPDX-License-Identifier: GPL-2.0 */ > > > +#ifndef _ASM_GENERIC_BITOPS___BITREV_H_ > > > +#define _ASM_GENERIC_BITOPS___BITREV_H_ > > > + > > > +#ifdef CONFIG_GENERIC_BITREVERSE > > > > The dependencies of this symbol seem insufficient, as I can trigger a > > build failure on next-20260429 like so: > > > > $ 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 > > ... > > > > $ scripts/config -s BITREVERSE > > undef > > > > $ rg BITREVERSE .config > > Confirm the same for x86 tinyconfig. > > The problem is that the patch makes generic bitrevXX() conditional > on CONFIG_GENERIC_BITREVERSE, while before they were conditional on > !CONFIG_HAVE_ARCH_BITREVERSE. So if you don't have arch bitreverse(), > and dont' enable BITREVERSE, the generic implementation is not defined > now. > > Luckily, the only user of bitrev() in unconditionally compiled objects > is CRC32, and it's not needed if CRC32 is disabled. > > This is the minimal working fix for me. Please let me know what do you > think. I can prepend Jinjie's pathes in my tree with it if it's OK for > you. I will run it through my full build matrix overnight and report back with any problems noticed. > diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h > index df8f88f63a70..245b206dd38b 100644 > --- a/include/linux/etherdevice.h > +++ b/include/linux/etherdevice.h > @@ -20,7 +20,9 @@ > #include <linux/if_ether.h> > #include <linux/netdevice.h> > #include <linux/random.h> > +#ifdef CONFIG_CRCC32 Initial testing shows that this should be #ifdef CONFIG_CRC32 here and below though. > #include <linux/crc32.h> > +#endif > #include <linux/unaligned.h> > #include <asm/bitsperlong.h> > > @@ -281,6 +283,7 @@ static inline void eth_hw_addr_random(struct net_device *dev) > dev->addr_assign_type = NET_ADDR_RANDOM; > } > > +#ifdef CONFIG_CRCC32 > /** > * eth_hw_addr_crc - Calculate CRC from netdev_hw_addr > * @ha: pointer to hardware address > @@ -291,6 +294,7 @@ static inline u32 eth_hw_addr_crc(struct netdev_hw_addr *ha) > { > return ether_crc(ETH_ALEN, ha->addr); > } > +#endif > > /** > * ether_addr_copy - Copy an Ethernet address -- Cheers, Nathan ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v5 2/3] bitops: Define generic __bitrev8/16/32 for reuse 2026-04-30 3:59 ` Nathan Chancellor @ 2026-04-30 16:41 ` Yury Norov 2026-04-30 19:02 ` Nathan Chancellor 0 siblings, 1 reply; 10+ messages in thread From: Yury Norov @ 2026-04-30 16:41 UTC (permalink / raw) To: Nathan Chancellor Cc: Jinjie Ruan, pjw, palmer, aou, alex, yury.norov, linux, arnd, akpm, linux-riscv, linux-kernel, linux-arch, david.laight.linux, cp0613, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni On Wed, Apr 29, 2026 at 08:59:43PM -0700, Nathan Chancellor wrote: > On Wed, Apr 29, 2026 at 09:47:12PM -0400, Yury Norov wrote: > > + networking maintainers > > > > On Wed, Apr 29, 2026 at 01:29:22PM -0700, Nathan Chancellor wrote: > > > Hi Jinjie, > > > > > > On Tue, Apr 21, 2026 at 09:07:51PM +0800, Jinjie Ruan wrote: > > > > 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> > > > > --- > > > > include/asm-generic/bitops/__bitrev.h | 25 +++++++++++++++++++++++++ > > > > include/linux/bitrev.h | 20 ++++---------------- > > > > 2 files changed, 29 insertions(+), 16 deletions(-) > > > > create mode 100644 include/asm-generic/bitops/__bitrev.h > > > > > > > > diff --git a/include/asm-generic/bitops/__bitrev.h b/include/asm-generic/bitops/__bitrev.h > > > > new file mode 100644 > > > > index 000000000000..f06af929678d > > > > --- /dev/null > > > > +++ b/include/asm-generic/bitops/__bitrev.h > > > > @@ -0,0 +1,25 @@ > > > > +/* SPDX-License-Identifier: GPL-2.0 */ > > > > +#ifndef _ASM_GENERIC_BITOPS___BITREV_H_ > > > > +#define _ASM_GENERIC_BITOPS___BITREV_H_ > > > > + > > > > +#ifdef CONFIG_GENERIC_BITREVERSE > > > > > > The dependencies of this symbol seem insufficient, as I can trigger a > > > build failure on next-20260429 like so: > > > > > > $ 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 > > > ... > > > > > > $ scripts/config -s BITREVERSE > > > undef > > > > > > $ rg BITREVERSE .config > > > > Confirm the same for x86 tinyconfig. > > > > The problem is that the patch makes generic bitrevXX() conditional > > on CONFIG_GENERIC_BITREVERSE, while before they were conditional on > > !CONFIG_HAVE_ARCH_BITREVERSE. So if you don't have arch bitreverse(), > > and dont' enable BITREVERSE, the generic implementation is not defined > > now. > > > > Luckily, the only user of bitrev() in unconditionally compiled objects > > is CRC32, and it's not needed if CRC32 is disabled. > > > > This is the minimal working fix for me. Please let me know what do you > > think. I can prepend Jinjie's pathes in my tree with it if it's OK for > > you. > > I will run it through my full build matrix overnight and report back > with any problems noticed. > > > diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h > > index df8f88f63a70..245b206dd38b 100644 > > --- a/include/linux/etherdevice.h > > +++ b/include/linux/etherdevice.h > > @@ -20,7 +20,9 @@ > > #include <linux/if_ether.h> > > #include <linux/netdevice.h> > > #include <linux/random.h> > > +#ifdef CONFIG_CRCC32 > > Initial testing shows that this should be > > #ifdef CONFIG_CRC32 > > here and below though. Sure. Please let me know if this works for you. If it does, I'll make it a regular patch, combine with Jinjie's work and my follow-up and resend. Meanwhile, removed all bitreverse material from bitmap-for-next. Thanks, Yury ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v5 2/3] bitops: Define generic __bitrev8/16/32 for reuse 2026-04-30 16:41 ` Yury Norov @ 2026-04-30 19:02 ` Nathan Chancellor 0 siblings, 0 replies; 10+ messages in thread From: Nathan Chancellor @ 2026-04-30 19:02 UTC (permalink / raw) To: Yury Norov Cc: Jinjie Ruan, pjw, palmer, aou, alex, yury.norov, linux, arnd, akpm, linux-riscv, linux-kernel, linux-arch, david.laight.linux, cp0613, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni On Thu, Apr 30, 2026 at 12:41:14PM -0400, Yury Norov wrote: > Sure. Please let me know if this works for you. If it does, I'll make > it a regular patch, combine with Jinjie's work and my follow-up and > resend. Meanwhile, removed all bitreverse material from > bitmap-for-next. My builds saw no issues overnight with the CONFIG_CRC32 version, so your plan seems good to me. -- Cheers, Nathan ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v5 3/3] arch/riscv: Add bitrev.h file to support rev8 and brev8 2026-04-21 13:07 [PATCH v5 0/3] arch/riscv: Add bitrev.h file to support rev8 and brev8 Jinjie Ruan 2026-04-21 13:07 ` [PATCH v5 1/3] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig Jinjie Ruan 2026-04-21 13:07 ` [PATCH v5 2/3] bitops: Define generic __bitrev8/16/32 for reuse Jinjie Ruan @ 2026-04-21 13:07 ` Jinjie Ruan 2026-04-27 20:18 ` [PATCH v5 0/3] " Yury Norov 3 siblings, 0 replies; 10+ messages in thread From: Jinjie Ruan @ 2026-04-21 13:07 UTC (permalink / raw) To: pjw, palmer, aou, alex, yury.norov, linux, arnd, akpm, ruanjinjie, linux-riscv, linux-kernel, linux-arch, david.laight.linux, nathan, cp0613 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> --- arch/riscv/Kconfig | 2 ++ arch/riscv/include/asm/bitrev.h | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 arch/riscv/include/asm/bitrev.h diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 90c531e6abf5..4f9e1caee5f9 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -105,6 +105,7 @@ config RISCV select FUNCTION_ALIGNMENT_8B if DYNAMIC_FTRACE_WITH_CALL_OPS select GENERIC_ARCH_TOPOLOGY select GENERIC_ATOMIC64 if !64BIT + select GENERIC_BITREVERSE select GENERIC_CLOCKEVENTS_BROADCAST if SMP select GENERIC_CPU_DEVICES select GENERIC_CPU_VULNERABILITIES @@ -128,6 +129,7 @@ config RISCV select HAS_IOPORT if MMU select HAVE_ALIGNED_STRUCT_PAGE select HAVE_ARCH_AUDITSYSCALL + select HAVE_ARCH_BITREVERSE if RISCV_ISA_ZBKB select HAVE_ARCH_HUGE_VMALLOC if HAVE_ARCH_HUGE_VMAP select HAVE_ARCH_HUGE_VMAP if MMU && 64BIT select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL diff --git a/arch/riscv/include/asm/bitrev.h b/arch/riscv/include/asm/bitrev.h new file mode 100644 index 000000000000..4b9b8d34cc3b --- /dev/null +++ b/arch/riscv/include/asm/bitrev.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_BITREV_H +#define __ASM_BITREV_H + +#include <linux/types.h> +#include <asm/cpufeature-macros.h> +#include <asm/hwcap.h> +#include <asm-generic/bitops/__bitrev.h> + +static __always_inline __attribute_const__ u32 __arch_bitrev32(u32 x) +{ + unsigned long result; + + if (!riscv_has_extension_likely(RISCV_ISA_EXT_ZBKB)) + return generic___bitrev32(x); + + asm volatile( + ".option push\n" + ".option arch,+zbkb\n" + "rev8 %0, %1\n" + "brev8 %0, %0\n" + ".option pop" + : "=r" (result) : "r" ((long)x) + ); + + return result >> (__riscv_xlen - 32); +} + +static __always_inline __attribute_const__ u16 __arch_bitrev16(u16 x) +{ + return __arch_bitrev32(x) >> 16; +} + +static __always_inline __attribute_const__ u8 __arch_bitrev8(u8 x) +{ + unsigned long result; + + if (!riscv_has_extension_likely(RISCV_ISA_EXT_ZBKB)) + return generic___bitrev8(x); + + asm volatile( + ".option push\n" + ".option arch,+zbkb\n" + "brev8 %0, %1\n" + ".option pop" + : "=r" (result) : "r" ((long)x) + ); + + return result; +} +#endif -- 2.34.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v5 0/3] arch/riscv: Add bitrev.h file to support rev8 and brev8 2026-04-21 13:07 [PATCH v5 0/3] arch/riscv: Add bitrev.h file to support rev8 and brev8 Jinjie Ruan ` (2 preceding siblings ...) 2026-04-21 13:07 ` [PATCH v5 3/3] arch/riscv: Add bitrev.h file to support rev8 and brev8 Jinjie Ruan @ 2026-04-27 20:18 ` Yury Norov 3 siblings, 0 replies; 10+ messages in thread From: Yury Norov @ 2026-04-27 20:18 UTC (permalink / raw) To: Jinjie Ruan Cc: pjw, palmer, aou, alex, yury.norov, linux, arnd, akpm, linux-riscv, linux-kernel, linux-arch, david.laight.linux, nathan, cp0613 On Tue, Apr 21, 2026 at 09:07:49PM +0800, Jinjie Ruan wrote: > Add bitrev.h file to support rev8 and brev8 for riscv. > > Tested functionally on riscv64 QEMU with: > "-M virt,acpi=on,zbkb=true,zbb=true" Applied in bitmap-for-next. Thanks! > Changes in v5: > - Rename NEED_BYTE_REV_TABLE to GENERIC_BITREVERSE. > - Add help text and make GENERIC_BITREVERSE depends on BITREVERSE, and > use def_bool. > - Split into three patches. > - Add suggested-by. > > Changes in v4: > - Update the riscv implementation as David suggested. > - Add new config called NEED_BYTE_REV_TABLE as David suggested to avoid > bloating the .data section for architectures that have full hardware > bit-reverse support and don't need the table. > > Changes in v3: > - Fix the build issue by remving the CONFIG_HAVE_ARCH_BITREVERSE macro > for byte_rev_table. > - Update the riscv implementation as David suggested. > - Add Reviwed-by. > > Changes in v2: > - Define generic __bitrev8/16/32 for reuse in riscv. > > Jinjie Ruan (3): > lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig > bitops: Define generic __bitrev8/16/32 for reuse > arch/riscv: Add bitrev.h file to support rev8 and brev8 > > arch/riscv/Kconfig | 2 ++ > arch/riscv/include/asm/bitrev.h | 51 +++++++++++++++++++++++++++ > include/asm-generic/bitops/__bitrev.h | 25 +++++++++++++ > include/linux/bitrev.h | 20 +++-------- > lib/Kconfig | 18 ++++++++++ > lib/bitrev.c | 4 +-- > 6 files changed, 102 insertions(+), 18 deletions(-) > create mode 100644 arch/riscv/include/asm/bitrev.h > create mode 100644 include/asm-generic/bitops/__bitrev.h > > -- > 2.34.1 ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-04-30 19:02 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-04-21 13:07 [PATCH v5 0/3] arch/riscv: Add bitrev.h file to support rev8 and brev8 Jinjie Ruan 2026-04-21 13:07 ` [PATCH v5 1/3] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig Jinjie Ruan 2026-04-21 13:07 ` [PATCH v5 2/3] bitops: Define generic __bitrev8/16/32 for reuse Jinjie Ruan 2026-04-29 20:29 ` Nathan Chancellor 2026-04-30 1:47 ` Yury Norov 2026-04-30 3:59 ` Nathan Chancellor 2026-04-30 16:41 ` Yury Norov 2026-04-30 19:02 ` Nathan Chancellor 2026-04-21 13:07 ` [PATCH v5 3/3] arch/riscv: Add bitrev.h file to support rev8 and brev8 Jinjie Ruan 2026-04-27 20:18 ` [PATCH v5 0/3] " Yury Norov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox