* [PATCH 2/9] libceph: avoid clang out-of-range warning
2024-03-28 14:30 [PATCH 0/9] address remaining -Wtautological-constant-out-of-range-compare Arnd Bergmann
@ 2024-03-28 14:30 ` Arnd Bergmann
2024-03-28 22:53 ` Justin Stitt
2024-03-29 0:06 ` Xiubo Li
2024-03-28 14:30 ` [PATCH 5/9] ipv4: tcp_output: avoid warning about NET_ADD_STATS Arnd Bergmann
` (2 subsequent siblings)
3 siblings, 2 replies; 13+ messages in thread
From: Arnd Bergmann @ 2024-03-28 14:30 UTC (permalink / raw)
To: linux-kernel, Xiubo Li, Ilya Dryomov, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Nathan Chancellor
Cc: Arnd Bergmann, Jeff Layton, Nick Desaulniers, Bill Wendling,
Justin Stitt, Milind Changire, Patrick Donnelly,
Christian Brauner, ceph-devel, netdev, llvm
From: Arnd Bergmann <arnd@arndb.de>
clang-14 points out that on 64-bit architectures, a u32
is never larger than constant based on SIZE_MAX:
net/ceph/osdmap.c:1425:10: error: result of comparison of constant 4611686018427387891 with expression of type 'u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
if (len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net/ceph/osdmap.c:1608:10: error: result of comparison of constant 2305843009213693945 with expression of type 'u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
if (len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The code is correct anyway, so just shut up that warning.
Fixes: 6f428df47dae ("libceph: pg_upmap[_items] infrastructure")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
fs/ceph/snap.c | 2 +-
net/ceph/osdmap.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
index c65f2b202b2b..521507ea8260 100644
--- a/fs/ceph/snap.c
+++ b/fs/ceph/snap.c
@@ -374,7 +374,7 @@ static int build_snap_context(struct ceph_mds_client *mdsc,
/* alloc new snap context */
err = -ENOMEM;
- if (num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64))
+ if ((size_t)num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64))
goto fail;
snapc = ceph_create_snap_context(num, GFP_NOFS);
if (!snapc)
diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
index 295098873861..8e7cb2fde6f1 100644
--- a/net/ceph/osdmap.c
+++ b/net/ceph/osdmap.c
@@ -1438,7 +1438,7 @@ static struct ceph_pg_mapping *__decode_pg_temp(void **p, void *end,
ceph_decode_32_safe(p, end, len, e_inval);
if (len == 0 && incremental)
return NULL; /* new_pg_temp: [] to remove */
- if (len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
+ if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
return ERR_PTR(-EINVAL);
ceph_decode_need(p, end, len * sizeof(u32), e_inval);
@@ -1621,7 +1621,7 @@ static struct ceph_pg_mapping *__decode_pg_upmap_items(void **p, void *end,
u32 len, i;
ceph_decode_32_safe(p, end, len, e_inval);
- if (len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
+ if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
return ERR_PTR(-EINVAL);
ceph_decode_need(p, end, 2 * len * sizeof(u32), e_inval);
--
2.39.2
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 2/9] libceph: avoid clang out-of-range warning
2024-03-28 14:30 ` [PATCH 2/9] libceph: avoid clang out-of-range warning Arnd Bergmann
@ 2024-03-28 22:53 ` Justin Stitt
2024-03-29 0:06 ` Xiubo Li
1 sibling, 0 replies; 13+ messages in thread
From: Justin Stitt @ 2024-03-28 22:53 UTC (permalink / raw)
To: Arnd Bergmann
Cc: linux-kernel, Xiubo Li, Ilya Dryomov, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Nathan Chancellor,
Arnd Bergmann, Jeff Layton, Nick Desaulniers, Bill Wendling,
Milind Changire, Patrick Donnelly, Christian Brauner, ceph-devel,
netdev, llvm
On Thu, Mar 28, 2024 at 7:31 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> clang-14 points out that on 64-bit architectures, a u32
> is never larger than constant based on SIZE_MAX:
>
> net/ceph/osdmap.c:1425:10: error: result of comparison of constant 4611686018427387891 with expression of type 'u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> if (len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
> ~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> net/ceph/osdmap.c:1608:10: error: result of comparison of constant 2305843009213693945 with expression of type 'u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> if (len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
> ~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> The code is correct anyway, so just shut up that warning.
OK.
>
> Fixes: 6f428df47dae ("libceph: pg_upmap[_items] infrastructure")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Justin Stitt <justinstitt@google.com>
> ---
> fs/ceph/snap.c | 2 +-
> net/ceph/osdmap.c | 4 ++--
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
> index c65f2b202b2b..521507ea8260 100644
> --- a/fs/ceph/snap.c
> +++ b/fs/ceph/snap.c
> @@ -374,7 +374,7 @@ static int build_snap_context(struct ceph_mds_client *mdsc,
>
> /* alloc new snap context */
> err = -ENOMEM;
> - if (num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64))
> + if ((size_t)num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64))
> goto fail;
> snapc = ceph_create_snap_context(num, GFP_NOFS);
> if (!snapc)
> diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
> index 295098873861..8e7cb2fde6f1 100644
> --- a/net/ceph/osdmap.c
> +++ b/net/ceph/osdmap.c
> @@ -1438,7 +1438,7 @@ static struct ceph_pg_mapping *__decode_pg_temp(void **p, void *end,
> ceph_decode_32_safe(p, end, len, e_inval);
> if (len == 0 && incremental)
> return NULL; /* new_pg_temp: [] to remove */
> - if (len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
> + if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
> return ERR_PTR(-EINVAL);
>
> ceph_decode_need(p, end, len * sizeof(u32), e_inval);
> @@ -1621,7 +1621,7 @@ static struct ceph_pg_mapping *__decode_pg_upmap_items(void **p, void *end,
> u32 len, i;
>
> ceph_decode_32_safe(p, end, len, e_inval);
> - if (len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
> + if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
> return ERR_PTR(-EINVAL);
>
> ceph_decode_need(p, end, 2 * len * sizeof(u32), e_inval);
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH 2/9] libceph: avoid clang out-of-range warning
2024-03-28 14:30 ` [PATCH 2/9] libceph: avoid clang out-of-range warning Arnd Bergmann
2024-03-28 22:53 ` Justin Stitt
@ 2024-03-29 0:06 ` Xiubo Li
1 sibling, 0 replies; 13+ messages in thread
From: Xiubo Li @ 2024-03-29 0:06 UTC (permalink / raw)
To: Arnd Bergmann, linux-kernel, Ilya Dryomov, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Nathan Chancellor
Cc: Arnd Bergmann, Jeff Layton, Nick Desaulniers, Bill Wendling,
Justin Stitt, Milind Changire, Patrick Donnelly,
Christian Brauner, ceph-devel, netdev, llvm
On 3/28/24 22:30, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> clang-14 points out that on 64-bit architectures, a u32
> is never larger than constant based on SIZE_MAX:
>
> net/ceph/osdmap.c:1425:10: error: result of comparison of constant 4611686018427387891 with expression of type 'u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> if (len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
> ~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> net/ceph/osdmap.c:1608:10: error: result of comparison of constant 2305843009213693945 with expression of type 'u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> if (len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
> ~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> The code is correct anyway, so just shut up that warning.
>
> Fixes: 6f428df47dae ("libceph: pg_upmap[_items] infrastructure")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> fs/ceph/snap.c | 2 +-
> net/ceph/osdmap.c | 4 ++--
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
> index c65f2b202b2b..521507ea8260 100644
> --- a/fs/ceph/snap.c
> +++ b/fs/ceph/snap.c
> @@ -374,7 +374,7 @@ static int build_snap_context(struct ceph_mds_client *mdsc,
>
> /* alloc new snap context */
> err = -ENOMEM;
> - if (num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64))
> + if ((size_t)num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64))
> goto fail;
> snapc = ceph_create_snap_context(num, GFP_NOFS);
> if (!snapc)
> diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
> index 295098873861..8e7cb2fde6f1 100644
> --- a/net/ceph/osdmap.c
> +++ b/net/ceph/osdmap.c
> @@ -1438,7 +1438,7 @@ static struct ceph_pg_mapping *__decode_pg_temp(void **p, void *end,
> ceph_decode_32_safe(p, end, len, e_inval);
> if (len == 0 && incremental)
> return NULL; /* new_pg_temp: [] to remove */
> - if (len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
> + if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
> return ERR_PTR(-EINVAL);
>
> ceph_decode_need(p, end, len * sizeof(u32), e_inval);
> @@ -1621,7 +1621,7 @@ static struct ceph_pg_mapping *__decode_pg_upmap_items(void **p, void *end,
> u32 len, i;
>
> ceph_decode_32_safe(p, end, len, e_inval);
> - if (len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
> + if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
> return ERR_PTR(-EINVAL);
>
> ceph_decode_need(p, end, 2 * len * sizeof(u32), e_inval);
Reviewed-by: Xiubo Li <xiubli@redhat.com>
Thanks
- Xiubo
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 5/9] ipv4: tcp_output: avoid warning about NET_ADD_STATS
2024-03-28 14:30 [PATCH 0/9] address remaining -Wtautological-constant-out-of-range-compare Arnd Bergmann
2024-03-28 14:30 ` [PATCH 2/9] libceph: avoid clang out-of-range warning Arnd Bergmann
@ 2024-03-28 14:30 ` Arnd Bergmann
2024-03-28 14:38 ` Eric Dumazet
2024-03-28 14:30 ` [PATCH 8/9] mlx5: stop warning for 64KB pages Arnd Bergmann
2024-03-29 20:00 ` [PATCH 0/9] address remaining -Wtautological-constant-out-of-range-compare patchwork-bot+netdevbpf
3 siblings, 1 reply; 13+ messages in thread
From: Arnd Bergmann @ 2024-03-28 14:30 UTC (permalink / raw)
To: linux-kernel, Eric Dumazet, David S. Miller, David Ahern,
Jakub Kicinski, Paolo Abeni, Nathan Chancellor
Cc: Arnd Bergmann, Nick Desaulniers, Bill Wendling, Justin Stitt,
Dmitry Safonov, Neal Cardwell, mfreemon@cloudflare.com, Yan Zhai,
netdev, llvm
From: Arnd Bergmann <arnd@arndb.de>
Clang warns about a range check in percpu_add_op() being impossible
to hit for an u8 variable:
net/ipv4/tcp_output.c:188:3: error: result of comparison of constant -1 with expression of type 'u8' (aka 'unsigned char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
NET_ADD_STATS(sock_net(sk), LINUX_MIB_TCPACKCOMPRESSED,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/net/ip.h:291:41: note: expanded from macro 'NET_ADD_STATS'
#define NET_ADD_STATS(net, field, adnd) SNMP_ADD_STATS((net)->mib.net_statistics, field, adnd)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/net/snmp.h:143:4: note: expanded from macro 'SNMP_ADD_STATS'
this_cpu_add(mib->mibs[field], addend)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/percpu-defs.h:509:33: note: expanded from macro 'this_cpu_add'
#define this_cpu_add(pcp, val) __pcpu_size_call(this_cpu_add_, pcp, val)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
<scratch space>:187:1: note: expanded from here
this_cpu_add_8
^
arch/x86/include/asm/percpu.h:326:35: note: expanded from macro 'this_cpu_add_8'
#define this_cpu_add_8(pcp, val) percpu_add_op(8, volatile, (pcp), val)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/include/asm/percpu.h:127:31: note: expanded from macro 'percpu_add_op'
((val) == 1 || (val) == -1)) ? \
~~~~~ ^ ~~
Avoid this warning with a cast to a signed 'int'.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
net/ipv4/tcp_output.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index e3167ad96567..dbe54fceee08 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -183,7 +183,7 @@ static inline void tcp_event_ack_sent(struct sock *sk, u32 rcv_nxt)
if (unlikely(tp->compressed_ack)) {
NET_ADD_STATS(sock_net(sk), LINUX_MIB_TCPACKCOMPRESSED,
- tp->compressed_ack);
+ (int)tp->compressed_ack);
tp->compressed_ack = 0;
if (hrtimer_try_to_cancel(&tp->compressed_ack_timer) == 1)
__sock_put(sk);
--
2.39.2
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 5/9] ipv4: tcp_output: avoid warning about NET_ADD_STATS
2024-03-28 14:30 ` [PATCH 5/9] ipv4: tcp_output: avoid warning about NET_ADD_STATS Arnd Bergmann
@ 2024-03-28 14:38 ` Eric Dumazet
2024-03-28 16:39 ` Arnd Bergmann
0 siblings, 1 reply; 13+ messages in thread
From: Eric Dumazet @ 2024-03-28 14:38 UTC (permalink / raw)
To: Arnd Bergmann
Cc: linux-kernel, David S. Miller, David Ahern, Jakub Kicinski,
Paolo Abeni, Nathan Chancellor, Arnd Bergmann, Nick Desaulniers,
Bill Wendling, Justin Stitt, Dmitry Safonov, Neal Cardwell,
mfreemon@cloudflare.com, Yan Zhai, netdev, llvm
On Thu, Mar 28, 2024 at 3:31 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> Clang warns about a range check in percpu_add_op() being impossible
> to hit for an u8 variable:
>
> net/ipv4/tcp_output.c:188:3: error: result of comparison of constant -1 with expression of type 'u8' (aka 'unsigned char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> NET_ADD_STATS(sock_net(sk), LINUX_MIB_TCPACKCOMPRESSED,
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> include/net/ip.h:291:41: note: expanded from macro 'NET_ADD_STATS'
> #define NET_ADD_STATS(net, field, adnd) SNMP_ADD_STATS((net)->mib.net_statistics, field, adnd)
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> include/net/snmp.h:143:4: note: expanded from macro 'SNMP_ADD_STATS'
> this_cpu_add(mib->mibs[field], addend)
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> include/linux/percpu-defs.h:509:33: note: expanded from macro 'this_cpu_add'
> #define this_cpu_add(pcp, val) __pcpu_size_call(this_cpu_add_, pcp, val)
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
> <scratch space>:187:1: note: expanded from here
> this_cpu_add_8
> ^
> arch/x86/include/asm/percpu.h:326:35: note: expanded from macro 'this_cpu_add_8'
> #define this_cpu_add_8(pcp, val) percpu_add_op(8, volatile, (pcp), val)
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> arch/x86/include/asm/percpu.h:127:31: note: expanded from macro 'percpu_add_op'
> ((val) == 1 || (val) == -1)) ? \
> ~~~~~ ^ ~~
>
This seems like a bug in the macro or the compiler, because val is not
a constant ?
__builtin_constant_p(val) should return false ???
+#define percpu_add_op(size, qual, var, val) \
+do { \
+ const int pao_ID__ = (__builtin_constant_p(val) && \
+ ((val) == 1 || (val) == -1)) ? \
+ (int)(val) : 0; \
+ if (0) { \
+ typeof(var) pao_tmp__; \
+ pao_tmp__ = (val); \
+ (void)pao_tmp__; \
+ } \
+ if (pao_ID__ == 1) \
+ percpu_unary_op(size, qual, "inc", var); \
+ else if (pao_ID__ == -1) \
+ percpu_unary_op(size, qual, "dec", var); \
+ else \
+ percpu_to_op(size, qual, "add", var, val); \
+} while (0)
+
> Avoid this warning with a cast to a signed 'int'.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> net/ipv4/tcp_output.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
> index e3167ad96567..dbe54fceee08 100644
> --- a/net/ipv4/tcp_output.c
> +++ b/net/ipv4/tcp_output.c
> @@ -183,7 +183,7 @@ static inline void tcp_event_ack_sent(struct sock *sk, u32 rcv_nxt)
>
> if (unlikely(tp->compressed_ack)) {
> NET_ADD_STATS(sock_net(sk), LINUX_MIB_TCPACKCOMPRESSED,
> - tp->compressed_ack);
> + (int)tp->compressed_ack);
> tp->compressed_ack = 0;
> if (hrtimer_try_to_cancel(&tp->compressed_ack_timer) == 1)
> __sock_put(sk);
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH 5/9] ipv4: tcp_output: avoid warning about NET_ADD_STATS
2024-03-28 14:38 ` Eric Dumazet
@ 2024-03-28 16:39 ` Arnd Bergmann
0 siblings, 0 replies; 13+ messages in thread
From: Arnd Bergmann @ 2024-03-28 16:39 UTC (permalink / raw)
To: Eric Dumazet, Arnd Bergmann
Cc: linux-kernel, David S . Miller, David Ahern, Jakub Kicinski,
Paolo Abeni, Nathan Chancellor, Nick Desaulniers, Bill Wendling,
Justin Stitt, Dmitry Safonov, Neal Cardwell,
mfreemon@cloudflare.com, Yan Zhai, Netdev, llvm
On Thu, Mar 28, 2024, at 15:38, Eric Dumazet wrote:
> On Thu, Mar 28, 2024 at 3:31 PM Arnd Bergmann <arnd@kernel.org> wrote:
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/percpu.h:127:31: note: expanded from macro 'percpu_add_op'
>> ((val) == 1 || (val) == -1)) ? \
>> ~~~~~ ^ ~~
>>
>
> This seems like a bug in the macro or the compiler, because val is not
> a constant ?
>
> __builtin_constant_p(val) should return false ???
>
> +#define percpu_add_op(size, qual, var, val) \
> +do { \
> + const int pao_ID__ = (__builtin_constant_p(val) && \
> + ((val) == 1 || (val) == -1)) ? \
> + (int)(val) : 0; \
It looks like gcc does the same thing, with the broader and
still disabled -Wtype-limits, see: https://godbolt.org/z/3EPTGx68n
As far as I can tell, it does not matter that the comparison
against -1 is never actually evaluated, since the warning
is already printed before it simplifies the condition.
This is the only such warning I got from percpu, but
I guess we could also add the cast inside of the macro,
such as
diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 44958ebaf626..5923d786e67a 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -181,12 +181,14 @@ do { \
*/
#define percpu_add_op(size, qual, var, val) \
do { \
- const int pao_ID__ = (__builtin_constant_p(val) && \
- ((val) == 1 || (val) == -1)) ? \
- (int)(val) : 0; \
+ __auto_type __val = (val); \
+ const int pao_ID__ = (__builtin_constant_p(__val) && \
+ ((__val) == (typeof(__val))1 || \
+ (__val) == (typeof(__val))-1)) ? \
+ (int)(__val) : 0; \
if (0) { \
typeof(var) pao_tmp__; \
- pao_tmp__ = (val); \
+ pao_tmp__ = (__val); \
(void)pao_tmp__; \
} \
if (pao_ID__ == 1) \
@@ -194,7 +196,7 @@ do { \
else if (pao_ID__ == -1) \
percpu_unary_op(size, qual, "dec", var); \
else \
- percpu_to_op(size, qual, "add", var, val); \
+ percpu_to_op(size, qual, "add", var, __val); \
} while (0)
#define percpu_from_op(size, qual, op, _var) \
I added a temporary variable there to avoid expanding
the argument too many times.
Arnd
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 8/9] mlx5: stop warning for 64KB pages
2024-03-28 14:30 [PATCH 0/9] address remaining -Wtautological-constant-out-of-range-compare Arnd Bergmann
2024-03-28 14:30 ` [PATCH 2/9] libceph: avoid clang out-of-range warning Arnd Bergmann
2024-03-28 14:30 ` [PATCH 5/9] ipv4: tcp_output: avoid warning about NET_ADD_STATS Arnd Bergmann
@ 2024-03-28 14:30 ` Arnd Bergmann
2024-03-28 15:37 ` Maxim Mikityanskiy
` (2 more replies)
2024-03-29 20:00 ` [PATCH 0/9] address remaining -Wtautological-constant-out-of-range-compare patchwork-bot+netdevbpf
3 siblings, 3 replies; 13+ messages in thread
From: Arnd Bergmann @ 2024-03-28 14:30 UTC (permalink / raw)
To: linux-kernel, Saeed Mahameed, Leon Romanovsky, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Nathan Chancellor,
Jonathan Lemon, Maxim Mikityanskiy, Daniel Borkmann
Cc: Arnd Bergmann, Nick Desaulniers, Bill Wendling, Justin Stitt,
Tariq Toukan, Gal Pressman, netdev, linux-rdma, llvm
From: Arnd Bergmann <arnd@arndb.de>
When building with 64KB pages, clang points out that xsk->chunk_size
can never be PAGE_SIZE:
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c:19:22: error: result of comparison of constant 65536 with expression of type 'u16' (aka 'unsigned short') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
if (xsk->chunk_size > PAGE_SIZE ||
~~~~~~~~~~~~~~~ ^ ~~~~~~~~~
In older versions of this code, using PAGE_SIZE was the only
possibility, so this would have never worked on 64KB page kernels,
but the patch apparently did not address this case completely.
As Maxim Mikityanskiy suggested, 64KB chunks are really not all that
useful, so just shut up the warning by adding a cast.
Fixes: 282c0c798f8e ("net/mlx5e: Allow XSK frames smaller than a page")
Link: https://lore.kernel.org/netdev/20211013150232.2942146-1-arnd@kernel.org/
Link: https://lore.kernel.org/lkml/a7b27541-0ebb-4f2d-bd06-270a4d404613@app.fastmail.com/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
index 06592b9f0424..9240cfe25d10 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
@@ -28,8 +28,10 @@ bool mlx5e_validate_xsk_param(struct mlx5e_params *params,
struct mlx5e_xsk_param *xsk,
struct mlx5_core_dev *mdev)
{
- /* AF_XDP doesn't support frames larger than PAGE_SIZE. */
- if (xsk->chunk_size > PAGE_SIZE || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) {
+ /* AF_XDP doesn't support frames larger than PAGE_SIZE,
+ * and xsk->chunk_size is limited to 65535 bytes.
+ */
+ if ((size_t)xsk->chunk_size > PAGE_SIZE || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) {
mlx5_core_err(mdev, "XSK chunk size %u out of bounds [%u, %lu]\n", xsk->chunk_size,
MLX5E_MIN_XSK_CHUNK_SIZE, PAGE_SIZE);
return false;
--
2.39.2
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 8/9] mlx5: stop warning for 64KB pages
2024-03-28 14:30 ` [PATCH 8/9] mlx5: stop warning for 64KB pages Arnd Bergmann
@ 2024-03-28 15:37 ` Maxim Mikityanskiy
2024-03-28 22:09 ` Justin Stitt
2024-03-28 22:39 ` Tariq Toukan
2 siblings, 0 replies; 13+ messages in thread
From: Maxim Mikityanskiy @ 2024-03-28 15:37 UTC (permalink / raw)
To: Arnd Bergmann
Cc: linux-kernel, Saeed Mahameed, Leon Romanovsky, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Nathan Chancellor,
Jonathan Lemon, Daniel Borkmann, Arnd Bergmann, Nick Desaulniers,
Bill Wendling, Justin Stitt, Tariq Toukan, Gal Pressman, netdev,
linux-rdma, llvm
On Thu, 28 Mar 2024 at 15:30:46 +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> When building with 64KB pages, clang points out that xsk->chunk_size
> can never be PAGE_SIZE:
>
> drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c:19:22: error: result of comparison of constant 65536 with expression of type 'u16' (aka 'unsigned short') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> if (xsk->chunk_size > PAGE_SIZE ||
> ~~~~~~~~~~~~~~~ ^ ~~~~~~~~~
>
> In older versions of this code, using PAGE_SIZE was the only
> possibility, so this would have never worked on 64KB page kernels,
> but the patch apparently did not address this case completely.
>
> As Maxim Mikityanskiy suggested, 64KB chunks are really not all that
> useful, so just shut up the warning by adding a cast.
>
> Fixes: 282c0c798f8e ("net/mlx5e: Allow XSK frames smaller than a page")
> Link: https://lore.kernel.org/netdev/20211013150232.2942146-1-arnd@kernel.org/
> Link: https://lore.kernel.org/lkml/a7b27541-0ebb-4f2d-bd06-270a4d404613@app.fastmail.com/
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
> index 06592b9f0424..9240cfe25d10 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
> @@ -28,8 +28,10 @@ bool mlx5e_validate_xsk_param(struct mlx5e_params *params,
> struct mlx5e_xsk_param *xsk,
> struct mlx5_core_dev *mdev)
> {
> - /* AF_XDP doesn't support frames larger than PAGE_SIZE. */
> - if (xsk->chunk_size > PAGE_SIZE || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) {
> + /* AF_XDP doesn't support frames larger than PAGE_SIZE,
> + * and xsk->chunk_size is limited to 65535 bytes.
> + */
> + if ((size_t)xsk->chunk_size > PAGE_SIZE || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) {
Acked-by: Maxim Mikityanskiy <maxtram95@gmail.com>
> mlx5_core_err(mdev, "XSK chunk size %u out of bounds [%u, %lu]\n", xsk->chunk_size,
> MLX5E_MIN_XSK_CHUNK_SIZE, PAGE_SIZE);
> return false;
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH 8/9] mlx5: stop warning for 64KB pages
2024-03-28 14:30 ` [PATCH 8/9] mlx5: stop warning for 64KB pages Arnd Bergmann
2024-03-28 15:37 ` Maxim Mikityanskiy
@ 2024-03-28 22:09 ` Justin Stitt
2024-03-28 22:21 ` Arnd Bergmann
2024-03-28 22:39 ` Tariq Toukan
2 siblings, 1 reply; 13+ messages in thread
From: Justin Stitt @ 2024-03-28 22:09 UTC (permalink / raw)
To: Arnd Bergmann
Cc: linux-kernel, Saeed Mahameed, Leon Romanovsky, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Nathan Chancellor,
Jonathan Lemon, Maxim Mikityanskiy, Daniel Borkmann,
Arnd Bergmann, Nick Desaulniers, Bill Wendling, Tariq Toukan,
Gal Pressman, netdev, linux-rdma, llvm
On Thu, Mar 28, 2024 at 7:32 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> When building with 64KB pages, clang points out that xsk->chunk_size
> can never be PAGE_SIZE:
This is under W=1 right? Otherwise this is a mighty annoying warning.
>
> drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c:19:22: error: result of comparison of constant 65536 with expression of type 'u16' (aka 'unsigned short') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> if (xsk->chunk_size > PAGE_SIZE ||
> ~~~~~~~~~~~~~~~ ^ ~~~~~~~~~
>
> In older versions of this code, using PAGE_SIZE was the only
> possibility, so this would have never worked on 64KB page kernels,
> but the patch apparently did not address this case completely.
>
> As Maxim Mikityanskiy suggested, 64KB chunks are really not all that
> useful, so just shut up the warning by adding a cast.
>
> Fixes: 282c0c798f8e ("net/mlx5e: Allow XSK frames smaller than a page")
> Link: https://lore.kernel.org/netdev/20211013150232.2942146-1-arnd@kernel.org/
> Link: https://lore.kernel.org/lkml/a7b27541-0ebb-4f2d-bd06-270a4d404613@app.fastmail.com/
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Justin Stitt <justinstitt@google.com>
> ---
> drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
> index 06592b9f0424..9240cfe25d10 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
> @@ -28,8 +28,10 @@ bool mlx5e_validate_xsk_param(struct mlx5e_params *params,
> struct mlx5e_xsk_param *xsk,
> struct mlx5_core_dev *mdev)
> {
> - /* AF_XDP doesn't support frames larger than PAGE_SIZE. */
> - if (xsk->chunk_size > PAGE_SIZE || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) {
> + /* AF_XDP doesn't support frames larger than PAGE_SIZE,
> + * and xsk->chunk_size is limited to 65535 bytes.
> + */
> + if ((size_t)xsk->chunk_size > PAGE_SIZE || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) {
> mlx5_core_err(mdev, "XSK chunk size %u out of bounds [%u, %lu]\n", xsk->chunk_size,
> MLX5E_MIN_XSK_CHUNK_SIZE, PAGE_SIZE);
> return false;
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH 8/9] mlx5: stop warning for 64KB pages
2024-03-28 22:09 ` Justin Stitt
@ 2024-03-28 22:21 ` Arnd Bergmann
0 siblings, 0 replies; 13+ messages in thread
From: Arnd Bergmann @ 2024-03-28 22:21 UTC (permalink / raw)
To: Justin Stitt, Arnd Bergmann
Cc: linux-kernel, Saeed Mahameed, Leon Romanovsky, David S . Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Nathan Chancellor,
Jonathan Lemon, Maxim Mikityanskiy, Daniel Borkmann,
Nick Desaulniers, Bill Wendling, Tariq Toukan, Gal Pressman,
Netdev, linux-rdma, llvm
On Thu, Mar 28, 2024, at 23:09, Justin Stitt wrote:
> On Thu, Mar 28, 2024 at 7:32 AM Arnd Bergmann <arnd@kernel.org> wrote:
>>
>> From: Arnd Bergmann <arnd@arndb.de>
>>
>> When building with 64KB pages, clang points out that xsk->chunk_size
>> can never be PAGE_SIZE:
>
> This is under W=1 right? Otherwise this is a mighty annoying warning.
At the moment yes. I'm fairly sure that I've covered all the
common cases with thousands of randconfig builds, so we should
be able to make it the default when this series is fully merged.
Arnd
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 8/9] mlx5: stop warning for 64KB pages
2024-03-28 14:30 ` [PATCH 8/9] mlx5: stop warning for 64KB pages Arnd Bergmann
2024-03-28 15:37 ` Maxim Mikityanskiy
2024-03-28 22:09 ` Justin Stitt
@ 2024-03-28 22:39 ` Tariq Toukan
2 siblings, 0 replies; 13+ messages in thread
From: Tariq Toukan @ 2024-03-28 22:39 UTC (permalink / raw)
To: Arnd Bergmann, linux-kernel, Saeed Mahameed, Leon Romanovsky,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Nathan Chancellor, Jonathan Lemon, Maxim Mikityanskiy,
Daniel Borkmann
Cc: Arnd Bergmann, Nick Desaulniers, Bill Wendling, Justin Stitt,
Gal Pressman, netdev, linux-rdma, llvm, Tariq Toukan
On 28/03/2024 16:30, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> When building with 64KB pages, clang points out that xsk->chunk_size
> can never be PAGE_SIZE:
>
> drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c:19:22: error: result of comparison of constant 65536 with expression of type 'u16' (aka 'unsigned short') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> if (xsk->chunk_size > PAGE_SIZE ||
> ~~~~~~~~~~~~~~~ ^ ~~~~~~~~~
>
> In older versions of this code, using PAGE_SIZE was the only
> possibility, so this would have never worked on 64KB page kernels,
> but the patch apparently did not address this case completely.
>
> As Maxim Mikityanskiy suggested, 64KB chunks are really not all that
> useful, so just shut up the warning by adding a cast.
>
> Fixes: 282c0c798f8e ("net/mlx5e: Allow XSK frames smaller than a page")
> Link: https://lore.kernel.org/netdev/20211013150232.2942146-1-arnd@kernel.org/
> Link: https://lore.kernel.org/lkml/a7b27541-0ebb-4f2d-bd06-270a4d404613@app.fastmail.com/
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Thanks for your patch.
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/9] address remaining -Wtautological-constant-out-of-range-compare
2024-03-28 14:30 [PATCH 0/9] address remaining -Wtautological-constant-out-of-range-compare Arnd Bergmann
` (2 preceding siblings ...)
2024-03-28 14:30 ` [PATCH 8/9] mlx5: stop warning for 64KB pages Arnd Bergmann
@ 2024-03-29 20:00 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 13+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-03-29 20:00 UTC (permalink / raw)
To: Arnd Bergmann
Cc: linux-kernel, arnd, idryomov, dongsheng.yang, axboe, jgg, leon,
agk, snitzer, mpatocka, dm-devel, saeedm, davem, edumazet, kuba,
pabeni, xiubli, jlayton, konishi.ryusuke, dvyukov, andreyknvl,
dsahern, masahiroy, nathan, nicolas, ndesaulniers, morbo,
justinstitt, keescook, gustavoars, tariqt, ceph-devel,
linux-block, linux-rdma, netdev, linux-nilfs, kasan-dev,
linux-kbuild, llvm
Hello:
This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 28 Mar 2024 15:30:38 +0100 you wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> The warning option was introduced a few years ago but left disabled
> by default. All of the actual bugs that this has found have been
> fixed in the meantime, and this series should address the remaining
> false-positives, as tested on arm/arm64/x86 randconfigs as well as
> allmodconfig builds for all architectures supported by clang.
>
> [...]
Here is the summary with links:
- [2/9] libceph: avoid clang out-of-range warning
(no matching commit)
- [5/9] ipv4: tcp_output: avoid warning about NET_ADD_STATS
(no matching commit)
- [8/9] mlx5: stop warning for 64KB pages
https://git.kernel.org/netdev/net-next/c/a5535e533694
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 13+ messages in thread