From: Shay Drory <shayd@nvidia.com>
To: <netdev-bot+sashiko@kernel.org>
Cc: Shay Drory <shayd@nvidia.com>, <tariqt@nvidia.com>,
<andrew+netdev@lunn.ch>, <davem@davemloft.net>,
<edumazet@kernel.org>, <kuba@kernel.org>,
<netdev@vger.kernel.org>, <pabeni@redhat.com>, <gal@nvidia.com>,
<leon@kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-rdma@vger.kernel.org>, <mbloch@nvidia.com>,
<markzhang@nvidia.com>, <moshe@nvidia.com>, <saeedm@nvidia.com>
Subject: Re: [PATCH net V2] net/mlx5e: rep, Fix races between devcom PAIR event and uplink close
Date: Mon, 16 Nov 2026 21:52:18 +0200 [thread overview]
Message-ID: <20261116195218.1120811-1-shayd@nvidia.com> (raw)
In-Reply-To: <179485349648.3136.17669005426251956349@kernel.org>
On 16/11/2026 20:24, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 · Medium: 0 · Low: 0
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [High] The new locking only works if the unsynchronized read of
> `esw->devcom` returns a valid pointer.
>
> --
>
> net/mlx5e: rep, Fix races between devcom PAIR event and uplink close
>
> This commit adds mlx5_devcom_comp_read_lock/unlock(), which take the
> devcom component semaphore for read whether or not comp->ready is set.
> It holds that lock across mlx5e_sqs2vport_start() and
> mlx5e_sqs2vport_stop() so that both are serialized against the
> ESW_OFFLOADS PAIR/UNPAIR handler.
>
>> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
>> index a50a42581528a..962c70b9b5661 100644
>> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
>> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
>
> [ ... ]
>
>> @@ -630,8 +627,12 @@ mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv)
>> struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
>> struct mlx5e_rep_priv *rpriv = priv->ppriv;
>> struct mlx5_eswitch_rep *rep = rpriv->rep;
>> + struct mlx5_devcom_comp_dev *devcom;
>>
>> + devcom = esw->devcom;
>> + mlx5_devcom_comp_read_lock(devcom);
>> + mlx5e_sqs2vport_stop(esw, rep);
>> + mlx5_devcom_comp_read_unlock(devcom);
>> }
>
> [Severity: High]
>
> Are the races still reachable if esw->devcom is NULL or stale when it is
> read here and in mlx5e_sqs2vport_start()?
>
> The load of esw->devcom is a plain unsynchronized read. The store side
> has no WRITE_ONCE() and the load side has no READ_ONCE().
> mlx5_devcom_comp_read_lock() also does nothing when passed NULL.
>
> In esw_offloads_enable(), the uplink and VF reps are loaded and their
> netdevs registered before mlx5_esw_offloads_devcom_init() runs. That
> function publishes the pointer and sends the PAIR event right away:
>
> drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c:mlx5_esw_offloads_devcom_init() {
> ...
> esw->devcom = mlx5_devcom_register_component(esw->dev->priv.devc,
> MLX5_DEVCOM_ESW_OFFLOADS,
> attr,
> mlx5_esw_offloads_devcom_event,
> esw);
> if (!esw->devcom)
> return;
>
> err = mlx5_devcom_send_event(esw->devcom,
> ESW_OFFLOADS_DEVCOM_PAIR,
> ...
> }
>
> The PAIR handler runs with comp->sem held for write. It goes through
> mlx5_esw_offloads_devcom_event()->mlx5_esw_offloads_pair()->
> mlx5e_vport_rep_event_pair(), which walks rpriv->vport_sqs_list for
> every loaded rep and calls xa_insert() on rep_sq->sq_peer.
>
> A rep ndo_open or ndo_stop holds rtnl and priv->state_lock. The
> devlink-locked enable path holds neither across this window. If the rep
> reads esw->devcom before the store above, two things can happen:
>
> - mlx5e_sqs2vport_start() snapshots devcom == NULL, so it takes no lock
> and sees peers_ready == false. It then does list_add() into
> rpriv->vport_sqs_list while the PAIR handler is walking that list.
> SQs added after the walk also never get their peer send-to-vport
> rules.
>
> - mlx5e_remove_sqs_fwd_rules() calls mlx5e_sqs2vport_stop() without
> the lock. That can list_del() and kfree() a rep_sq and its sq_peer
> entries while mlx5e_vport_rep_event_pair() is still using them.
>
> These are the two races the commit message describes as fixed.
>
> On teardown, esw_offloads_disable() calls the devcom cleanup while the
> VF rep netdevs are still registered:
>
> mlx5_esw_offloads_devcom_cleanup(esw);
> mlx5_eswitch_disable_pf_vf_vports(esw);
> mlx5_esw_offloads_rep_unload(esw, MLX5_VPORT_UPLINK);
>
> mlx5_esw_offloads_devcom_cleanup() frees the comp_dev before it clears
> the pointer:
>
> mlx5_devcom_unregister_component(esw->devcom);
> xa_destroy(&esw->paired);
> xa_destroy(&esw->fdb_table.offloads.peer_miss_rules);
> esw->devcom = NULL;
>
> Inside mlx5_devcom_unregister_component(), devcom_free_comp_dev() does:
>
> down_write(&comp->sem);
> list_del(&devcom->list);
> WRITE_ONCE(comp->nr_devs, comp->nr_devs - 1);
> up_write(&comp->sem);
>
> kref_put(&devcom->devc->ref, mlx5_devcom_dev_release);
> kfree(devcom);
> kref_put(&comp->ref, mlx5_devcom_comp_release);
>
> The write lock only excludes readers that already hold comp->sem.
>
> Could a concurrent VF rep ndo_stop load the old esw->devcom in
> mlx5e_remove_sqs_fwd_rules() and then call down_read(&devcom->comp->sem)
> after the kfree()? The stop path did not touch esw->devcom before this
> patch, so this use-after-free would be new on the close path.
>
> Would it work better to serialize publishing and clearing esw->devcom
> against rep start/stop, instead of locking whatever pointer happens to be
> read at that moment?
The esw->devcom NULL/stale reads are a devcom lifecycle issue, not
specific to this patch, and will be addressed in a separate patch.
This patch fixes the PAIR/UNPAIR vs. rep start/stop race on an
established devcom.
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112182403.3646298-1-tariqt%40nvidia.com
next prev parent reply other threads:[~2026-11-16 19:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 18:24 [PATCH net V2] net/mlx5e: rep, Fix races between devcom PAIR event and uplink close Tariq Toukan
2026-11-13 15:27 ` netdev-bot+sinfo
2026-11-15 11:26 ` Shay Drory
2026-11-14 15:21 ` sashiko-bot
2026-11-16 18:24 ` netdev-bot+sashiko
2026-11-16 19:52 ` Shay Drory [this message]
2026-11-17 15:20 ` patchwork-bot+netdevbpf
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=20261116195218.1120811-1-shayd@nvidia.com \
--to=shayd@nvidia.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=gal@nvidia.com \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=markzhang@nvidia.com \
--cc=mbloch@nvidia.com \
--cc=moshe@nvidia.com \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=saeedm@nvidia.com \
--cc=tariqt@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.