From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B924C41E6C for ; Fri, 10 Mar 2023 18:06:55 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B252F4113D; Fri, 10 Mar 2023 18:06:55 +0100 (CET) Received: from agw.arknetworks.am (agw.arknetworks.am [79.141.165.80]) by mails.dpdk.org (Postfix) with ESMTP id 17BD840685; Fri, 10 Mar 2023 18:06:53 +0100 (CET) Received: from localhost.localdomain (unknown [78.109.76.31]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by agw.arknetworks.am (Postfix) with ESMTPSA id 77356E0C66; Fri, 10 Mar 2023 21:06:52 +0400 (+04) From: Ivan Malov To: dev@dpdk.org Cc: Andrew Rybchenko , Ferruh Yigit , stable@dpdk.org, Andy Moreton Subject: [PATCH] net/sfc: invalidate switch port entry on representor unplug Date: Fri, 10 Mar 2023 21:07:17 +0400 Message-Id: <20230310170717.7352-1-ivan.malov@arknetworks.am> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org 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: 1fb65e4dae8a ("net/sfc: support flow action port ID in transfer rules") Fixes: a62ec90522a6 ("net/sfc: add port representors infrastructure") Cc: stable@dpdk.org Signed-off-by: Ivan Malov Reviewed-by: Andy Moreton --- drivers/net/sfc/sfc_repr.c | 2 ++ drivers/net/sfc/sfc_switch.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/drivers/net/sfc/sfc_repr.c b/drivers/net/sfc/sfc_repr.c index 291860ec56..b3a41167fb 100644 --- a/drivers/net/sfc/sfc_repr.c +++ b/drivers/net/sfc/sfc_repr.c @@ -837,6 +837,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; diff --git a/drivers/net/sfc/sfc_switch.c b/drivers/net/sfc/sfc_switch.c index 5c10e8fc74..8f1ee97fa8 100644 --- a/drivers/net/sfc/sfc_switch.c +++ b/drivers/net/sfc/sfc_switch.c @@ -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); @@ -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; } -- 2.17.1