Skip to content

Commit

Permalink
net/ice: fix link update
Browse files Browse the repository at this point in the history
[ upstream commit 4e5dc111464e83e9a55fa466d8f682f0027b721e ]

The ice_aq_get_link_info function is not thread-safe. However,
it is possible to simultaneous invocations during both the dev_start
and the LSC interrupt handler, potentially leading to unexpected adminq
errors. This patch addresses the issue by introducing a thread-safe
wrapper that utilizes a spinlock.

Fixes: cf911d9 ("net/ice: support link update")

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
Acked-by: Qiming Yang <qiming.yang@intel.com>
  • Loading branch information
qzhan16 authored and kevintraynor committed Mar 5, 2024
1 parent 4f2f83c commit 78c0d6d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
26 changes: 20 additions & 6 deletions drivers/net/ice/ice_ethdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,7 @@ ice_pf_setup(struct ice_pf *pf)
}

pf->main_vsi = vsi;
rte_spinlock_init(&pf->link_lock);

return 0;
}
Expand Down Expand Up @@ -3476,17 +3477,31 @@ ice_rxq_intr_setup(struct rte_eth_dev *dev)
return 0;
}

static enum ice_status
ice_get_link_info_safe(struct ice_pf *pf, bool ena_lse,
struct ice_link_status *link)
{
struct ice_hw *hw = ICE_PF_TO_HW(pf);
int ret;

rte_spinlock_lock(&pf->link_lock);

ret = ice_aq_get_link_info(hw->port_info, ena_lse, link, NULL);

rte_spinlock_unlock(&pf->link_lock);

return ret;
}

static void
ice_get_init_link_status(struct rte_eth_dev *dev)
{
struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
struct ice_link_status link_status;
int ret;

ret = ice_aq_get_link_info(hw->port_info, enable_lse,
&link_status, NULL);
ret = ice_get_link_info_safe(pf, enable_lse, &link_status);
if (ret != ICE_SUCCESS) {
PMD_DRV_LOG(ERR, "Failed to get link info");
pf->init_link_up = false;
Expand Down Expand Up @@ -3841,7 +3856,7 @@ ice_link_update(struct rte_eth_dev *dev, int wait_to_complete)
{
#define CHECK_INTERVAL 50 /* 50ms */
#define MAX_REPEAT_TIME 40 /* 2s (40 * 50ms) in total */
struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
struct ice_link_status link_status;
struct rte_eth_link link, old;
int status;
Expand All @@ -3855,8 +3870,7 @@ ice_link_update(struct rte_eth_dev *dev, int wait_to_complete)

do {
/* Get link status information from hardware */
status = ice_aq_get_link_info(hw->port_info, enable_lse,
&link_status, NULL);
status = ice_get_link_info_safe(pf, enable_lse, &link_status);
if (status != ICE_SUCCESS) {
link.link_speed = RTE_ETH_SPEED_NUM_100M;
link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
Expand Down
4 changes: 4 additions & 0 deletions drivers/net/ice/ice_ethdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ struct ice_pf {
uint64_t old_tx_bytes;
uint64_t supported_rxdid; /* bitmap for supported RXDID */
uint64_t rss_hf;
/* lock prevent race condition between lsc interrupt handler
* and link status update during dev_start.
*/
rte_spinlock_t link_lock;
};

#define ICE_MAX_QUEUE_NUM 2048
Expand Down

0 comments on commit 78c0d6d

Please sign in to comment.