Skip to content

Commit

Permalink
net/i40e: fix multi-process shared data
Browse files Browse the repository at this point in the history
[ upstream commit e391a7b ]

The rte_eth_devices array is not in share memory, it should not be
referenced by i40e_adapter which is shared by primary and secondary.
Any process set i40e_adapter->eth_dev will corrupt another process's
context.

The patch removed the field "eth_dev" from i40e_adapter.
Now, when the data paths try to access the rte_eth_dev_data instance,
they should replace adapter->eth_dev->data with adapter->pf.dev_data.

Fixes: 4861cde ("i40e: new poll mode driver")

Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
Acked-by: Qi Zhang <qi.z.zhang@intel.com>
  • Loading branch information
yudapengx authored and bluca committed Jul 12, 2021
1 parent 5299dc3 commit 37a61f4
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 47 deletions.
44 changes: 22 additions & 22 deletions drivers/net/i40e/i40e_ethdev.c
Expand Up @@ -727,10 +727,11 @@ i40e_write_global_rx_ctl(struct i40e_hw *hw, uint32_t reg_addr,
uint32_t reg_val)
{
uint32_t ori_reg_val;
struct rte_eth_dev *dev;
struct rte_eth_dev_data *dev_data =
((struct i40e_adapter *)hw->back)->pf.dev_data;
struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];

ori_reg_val = i40e_read_rx_ctl(hw, reg_addr);
dev = ((struct i40e_adapter *)hw->back)->eth_dev;
i40e_write_rx_ctl(hw, reg_addr, reg_val);
if (ori_reg_val != reg_val)
PMD_DRV_LOG(WARNING,
Expand Down Expand Up @@ -1321,7 +1322,9 @@ i40e_aq_debug_write_global_register(struct i40e_hw *hw,
struct i40e_asq_cmd_details *cmd_details)
{
uint64_t ori_reg_val;
struct rte_eth_dev *dev;
struct rte_eth_dev_data *dev_data =
((struct i40e_adapter *)hw->back)->pf.dev_data;
struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
int ret;

ret = i40e_aq_debug_read_register(hw, reg_addr, &ori_reg_val, NULL);
Expand All @@ -1331,7 +1334,6 @@ i40e_aq_debug_write_global_register(struct i40e_hw *hw,
reg_addr);
return -EIO;
}
dev = ((struct i40e_adapter *)hw->back)->eth_dev;

if (ori_reg_val != reg_val)
PMD_DRV_LOG(WARNING,
Expand Down Expand Up @@ -1506,7 +1508,6 @@ eth_i40e_dev_init(struct rte_eth_dev *dev, void *init_params __rte_unused)
dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;

pf->adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
pf->adapter->eth_dev = dev;
pf->dev_data = dev->data;

hw->back = I40E_PF_TO_ADAPTER(pf);
Expand Down Expand Up @@ -2039,7 +2040,7 @@ i40e_dev_configure(struct rte_eth_dev *dev)
void
i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
{
struct rte_eth_dev *dev = vsi->adapter->eth_dev;
struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
Expand Down Expand Up @@ -2155,7 +2156,7 @@ __vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t msix_vect,
int
i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t itr_idx)
{
struct rte_eth_dev *dev = vsi->adapter->eth_dev;
struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
Expand Down Expand Up @@ -2231,7 +2232,7 @@ i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t itr_idx)
void
i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
{
struct rte_eth_dev *dev = vsi->adapter->eth_dev;
struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
Expand All @@ -2258,7 +2259,7 @@ i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
void
i40e_vsi_disable_queues_intr(struct i40e_vsi *vsi)
{
struct rte_eth_dev *dev = vsi->adapter->eth_dev;
struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
Expand Down Expand Up @@ -6472,8 +6473,7 @@ i40e_dev_tx_init(struct i40e_pf *pf)
break;
}
if (ret == I40E_SUCCESS)
i40e_set_tx_function(container_of(pf, struct i40e_adapter, pf)
->eth_dev);
i40e_set_tx_function(&rte_eth_devices[pf->dev_data->port_id]);

return ret;
}
Expand Down Expand Up @@ -6501,8 +6501,7 @@ i40e_dev_rx_init(struct i40e_pf *pf)
}
}
if (ret == I40E_SUCCESS)
i40e_set_rx_function(container_of(pf, struct i40e_adapter, pf)
->eth_dev);
i40e_set_rx_function(&rte_eth_devices[pf->dev_data->port_id]);

return ret;
}
Expand Down Expand Up @@ -7941,7 +7940,7 @@ i40e_status_code i40e_replace_mpls_l1_filter(struct i40e_pf *pf)
struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
struct i40e_hw *hw = I40E_PF_TO_HW(pf);
struct rte_eth_dev *dev = ((struct i40e_adapter *)hw->back)->eth_dev;
struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
enum i40e_status_code status = I40E_SUCCESS;

if (pf->support_multi_driver) {
Expand Down Expand Up @@ -8002,7 +8001,7 @@ i40e_status_code i40e_replace_mpls_cloud_filter(struct i40e_pf *pf)
struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
struct i40e_hw *hw = I40E_PF_TO_HW(pf);
struct rte_eth_dev *dev = ((struct i40e_adapter *)hw->back)->eth_dev;
struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
enum i40e_status_code status = I40E_SUCCESS;

if (pf->support_multi_driver) {
Expand Down Expand Up @@ -8077,7 +8076,7 @@ i40e_replace_gtp_l1_filter(struct i40e_pf *pf)
struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
struct i40e_hw *hw = I40E_PF_TO_HW(pf);
struct rte_eth_dev *dev = ((struct i40e_adapter *)hw->back)->eth_dev;
struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
enum i40e_status_code status = I40E_SUCCESS;

if (pf->support_multi_driver) {
Expand Down Expand Up @@ -8165,7 +8164,7 @@ i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
struct i40e_hw *hw = I40E_PF_TO_HW(pf);
struct rte_eth_dev *dev = ((struct i40e_adapter *)hw->back)->eth_dev;
struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
enum i40e_status_code status = I40E_SUCCESS;

if (pf->support_multi_driver) {
Expand Down Expand Up @@ -8240,7 +8239,7 @@ i40e_replace_port_l1_filter(struct i40e_pf *pf,
struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
enum i40e_status_code status = I40E_SUCCESS;
struct i40e_hw *hw = I40E_PF_TO_HW(pf);
struct rte_eth_dev *dev = ((struct i40e_adapter *)hw->back)->eth_dev;
struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];

if (pf->support_multi_driver) {
PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
Expand Down Expand Up @@ -8312,7 +8311,7 @@ i40e_replace_port_cloud_filter(struct i40e_pf *pf,
struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
enum i40e_status_code status = I40E_SUCCESS;
struct i40e_hw *hw = I40E_PF_TO_HW(pf);
struct rte_eth_dev *dev = ((struct i40e_adapter *)hw->back)->eth_dev;
struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];

if (pf->support_multi_driver) {
PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
Expand Down Expand Up @@ -9646,9 +9645,10 @@ void
i40e_check_write_global_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
{
uint32_t reg = i40e_read_rx_ctl(hw, addr);
struct rte_eth_dev *dev;
struct rte_eth_dev_data *dev_data =
((struct i40e_adapter *)hw->back)->pf.dev_data;
struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];

dev = ((struct i40e_adapter *)hw->back)->eth_dev;
if (reg != val) {
i40e_write_rx_ctl(hw, addr, val);
PMD_DRV_LOG(WARNING,
Expand Down Expand Up @@ -12493,7 +12493,7 @@ i40e_cloud_filter_qinq_create(struct i40e_pf *pf)
struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
struct i40e_hw *hw = I40E_PF_TO_HW(pf);
struct rte_eth_dev *dev = ((struct i40e_adapter *)hw->back)->eth_dev;
struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];

if (pf->support_multi_driver) {
PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
Expand Down
7 changes: 4 additions & 3 deletions drivers/net/i40e/i40e_ethdev.h
Expand Up @@ -88,8 +88,10 @@
do { \
uint32_t ori_val; \
struct rte_eth_dev *dev; \
struct rte_eth_dev_data *dev_data; \
ori_val = I40E_READ_REG((hw), (reg)); \
dev = ((struct i40e_adapter *)hw->back)->eth_dev; \
dev_data = ((struct i40e_adapter *)hw->back)->pf.dev_data; \
dev = &rte_eth_devices[dev_data->port_id]; \
I40E_PCI_REG_WRITE(I40E_PCI_REG_ADDR((hw), \
(reg)), (value)); \
if (ori_val != value) \
Expand Down Expand Up @@ -1264,7 +1266,6 @@ struct i40e_vf {
struct i40e_adapter {
/* Common for both PF and VF */
struct i40e_hw hw;
struct rte_eth_dev *eth_dev;

/* Specific for PF or VF */
union {
Expand Down Expand Up @@ -1514,7 +1515,7 @@ i40e_get_vsi_from_adapter(struct i40e_adapter *adapter)
#define I40E_VSI_TO_DEV_DATA(vsi) \
(((struct i40e_vsi *)vsi)->adapter->pf.dev_data)
#define I40E_VSI_TO_ETH_DEV(vsi) \
(((struct i40e_vsi *)vsi)->adapter->eth_dev)
(&rte_eth_devices[((struct i40e_vsi *)vsi)->adapter->pf.dev_data->port_id])

/* I40E_PF_TO */
#define I40E_PF_TO_HW(pf) \
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/i40e/i40e_fdir.c
Expand Up @@ -159,7 +159,7 @@ i40e_fdir_setup(struct i40e_pf *pf)
int err = I40E_SUCCESS;
char z_name[RTE_MEMZONE_NAMESIZE];
const struct rte_memzone *mz = NULL;
struct rte_eth_dev *eth_dev = pf->adapter->eth_dev;
struct rte_eth_dev *eth_dev = &rte_eth_devices[pf->dev_data->port_id];
uint16_t i;

if ((pf->flags & I40E_FLAG_FDIR) == 0) {
Expand Down Expand Up @@ -283,7 +283,7 @@ i40e_fdir_teardown(struct i40e_pf *pf)
{
struct i40e_hw *hw = I40E_PF_TO_HW(pf);
struct i40e_vsi *vsi;
struct rte_eth_dev *dev = pf->adapter->eth_dev;
struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];

vsi = pf->fdir.fdir_vsi;
if (!vsi)
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/i40e/i40e_flow.c
Expand Up @@ -5458,7 +5458,7 @@ i40e_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error)
static int
i40e_flow_flush_fdir_filter(struct i40e_pf *pf)
{
struct rte_eth_dev *dev = pf->adapter->eth_dev;
struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
struct i40e_fdir_info *fdir_info = &pf->fdir;
struct i40e_fdir_filter *fdir_filter;
enum i40e_filter_pctype pctype;
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/i40e/i40e_rxtx.c
Expand Up @@ -2952,7 +2952,7 @@ i40e_fdir_setup_tx_resources(struct i40e_pf *pf)
return I40E_ERR_BAD_PTR;
}

dev = pf->adapter->eth_dev;
dev = &rte_eth_devices[pf->dev_data->port_id];

/* Allocate the TX queue data structure. */
txq = rte_zmalloc_socket("i40e fdir tx queue",
Expand Down Expand Up @@ -3010,7 +3010,7 @@ i40e_fdir_setup_rx_resources(struct i40e_pf *pf)
return I40E_ERR_BAD_PTR;
}

dev = pf->adapter->eth_dev;
dev = &rte_eth_devices[pf->dev_data->port_id];

/* Allocate the RX queue data structure. */
rxq = rte_zmalloc_socket("i40e fdir rx queue",
Expand Down

0 comments on commit 37a61f4

Please sign in to comment.