Skip to contentSkip to conversation

linux/bits.h: adjust GENMASK_INPUT_CHECK() check

PATCH Superseded Emil Velikov 3 participants 7 messages May 19, 2020 – May 25, 2020 Bitmap API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux/bits.h: adjust GENMASK_INPUT_CHECK() check

Recently the GENMASK_INPUT_CHECK() was added, aiming to catch cases where there GENMASK arguments are flipped.

Although it seems to be triggering -Wtype-limits in the following cases:

   unsigned foo = (10 + x);
   unsigned bar = GENMASK(foo, 0);

   const unsigned foo = (10 + x);
   unsigned bar = GENMASK(foo, 0);

Here are the warnings, from my GCC 9.2 box.

warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
__builtin_constant_p((l) > (h)), (l) > (h), 0)))

                            ^
warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
   __builtin_constant_p((l) > (h)), (l) > (h), 0)))
                                        ^

This results in people disabling the warning all together or promoting foo to signed. Either of which being a sub par option IMHO.

Add a trivial "+ 1" to each h and l in the constant expression.

Fixes 295bcca84916 ("linux/bits.h: add compile time sanity check of

GENMASK inputs")

Cc Rikard Falkeborn <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Chris Wilson <[email protected]>

---
From some quick testing, this works as expected although I could be wrong.

-Emil

---
 include/linux/bits.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/bits.h +2 -2
index 4671fbf28842..5e3ca57adc20 100644
@@ -22,8 +22,8 @@
 	(!defined(CONFIG_CC_IS_GCC) || CONFIG_GCC_VERSION >= 49000)
 #include <linux/build_bug.h>
 #define GENMASK_INPUT_CHECK(h, l) \
-	(BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
-		__builtin_constant_p((l) > (h)), (l) > (h), 0)))
+	(BUILD_BUG_ON_ZERO(!__builtin_choose_expr( \
+		__builtin_constant_p((l + 1) > (h + 1)), (l + 1) > (h + 1), 0)))
 #else
 /*
  * BUILD_BUG_ON_ZERO is not available in h files included from asm files,
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Thank you for the patch! Perhaps something to improve:

Hi Emil,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tegra-drm/drm/tegra/for-next]
[also build test WARNING on linus/master v5.7-rc6 next-20200518] [cannot apply to linux/master]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Emil-Velikov/linux-bits-h-adjust-GENMASK_INPUT_CHECK-check/20200519-205452
base:   git://anongit.freedesktop.org/tegra/linux.git drm/tegra/for-next
config: arc-defconfig (attached as .config)
compiler: arc-elf-gcc (GCC) 9.3.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arc

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>, old ones prefixed by <<):

In file included from include/linux/bits.h:23,
from include/linux/bitops.h:5,
from drivers/clk/clk-multiplier.c:6:
drivers/clk/clk-multiplier.c: In function 'clk_multiplier_recalc_rate':
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~

>> drivers/clk/clk-multiplier.c:48:9: note: in expansion of macro 'GENMASK'

48 | val &= GENMASK(mult->width - 1, 0);
| ^~~~~~~
drivers/clk/clk-multiplier.c: In function 'clk_multiplier_set_rate':
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
drivers/clk/clk-multiplier.c:139:10: note: in expansion of macro 'GENMASK' 139 | val &= ~GENMASK(mult->width + mult->shift - 1, mult->shift);
| ^~~~~~~
--
In file included from include/linux/bits.h:23,
from include/linux/bitops.h:5,
from include/linux/of.h:15,
from include/linux/clk-provider.h:9,
from drivers/clk/clk-fractional-divider.c:10:
drivers/clk/clk-fractional-divider.c: In function 'clk_fd_general_approximation':
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~

>> drivers/clk/clk-fractional-divider.c:88:4: note: in expansion of macro 'GENMASK'

88 | GENMASK(fd->mwidth - 1, 0), GENMASK(fd->nwidth - 1, 0),
| ^~~~~~~
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
drivers/clk/clk-fractional-divider.c:88:32: note: in expansion of macro 'GENMASK'
88 | GENMASK(fd->mwidth - 1, 0), GENMASK(fd->nwidth - 1, 0),
| ^~~~~~~
drivers/clk/clk-fractional-divider.c: In function 'clk_fd_set_rate':
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
drivers/clk/clk-fractional-divider.c:122:4: note: in expansion of macro 'GENMASK'
122 | GENMASK(fd->mwidth - 1, 0), GENMASK(fd->nwidth - 1, 0),
| ^~~~~~~
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
drivers/clk/clk-fractional-divider.c:122:32: note: in expansion of macro 'GENMASK'
122 | GENMASK(fd->mwidth - 1, 0), GENMASK(fd->nwidth - 1, 0),
| ^~~~~~~
drivers/clk/clk-fractional-divider.c: In function 'clk_hw_register_fractional_divider':
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
drivers/clk/clk-fractional-divider.c:178:14: note: in expansion of macro 'GENMASK' 178 | fd->mmask = GENMASK(mwidth - 1, 0) << mshift;
| ^~~~~~~
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
drivers/clk/clk-fractional-divider.c:181:14: note: in expansion of macro 'GENMASK' 181 | fd->nmask = GENMASK(nwidth - 1, 0) << nshift;
| ^~~~~~~
--
In file included from include/linux/bits.h:23,
from include/linux/bitops.h:5,
from include/linux/kernel.h:12,
from include/linux/interrupt.h:6,
from drivers/clocksource/arc_timer.c:15:
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:45:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 45 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK_ULL(h, l))
| ^~~~~~~~~~~~~~~~~~~
include/linux/clocksource.h:136:32: note: in expansion of macro 'GENMASK_ULL' 136 | #define CLOCKSOURCE_MASK(bits) GENMASK_ULL((bits) - 1, 0)
| ^~~~~~~~~~~

>> drivers/clocksource/arc_timer.c:99:12: note: in expansion of macro 'CLOCKSOURCE_MASK'

99 | .mask = CLOCKSOURCE_MASK(64),
| ^~~~~~~~~~~~~~~~
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:45:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 45 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK_ULL(h, l))
| ^~~~~~~~~~~~~~~~~~~
include/linux/clocksource.h:136:32: note: in expansion of macro 'GENMASK_ULL' 136 | #define CLOCKSOURCE_MASK(bits) GENMASK_ULL((bits) - 1, 0)
| ^~~~~~~~~~~
drivers/clocksource/arc_timer.c:157:12: note: in expansion of macro 'CLOCKSOURCE_MASK'
157 | .mask = CLOCKSOURCE_MASK(64),
| ^~~~~~~~~~~~~~~~
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:45:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 45 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK_ULL(h, l))
| ^~~~~~~~~~~~~~~~~~~
include/linux/clocksource.h:136:32: note: in expansion of macro 'GENMASK_ULL' 136 | #define CLOCKSOURCE_MASK(bits) GENMASK_ULL((bits) - 1, 0)
| ^~~~~~~~~~~
drivers/clocksource/arc_timer.c:210:12: note: in expansion of macro 'CLOCKSOURCE_MASK'
210 | .mask = CLOCKSOURCE_MASK(32),
| ^~~~~~~~~~~~~~~~
--
In file included from include/linux/kernel.h:11,
from include/linux/list.h:9,
from include/linux/module.h:12,
from net/core/filter.c:20:
net/core/filter.c: In function '____bpf_skb_set_tunnel_opt':
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/compiler.h:78:42: note: in definition of macro 'unlikely' 78 | # define unlikely(x) __builtin_expect(!!(x), 0)
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
include/net/ip_tunnels.h:66:2: note: in expansion of macro 'GENMASK'
66 | GENMASK((sizeof_field(struct ip_tunnel_info, | ^~~~~~~
net/core/filter.c:3945:22: note: in expansion of macro 'IP_TUNNEL_OPTS_MAX' 3945 | if (unlikely(size > IP_TUNNEL_OPTS_MAX))
| ^~~~~~~~~~~~~~~~~~
In file included from include/linux/bits.h:23,
from include/linux/bitops.h:5,
from include/linux/kernel.h:12,
from include/linux/list.h:9,
from include/linux/module.h:12,
from net/core/filter.c:20:
net/core/filter.c: In function 'bpf_get_skb_set_tunnel_proto':
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
include/net/ip_tunnels.h:66:2: note: in expansion of macro 'GENMASK'
66 | GENMASK((sizeof_field(struct ip_tunnel_info, | ^~~~~~~
net/core/filter.c:3968:35: note: in expansion of macro 'IP_TUNNEL_OPTS_MAX'
3968 | tmp = metadata_dst_alloc_percpu(IP_TUNNEL_OPTS_MAX,
| ^~~~~~~~~~~~~~~~~~
In file included from include/linux/bitops.h:5,
from include/linux/kernel.h:12,
from include/linux/list.h:9,
from include/linux/module.h:12,
from net/core/filter.c:20:

>> include/linux/bits.h:39:2: warning: conversion from 'long unsigned int' to 'u8' {aka 'unsigned char'} changes value from '256' to '0' [-Woverflow]

39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/net/ip_tunnels.h:66:2: note: in expansion of macro 'GENMASK'
66 | GENMASK((sizeof_field(struct ip_tunnel_info, | ^~~~~~~
net/core/filter.c:3968:35: note: in expansion of macro 'IP_TUNNEL_OPTS_MAX'
3968 | tmp = metadata_dst_alloc_percpu(IP_TUNNEL_OPTS_MAX,
| ^~~~~~~~~~~~~~~~~~

vim +39 include/linux/bits.h

295bcca84916cb Rikard Falkeborn 2020-04-06  34  
295bcca84916cb Rikard Falkeborn 2020-04-06  35  #define __GENMASK(h, l) \
95b980d62d52c4 Masahiro Yamada  2019-07-16  36  	(((~UL(0)) - (UL(1) << (l)) + 1) & \
95b980d62d52c4 Masahiro Yamada  2019-07-16  37  	 (~UL(0) >> (BITS_PER_LONG - 1 - (h))))
295bcca84916cb Rikard Falkeborn 2020-04-06  38  #define GENMASK(h, l) \

295bcca84916cb Rikard Falkeborn 2020-04-06 @39 (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
8bd9cb51daac89 Will Deacon 2018-06-19 40

:::::: The code at line 39 was first introduced by commit
:::::: 295bcca84916cb5079140a89fccb472bb8d1f6e2 linux/bits.h: add compile time sanity check of GENMASK inputs

:::::: TO: Rikard Falkeborn <[email protected]> :::::: CC: Linus Torvalds <[email protected]>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#2 lore raw
In reply to Emil Velikov
Thank you for the patch! Perhaps something to improve:

Hi Emil,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tegra-drm/drm/tegra/for-next]
[also build test WARNING on linus/master v5.7-rc6 next-20200518] [cannot apply to linux/master]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Emil-Velikov/linux-bits-h-adjust-GENMASK_INPUT_CHECK-check/20200519-205452
base:   git://anongit.freedesktop.org/tegra/linux.git drm/tegra/for-next
config: mips-allyesconfig (attached as .config)
compiler: mips-linux-gcc (GCC) 9.3.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=mips

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>, old ones prefixed by <<):

In file included from include/linux/bits.h:23,
from include/linux/bitops.h:5,
from include/linux/kernel.h:12,
from include/linux/list.h:9,
from include/linux/preempt.h:11,
from include/linux/spinlock.h:51,
from include/linux/seqlock.h:36,
from include/linux/time.h:6,
from include/linux/compat.h:10,
from arch/mips/kernel/asm-offsets.c:12:
arch/mips/include/asm/mips-cm.h: In function 'mips_cm_max_vp_width':
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~

>> arch/mips/include/asm/mips-cm.h:152:28: note: in expansion of macro 'GENMASK'
152 | #define CM_GCR_REV_MAJOR   GENMASK(15, 8)
|                            ^~~~~~~
>> arch/mips/include/asm/mips-cm.h:156:22: note: in expansion of macro 'CM_GCR_REV_MAJOR'
156 |   (((major) << __ffs(CM_GCR_REV_MAJOR)) |          |                      ^~~~~~~~~~~~~~~~
>> arch/mips/include/asm/mips-cm.h:161:23: note: in expansion of macro 'CM_ENCODE_REV'
161 | #define CM_REV_CM3    CM_ENCODE_REV(8, 0)
|                       ^~~~~~~~~~~~~
>> arch/mips/include/asm/mips-cm.h:367:28: note: in expansion of macro 'CM_REV_CM3'

367 | if (mips_cm_revision() >= CM_REV_CM3)
| ^~~~~~~~~~
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:153:28: note: in expansion of macro 'GENMASK'
153 | #define CM_GCR_REV_MINOR GENMASK(7, 0)
| ^~~~~~~

>> arch/mips/include/asm/mips-cm.h:157:22: note: in expansion of macro 'CM_GCR_REV_MINOR'
157 |    ((minor) << __ffs(CM_GCR_REV_MINOR)))
|                      ^~~~~~~~~~~~~~~~
>> arch/mips/include/asm/mips-cm.h:161:23: note: in expansion of macro 'CM_ENCODE_REV'
161 | #define CM_REV_CM3    CM_ENCODE_REV(8, 0)
|                       ^~~~~~~~~~~~~
>> arch/mips/include/asm/mips-cm.h:367:28: note: in expansion of macro 'CM_REV_CM3'

367 | if (mips_cm_revision() >= CM_REV_CM3)
| ^~~~~~~~~~
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:239:36: note: in expansion of macro 'GENMASK' 239 | #define CM_GCR_SYS_CONFIG2_MAXVPW GENMASK(3, 0)
| ^~~~~~~

>> arch/mips/include/asm/mips-cm.h:368:35: note: in expansion of macro 'CM_GCR_SYS_CONFIG2_MAXVPW'

368 | return read_gcr_sys_config2() & CM_GCR_SYS_CONFIG2_MAXVPW;
| ^~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:293:33: note: in expansion of macro 'GENMASK'
293 | #define CM_GCR_Cx_CONFIG_PVPE GENMASK(9, 0)
| ^~~~~~~

>> arch/mips/include/asm/mips-cm.h:376:32: note: in expansion of macro 'CM_GCR_Cx_CONFIG_PVPE'

376 | cfg = read_gcr_cl_config() & CM_GCR_Cx_CONFIG_PVPE;
| ^~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:293:33: note: in expansion of macro 'GENMASK'
293 | #define CM_GCR_Cx_CONFIG_PVPE GENMASK(9, 0)
| ^~~~~~~
arch/mips/include/asm/mips-cm.h:377:24: note: in expansion of macro 'CM_GCR_Cx_CONFIG_PVPE'
377 | return (cfg >> __ffs(CM_GCR_Cx_CONFIG_PVPE)) + 1;
| ^~~~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cps.h: In function 'mips_cps_numclusters':
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~

>> arch/mips/include/asm/mips-cm.h:152:28: note: in expansion of macro 'GENMASK'
152 | #define CM_GCR_REV_MAJOR   GENMASK(15, 8)
|                            ^~~~~~~
>> arch/mips/include/asm/mips-cm.h:156:22: note: in expansion of macro 'CM_GCR_REV_MAJOR'

156 | (((major) << __ffs(CM_GCR_REV_MAJOR)) | | ^~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:162:25: note: in expansion of macro 'CM_ENCODE_REV'
162 | #define CM_REV_CM3_5 CM_ENCODE_REV(9, 0)
| ^~~~~~~~~~~~~

>> arch/mips/include/asm/mips-cps.h:117:27: note: in expansion of macro 'CM_REV_CM3_5'

117 | if (mips_cm_revision() < CM_REV_CM3_5)
| ^~~~~~~~~~~~
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:153:28: note: in expansion of macro 'GENMASK'
153 | #define CM_GCR_REV_MINOR GENMASK(7, 0)
| ^~~~~~~

>> arch/mips/include/asm/mips-cm.h:157:22: note: in expansion of macro 'CM_GCR_REV_MINOR'

157 | ((minor) << __ffs(CM_GCR_REV_MINOR)))
| ^~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:162:25: note: in expansion of macro 'CM_ENCODE_REV'
162 | #define CM_REV_CM3_5 CM_ENCODE_REV(9, 0)
| ^~~~~~~~~~~~~

>> arch/mips/include/asm/mips-cps.h:117:27: note: in expansion of macro 'CM_REV_CM3_5'

117 | if (mips_cm_revision() < CM_REV_CM3_5)
| ^~~~~~~~~~~~
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:133:37: note: in expansion of macro 'GENMASK' 133 | #define CM_GCR_CONFIG_NUM_CLUSTERS GENMASK(29, 23)
| ^~~~~~~

>> arch/mips/include/asm/mips-cps.h:120:37: note: in expansion of macro 'CM_GCR_CONFIG_NUM_CLUSTERS'

120 | num_clusters = read_gcr_config() & CM_GCR_CONFIG_NUM_CLUSTERS;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK'
39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:133:37: note: in expansion of macro 'GENMASK'
133 | #define CM_GCR_CONFIG_NUM_CLUSTERS GENMASK(29, 23)
| ^~~~~~~
arch/mips/include/asm/mips-cps.h:121:25: note: in expansion of macro 'CM_GCR_CONFIG_NUM_CLUSTERS' 121 | num_clusters >>= __ffs(CM_GCR_CONFIG_NUM_CLUSTERS);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cps.h: In function 'mips_cps_cluster_config':
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK'
39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~

>> arch/mips/include/asm/mips-cm.h:152:28: note: in expansion of macro 'GENMASK'
152 | #define CM_GCR_REV_MAJOR   GENMASK(15, 8)
|                            ^~~~~~~
>> arch/mips/include/asm/mips-cm.h:156:22: note: in expansion of macro 'CM_GCR_REV_MAJOR'

156 | (((major) << __ffs(CM_GCR_REV_MAJOR)) | | ^~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:162:25: note: in expansion of macro 'CM_ENCODE_REV'
162 | #define CM_REV_CM3_5 CM_ENCODE_REV(9, 0)
| ^~~~~~~~~~~~~
arch/mips/include/asm/mips-cps.h:137:27: note: in expansion of macro 'CM_REV_CM3_5' 137 | if (mips_cm_revision() < CM_REV_CM3_5) {
| ^~~~~~~~~~~~
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:153:28: note: in expansion of macro 'GENMASK'
153 | #define CM_GCR_REV_MINOR GENMASK(7, 0)
| ^~~~~~~

>> arch/mips/include/asm/mips-cm.h:157:22: note: in expansion of macro 'CM_GCR_REV_MINOR'

157 | ((minor) << __ffs(CM_GCR_REV_MINOR)))
| ^~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:162:25: note: in expansion of macro 'CM_ENCODE_REV'
162 | #define CM_REV_CM3_5 CM_ENCODE_REV(9, 0)
| ^~~~~~~~~~~~~
arch/mips/include/asm/mips-cps.h:137:27: note: in expansion of macro 'CM_REV_CM3_5' 137 | if (mips_cm_revision() < CM_REV_CM3_5) {
| ^~~~~~~~~~~~
arch/mips/include/asm/mips-cps.h: In function 'mips_cps_numcores':
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:135:32: note: in expansion of macro 'GENMASK'
135 | #define CM_GCR_CONFIG_PCORES GENMASK(7, 0)
| ^~~~~~~

>> arch/mips/include/asm/mips-cps.h:172:50: note: in expansion of macro 'CM_GCR_CONFIG_PCORES'

172 | return (mips_cps_cluster_config(cluster) + 1) & CM_GCR_CONFIG_PCORES;
| ^~~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cps.h: In function 'mips_cps_numiocu':
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:134:33: note: in expansion of macro 'GENMASK'
134 | #define CM_GCR_CONFIG_NUMIOCU GENMASK(15, 8)
| ^~~~~~~

>> arch/mips/include/asm/mips-cps.h:189:48: note: in expansion of macro 'CM_GCR_CONFIG_NUMIOCU'

189 | num_iocu = mips_cps_cluster_config(cluster) & CM_GCR_CONFIG_NUMIOCU;
| ^~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:134:33: note: in expansion of macro 'GENMASK'
134 | #define CM_GCR_CONFIG_NUMIOCU GENMASK(15, 8)
| ^~~~~~~
arch/mips/include/asm/mips-cps.h:190:21: note: in expansion of macro 'CM_GCR_CONFIG_NUMIOCU' 190 | num_iocu >>= __ffs(CM_GCR_CONFIG_NUMIOCU);
| ^~~~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cps.h: In function 'mips_cps_numvps':
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:152:28: note: in expansion of macro 'GENMASK'
152 | #define CM_GCR_REV_MAJOR GENMASK(15, 8)
| ^~~~~~~
arch/mips/include/asm/mips-cm.h:156:22: note: in expansion of macro 'CM_GCR_REV_MAJOR'
156 | (((major) << __ffs(CM_GCR_REV_MAJOR)) | | ^~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:162:25: note: in expansion of macro 'CM_ENCODE_REV'
162 | #define CM_REV_CM3_5 CM_ENCODE_REV(9, 0)
| ^~~~~~~~~~~~~
arch/mips/include/asm/mips-cps.h:216:27: note: in expansion of macro 'CM_REV_CM3_5' 216 | if (mips_cm_revision() < CM_REV_CM3_5) {
| ^~~~~~~~~~~~
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:153:28: note: in expansion of macro 'GENMASK'
153 | #define CM_GCR_REV_MINOR GENMASK(7, 0)
| ^~~~~~~
arch/mips/include/asm/mips-cm.h:157:22: note: in expansion of macro 'CM_GCR_REV_MINOR'
157 | ((minor) << __ffs(CM_GCR_REV_MINOR)))
| ^~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:162:25: note: in expansion of macro 'CM_ENCODE_REV'
162 | #define CM_REV_CM3_5 CM_ENCODE_REV(9, 0)
| ^~~~~~~~~~~~~
arch/mips/include/asm/mips-cps.h:216:27: note: in expansion of macro 'CM_REV_CM3_5' 216 | if (mips_cm_revision() < CM_REV_CM3_5) {
| ^~~~~~~~~~~~
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
arch/mips/include/asm/mips-cm.h:293:33: note: in expansion of macro 'GENMASK'
293 | #define CM_GCR_Cx_CONFIG_PVPE GENMASK(9, 0)
| ^~~~~~~
arch/mips/include/asm/mips-cps.h:233:21: note: in expansion of macro 'CM_GCR_Cx_CONFIG_PVPE' 233 | return (cfg + 1) & CM_GCR_Cx_CONFIG_PVPE;
| ^~~~~~~~~~~~~~~~~~~~~
In file included from include/linux/bits.h:23,
from include/linux/bitops.h:5,
from include/linux/kernel.h:12,
from include/linux/list.h:9,
from include/linux/preempt.h:11,
from include/linux/spinlock.h:51,
from include/linux/seqlock.h:36,
from include/linux/time.h:6,
from include/linux/compat.h:10,
from arch/mips/kernel/asm-offsets.c:12:
include/linux/kvm_host.h: In function 'kvm_make_request':
include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:25:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
25 | (BUILD_BUG_ON_ZERO(!__builtin_choose_expr( | ^~~~~~~~~~~~~~~~~
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
include/linux/kvm_host.h:138:36: note: in expansion of macro 'GENMASK'
138 | #define KVM_REQUEST_MASK GENMASK(7,0)
| ^~~~~~~
include/linux/kvm_host.h:1231:16: note: in expansion of macro 'KVM_REQUEST_MASK' 1231 | set_bit(req & KVM_REQUEST_MASK, (void *)&vcpu->requests);

vim +/GENMASK +152 arch/mips/include/asm/mips-cm.h

93c5bba575cedbe Paul Burton 2017-08-12  149  
93c5bba575cedbe Paul Burton 2017-08-12  150  /* GCR_REV - Indicates the Coherence Manager revision */
b025d51873d5fe6 Paul Burton 2017-08-12  151  GCR_ACCESSOR_RO(32, 0x030, rev)
93c5bba575cedbe Paul Burton 2017-08-12 @152  #define CM_GCR_REV_MAJOR			GENMASK(15, 8)
93c5bba575cedbe Paul Burton 2017-08-12  153  #define CM_GCR_REV_MINOR			GENMASK(7, 0)
93c5bba575cedbe Paul Burton 2017-08-12  154  
93c5bba575cedbe Paul Burton 2017-08-12  155  #define CM_ENCODE_REV(major, minor) \
93c5bba575cedbe Paul Burton 2017-08-12 @156  		(((major) << __ffs(CM_GCR_REV_MAJOR)) | \
93c5bba575cedbe Paul Burton 2017-08-12 @157  		 ((minor) << __ffs(CM_GCR_REV_MINOR)))
93c5bba575cedbe Paul Burton 2017-08-12  158  
93c5bba575cedbe Paul Burton 2017-08-12  159  #define CM_REV_CM2				CM_ENCODE_REV(6, 0)
93c5bba575cedbe Paul Burton 2017-08-12  160  #define CM_REV_CM2_5				CM_ENCODE_REV(7, 0)

93c5bba575cedbe Paul Burton 2017-08-12 @161 #define CM_REV_CM3 CM_ENCODE_REV(8, 0)
23cb600e3fd4068 Paul Burton 2017-08-12 162 #define CM_REV_CM3_5 CM_ENCODE_REV(9, 0)
93c5bba575cedbe Paul Burton 2017-08-12 163

:::::: The code@line 152 was first introduced by commit
:::::: 93c5bba575cedbeb50c9e1b0676230139b0d1be1 MIPS: CM: Use BIT/GENMASK for register fields, order & drop shifts

:::::: TO: Paul Burton <[email protected]>
:::::: CC: Ralf Baechle <[email protected]>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#3 lore raw

PATCH v2 1/1 linux/bits.h: adjust GENMASK_INPUT_CHECK() check

In reply to Emil Velikov

Recently the GENMASK_INPUT_CHECK() was added, aiming to catch cases where there GENMASK arguments are flipped.

Although it seems to be triggering -Wtype-limits in the following cases:

   unsigned foo = (10 + x);
   unsigned bar = GENMASK(foo, 0);

   const unsigned foo = (10 + x);
   unsigned bar = GENMASK(foo, 0);

Here are the warnings, from my GCC 9.2 box.

warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
__builtin_constant_p((l) > (h)), (l) > (h), 0)))

                            ^
warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
   __builtin_constant_p((l) > (h)), (l) > (h), 0)))
                                        ^

This results in people disabling the warning all together or promoting foo to signed. Either of which being a sub par option IMHO.

Add a trivial "+ 1" to each h and l in the constant expression.

v2: drop accidental !

Fixes 295bcca84916 ("linux/bits.h: add compile time sanity check of

GENMASK inputs")

---
 include/linux/bits.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/bits.h +1 -1
index 4671fbf28842..02a42866d198 100644
@@ -23,7 +23,7 @@
 #include <linux/build_bug.h>
 #define GENMASK_INPUT_CHECK(h, l) \
 	(BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
-		__builtin_constant_p((l) > (h)), (l) > (h), 0)))
+		__builtin_constant_p((l + 1) > (h + 1)), (l + 1) > (h + 1), 0)))
 #else
 /*
  * BUILD_BUG_ON_ZERO is not available in h files included from asm files,
Signature · 6 lines
2.25.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

+ Andrew et al who recieved mail from the build robot this morning about the same issue.

Quoted 45 lines · Emil Velikov

Recently the GENMASK_INPUT_CHECK() was added, aiming to catch cases where there GENMASK arguments are flipped.

Although it seems to be triggering -Wtype-limits in the following cases:

   unsigned foo = (10 + x);
   unsigned bar = GENMASK(foo, 0);

   const unsigned foo = (10 + x);
   unsigned bar = GENMASK(foo, 0);

Here are the warnings, from my GCC 9.2 box.

warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
__builtin_constant_p((l) > (h)), (l) > (h), 0)))

                            ^
warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
   __builtin_constant_p((l) > (h)), (l) > (h), 0)))
                                        ^

This results in people disabling the warning all together or promoting foo to signed. Either of which being a sub par option IMHO.

Add a trivial "+ 1" to each h and l in the constant expression.

v2: drop accidental !

Fixes 295bcca84916 ("linux/bits.h: add compile time sanity check of

GENMASK inputs")

---
 include/linux/bits.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/bits.h +0 -0
index 4671fbf28842..02a42866d198 100644

include/linux/bits.h line 26

Quoted 5 lines
include/linux/bits.h +1 -1
@@ -23,7 +23,7 @@
 #include <linux/build_bug.h>
 #define GENMASK_INPUT_CHECK(h, l) \
 	(BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
-		__builtin_constant_p((l) > (h)), (l) > (h), 0)))
+		__builtin_constant_p((l + 1) > (h + 1)), (l + 1) > (h + 1), 0)))

You need parentheses around l and h here.

I think I would have prefered a cast to int here instead but I'm fine with either (I don't think pragmas for disabling the warning can be used since the check is added to the mask). Either way, I think we need a comment on why this is done.

Quoted 6 lines
include/linux/bits.h +0 -0
 #else
 /*
  * BUILD_BUG_ON_ZERO is not available in h files included from asm files,
Signature · 1 line
2.25.1

I can't reproduce this with gcc 10 and kernelci.org does not show the warning (but those builds seem to be gcc 8 only, so maybe this is a gcc 9 thing only). A bit strange this shows up now, it's been in Linus's tree for six weeks and in next for even longer, but oh well.

Rikard
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw

Hi Rikard,

Quoted 44 lines · Rikard Falkeborn

+ Andrew et al who recieved mail from the build robot this morning about the same issue.

Quoted 40 lines · Emil Velikov

Recently the GENMASK_INPUT_CHECK() was added, aiming to catch cases where there GENMASK arguments are flipped.

Although it seems to be triggering -Wtype-limits in the following cases:

   unsigned foo = (10 + x);
   unsigned bar = GENMASK(foo, 0);

   const unsigned foo = (10 + x);
   unsigned bar = GENMASK(foo, 0);

Here are the warnings, from my GCC 9.2 box.

warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
__builtin_constant_p((l) > (h)), (l) > (h), 0)))

                            ^
warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
   __builtin_constant_p((l) > (h)), (l) > (h), 0)))
                                        ^

This results in people disabling the warning all together or promoting foo to signed. Either of which being a sub par option IMHO.

Add a trivial "+ 1" to each h and l in the constant expression.

v2: drop accidental !

Fixes 295bcca84916 ("linux/bits.h: add compile time sanity check of

GENMASK inputs")

---
 include/linux/bits.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

include/linux/bits.h line 26

Quoted 10 lines
include/linux/bits.h +1 -1
index 4671fbf28842..02a42866d198 100644
@@ -23,7 +23,7 @@
 #include <linux/build_bug.h>
 #define GENMASK_INPUT_CHECK(h, l) \
 	(BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
-		__builtin_constant_p((l) > (h)), (l) > (h), 0)))
+		__builtin_constant_p((l + 1) > (h + 1)), (l + 1) > (h + 1), 0)))

You need parentheses around l and h here.

Sure will do.

Quoted 4 lines

I think I would have prefered a cast to int here instead but I'm fine with either (I don't think pragmas for disabling the warning can be used since the check is added to the mask). Either way, I think we need a comment on why this is done.

How about:

Add trivial "+ 1" when to the h/l arguments. Without this GCC will complain when comparing unsigned vs 0. Depending on the GCC version, that can happen within __builtin_constant_p and/or the BUILD_BUG_ON_ZERO macro.

Quoted 8 lines
Quoted 7 lines
include/linux/bits.h +0 -0
 #else
 /*
  * BUILD_BUG_ON_ZERO is not available in h files included from asm files,
Signature · 1 line
2.25.1
Quoted 5 lines

I can't reproduce this with gcc 10 and kernelci.org does not show the warning (but those builds seem to be gcc 8 only, so maybe this is a gcc 9 thing only). A bit strange this shows up now, it's been in Linus's tree for six weeks and in next for even longer, but oh well.

I would imagine that people either use "interesting" workarounds like this [1], or outright disable -Wtype-limits - grep for Wtype-limits.

I'm glad that GCC 10 is saner, although it's far from being the minimum required for building the kernel :-\

Let me know if the above comment works for you and I'll send out the next revision.

Thanks
Emil

[1]
https://cgit.freedesktop.org/drm/drm-misc/commit/?id=2803aa743fd38f66acca555ae6e5fc677bb71251
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw
Quoted 92 lines · Emil Velikov

Hi Rikard,

Quoted 44 lines · Rikard Falkeborn

+ Andrew et al who recieved mail from the build robot this morning about the same issue.

Quoted 40 lines · Emil Velikov

Recently the GENMASK_INPUT_CHECK() was added, aiming to catch cases where there GENMASK arguments are flipped.

Although it seems to be triggering -Wtype-limits in the following cases:

   unsigned foo = (10 + x);
   unsigned bar = GENMASK(foo, 0);

   const unsigned foo = (10 + x);
   unsigned bar = GENMASK(foo, 0);

Here are the warnings, from my GCC 9.2 box.

warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
__builtin_constant_p((l) > (h)), (l) > (h), 0)))

                            ^
warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
   __builtin_constant_p((l) > (h)), (l) > (h), 0)))
                                        ^

This results in people disabling the warning all together or promoting foo to signed. Either of which being a sub par option IMHO.

Add a trivial "+ 1" to each h and l in the constant expression.

v2: drop accidental !

Fixes 295bcca84916 ("linux/bits.h: add compile time sanity check of

GENMASK inputs")

---
 include/linux/bits.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

include/linux/bits.h line 26

Quoted 10 lines
include/linux/bits.h +1 -1
index 4671fbf28842..02a42866d198 100644
@@ -23,7 +23,7 @@
 #include <linux/build_bug.h>
 #define GENMASK_INPUT_CHECK(h, l) \
 	(BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
-		__builtin_constant_p((l) > (h)), (l) > (h), 0)))
+		__builtin_constant_p((l + 1) > (h + 1)), (l + 1) > (h + 1), 0)))

You need parentheses around l and h here.

Sure will do.

Quoted 4 lines

I think I would have prefered a cast to int here instead but I'm fine with either (I don't think pragmas for disabling the warning can be used since the check is added to the mask). Either way, I think we need a comment on why this is done.

How about:

Add trivial "+ 1" when to the h/l arguments. Without this GCC will complain when comparing unsigned vs 0. Depending on the GCC version, that can happen within __builtin_constant_p and/or the BUILD_BUG_ON_ZERO macro.

Quoted 8 lines
Quoted 7 lines
include/linux/bits.h +0 -0
 #else
 /*
  * BUILD_BUG_ON_ZERO is not available in h files included from asm files,
Signature · 1 line
2.25.1
Quoted 5 lines

I can't reproduce this with gcc 10 and kernelci.org does not show the warning (but those builds seem to be gcc 8 only, so maybe this is a gcc 9 thing only). A bit strange this shows up now, it's been in Linus's tree for six weeks and in next for even longer, but oh well.

I would imagine that people either use "interesting" workarounds like this [1], or outright disable -Wtype-limits - grep for Wtype-limits.

Quoted 7 lines

I'm glad that GCC 10 is saner, although it's far from being the minimum required for building the kernel :-\

Let me know if the above comment works for you and I'll send out the next revision.

That works for me, but I'm not the one you need to convince. :)

Rikard

Quoted 6 lines

Thanks
Emil

[1]
https://cgit.freedesktop.org/drm/drm-misc/commit/?id=2803aa743fd38f66acca555ae6e5fc677bb71251

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel