ice_eswitch_mode_set() refuses a mode change only while VFs exist, but a subfunction port has a representor and a switchdev session too. devlink core usually refuses the change first, because of the devlink rate nodes 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. Refuse the mode change while the representor xarray is not empty. Found by AI code review. Reproduced on an E810-C (FW 8.1.1, ICE COMMS package 1.3.55.0) with the firmware LLDP agent off, without kernel changes: dcb ets set dev $PF tc-tsa all:ets tc-bw 0:50 1:50 prio-tc 1:1 devlink dev eswitch set pci/$BDF mode switchdev devlink port add pci/$BDF flavour pcisf pfnum 0 sfnum 88 devlink dev eswitch set pci/$BDF mode legacy The last command succeeded, the representor netdev stayed registered and promisc off no longer took effect on the PF. With this patch the command fails with "Remove all subfunction ports before changing eswitch mode". No kernel selftests cover this. Fixes: 977514fb0fa8 ("ice: create port representor for SF") Signed-off-by: Petr Oros --- v5: - New patch. Without it a switch to legacy can orphan a switchdev session, and patch 3 resyncs the uplink only when a session ends. --- drivers/net/ethernet/intel/ice/ice_eswitch.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/ethernet/intel/ice/ice_eswitch.c b/drivers/net/ethernet/intel/ice/ice_eswitch.c index 6e7bba4738989b..c96b201901f48c 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)) { + NL_SET_ERR_MSG_MOD(extack, + "Remove all subfunction ports before changing eswitch mode"); + return -EOPNOTSUPP; + } + switch (mode) { case DEVLINK_ESWITCH_MODE_LEGACY: dev_info(ice_pf_to_dev(pf), "PF %d changed eswitch mode to legacy", -- 2.56.1