Skip to content

Commit

Permalink
net/hns3: fix crash with multi-process
Browse files Browse the repository at this point in the history
[ upstream commit 6b978ea ]

In current version, procedure of saving eth_dev in
hns3 PMD init will be called more than twice, one
for primary, the other for secondary. That will cause
segmentation fault in Multi-process as eth_dev will
be changed in secondary process, which is different
from one in primary process.

The initial problem was access to 'rte_eth_devices'
global variable, which is wrong. But current approach
can cause problem for the secondaries, moving 'eth_dev'
to process private can work but before making things
more complex.

This patch deserted the procedure of saving eth_dev in
hns3 PMD init. Instead, it creates an internal function
that gets "struct hns3_hw" as parameter and it can be
called internally without knowing 'eth_dev'and the
.dev_ops can be wrapper to this.

Fixes: 2390bf2 ("net/hns3: fix FEC state query")

Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
Signed-off-by: Lijun Ou <oulijun@huawei.com>
  • Loading branch information
hushenggitcount authored and bluca committed Feb 4, 2021
1 parent c8f0d15 commit 708ae01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 10 additions & 6 deletions drivers/net/hns3/hns3_ethdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -5812,10 +5812,9 @@ get_current_fec_auto_state(struct hns3_hw *hw, uint8_t *state)
}

static int
hns3_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa)
hns3_fec_get_internal(struct hns3_hw *hw, uint32_t *fec_capa)
{
#define QUERY_ACTIVE_SPEED 1
struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
struct hns3_sfp_speed_cmd *resp;
uint32_t tmp_fec_capa;
uint8_t auto_state;
Expand Down Expand Up @@ -5875,6 +5874,14 @@ hns3_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa)
return 0;
}

static int
hns3_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa)
{
struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);

return hns3_fec_get_internal(hw, fec_capa);
}

static int
hns3_set_fec_hw(struct hns3_hw *hw, uint32_t mode)
{
Expand Down Expand Up @@ -6008,10 +6015,9 @@ hns3_query_dev_fec_info(struct hns3_hw *hw)
{
struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(hns);
struct rte_eth_dev *eth_dev = hns->eth_dev;
int ret;

ret = hns3_fec_get(eth_dev, &pf->fec_mode);
ret = hns3_fec_get_internal(hw, &pf->fec_mode);
if (ret)
hns3_err(hw, "query device FEC info failed, ret = %d", ret);

Expand Down Expand Up @@ -6097,8 +6103,6 @@ hns3_dev_init(struct rte_eth_dev *eth_dev)

PMD_INIT_FUNC_TRACE();

hns->eth_dev = eth_dev;

eth_dev->process_private = (struct hns3_process_private *)
rte_zmalloc_socket("hns3_filter_list",
sizeof(struct hns3_process_private),
Expand Down
2 changes: 0 additions & 2 deletions drivers/net/hns3/hns3_ethdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,6 @@ struct hns3_adapter {
struct hns3_vf vf;
};

struct rte_eth_dev *eth_dev;

bool rx_simple_allowed;
bool rx_vec_allowed;
bool tx_simple_allowed;
Expand Down

0 comments on commit 708ae01

Please sign in to comment.