Skip to content

Commit

Permalink
net/sfc: invalidate switch port entry on representor unplug
Browse files Browse the repository at this point in the history
[ upstream commit 723327bed49fb434bfb24b1e4393d5c4db537fda ]

Once allocated, a switch port list entry always stays there,
even after unplugging the ethdev that created it. Currently,
the entry's ethdev ID is not cleared on unplug. Referencing
the ethdev ID of a detached representor from a flow rule is
going to succeed, which is a bug. Also, if the user unplugs
endpoint "A" representor and plugs one for "B" instead, the
latter will pick the same ethdev ID as the gone representor,
but it will have a new port list entry added for it. If the
user tries to reference the ethdev ID from a flow rule, the
code will fetch the wrong entry ("A" rather than "B") since
it sits closer to the list head. That is a serious bug, too.

Make the driver invalidate ethdev ID field on ethdev unplug.

Fixes: 1fb65e4 ("net/sfc: support flow action port ID in transfer rules")
Fixes: a62ec90 ("net/sfc: add port representors infrastructure")

Signed-off-by: Ivan Malov <ivan.malov@arknetworks.am>
Reviewed-by: Andy Moreton <amoreton@xilinx.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
  • Loading branch information
okt-imalov authored and kevintraynor committed Mar 21, 2023
1 parent f5922d3 commit 998d704
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/net/sfc/sfc_repr.c
Expand Up @@ -841,6 +841,8 @@ sfc_repr_dev_close(struct rte_eth_dev *dev)

(void)sfc_repr_proxy_del_port(srs->pf_port_id, srs->repr_id);

sfc_mae_clear_switch_port(srs->switch_domain_id, srs->switch_port_id);

dev->rx_pkt_burst = NULL;
dev->tx_pkt_burst = NULL;
dev->dev_ops = NULL;
Expand Down
12 changes: 12 additions & 0 deletions drivers/net/sfc/sfc_switch.c
Expand Up @@ -489,6 +489,7 @@ sfc_mae_clear_switch_port(uint16_t switch_domain_id,
uint16_t switch_port_id)
{
struct sfc_mae_switch_domain *domain;
struct sfc_mae_switch_port *port;

rte_spinlock_lock(&sfc_mae_switch.lock);

Expand All @@ -504,6 +505,17 @@ sfc_mae_clear_switch_port(uint16_t switch_domain_id,
domain->mae_admin_port = NULL;
}

TAILQ_FOREACH(port, &domain->ports, switch_domain_ports) {
if (port->id == switch_port_id) {
/*
* Invalidate the field to prevent wrong
* look-ups from flow rule handling path.
*/
port->ethdev_port_id = RTE_MAX_ETHPORTS;
break;
}
}

rte_spinlock_unlock(&sfc_mae_switch.lock);
return 0;
}
Expand Down

0 comments on commit 998d704

Please sign in to comment.