* [linux-next:master 4911/5794] include/linux/bitfield.h:119:3: error: call to '__bad_mask' declared with attribute error: bad bitfield mask
@ 2020-11-15 19:58 kernel test robot
2020-11-16 9:08 ` [PATCH RFC] pwm: keembay: Fix build failure with -Os Uwe Kleine-König
0 siblings, 1 reply; 8+ messages in thread
From: kernel test robot @ 2020-11-15 19:58 UTC (permalink / raw)
To: Vijayakannan Ayyathurai
Cc: kbuild-all, Linux Memory Management List, Thierry Reding, Lai,
Poey Seng, Vineetha G. Jaya Kumaran, Andy Shevchenko,
Uwe Kleine-König
[-- Attachment #1: Type: text/plain, Size: 11735 bytes --]
tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head: 92edc4aef86780a8ad01b092c6d6630bb3cb423d
commit: 4a2d447bea5bdb175e0defaefcba74fc1517dff0 [4911/5794] pwm: Add PWM driver for Intel Keem Bay
config: arm64-randconfig-p002-20201116 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=4a2d447bea5bdb175e0defaefcba74fc1517dff0
git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
git fetch --no-tags linux-next master
git checkout 4a2d447bea5bdb175e0defaefcba74fc1517dff0
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
In file included from drivers/pwm/pwm-keembay.c:16:
In function 'field_multiplier',
inlined from 'keembay_pwm_update_bits.isra.0' at include/linux/bitfield.h:124:17:
>> include/linux/bitfield.h:119:3: error: call to '__bad_mask' declared with attribute error: bad bitfield mask
119 | __bad_mask();
| ^~~~~~~~~~~~
In function 'field_multiplier',
inlined from 'keembay_pwm_update_bits.isra.0' at include/linux/bitfield.h:154:1:
>> include/linux/bitfield.h:119:3: error: call to '__bad_mask' declared with attribute error: bad bitfield mask
119 | __bad_mask();
| ^~~~~~~~~~~~
vim +/__bad_mask +119 include/linux/bitfield.h
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 43
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 44 #define __BF_FIELD_CHECK(_mask, _reg, _val, _pfx) \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 45 ({ \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 46 BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask), \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 47 _pfx "mask is not constant"); \
e36488c83b6d871 Arnd Bergmann 2018-08-17 48 BUILD_BUG_ON_MSG((_mask) == 0, _pfx "mask is zero"); \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 49 BUILD_BUG_ON_MSG(__builtin_constant_p(_val) ? \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 50 ~((_mask) >> __bf_shf(_mask)) & (_val) : 0, \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 51 _pfx "value too large for the field"); \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 52 BUILD_BUG_ON_MSG((_mask) > (typeof(_reg))~0ull, \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 53 _pfx "type of reg too small for mask"); \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 54 __BUILD_BUG_ON_NOT_POWER_OF_2((_mask) + \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 55 (1ULL << __bf_shf(_mask))); \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 56 })
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 57
e31a50162feb352 Alex Elder 2020-03-12 58 /**
e31a50162feb352 Alex Elder 2020-03-12 59 * FIELD_MAX() - produce the maximum value representable by a field
e31a50162feb352 Alex Elder 2020-03-12 60 * @_mask: shifted mask defining the field's length and position
e31a50162feb352 Alex Elder 2020-03-12 61 *
e31a50162feb352 Alex Elder 2020-03-12 62 * FIELD_MAX() returns the maximum value that can be held in the field
e31a50162feb352 Alex Elder 2020-03-12 63 * specified by @_mask.
e31a50162feb352 Alex Elder 2020-03-12 64 */
e31a50162feb352 Alex Elder 2020-03-12 65 #define FIELD_MAX(_mask) \
e31a50162feb352 Alex Elder 2020-03-12 66 ({ \
e31a50162feb352 Alex Elder 2020-03-12 67 __BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_MAX: "); \
e31a50162feb352 Alex Elder 2020-03-12 68 (typeof(_mask))((_mask) >> __bf_shf(_mask)); \
e31a50162feb352 Alex Elder 2020-03-12 69 })
e31a50162feb352 Alex Elder 2020-03-12 70
1697599ee301a52 Jakub Kicinski 2017-02-09 71 /**
1697599ee301a52 Jakub Kicinski 2017-02-09 72 * FIELD_FIT() - check if value fits in the field
1697599ee301a52 Jakub Kicinski 2017-02-09 73 * @_mask: shifted mask defining the field's length and position
1697599ee301a52 Jakub Kicinski 2017-02-09 74 * @_val: value to test against the field
1697599ee301a52 Jakub Kicinski 2017-02-09 75 *
1697599ee301a52 Jakub Kicinski 2017-02-09 76 * Return: true if @_val can fit inside @_mask, false if @_val is too big.
1697599ee301a52 Jakub Kicinski 2017-02-09 77 */
1697599ee301a52 Jakub Kicinski 2017-02-09 78 #define FIELD_FIT(_mask, _val) \
1697599ee301a52 Jakub Kicinski 2017-02-09 79 ({ \
444da3f52407d74 Jakub Kicinski 2020-08-10 80 __BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_FIT: "); \
1697599ee301a52 Jakub Kicinski 2017-02-09 81 !((((typeof(_mask))_val) << __bf_shf(_mask)) & ~(_mask)); \
1697599ee301a52 Jakub Kicinski 2017-02-09 82 })
1697599ee301a52 Jakub Kicinski 2017-02-09 83
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 84 /**
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 85 * FIELD_PREP() - prepare a bitfield element
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 86 * @_mask: shifted mask defining the field's length and position
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 87 * @_val: value to put in the field
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 88 *
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 89 * FIELD_PREP() masks and shifts up the value. The result should
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 90 * be combined with other fields of the bitfield using logical OR.
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 91 */
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 92 #define FIELD_PREP(_mask, _val) \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 93 ({ \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 94 __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 95 ((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask); \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 96 })
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 97
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 98 /**
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 99 * FIELD_GET() - extract a bitfield element
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 100 * @_mask: shifted mask defining the field's length and position
7240767450d6d83 Masahiro Yamada 2017-10-03 101 * @_reg: value of entire bitfield
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 102 *
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 103 * FIELD_GET() extracts the field specified by @_mask from the
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 104 * bitfield passed in as @_reg by masking and shifting it down.
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 105 */
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 106 #define FIELD_GET(_mask, _reg) \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 107 ({ \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 108 __BF_FIELD_CHECK(_mask, _reg, 0U, "FIELD_GET: "); \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 109 (typeof(_mask))(((_reg) & (_mask)) >> __bf_shf(_mask)); \
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 110 })
3e9b3112ec74f19 Jakub Kicinski 2016-08-31 111
e7d4a95da86e0b0 Johannes Berg 2018-06-20 112 extern void __compiletime_error("value doesn't fit into mask")
00b0c9b82663ac4 Al Viro 2017-12-14 113 __field_overflow(void);
00b0c9b82663ac4 Al Viro 2017-12-14 114 extern void __compiletime_error("bad bitfield mask")
00b0c9b82663ac4 Al Viro 2017-12-14 115 __bad_mask(void);
00b0c9b82663ac4 Al Viro 2017-12-14 116 static __always_inline u64 field_multiplier(u64 field)
00b0c9b82663ac4 Al Viro 2017-12-14 117 {
00b0c9b82663ac4 Al Viro 2017-12-14 118 if ((field | (field - 1)) & ((field | (field - 1)) + 1))
00b0c9b82663ac4 Al Viro 2017-12-14 @119 __bad_mask();
00b0c9b82663ac4 Al Viro 2017-12-14 120 return field & -field;
00b0c9b82663ac4 Al Viro 2017-12-14 121 }
00b0c9b82663ac4 Al Viro 2017-12-14 122 static __always_inline u64 field_mask(u64 field)
00b0c9b82663ac4 Al Viro 2017-12-14 123 {
00b0c9b82663ac4 Al Viro 2017-12-14 124 return field / field_multiplier(field);
00b0c9b82663ac4 Al Viro 2017-12-14 125 }
e31a50162feb352 Alex Elder 2020-03-12 126 #define field_max(field) ((typeof(field))field_mask(field))
00b0c9b82663ac4 Al Viro 2017-12-14 127 #define ____MAKE_OP(type,base,to,from) \
00b0c9b82663ac4 Al Viro 2017-12-14 128 static __always_inline __##type type##_encode_bits(base v, base field) \
00b0c9b82663ac4 Al Viro 2017-12-14 129 { \
e7d4a95da86e0b0 Johannes Berg 2018-06-20 130 if (__builtin_constant_p(v) && (v & ~field_mask(field))) \
00b0c9b82663ac4 Al Viro 2017-12-14 131 __field_overflow(); \
00b0c9b82663ac4 Al Viro 2017-12-14 132 return to((v & field_mask(field)) * field_multiplier(field)); \
00b0c9b82663ac4 Al Viro 2017-12-14 133 } \
00b0c9b82663ac4 Al Viro 2017-12-14 134 static __always_inline __##type type##_replace_bits(__##type old, \
00b0c9b82663ac4 Al Viro 2017-12-14 135 base val, base field) \
00b0c9b82663ac4 Al Viro 2017-12-14 136 { \
00b0c9b82663ac4 Al Viro 2017-12-14 137 return (old & ~to(field)) | type##_encode_bits(val, field); \
00b0c9b82663ac4 Al Viro 2017-12-14 138 } \
00b0c9b82663ac4 Al Viro 2017-12-14 139 static __always_inline void type##p_replace_bits(__##type *p, \
00b0c9b82663ac4 Al Viro 2017-12-14 140 base val, base field) \
00b0c9b82663ac4 Al Viro 2017-12-14 141 { \
00b0c9b82663ac4 Al Viro 2017-12-14 142 *p = (*p & ~to(field)) | type##_encode_bits(val, field); \
00b0c9b82663ac4 Al Viro 2017-12-14 143 } \
00b0c9b82663ac4 Al Viro 2017-12-14 144 static __always_inline base type##_get_bits(__##type v, base field) \
00b0c9b82663ac4 Al Viro 2017-12-14 145 { \
00b0c9b82663ac4 Al Viro 2017-12-14 146 return (from(v) & field)/field_multiplier(field); \
00b0c9b82663ac4 Al Viro 2017-12-14 147 }
00b0c9b82663ac4 Al Viro 2017-12-14 148 #define __MAKE_OP(size) \
00b0c9b82663ac4 Al Viro 2017-12-14 149 ____MAKE_OP(le##size,u##size,cpu_to_le##size,le##size##_to_cpu) \
00b0c9b82663ac4 Al Viro 2017-12-14 150 ____MAKE_OP(be##size,u##size,cpu_to_be##size,be##size##_to_cpu) \
00b0c9b82663ac4 Al Viro 2017-12-14 151 ____MAKE_OP(u##size,u##size,,)
37a3862e1238262 Johannes Berg 2018-06-20 152 ____MAKE_OP(u8,u8,,)
00b0c9b82663ac4 Al Viro 2017-12-14 153 __MAKE_OP(16)
00b0c9b82663ac4 Al Viro 2017-12-14 154 __MAKE_OP(32)
00b0c9b82663ac4 Al Viro 2017-12-14 155 __MAKE_OP(64)
00b0c9b82663ac4 Al Viro 2017-12-14 156 #undef __MAKE_OP
00b0c9b82663ac4 Al Viro 2017-12-14 157 #undef ____MAKE_OP
00b0c9b82663ac4 Al Viro 2017-12-14 158
:::::: The code at line 119 was first introduced by commit
:::::: 00b0c9b82663ac42e5a09f58ce960f81f29d64ee Add primitives for manipulating bitfields both in host- and fixed-endian.
:::::: TO: Al Viro <viro@zeniv.linux.org.uk>
:::::: CC: Al Viro <viro@zeniv.linux.org.uk>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 38893 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH RFC] pwm: keembay: Fix build failure with -Os
2020-11-15 19:58 [linux-next:master 4911/5794] include/linux/bitfield.h:119:3: error: call to '__bad_mask' declared with attribute error: bad bitfield mask kernel test robot
@ 2020-11-16 9:08 ` Uwe Kleine-König
2020-11-17 17:29 ` Ayyathurai, Vijayakannan
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Uwe Kleine-König @ 2020-11-16 9:08 UTC (permalink / raw)
To: Vijayakannan Ayyathurai, Thierry Reding
Cc: kbuild-all, Linux Memory Management List, Lai, Poey Seng,
Vineetha G. Jaya Kumaran, Andy Shevchenko, linux-kernel, kernel,
kernel test robot
The driver used this construct:
#define KMB_PWM_LEADIN_MASK GENMASK(30, 0)
static inline void keembay_pwm_update_bits(struct keembay_pwm *priv, u32 mask,
u32 val, u32 offset)
{
u32 buff = readl(priv->base + offset);
buff = u32_replace_bits(buff, val, mask);
writel(buff, priv->base + offset);
}
...
keembay_pwm_update_bits(priv, KMB_PWM_LEADIN_MASK, 0,
KMB_PWM_LEADIN_OFFSET(pwm->hwpwm));
With CONFIG_CC_OPTIMIZE_FOR_SIZE the compiler (here: gcc 10.2.0) this
triggers:
In file included from /home/uwe/gsrc/linux/drivers/pwm/pwm-keembay.c:16:
In function ‘field_multiplier’,
inlined from ‘keembay_pwm_update_bits’ at /home/uwe/gsrc/linux/include/linux/bitfield.h:124:17:
/home/uwe/gsrc/linux/include/linux/bitfield.h:119:3: error: call to ‘__bad_mask’ declared with attribute error: bad bitfield mask
119 | __bad_mask();
| ^~~~~~~~~~~~
In function ‘field_multiplier’,
inlined from ‘keembay_pwm_update_bits’ at /home/uwe/gsrc/linux/include/linux/bitfield.h:154:1:
/home/uwe/gsrc/linux/include/linux/bitfield.h:119:3: error: call to ‘__bad_mask’ declared with attribute error: bad bitfield mask
119 | __bad_mask();
| ^~~~~~~~~~~~
The compiler doesn't seem to be able to notice that with field being
0x3ffffff the expression
if ((field | (field - 1)) & ((field | (field - 1)) + 1))
__bad_mask();
can be optimized away.
So use __always_inline and document the problem in a comment to fix
this.
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello,
I'm not sure this is the right fix. Maybe the bitfield stuff can be
changed somehow to make this problem go away, too?
Best regards
Uwe
drivers/pwm/pwm-keembay.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/pwm/pwm-keembay.c b/drivers/pwm/pwm-keembay.c
index 2b6dd070daa4..cdfdef66ff8e 100644
--- a/drivers/pwm/pwm-keembay.c
+++ b/drivers/pwm/pwm-keembay.c
@@ -63,7 +63,12 @@ static int keembay_clk_enable(struct device *dev, struct clk *clk)
return devm_add_action_or_reset(dev, keembay_clk_unprepare, clk);
}
-static inline void keembay_pwm_update_bits(struct keembay_pwm *priv, u32 mask,
+/*
+ * With gcc 10, CONFIG_CC_OPTIMIZE_FOR_SIZE and only "inline" instead of
+ * "__always_inline" this fails to compile because the compiler doesn't notice
+ * for all valid masks (e.g. KMB_PWM_LEADIN_MASK) that they are ok.
+ */
+static __always_inline void keembay_pwm_update_bits(struct keembay_pwm *priv, u32 mask,
u32 val, u32 offset)
{
u32 buff = readl(priv->base + offset);
--
2.28.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* RE: [PATCH RFC] pwm: keembay: Fix build failure with -Os
2020-11-16 9:08 ` [PATCH RFC] pwm: keembay: Fix build failure with -Os Uwe Kleine-König
@ 2020-11-17 17:29 ` Ayyathurai, Vijayakannan
2020-11-18 9:48 ` Uwe Kleine-König
2020-11-18 10:06 ` Uwe Kleine-König
2020-11-18 18:00 ` Thierry Reding
2 siblings, 1 reply; 8+ messages in thread
From: Ayyathurai, Vijayakannan @ 2020-11-17 17:29 UTC (permalink / raw)
To: Uwe Kleine-König, Thierry Reding
Cc: kbuild-all, Linux Memory Management List, Lai, Poey Seng,
Andy Shevchenko, linux-kernel, kernel, lkp
Hi Uwe,
> From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> Sent: Monday, 16 November, 2020 5:08 PM
> Subject: [PATCH RFC] pwm: keembay: Fix build failure with -Os
>
> The driver used this construct:
>
> #define KMB_PWM_LEADIN_MASK GENMASK(30, 0)
>
> static inline void keembay_pwm_update_bits(struct keembay_pwm
> *priv, u32 mask,
> u32 val, u32 offset)
> {
> u32 buff = readl(priv->base + offset);
>
> buff = u32_replace_bits(buff, val, mask);
> writel(buff, priv->base + offset);
> }
>
> ...
> keembay_pwm_update_bits(priv, KMB_PWM_LEADIN_MASK, 0,
> KMB_PWM_LEADIN_OFFSET(pwm-
> >hwpwm));
>
> With CONFIG_CC_OPTIMIZE_FOR_SIZE the compiler (here: gcc 10.2.0) this
> triggers:
>
> In file included from /home/uwe/gsrc/linux/drivers/pwm/pwm-
> keembay.c:16:
> In function ‘field_multiplier’,
> inlined from ‘keembay_pwm_update_bits’ at
> /home/uwe/gsrc/linux/include/linux/bitfield.h:124:17:
> /home/uwe/gsrc/linux/include/linux/bitfield.h:119:3: error: call to
> ‘__bad_mask’ declared with attribute error: bad bitfield mask
> 119 | __bad_mask();
> | ^~~~~~~~~~~~
> In function ‘field_multiplier’,
> inlined from ‘keembay_pwm_update_bits’ at
> /home/uwe/gsrc/linux/include/linux/bitfield.h:154:1:
> /home/uwe/gsrc/linux/include/linux/bitfield.h:119:3: error: call to
> ‘__bad_mask’ declared with attribute error: bad bitfield mask
> 119 | __bad_mask();
> | ^~~~~~~~~~~~
>
> The compiler doesn't seem to be able to notice that with field being
> 0x3ffffff the expression
>
> if ((field | (field - 1)) & ((field | (field - 1)) + 1))
> __bad_mask();
>
> can be optimized away.
>
> So use __always_inline and document the problem in a comment to fix
> this.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Thank you for spending time in resolving this build failure.
I shall prepare and share the next version of patch with your approach.
> ---
> Hello,
>
> I'm not sure this is the right fix. Maybe the bitfield stuff can be
> changed somehow to make this problem go away, too?
>
> Best regards
> Uwe
>
> drivers/pwm/pwm-keembay.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pwm/pwm-keembay.c b/drivers/pwm/pwm-keembay.c
> index 2b6dd070daa4..cdfdef66ff8e 100644
> --- a/drivers/pwm/pwm-keembay.c
> +++ b/drivers/pwm/pwm-keembay.c
> @@ -63,7 +63,12 @@ static int keembay_clk_enable(struct device *dev,
> struct clk *clk)
> return devm_add_action_or_reset(dev, keembay_clk_unprepare, clk);
> }
>
> -static inline void keembay_pwm_update_bits(struct keembay_pwm *priv, u32
> mask,
> +/*
> + * With gcc 10, CONFIG_CC_OPTIMIZE_FOR_SIZE and only "inline" instead of
> + * "__always_inline" this fails to compile because the compiler doesn't notice
> + * for all valid masks (e.g. KMB_PWM_LEADIN_MASK) that they are ok.
> + */
> +static __always_inline void keembay_pwm_update_bits(struct
> keembay_pwm *priv, u32 mask,
> u32 val, u32 offset)
> {
> u32 buff = readl(priv->base + offset);
> --
> 2.28.0
Thanks,
Vijay
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH RFC] pwm: keembay: Fix build failure with -Os
2020-11-17 17:29 ` Ayyathurai, Vijayakannan
@ 2020-11-18 9:48 ` Uwe Kleine-König
0 siblings, 0 replies; 8+ messages in thread
From: Uwe Kleine-König @ 2020-11-18 9:48 UTC (permalink / raw)
To: Ayyathurai, Vijayakannan
Cc: Thierry Reding, kbuild-all, lkp, linux-kernel,
Linux Memory Management List, kernel, Andy Shevchenko, Lai,
Poey Seng
[-- Attachment #1: Type: text/plain, Size: 2634 bytes --]
On Tue, Nov 17, 2020 at 05:29:01PM +0000, Ayyathurai, Vijayakannan wrote:
> Hi Uwe,
>
> > From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > Sent: Monday, 16 November, 2020 5:08 PM
> > Subject: [PATCH RFC] pwm: keembay: Fix build failure with -Os
> >
> > The driver used this construct:
> >
> > #define KMB_PWM_LEADIN_MASK GENMASK(30, 0)
> >
> > static inline void keembay_pwm_update_bits(struct keembay_pwm
> > *priv, u32 mask,
> > u32 val, u32 offset)
> > {
> > u32 buff = readl(priv->base + offset);
> >
> > buff = u32_replace_bits(buff, val, mask);
> > writel(buff, priv->base + offset);
> > }
> >
> > ...
> > keembay_pwm_update_bits(priv, KMB_PWM_LEADIN_MASK, 0,
> > KMB_PWM_LEADIN_OFFSET(pwm-
> > >hwpwm));
> >
> > With CONFIG_CC_OPTIMIZE_FOR_SIZE the compiler (here: gcc 10.2.0) this
> > triggers:
> >
> > In file included from /home/uwe/gsrc/linux/drivers/pwm/pwm-
> > keembay.c:16:
> > In function ‘field_multiplier’,
> > inlined from ‘keembay_pwm_update_bits’ at
> > /home/uwe/gsrc/linux/include/linux/bitfield.h:124:17:
> > /home/uwe/gsrc/linux/include/linux/bitfield.h:119:3: error: call to
> > ‘__bad_mask’ declared with attribute error: bad bitfield mask
> > 119 | __bad_mask();
> > | ^~~~~~~~~~~~
> > In function ‘field_multiplier’,
> > inlined from ‘keembay_pwm_update_bits’ at
> > /home/uwe/gsrc/linux/include/linux/bitfield.h:154:1:
> > /home/uwe/gsrc/linux/include/linux/bitfield.h:119:3: error: call to
> > ‘__bad_mask’ declared with attribute error: bad bitfield mask
> > 119 | __bad_mask();
> > | ^~~~~~~~~~~~
> >
> > The compiler doesn't seem to be able to notice that with field being
> > 0x3ffffff the expression
> >
> > if ((field | (field - 1)) & ((field | (field - 1)) + 1))
> > __bad_mask();
> >
> > can be optimized away.
> >
> > So use __always_inline and document the problem in a comment to fix
> > this.
> >
> > Reported-by: kernel test robot <lkp@intel.com>
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
>
> Thank you for spending time in resolving this build failure.
>
> I shall prepare and share the next version of patch with your approach.
I don't understand this last sentence. IMHO there is currently nothing
you have to do for this problem. You can send an Ack however if you want
to.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH RFC] pwm: keembay: Fix build failure with -Os
2020-11-16 9:08 ` [PATCH RFC] pwm: keembay: Fix build failure with -Os Uwe Kleine-König
2020-11-17 17:29 ` Ayyathurai, Vijayakannan
@ 2020-11-18 10:06 ` Uwe Kleine-König
2020-11-18 17:41 ` Ayyathurai, Vijayakannan
2020-11-18 18:00 ` Thierry Reding
2 siblings, 1 reply; 8+ messages in thread
From: Uwe Kleine-König @ 2020-11-18 10:06 UTC (permalink / raw)
To: Vijayakannan Ayyathurai, Thierry Reding
Cc: kbuild-all, kernel test robot, linux-kernel,
Linux Memory Management List, Vineetha G. Jaya Kumaran, kernel,
Andy Shevchenko, Lai, Poey Seng, linux-pwm
[-- Attachment #1: Type: text/plain, Size: 2448 bytes --]
[Cc: += linux-pwm which I forgot for the initial submission]
Hello,
On Mon, Nov 16, 2020 at 10:08:04AM +0100, Uwe Kleine-König wrote:
> The driver used this construct:
>
> #define KMB_PWM_LEADIN_MASK GENMASK(30, 0)
>
> static inline void keembay_pwm_update_bits(struct keembay_pwm *priv, u32 mask,
> u32 val, u32 offset)
> {
> u32 buff = readl(priv->base + offset);
>
> buff = u32_replace_bits(buff, val, mask);
> writel(buff, priv->base + offset);
> }
>
> ...
> keembay_pwm_update_bits(priv, KMB_PWM_LEADIN_MASK, 0,
> KMB_PWM_LEADIN_OFFSET(pwm->hwpwm));
>
> With CONFIG_CC_OPTIMIZE_FOR_SIZE the compiler (here: gcc 10.2.0) this
> triggers:
>
> In file included from /home/uwe/gsrc/linux/drivers/pwm/pwm-keembay.c:16:
> In function ‘field_multiplier’,
> inlined from ‘keembay_pwm_update_bits’ at /home/uwe/gsrc/linux/include/linux/bitfield.h:124:17:
> /home/uwe/gsrc/linux/include/linux/bitfield.h:119:3: error: call to ‘__bad_mask’ declared with attribute error: bad bitfield mask
> 119 | __bad_mask();
> | ^~~~~~~~~~~~
> In function ‘field_multiplier’,
> inlined from ‘keembay_pwm_update_bits’ at /home/uwe/gsrc/linux/include/linux/bitfield.h:154:1:
> /home/uwe/gsrc/linux/include/linux/bitfield.h:119:3: error: call to ‘__bad_mask’ declared with attribute error: bad bitfield mask
> 119 | __bad_mask();
> | ^~~~~~~~~~~~
>
> The compiler doesn't seem to be able to notice that with field being
> 0x3ffffff the expression
>
> if ((field | (field - 1)) & ((field | (field - 1)) + 1))
> __bad_mask();
>
> can be optimized away.
>
> So use __always_inline and document the problem in a comment to fix
> this.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
>
> I'm not sure this is the right fix. Maybe the bitfield stuff can be
> changed somehow to make this problem go away, too?
Note, this patch
Fixes: cdbea243f419 ("pwm: Add PWM driver for Intel Keem Bay")
so this isn't critical for v5.10.
@thierry: If this is ok for you and Vijayakannan, you can squash this
into the original commit.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH RFC] pwm: keembay: Fix build failure with -Os
2020-11-18 10:06 ` Uwe Kleine-König
@ 2020-11-18 17:41 ` Ayyathurai, Vijayakannan
2020-11-18 18:01 ` Thierry Reding
0 siblings, 1 reply; 8+ messages in thread
From: Ayyathurai, Vijayakannan @ 2020-11-18 17:41 UTC (permalink / raw)
To: Uwe Kleine-König, Thierry Reding
Cc: kbuild-all, lkp, linux-kernel, Linux Memory Management List,
kernel, Andy Shevchenko, Lai, Poey Seng, linux-pwm
Hi Thierry,
> From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> Subject: Re: [PATCH RFC] pwm: keembay: Fix build failure with -Os
>
> [Cc: += linux-pwm which I forgot for the initial submission]
>
> Hello,
>
> On Mon, Nov 16, 2020 at 10:08:04AM +0100, Uwe Kleine-König wrote:
> > The driver used this construct:
> >
> > #define KMB_PWM_LEADIN_MASK GENMASK(30, 0)
> >
> > static inline void keembay_pwm_update_bits(struct keembay_pwm
> *priv, u32 mask,
> > u32 val, u32 offset)
> > {
> > u32 buff = readl(priv->base + offset);
> >
> > buff = u32_replace_bits(buff, val, mask);
> > writel(buff, priv->base + offset);
> > }
> >
> > ...
> > keembay_pwm_update_bits(priv, KMB_PWM_LEADIN_MASK, 0,
> > KMB_PWM_LEADIN_OFFSET(pwm-
> >hwpwm));
> >
> > With CONFIG_CC_OPTIMIZE_FOR_SIZE the compiler (here: gcc 10.2.0) this
> > triggers:
> >
> > In file included from /home/uwe/gsrc/linux/drivers/pwm/pwm-
> keembay.c:16:
> > In function ‘field_multiplier’,
> > inlined from ‘keembay_pwm_update_bits’ at
> /home/uwe/gsrc/linux/include/linux/bitfield.h:124:17:
> > /home/uwe/gsrc/linux/include/linux/bitfield.h:119:3: error: call to
> ‘__bad_mask’ declared with attribute error: bad bitfield mask
> > 119 | __bad_mask();
> > | ^~~~~~~~~~~~
> > In function ‘field_multiplier’,
> > inlined from ‘keembay_pwm_update_bits’ at
> /home/uwe/gsrc/linux/include/linux/bitfield.h:154:1:
> > /home/uwe/gsrc/linux/include/linux/bitfield.h:119:3: error: call to
> ‘__bad_mask’ declared with attribute error: bad bitfield mask
> > 119 | __bad_mask();
> > | ^~~~~~~~~~~~
> >
> > The compiler doesn't seem to be able to notice that with field being
> > 0x3ffffff the expression
> >
> > if ((field | (field - 1)) & ((field | (field - 1)) + 1))
> > __bad_mask();
> >
> > can be optimized away.
> >
> > So use __always_inline and document the problem in a comment to fix
> > this.
> >
> > Reported-by: kernel test robot <lkp@intel.com>
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > ---
> > Hello,
> >
> > I'm not sure this is the right fix. Maybe the bitfield stuff can be
> > changed somehow to make this problem go away, too?
>
> Note, this patch
>
> Fixes: cdbea243f419 ("pwm: Add PWM driver for Intel Keem Bay")
>
> so this isn't critical for v5.10.
>
> @thierry: If this is ok for you and Vijayakannan, you can squash this
> into the original commit.
>
I am ok with Uwe approach.
I have compiled the change and tested in Keembay board as well.
> Best regards
> Uwe
>
> --
> Pengutronix e.K. | Uwe Kleine-König |
> Industrial Linux Solutions | https://www.pengutronix.de/ |
Thanks,
Vijay
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH RFC] pwm: keembay: Fix build failure with -Os
2020-11-16 9:08 ` [PATCH RFC] pwm: keembay: Fix build failure with -Os Uwe Kleine-König
2020-11-17 17:29 ` Ayyathurai, Vijayakannan
2020-11-18 10:06 ` Uwe Kleine-König
@ 2020-11-18 18:00 ` Thierry Reding
2 siblings, 0 replies; 8+ messages in thread
From: Thierry Reding @ 2020-11-18 18:00 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: Vijayakannan Ayyathurai, kbuild-all,
Linux Memory Management List, Lai, Poey Seng,
Vineetha G. Jaya Kumaran, Andy Shevchenko, linux-kernel, kernel,
kernel test robot
[-- Attachment #1: Type: text/plain, Size: 2125 bytes --]
On Mon, Nov 16, 2020 at 10:08:04AM +0100, Uwe Kleine-König wrote:
> The driver used this construct:
>
> #define KMB_PWM_LEADIN_MASK GENMASK(30, 0)
>
> static inline void keembay_pwm_update_bits(struct keembay_pwm *priv, u32 mask,
> u32 val, u32 offset)
> {
> u32 buff = readl(priv->base + offset);
>
> buff = u32_replace_bits(buff, val, mask);
> writel(buff, priv->base + offset);
> }
>
> ...
> keembay_pwm_update_bits(priv, KMB_PWM_LEADIN_MASK, 0,
> KMB_PWM_LEADIN_OFFSET(pwm->hwpwm));
>
> With CONFIG_CC_OPTIMIZE_FOR_SIZE the compiler (here: gcc 10.2.0) this
> triggers:
>
> In file included from /home/uwe/gsrc/linux/drivers/pwm/pwm-keembay.c:16:
> In function ‘field_multiplier’,
> inlined from ‘keembay_pwm_update_bits’ at /home/uwe/gsrc/linux/include/linux/bitfield.h:124:17:
> /home/uwe/gsrc/linux/include/linux/bitfield.h:119:3: error: call to ‘__bad_mask’ declared with attribute error: bad bitfield mask
> 119 | __bad_mask();
> | ^~~~~~~~~~~~
> In function ‘field_multiplier’,
> inlined from ‘keembay_pwm_update_bits’ at /home/uwe/gsrc/linux/include/linux/bitfield.h:154:1:
> /home/uwe/gsrc/linux/include/linux/bitfield.h:119:3: error: call to ‘__bad_mask’ declared with attribute error: bad bitfield mask
> 119 | __bad_mask();
> | ^~~~~~~~~~~~
>
> The compiler doesn't seem to be able to notice that with field being
> 0x3ffffff the expression
>
> if ((field | (field - 1)) & ((field | (field - 1)) + 1))
> __bad_mask();
>
> can be optimized away.
>
> So use __always_inline and document the problem in a comment to fix
> this.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
>
> I'm not sure this is the right fix. Maybe the bitfield stuff can be
> changed somehow to make this problem go away, too?
>
> Best regards
> Uwe
>
> drivers/pwm/pwm-keembay.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
Applied, thanks.
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH RFC] pwm: keembay: Fix build failure with -Os
2020-11-18 17:41 ` Ayyathurai, Vijayakannan
@ 2020-11-18 18:01 ` Thierry Reding
0 siblings, 0 replies; 8+ messages in thread
From: Thierry Reding @ 2020-11-18 18:01 UTC (permalink / raw)
To: Ayyathurai, Vijayakannan
Cc: Uwe Kleine-König, kbuild-all, lkp, linux-kernel,
Linux Memory Management List, kernel, Andy Shevchenko, Lai,
Poey Seng, linux-pwm
[-- Attachment #1: Type: text/plain, Size: 3124 bytes --]
On Wed, Nov 18, 2020 at 05:41:57PM +0000, Ayyathurai, Vijayakannan wrote:
> Hi Thierry,
>
> > From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > Subject: Re: [PATCH RFC] pwm: keembay: Fix build failure with -Os
> >
> > [Cc: += linux-pwm which I forgot for the initial submission]
> >
> > Hello,
> >
> > On Mon, Nov 16, 2020 at 10:08:04AM +0100, Uwe Kleine-König wrote:
> > > The driver used this construct:
> > >
> > > #define KMB_PWM_LEADIN_MASK GENMASK(30, 0)
> > >
> > > static inline void keembay_pwm_update_bits(struct keembay_pwm
> > *priv, u32 mask,
> > > u32 val, u32 offset)
> > > {
> > > u32 buff = readl(priv->base + offset);
> > >
> > > buff = u32_replace_bits(buff, val, mask);
> > > writel(buff, priv->base + offset);
> > > }
> > >
> > > ...
> > > keembay_pwm_update_bits(priv, KMB_PWM_LEADIN_MASK, 0,
> > > KMB_PWM_LEADIN_OFFSET(pwm-
> > >hwpwm));
> > >
> > > With CONFIG_CC_OPTIMIZE_FOR_SIZE the compiler (here: gcc 10.2.0) this
> > > triggers:
> > >
> > > In file included from /home/uwe/gsrc/linux/drivers/pwm/pwm-
> > keembay.c:16:
> > > In function ‘field_multiplier’,
> > > inlined from ‘keembay_pwm_update_bits’ at
> > /home/uwe/gsrc/linux/include/linux/bitfield.h:124:17:
> > > /home/uwe/gsrc/linux/include/linux/bitfield.h:119:3: error: call to
> > ‘__bad_mask’ declared with attribute error: bad bitfield mask
> > > 119 | __bad_mask();
> > > | ^~~~~~~~~~~~
> > > In function ‘field_multiplier’,
> > > inlined from ‘keembay_pwm_update_bits’ at
> > /home/uwe/gsrc/linux/include/linux/bitfield.h:154:1:
> > > /home/uwe/gsrc/linux/include/linux/bitfield.h:119:3: error: call to
> > ‘__bad_mask’ declared with attribute error: bad bitfield mask
> > > 119 | __bad_mask();
> > > | ^~~~~~~~~~~~
> > >
> > > The compiler doesn't seem to be able to notice that with field being
> > > 0x3ffffff the expression
> > >
> > > if ((field | (field - 1)) & ((field | (field - 1)) + 1))
> > > __bad_mask();
> > >
> > > can be optimized away.
> > >
> > > So use __always_inline and document the problem in a comment to fix
> > > this.
> > >
> > > Reported-by: kernel test robot <lkp@intel.com>
> > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > > ---
> > > Hello,
> > >
> > > I'm not sure this is the right fix. Maybe the bitfield stuff can be
> > > changed somehow to make this problem go away, too?
> >
> > Note, this patch
> >
> > Fixes: cdbea243f419 ("pwm: Add PWM driver for Intel Keem Bay")
> >
> > so this isn't critical for v5.10.
> >
> > @thierry: If this is ok for you and Vijayakannan, you can squash this
> > into the original commit.
> >
>
> I am ok with Uwe approach.
> I have compiled the change and tested in Keembay board as well.
I'll take that as a Tested-by. Next time, if you go through the trouble
of testing a patch, make sure to reply with a:
Tested-by: Your Name <your@email.com>
So that patchwork can pick that up and credit you for it.
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-11-18 18:01 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-15 19:58 [linux-next:master 4911/5794] include/linux/bitfield.h:119:3: error: call to '__bad_mask' declared with attribute error: bad bitfield mask kernel test robot
2020-11-16 9:08 ` [PATCH RFC] pwm: keembay: Fix build failure with -Os Uwe Kleine-König
2020-11-17 17:29 ` Ayyathurai, Vijayakannan
2020-11-18 9:48 ` Uwe Kleine-König
2020-11-18 10:06 ` Uwe Kleine-König
2020-11-18 17:41 ` Ayyathurai, Vijayakannan
2020-11-18 18:01 ` Thierry Reding
2020-11-18 18:00 ` Thierry Reding
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).