From: Ratheesh Kannoth <rkannoth@marvell.com>
To: "Sergey V. Frolov" <Sergey.V.Frolov@kaspersky.com>
Cc: "andrew+netdev@lunn.ch" <andrew+netdev@lunn.ch>,
"sbhatta@marvell.com" <sbhatta@marvell.com>,
"davem@davemloft.net" <davem@davemloft.net>,
"bbhushan2@marvell.com" <bbhushan2@marvell.com>,
"gakula@marvell.com" <gakula@marvell.com>,
"kuba@kernel.org" <kuba@kernel.org>,
"sgoutham@marvell.com" <sgoutham@marvell.com>,
"edumazet@google.com" <edumazet@google.com>,
"pabeni@redhat.com" <pabeni@redhat.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH net] net: octeontx2-pf: Fix UB in shift operation
Date: Tue, 28 Jul 2026 09:17:26 +0530 [thread overview]
Message-ID: <amgmTvxY7_Z_u7tq@rkannoth-OptiPlex-7090> (raw)
In-Reply-To: <159a6806dd1ea12bbd559f664ce30d306cdf1178.camel@kaspersky.com>
On 2026-07-27 at 17:16:24, Sergey V. Frolov (Sergey.V.Frolov@kaspersky.com) wrote:
> On Mon, 2026-07-27 at 08:57 +0530, Ratheesh Kannoth wrote:
> >
> > >
> > > Signed-off-by: Sergey.V.Frolov <Sergey.V.Frolov@kaspersky.com>
> > > ---
> > > drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c | 11
> > > ++++++++---
> > > 1 file changed, 8 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c
> > > b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c
> > > index 40162b08014d..39bd73a214af 100644
> > > --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c
> > > +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c
> > > @@ -53,10 +53,15 @@ static void otx2_get_egress_burst_cfg(struct
> > > otx2_nic *nic, u32 burst,
> > > if (burst) {
> > > *burst_exp = ilog2(burst) ? ilog2(burst) - 1 : 0;
> > > tmp = burst - rounddown_pow_of_two(burst);
> > > - if (burst < max_mantissa)
> > > + if (burst <= max_mantissa) {
> >
> > Thanks.
> > can we handle 255 case with <= ? it looks simple to me.
>
> Thank you for reviewing the patch. I see that your simplification works
> with the current value of max_mantissa (which is 255).
>
> However, my concern is that this approach introduces an implicit
> dependency on the fact that max_mantissa never being changed. If in the
> future someone updates this constant (e.g. to support new hardware),
> the shift operation could become invalid again, and the UB would
> return. if max_mantissa becomes 127, then UB would reappear for burst
> values in the range 128-255 (where burst_exp would be 6, making
> *burst_exp - 7 = -1).
>
> My original patch explicitly handles both cases (*burst_exp >= 7 and <
> 7), so it's robust regardless of max_mantissa value. I'd prefer to keep
> the explicit check to avoid introducing a hidden dependency that might
> affect future maintainability.
>
> What do you think?
Thank you for the clarification.
I appreciate the robustness argument, but I'd like to provide some
hardware context that I think is relevant here.
On newer platforms (CN10K/CN20K), max_mantissa is 32767 — significantly
larger than the current OTX2/98xx value of 255. Given this trend, a
future reduction of max_mantissa below 256 would represent a major
architectural regression and is, in practice, highly unlikely.
It is also worth noting that in the proposed patch, the new else branch:
*burst_mantissa = tmp * (1ULL << (7 - *burst_exp));
is entirely unreachable dead code on CN10K/CN20K.
Rather than carrying dead code to guard against a hypothetical future
scenario, Could you consider following minimal approach:
1) Fix the off-by-one boundary condition by changing:
if (burst < max_mantissa)
to
if (burst <= max_mantissa)
2) Add a WARN_ON(*burst_exp < 7) before the else branch as an
explicit safeguard. This ensures that if max_mantissa ever changes
in a way that reintroduces this condition, it will be immediately
caught at runtime rather than silently triggering UB.
This keeps the fix minimal and correct for all current platforms, while
still providing a clear safety net against future regressions — without
adding unreachable code paths.
next prev parent reply other threads:[~2026-07-28 3:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 12:19 [PATCH net] net: octeontx2-pf: Fix UB in shift operation Sergey.V.Frolov
2026-07-27 3:27 ` Ratheesh Kannoth
2026-07-27 11:46 ` Sergey V. Frolov
2026-07-28 3:47 ` Ratheesh Kannoth [this message]
2026-07-28 8:13 ` Sergey V. Frolov
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=amgmTvxY7_Z_u7tq@rkannoth-OptiPlex-7090 \
--to=rkannoth@marvell.com \
--cc=Sergey.V.Frolov@kaspersky.com \
--cc=andrew+netdev@lunn.ch \
--cc=bbhushan2@marvell.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gakula@marvell.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sbhatta@marvell.com \
--cc=sgoutham@marvell.com \
/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