From: Petr Oros <poros@redhat.com>
To: netdev@vger.kernel.org
Cc: Petr Oros <poros@redhat.com>,
Tony Nguyen <anthony.l.nguyen@intel.com>,
Przemek Kitszel <przemyslaw.kitszel@intel.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Aleksandr Loktionov <aleksandr.loktionov@intel.com>,
Simon Horman <horms@kernel.org>,
Michal Swiatkowski <michal.swiatkowski@linux.intel.com>,
Grzegorz Nitka <grzegorz.nitka@intel.com>,
Paul Menzel <pmenzel@molgen.mpg.de>,
Wojciech Drewek <wojciech.drewek@intel.com>,
Marcin Szycik <marcin.szycik@linux.intel.com>,
Martyna Szapar-Mudlaw <martyna.szapar-mudlaw@linux.intel.com>,
Ivan Vecera <ivecera@redhat.com>,
Alice Michael <alice.michael@intel.com>,
Jacob Keller <jacob.e.keller@intel.com>,
Jesse Brandeburg <jbrandeb@kernel.org>,
Patryk Holda <patryk.holda@intel.com>,
Rinitha S <sx.rinitha@intel.com>,
Aaron Ma <aaron.ma@canonical.com>,
intel-wired-lan@lists.osuosl.org, linux-kernel@vger.kernel.org
Subject: [PATCH net v6 2/4] ice: do not leave switchdev mode while subfunction ports exist
Date: Mon, 30 Nov 2026 14:21:04 +0100 [thread overview]
Message-ID: <20261130132107.1177185-3-poros@redhat.com> (raw)
In-Reply-To: <20261130132107.1177185-1-poros@redhat.com>
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 and the uplink stays in its switchdev configuration. Deleting
the SF port afterwards frees its devlink port while it stays
registered, so a later devlink port dump reads freed memory.
Refuse the switch to legacy while subfunction ports exist. Check
pf->dyn_ports, which only changes under the devlink instance lock held
here, while ice_sf_dev_probe() can change the representor xarray
without it.
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. Deleting the SF
port then returned 0 and the next devlink port list read its freed
devlink port, KASAN reported a slab use after free in
devlink_nl_port_fill(). With this patch the mode switch fails with
"Remove all subfunction ports before changing eswitch mode", after
the SF port is deleted it succeeds, and promisc off takes effect
again. No kernel selftests cover this.
Fixes: 977514fb0fa8 ("ice: create port representor for SF")
Signed-off-by: Petr Oros <poros@redhat.com>
---
v6:
- Check pf->dyn_ports instead of the representor xarray, which
ice_sf_dev_probe() can change without the devlink lock of the PF.
- Refuse only the switch to legacy, so an unknown mode gets "Unknown
eswitch mode" again.
- The message says what deleting the SF port does after such a switch
and names the use after free that the devlink port dump then hits.
- New title, was "ice: do not leave switchdev mode while representors
exist".
- Dropped Ivan's Reviewed-by because the check changed.
All after the Sashiko review of v5.
v5: https://lore.kernel.org/all/20261127085714.1207361-3-poros@redhat.com/
---
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..44ef1fcfc6e4a5 100644
--- a/drivers/net/ethernet/intel/ice/ice_eswitch.c
+++ b/drivers/net/ethernet/intel/ice/ice_eswitch.c
@@ -356,6 +356,13 @@ ice_eswitch_mode_set(struct devlink *devlink, u16 mode,
switch (mode) {
case DEVLINK_ESWITCH_MODE_LEGACY:
+ /* subfunction ports have representors too */
+ if (!xa_empty(&pf->dyn_ports)) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Remove all subfunction ports before changing eswitch mode");
+ return -EOPNOTSUPP;
+ }
+
dev_info(ice_pf_to_dev(pf), "PF %d changed eswitch mode to legacy",
pf->hw.pf_id);
xa_destroy(&pf->eswitch.reprs);
--
2.56.1
next prev parent reply other threads:[~2026-11-30 13:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 13:21 [PATCH net v6 0/4] ice: fix DFLT Rx rule handling for promisc and switchdev Petr Oros
2026-11-30 13:21 ` [PATCH net v6 1/4] ice: stop the service task before the PF is unloaded Petr Oros
2026-11-30 13:21 ` Petr Oros [this message]
2026-11-30 13:21 ` [PATCH net v6 3/4] ice: resync uplink filters after a switchdev session Petr Oros
2026-11-30 13:21 ` [PATCH net v6 4/4] ice: use a VLAN agnostic multicast promisc rule pair for PF VSIs Petr Oros
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=20261130132107.1177185-3-poros@redhat.com \
--to=poros@redhat.com \
--cc=aaron.ma@canonical.com \
--cc=aleksandr.loktionov@intel.com \
--cc=alice.michael@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=anthony.l.nguyen@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=grzegorz.nitka@intel.com \
--cc=horms@kernel.org \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=ivecera@redhat.com \
--cc=jacob.e.keller@intel.com \
--cc=jbrandeb@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcin.szycik@linux.intel.com \
--cc=martyna.szapar-mudlaw@linux.intel.com \
--cc=michal.swiatkowski@linux.intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=patryk.holda@intel.com \
--cc=pmenzel@molgen.mpg.de \
--cc=przemyslaw.kitszel@intel.com \
--cc=sx.rinitha@intel.com \
--cc=wojciech.drewek@intel.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