Netdev List
 help / color / mirror / Atom feed
From: "Holger Hoffstätte" <holger@applied-asynchrony.com>
To: Oleksandr Natalenko <oleksandr@natalenko.name>,
	Neal Cardwell <ncardwell@google.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [bbr3] Suspicious use of bbr_param
Date: Wed, 25 Dec 2024 13:40:29 +0100	[thread overview]
Message-ID: <4ea88dcb-6328-233f-eddc-1fe49313c3ab@applied-asynchrony.com> (raw)
In-Reply-To: <4616579.LvFx2qVVIh@natalenko.name>

On 2024-12-24 22:04, Oleksandr Natalenko wrote:
> Hello Neal.
> 
> One of my users reports [1] that BBRv3 from [2] cannot be built with LLVM=1 and WERROR=y because of the following warnings:
> 
> net/ipv4/tcp_bbr.c:1079:48: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand]
>   1079 |         if (!bbr->ecn_eligible && bbr_can_use_ecn(sk) &&
>        |                                                       ^
>   1080 |             bbr_param(sk, ecn_factor) &&
>        |             ~~~~~~~~~~~~~~~~~~~~~~~~~
> net/ipv4/tcp_bbr.c:1079:48: note: use '&' for a bitwise operation
>   1079 |         if (!bbr->ecn_eligible && bbr_can_use_ecn(sk) &&
>        |                                                       ^~
>        |                                                       &
> net/ipv4/tcp_bbr.c:1079:48: note: remove constant to silence this warning
>   1079 |         if (!bbr->ecn_eligible && bbr_can_use_ecn(sk) &&
>        |                                                       ^~
>   1080 |             bbr_param(sk, ecn_factor) &&
>        |             ~~~~~~~~~~~~~~~~~~~~~~~~~
> net/ipv4/tcp_bbr.c:1187:24: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand]
>   1187 |             bbr->ecn_eligible && bbr_param(sk, ecn_thresh)) {
>        |                               ^  ~~~~~~~~~~~~~~~~~~~~~~~~~
> net/ipv4/tcp_bbr.c:1187:24: note: use '&' for a bitwise operation
>   1187 |             bbr->ecn_eligible && bbr_param(sk, ecn_thresh)) {
>        |                               ^~
>        |                               &
> net/ipv4/tcp_bbr.c:1187:24: note: remove constant to silence this warning
>   1187 |             bbr->ecn_eligible && bbr_param(sk, ecn_thresh)) {
>        |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> net/ipv4/tcp_bbr.c:1385:24: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand]
>   1385 |         if (bbr->ecn_in_round && bbr_param(sk, ecn_factor)) {
>        |                               ^  ~~~~~~~~~~~~~~~~~~~~~~~~~
> net/ipv4/tcp_bbr.c:1385:24: note: use '&' for a bitwise operation
>   1385 |         if (bbr->ecn_in_round && bbr_param(sk, ecn_factor)) {
>        |                               ^~
>        |                               &
> net/ipv4/tcp_bbr.c:1385:24: note: remove constant to silence this warning
>   1385 |         if (bbr->ecn_in_round && bbr_param(sk, ecn_factor)) {
>        |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 3 warnings generated.
> 
> The usage of bbr_param() with ecn_thresh and ecn_factor here does indeed look suspicious. In both cases, the bbr_param() macro gets evaluated to `static const u32` values, and those get &&'ed in the if statements. The consts are positive, so they do not have any impact in the conditional expressions. FWIW, the sk argument is dropped by the macro altogether, so I'm not sure what was the intention here.
> 
> Interestingly, unlike Clang, GCC stays silent.

This looks a lot like https://github.com/llvm/llvm-project/issues/75199

Judging by the number of related issues and PRs this seems to be a known problem,
and to me it looks like clang's complaint is "technically correct" while going
against "common in reality" usage.

Many projects seem to use -Wno-constant-logical-operand to work around this.

cheers
Holger

      reply	other threads:[~2024-12-25 12:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-24 21:04 [bbr3] Suspicious use of bbr_param Oleksandr Natalenko
2024-12-25 12:40 ` Holger Hoffstätte [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4ea88dcb-6328-233f-eddc-1fe49313c3ab@applied-asynchrony.com \
    --to=holger@applied-asynchrony.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=oleksandr@natalenko.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox