All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Dariusz Sosnowski <dsosnowski@nvidia.com>
Cc: <dev@dpdk.org>, <stable@dpdk.org>,
	Viacheslav Ovsiienko <viacheslavo@nvidia.com>,
	Bing Zhao <bingz@nvidia.com>, Ori Kam <orika@nvidia.com>,
	Suanming Mou <suanmingm@nvidia.com>,
	Matan Azrad <matan@nvidia.com>, Erez Shitrit <erezsh@nvidia.com>,
	Alex Vesker <valex@nvidia.com>
Subject: Re: [PATCH v5 5/6] net/mlx5: fix LTO stringop-overflow warning
Date: Thu, 5 Feb 2026 09:07:46 -0800	[thread overview]
Message-ID: <20260205090746.67bedd30@phoenix.local> (raw)
In-Reply-To: <fn3ooyikqw7dwka3kmwz2mtpigukakvwyema44othruighbmjn@ye5xqkfbnzm7>

On Thu, 5 Feb 2026 14:43:35 +0100
Dariusz Sosnowski <dsosnowski@nvidia.com> wrote:

> On Tue, Jan 20, 2026 at 11:52:10AM -0800, Stephen Hemminger wrote:
> > When compiling with LTO (Link Time Optimization) enabled, GCC's
> > interprocedural analysis produces false positive warnings about
> > potential buffer overflow in mlx5dr_action_prepare_decap_l3_data():
> > 
> >   In function 'mlx5dr_action_prepare_decap_l3_data',
> >       inlined from 'mlx5dr_action_handle_tunnel_l3_to_l2',
> >       inlined from 'mlx5dr_action_create_reformat_hws':
> >   warning: writing 4 bytes into a region of size 0 [-Wstringop-overflow=]
> >     memcpy(dst, e_src, MLX5DR_ACTION_INLINE_DATA_SIZE);
> >   note: at offset [140, 524248] into destination object 'mh_data' of size 64
> > 
> > With LTO, the function chain is fully inlined, giving GCC visibility
> > into the 64-byte stack buffer 'mh_data'. However, GCC's static analysis
> > cannot determine that num_of_actions is constrained to either
> > DECAP_L3_NUM_ACTIONS_W_NO_VLAN (6) or DECAP_L3_NUM_ACTIONS_W_VLAN (7)
> > by the callers. It assumes worst-case bounds that greatly exceed the
> > buffer size.
> > 
> > Fix this by adding an explicit bounds check at function entry. The
> > valid values for num_of_actions are 6 (no VLAN) or 7 (with VLAN),
> > which produce maximum buffer usage well under 64 bytes:
> >   - offset 12 + (num_of_actions-3) * 8 + 2 = max 46 bytes for 7 actions
> > 
> > This provides GCC with the proof it needs that subsequent memcpy
> > operations are safe.
> > 
> > This is not a data path function - it executes only during flow rule
> > creation, so the additional check has no performance impact.
> > 
> > Bugzilla ID: 1710
> > Fixes: f8c8a6d8440d ("net/mlx5/hws: add action object")
> > Cc: stable@dpdk.org
> > 
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > ---
> >  drivers/net/mlx5/hws/mlx5dr_action.c | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> > 
> > diff --git a/drivers/net/mlx5/hws/mlx5dr_action.c b/drivers/net/mlx5/hws/mlx5dr_action.c
> > index b35bf07c3c..3b12506577 100644
> > --- a/drivers/net/mlx5/hws/mlx5dr_action.c
> > +++ b/drivers/net/mlx5/hws/mlx5dr_action.c
> > @@ -3620,6 +3620,20 @@ mlx5dr_action_prepare_decap_l3_data(uint8_t *src, uint8_t *dst,
> >  	uint8_t *e_src;
> >  	int i;
> >  
> > +	/*
> > +	 * Bounds check to help GCC LTO static analysis.
> > +	 *
> > +	 * When LTO inlines this into mlx5dr_action_handle_tunnel_l3_to_l2(),
> > +	 * GCC sees the 64-byte mh_data buffer but cannot prove num_of_actions
> > +	 * is bounded, causing false -Wstringop-overflow warnings.
> > +	 *
> > +	 * Valid num_of_actions values are DECAP_L3_NUM_ACTIONS_W_NO_VLAN (6)
> > +	 * or DECAP_L3_NUM_ACTIONS_W_VLAN (7). This check gives GCC the proof
> > +	 * it needs that the loop iterations stay within buffer bounds.
> > +	 */
> > +	if (unlikely(num_of_actions > DECAP_L3_NUM_ACTIONS_W_VLAN))
> > +		return;  
> 
> This function can be executed as part of fast path
> in async flow creation, so if possible
> I would avoid adding such a condition.
> 
> I tested locally with GCC 14.2.0 and it looks like
> if this condition is changed to equivalent __rte_assume(),
> then this condition is removed from generated code
> (https://godbolt.org/z/afx8jjr6Y as an example,
> code generated by LTO also optimizes the relevant code).
> __rte_assume() also fixes the LTO warning.
> 
> Could you please change the condition to equivalent __rte_assume()?
> 
> > +
> >  	/* num_of_actions = remove l3l2 + 4/5 inserts + remove extra 2 bytes
> >  	 * copy from end of src to the start of dst.
> >  	 * move to the end, 2 is the leftover from 14B or 18B
> > -- 
> > 2.51.0
> >   

Yes rte_assume works will resend

  reply	other threads:[~2026-02-05 17:07 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-23 19:41 [RFC 0/3] common/cnxk: remove dependence on VLA Stephen Hemminger
2025-10-23 19:41 ` [RFC 1/3] common/cnxk: replace variable length state array Stephen Hemminger
2025-10-23 19:41 ` [RFC 2/3] common/cnxk: replace variable length array Stephen Hemminger
2025-10-27  5:22   ` [EXTERNAL] " Harman Kalra
2025-10-23 19:41 ` [RFC 3/3] common/cnxk: re-enable vla warnings Stephen Hemminger
2026-01-14  1:49 ` [PATCH v2 0/3] common/cnxk: remove variable length arrays Stephen Hemminger
2026-01-14  1:49   ` [PATCH v2 1/3] common/cnxk: replace variable length state array Stephen Hemminger
2026-01-14  1:50   ` [PATCH v2 2/3] common/cnxk: replace variable length array Stephen Hemminger
2026-01-14  1:50   ` [PATCH v2 3/3] common/cnxk: re-enable vla warnings Stephen Hemminger
2026-01-16  6:46 ` [PATCH v3 0/6] fix GCC warnings when building with LTO Stephen Hemminger
2026-01-16  6:46   ` [PATCH v3 1/6] test/soring: fix buffer overflow warnings " Stephen Hemminger
2026-01-16  9:32     ` Morten Brørup
2026-01-19 22:48       ` Stephen Hemminger
2026-01-20  8:49         ` Morten Brørup
2026-01-20 14:34           ` Stephen Hemminger
2026-01-20 15:01             ` Morten Brørup
2026-01-20 15:40               ` Konstantin Ananyev
2026-01-20 15:48                 ` Stephen Hemminger
2026-01-20 16:52                 ` Stephen Hemminger
2026-01-20 19:27                 ` Stephen Hemminger
2026-01-21 10:40                   ` Morten Brørup
2026-01-21 12:56                   ` Konstantin Ananyev
2026-01-21 14:57                     ` Stephen Hemminger
2026-01-16  6:46   ` [PATCH v3 2/6] common/cnxk: replace variable length state array Stephen Hemminger
2026-01-16  6:46   ` [PATCH v3 3/6] common/cnxk: replace variable length array Stephen Hemminger
2026-01-16  6:46   ` [PATCH v3 4/6] common/cnxk: re-enable vla warnings Stephen Hemminger
2026-01-16  6:46   ` [PATCH v3 5/6] common/cnxk: fix buffer overflow in reassembly SA setup Stephen Hemminger
2026-01-16  6:46   ` [PATCH v3 6/6] net/mlx5/hws: fix LTO false positive stringop-overflow warning Stephen Hemminger
2026-01-19 22:44 ` [PATCH v4 0/6] fix build failures with LTO enabled Stephen Hemminger
2026-01-19 22:44   ` [PATCH v4 1/6] common/cnxk: replace variable length state array Stephen Hemminger
2026-01-19 22:44   ` [PATCH v4 2/6] common/cnxk: replace variable length array Stephen Hemminger
2026-01-19 22:44   ` [PATCH v4 3/6] common/cnxk: re-enable vla warnings Stephen Hemminger
2026-01-19 22:44   ` [PATCH v4 4/6] common/cnxk: fix buffer overflow in reassembly SA setup Stephen Hemminger
2026-01-19 22:44   ` [PATCH v4 5/6] net/mlx5: fix LTO false positive stringop-overflow warning Stephen Hemminger
2026-01-19 22:44   ` [PATCH v4 6/6] test/soring: fix stringop-overflow warning with LTO Stephen Hemminger
2026-01-20 19:52 ` [PATCH 0/6] Fix LTO compilation warnings Stephen Hemminger
2026-01-20 19:52   ` [PATCH v5 1/6] common/cnxk: replace variable length state array Stephen Hemminger
2026-01-20 19:52   ` [PATCH v5 2/6] common/cnxk: replace variable length array Stephen Hemminger
2026-01-20 19:52   ` [PATCH v5 3/6] common/cnxk: re-enable vla warnings Stephen Hemminger
2026-01-20 19:52   ` [PATCH v5 4/6] common/cnxk: fix buffer overflow in SA setup Stephen Hemminger
2026-01-20 19:52   ` [PATCH v5 5/6] net/mlx5: fix LTO stringop-overflow warning Stephen Hemminger
2026-02-05 13:43     ` Dariusz Sosnowski
2026-02-05 17:07       ` Stephen Hemminger [this message]
2026-01-20 19:52   ` [PATCH v5 6/6] ring: use inline instead of always inline in soring Stephen Hemminger
2026-01-22  9:52     ` Konstantin Ananyev
2026-01-22 10:49       ` Morten Brørup
2026-02-05 17:55   ` [PATCH v6 0/6] Fix LTO compilation warnings Stephen Hemminger
2026-02-05 17:55     ` [PATCH v6 1/6] common/cnxk: replace variable length state array Stephen Hemminger
2026-03-02 19:06       ` [EXTERNAL] " Tejasree Kondoj
2026-03-02 19:36         ` Stephen Hemminger
2026-02-05 17:55     ` [PATCH v6 2/6] common/cnxk: replace variable length array Stephen Hemminger
2026-03-02 10:51       ` [EXTERNAL] " Tejasree Kondoj
2026-02-05 17:55     ` [PATCH v6 3/6] common/cnxk: re-enable vla warnings Stephen Hemminger
2026-03-02 16:50       ` Nithin Dabilpuram
2026-02-05 17:55     ` [PATCH v6 4/6] common/cnxk: fix buffer overflow in SA setup Stephen Hemminger
2026-03-02 16:40       ` Nithin Dabilpuram
2026-02-05 17:55     ` [PATCH v6 5/6] ring: use inline instead of always inline in soring Stephen Hemminger
2026-02-05 17:55     ` [PATCH v6 6/6] net/mlx5: fix LTO stringop-overflow warning Stephen Hemminger
2026-02-06  9:51       ` Dariusz Sosnowski
2026-02-27  7:57     ` [PATCH v6 0/6] Fix LTO compilation warnings David Marchand
2026-03-03 16:24     ` David Marchand

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=20260205090746.67bedd30@phoenix.local \
    --to=stephen@networkplumber.org \
    --cc=bingz@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=dsosnowski@nvidia.com \
    --cc=erezsh@nvidia.com \
    --cc=matan@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=stable@dpdk.org \
    --cc=suanmingm@nvidia.com \
    --cc=valex@nvidia.com \
    --cc=viacheslavo@nvidia.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.