[RHEL8,COMMIT] ms/linux/bits.h: make BIT(), GENMASK(), and friends available in assembly

Submitted by Konstantin Khorenko on Jan. 22, 2020, 10:23 a.m.

Details

Message ID 202001221023.00MANC8L023166@finist_co8.work.ct
State New
Series "ms/linux/bits.h: make BIT(), GENMASK(), and friends available in assembly"
Headers show

Commit Message

Konstantin Khorenko Jan. 22, 2020, 10:23 a.m.
The commit is pushed to "branch-rh8-4.18.0-80.1.2.vz8.3.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-80.1.2.vz8.3.1
------>
commit dbcaef0e63d688a6d8feffe02fe940c4d61a5b88
Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Date:   Wed Jan 22 13:23:12 2020 +0300

    ms/linux/bits.h: make BIT(), GENMASK(), and friends available in assembly
    
    BIT(),  GENMASK(), etc. are useful to define register bits of hardware.
    However, low-level code is often written in assembly, where they are
    not available due to the hard-coded 1UL, 0UL.
    
    In fact, in-kernel headers such as arch/arm64/include/asm/sysreg.h
    use _BITUL() instead of BIT() so that the register bit macros are
    available in assembly.
    
    Using macros in include/uapi/linux/const.h have two reasons:
    
    [1] For use in uapi headers
      We should use underscore-prefixed variants for user-space.
    
    [2] For use in assembly code
      Since _BITUL() uses UL(1) instead of 1UL, it can be used as an
      alternative of BIT().
    
    For [2], it is pretty easy to change BIT() etc. for use in assembly.
    
    This allows to replace _BUTUL() in kernel-space headers with BIT().
    
    Link: http://lkml.kernel.org/r/20190609153941.17249-1-yamada.masahiro@socionext.com
    Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
    Cc: Catalin Marinas <catalin.marinas@arm.com>
    Cc: Christian Borntraeger <borntraeger@de.ibm.com>
    Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
    Cc: Vasily Gorbik <gor@linux.ibm.com>
    Cc: Vineet Gupta <vgupta@synopsys.com>
    Cc: Will Deacon <will.deacon@arm.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    
    eshatokhin@: this commit is needed when rebuilding the kernel with
    GCC 9+ for Syzkaller testing. Without it, the build may fail like
    this:
    
      arch/x86/entry/entry_64.S: Assembler messages:
      arch/x86/entry/entry_64.S:1191: Error: found 'L', expected: ')'
      arch/x86/entry/entry_64.S:1191: Error: junk `L<<(0))' after expression
      arch/x86/entry/entry_64.S:1614: Error: found 'L', expected: ')'
      arch/x86/entry/entry_64.S:1614: Error: junk `L<<(0))' after expression
      make[2]: *** [arch/x86/entry/entry_64.o] Error 1
    
    Commit 95b980d62d52c4c1768ee719e8db3efe27ef52b2 in the mainline kernel.
    
    Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
---
 include/linux/bits.h | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

Patch hide | download patch | download mbox

diff --git a/include/linux/bits.h b/include/linux/bits.h
index 2b7b532c1d51..669d69441a62 100644
--- a/include/linux/bits.h
+++ b/include/linux/bits.h
@@ -1,13 +1,15 @@ 
 /* SPDX-License-Identifier: GPL-2.0 */
 #ifndef __LINUX_BITS_H
 #define __LINUX_BITS_H
+
+#include <linux/const.h>
 #include <asm/bitsperlong.h>
 
-#define BIT(nr)			(1UL << (nr))
-#define BIT_ULL(nr)		(1ULL << (nr))
-#define BIT_MASK(nr)		(1UL << ((nr) % BITS_PER_LONG))
+#define BIT(nr)			(UL(1) << (nr))
+#define BIT_ULL(nr)		(ULL(1) << (nr))
+#define BIT_MASK(nr)		(UL(1) << ((nr) % BITS_PER_LONG))
 #define BIT_WORD(nr)		((nr) / BITS_PER_LONG)
-#define BIT_ULL_MASK(nr)	(1ULL << ((nr) % BITS_PER_LONG_LONG))
+#define BIT_ULL_MASK(nr)	(ULL(1) << ((nr) % BITS_PER_LONG_LONG))
 #define BIT_ULL_WORD(nr)	((nr) / BITS_PER_LONG_LONG)
 #define BITS_PER_BYTE		8
 
@@ -17,10 +19,11 @@ 
  * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
  */
 #define GENMASK(h, l) \
-	(((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+	(((~UL(0)) - (UL(1) << (l)) + 1) & \
+	 (~UL(0) >> (BITS_PER_LONG - 1 - (h))))
 
 #define GENMASK_ULL(h, l) \
-	(((~0ULL) - (1ULL << (l)) + 1) & \
-	 (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
+	(((~ULL(0)) - (ULL(1) << (l)) + 1) & \
+	 (~ULL(0) >> (BITS_PER_LONG_LONG - 1 - (h))))
 
 #endif	/* __LINUX_BITS_H */