Re: [PATCH net v5 2/4] ice: do not leave switchdev mode while representors exist
From: netdev-bot+sashiko
Date: Sat Nov 28 2026 - 04:30:42 EST
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 3
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).
- [Medium] The new `xa_empty(&pf->eswitch.reprs)` check in
ice_eswitch_mode_set() is protected only by the PF devlink lock, which…
- [Low] The commit message understates what this patch fixes.
- [Low] In ice_eswitch_mode_set(), the new
`!xa_empty(&pf->eswitch.reprs)` check (ice_eswitch.c:358) runs before…
- [Low] The new gate checks whether pf->eswitch.reprs is empty, not
whether SF ports exist.
--
ice: do not leave switchdev mode while representors exist
This patch makes ice_eswitch_mode_set() refuse an eswitch mode change
while the representor xarray is not empty. Before the patch, switching to
legacy mode with DCB active could destroy the xarray under a running
switchdev session that still had a subfunction port representor.
> the representors export, but ice exports none while DCB is active. A
> switch to legacy then destroys the representor xarray under the running
> session, the representors leak, and the uplink stays in its switchdev
> configuration.
[Severity: Low]
Does "the representors leak" describe the whole consequence? Before this
patch, the later SF port deletion looks like it ends in a use-after-free
of dyn_port.
Once the switch to legacy has run xa_destroy(&pf->eswitch.reprs), a
devlink port del on the SF port goes through
ice_devlink_port_del()->ice_dealloc_dynamic_port(), which calls:
drivers/net/ethernet/intel/ice/ice_eswitch.c:ice_eswitch_detach_sf() {
struct ice_repr *repr = xa_load(&pf->eswitch.reprs, sf->repr_id);
if (!repr)
return;
...
}
So ice_repr_rem_sf() never runs. That means neither
unregister_netdev(repr->netdev) nor
ice_devlink_destroy_sf_port()->devl_port_unregister() is called.
ice_dealloc_dynamic_port() then does:
ice_eswitch_detach_sf(pf, dyn_port);
xa_erase(&pf->dyn_ports, dyn_port->vsi->idx);
ice_vsi_free(dyn_port->vsi);
kfree(dyn_port);
The embedded dyn_port->devlink_port is still registered in devlink->ports.
The representor netdev is also still registered, and it keeps pointers
into the freed dyn_port: repr->sf, and the devlink port set through
SET_NETDEV_DEVLINK_PORT(). Driver removal takes the same path through
ice_remove()->ice_dealloc_all_dynamic_ports().
The code change closes this path. Could the commit message mention the
use-after-free, so stable and CVE triage can weigh the fix correctly?
> diff --git a/drivers/net/ethernet/intel/ice/ice_eswitch.c b/drivers/net/ethernet/intel/ice/ice_eswitch.c
> index 6e7bba4738989..c96b201901f48 100644
> --- a/drivers/net/ethernet/intel/ice/ice_eswitch.c
> +++ b/drivers/net/ethernet/intel/ice/ice_eswitch.c
> @@ -354,6 +354,13 @@ ice_eswitch_mode_set(struct devlink *devlink, u16 mode,
> return -EOPNOTSUPP;
> }
>
> + /* subfunction ports have representors too */
> + if (!xa_empty(&pf->eswitch.reprs)) {
[Severity: Medium]
Is the result of xa_empty(&pf->eswitch.reprs) stable under the lock held
here? devlink core holds only the PF devlink lock around
ice_eswitch_mode_set(). However, ice_eswitch_update_repr() changes the
same xarray from ice_sf_dev_probe(), and that path holds only the SF's
own devlink lock:
drivers/net/ethernet/intel/ice/ice_sf_eth.c:ice_sf_dev_probe() {
...
devlink = priv_to_devlink(priv);
devl_lock(devlink);
err = ice_vsi_cfg(vsi);
...
ice_eswitch_update_repr(&dyn_port->repr_id, vsi);
...
}
drivers/net/ethernet/intel/ice/ice_eswitch.c:ice_eswitch_update_repr() {
...
if (repr->id != vsi->vsi_num) {
xa_erase(&pf->eswitch.reprs, repr->id);
repr->id = vsi->vsi_num;
if (xa_insert(&pf->eswitch.reprs, repr->id, repr, GFP_KERNEL))
...
}
ice_sf_dev_remove() does not delete the hardware VSI. So if the ice.sf.N
auxiliary device is unbound and then rebound through sysfs, ice_vsi_cfg()
runs with ICE_VSI_FLAG_INIT and allocates a new VSI number. That takes
the erase/insert branch above.
With a single SF representor and no VFs, can a concurrent eswitch mode
change see the xarray empty between the erase and the insert?
CPU1 (SF rebind, SF devlink lock only)
ice_eswitch_update_repr()
xa_erase(&pf->eswitch.reprs, old_id);
CPU2 (PF devlink lock held)
ice_eswitch_mode_set(LEGACY)
!xa_empty(&pf->eswitch.reprs) is false, check passes
xa_destroy(&pf->eswitch.reprs);
pf->eswitch_mode = mode;
CPU1
xa_insert(&pf->eswitch.reprs, new_id, repr, GFP_KERNEL);
The result is legacy mode with a live SF representor, and
pf->eswitch.is_running stays true because ice_eswitch_disable_switchdev()
is never called. The uplink keeps its switchdev configuration until the
SF port is deleted. This same check then refuses a switch back to
switchdev.
Would checking pf->dyn_ports instead close this? Its writers,
ice_alloc_dynamic_port() and ice_dealloc_dynamic_port(), run under the PF
devlink lock, so they would be serialized with mode_set.
[Severity: Low]
A related case: if that xa_insert() fails, ice_eswitch_update_repr() only
logs an error:
if (xa_insert(&pf->eswitch.reprs, repr->id, repr, GFP_KERNEL))
dev_err(ice_pf_to_dev(pf), "Failed to reload port representor %d",
repr->id);
If that was the only SF representor, pf->eswitch.reprs is now empty. The
SF devlink port is still in pf->dyn_ports, and pf->eswitch.is_running is
still true.
Would ice_eswitch_mode_set(LEGACY) then pass both ice_has_vfs() and the
new xa_empty() check? If so, it would run xa_destroy() and switch to
legacy without calling ice_eswitch_disable_switchdev(), leaving the same
orphaned session this patch is meant to prevent.
The dropped-entry handling in ice_eswitch_update_repr() predates this
patch, but a check on pf->dyn_ports would also cover this case.
> + NL_SET_ERR_MSG_MOD(extack,
> + "Remove all subfunction ports before changing eswitch mode");
> + return -EOPNOTSUPP;
> + }
> +
> switch (mode) {
[Severity: Low]
Should the requested mode be validated before the representor check? The
devlink policy accepts DEVLINK_ATTR_ESWITCH_MODE values up to 2
(NLA_POLICY_MAX(NLA_U16, 2) in net/devlink/netlink_gen.c). So
DEVLINK_ESWITCH_MODE_SWITCHDEV_INACTIVE reaches the driver, and ice
rejects it only in the default branch:
default:
NL_SET_ERR_MSG_MOD(extack, "Unknown eswitch mode");
return -EINVAL;
With the PF in switchdev mode and an SF port present, a switchdev_inactive
request now fails with -EOPNOTSUPP and "Remove all subfunction ports
before changing eswitch mode". If the SF ports are removed as the message
says, the retry still fails, this time with -EINVAL.
The existing ice_has_vfs() check has the same ordering, but this patch
adds a new path that reports the wrong reason. Would it be better to
validate the mode first, or to apply the representor check only to
supported transitions?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127085714.1207361-1-poros%40redhat.com