[PATCH v1 7/7] net/iavf: do not store ethdev pointer
Anatoly Burakov
anatoly.burakov at intel.com
Wed Oct 14 17:18:50 CEST 2026
We should not be storing rte_eth_dev pointers in shared memory, because
rte_eth_dev pointers are process local. To address that, remove the pointer
from iavf_info, replace it with `rte_eth_devices`-based lookup, and rework
the call paths to either use that lookup, or not require ethdev pointer
in the first place.
Signed-off-by: Anatoly Burakov <anatoly.burakov at intel.com>
---
drivers/net/intel/iavf/iavf.h | 9 ++++++--
drivers/net/intel/iavf/iavf_ethdev.c | 13 ++++++------
drivers/net/intel/iavf/iavf_ipsec_crypto.c | 24 +++++++++++-----------
drivers/net/intel/iavf/iavf_ipsec_crypto.h | 4 ++--
drivers/net/intel/iavf/iavf_vchnl.c | 7 ++++---
5 files changed, 31 insertions(+), 26 deletions(-)
diff --git a/drivers/net/intel/iavf/iavf.h b/drivers/net/intel/iavf/iavf.h
index c40b97444b5..1f277eeee29 100644
--- a/drivers/net/intel/iavf/iavf.h
+++ b/drivers/net/intel/iavf/iavf.h
@@ -7,6 +7,7 @@
#include <sys/queue.h>
+#include <ethdev_driver.h>
#include <rte_kvargs.h>
#include <rte_tm_driver.h>
@@ -293,8 +294,6 @@ struct iavf_info {
struct iavf_qtc_map *qtc_map;
struct iavf_tm_conf tm_conf;
- struct rte_eth_dev *eth_dev;
-
RTE_ATOMIC(bool)in_reset_recovery;
bool reset_pending;
bool pf_reset_in_progress;
@@ -408,6 +407,12 @@ struct iavf_adapter {
uint16_t tpid; /* VLAN tag identifier */
};
+static inline struct rte_eth_dev *
+iavf_get_eth_dev(struct iavf_adapter *adapter)
+{
+ return &rte_eth_devices[adapter->dev_data->port_id];
+}
+
/* IAVF_DEV_PRIVATE_TO */
#define IAVF_DEV_PRIVATE_TO_ADAPTER(adapter) \
((struct iavf_adapter *)adapter)
diff --git a/drivers/net/intel/iavf/iavf_ethdev.c b/drivers/net/intel/iavf/iavf_ethdev.c
index 6cf12ec34f1..76c51e7c25b 100644
--- a/drivers/net/intel/iavf/iavf_ethdev.c
+++ b/drivers/net/intel/iavf/iavf_ethdev.c
@@ -326,6 +326,7 @@ static void
iavf_dev_watchdog(void *cb_arg)
{
struct iavf_adapter *adapter = cb_arg;
+ struct rte_eth_dev *dev = iavf_get_eth_dev(adapter);
struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
int vfr_inprogress = 0, rc = 0;
@@ -339,7 +340,7 @@ iavf_dev_watchdog(void *cb_arg)
if (!vfr_inprogress) {
PMD_DRV_LOG(INFO, "VF \"%s\" reset has completed",
- adapter->vf.eth_dev->data->name);
+ dev->data->name);
adapter->vf.vf_reset = false;
iavf_set_no_poll(adapter, false);
}
@@ -350,14 +351,14 @@ iavf_dev_watchdog(void *cb_arg)
if (vfr_inprogress) {
PMD_DRV_LOG(INFO,
"VF \"%s\" reset event detected by watchdog",
- adapter->vf.eth_dev->data->name);
+ dev->data->name);
/* enter reset state with VFLR event */
adapter->vf.vf_reset = true;
iavf_set_no_poll(adapter, false);
adapter->vf.link_up = false;
- iavf_dev_event_post(adapter->vf.eth_dev, RTE_ETH_EVENT_INTR_RESET,
+ iavf_dev_event_post(dev, RTE_ETH_EVENT_INTR_RESET,
NULL, 0);
}
}
@@ -365,11 +366,11 @@ iavf_dev_watchdog(void *cb_arg)
if (adapter->devargs.watchdog_period) {
/* re-alarm watchdog */
rc = rte_eal_alarm_set(adapter->devargs.watchdog_period,
- &iavf_dev_watchdog, cb_arg);
+ &iavf_dev_watchdog, dev);
if (rc)
PMD_DRV_LOG(ERR, "Failed \"%s\" to reset device watchdog alarm",
- adapter->vf.eth_dev->data->name);
+ dev->data->name);
}
}
@@ -2674,8 +2675,6 @@ iavf_init_vf(struct rte_eth_dev *dev)
struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
- vf->eth_dev = dev;
-
err = iavf_parse_devargs(dev);
if (err) {
PMD_INIT_LOG(ERR, "Failed to parse devargs");
diff --git a/drivers/net/intel/iavf/iavf_ipsec_crypto.c b/drivers/net/intel/iavf/iavf_ipsec_crypto.c
index cd13e14ae74..8056c889cb1 100644
--- a/drivers/net/intel/iavf/iavf_ipsec_crypto.c
+++ b/drivers/net/intel/iavf/iavf_ipsec_crypto.c
@@ -689,11 +689,9 @@ iavf_ipsec_crypto_session_create(void *device,
* returns: 1 if valid
*/
uint32_t
-iavf_ipsec_crypto_action_valid(struct rte_eth_dev *ethdev,
+iavf_ipsec_crypto_action_valid(struct iavf_adapter *adapter,
const struct rte_security_session *session, uint32_t spi)
{
- struct iavf_adapter *adapter =
- IAVF_DEV_PRIVATE_TO_ADAPTER(ethdev->data->dev_private);
const struct iavf_security_session *sess = (const void *)session->driver_priv_data;
/* verify we have a valid session and that it belong to this adapter */
@@ -1502,24 +1500,25 @@ static struct rte_security_ops iavf_ipsec_crypto_ops = {
int
iavf_security_ctx_create(struct iavf_adapter *adapter)
{
+ struct rte_eth_dev *dev = iavf_get_eth_dev(adapter);
struct rte_security_ctx *sctx;
sctx = rte_malloc("security_ctx", sizeof(struct rte_security_ctx), 0);
if (sctx == NULL)
return -ENOMEM;
- sctx->device = adapter->vf.eth_dev;
+ sctx->device = dev;
sctx->ops = &iavf_ipsec_crypto_ops;
sctx->sess_cnt = 0;
- adapter->vf.eth_dev->security_ctx = sctx;
+ dev->security_ctx = sctx;
if (adapter->security_ctx == NULL) {
adapter->security_ctx = rte_malloc("iavf_security_ctx",
sizeof(struct iavf_security_ctx), 0);
if (adapter->security_ctx == NULL) {
- rte_free(adapter->vf.eth_dev->security_ctx);
- adapter->vf.eth_dev->security_ctx = NULL;
+ rte_free(dev->security_ctx);
+ dev->security_ctx = NULL;
return -ENOMEM;
}
}
@@ -1565,7 +1564,8 @@ iavf_security_get_pkt_md_offset(struct iavf_adapter *adapter)
int
iavf_security_ctx_destroy(struct iavf_adapter *adapter)
{
- struct rte_security_ctx *sctx = adapter->vf.eth_dev->security_ctx;
+ struct rte_eth_dev *dev = iavf_get_eth_dev(adapter);
+ struct rte_security_ctx *sctx = dev->security_ctx;
struct iavf_security_ctx *iavf_sctx = adapter->security_ctx;
if (iavf_sctx == NULL)
@@ -1578,7 +1578,7 @@ iavf_security_ctx_destroy(struct iavf_adapter *adapter)
rte_free(sctx);
adapter->security_ctx = NULL;
- adapter->vf.eth_dev->security_ctx = NULL;
+ dev->security_ctx = NULL;
return 0;
}
@@ -1748,7 +1748,7 @@ parse_udp_item(const struct rte_flow_item_udp *item, struct rte_udp_hdr *udp)
}
static struct iavf_ipsec_flow_item *
-iavf_ipsec_flow_item_parse(struct rte_eth_dev *ethdev,
+iavf_ipsec_flow_item_parse(struct iavf_adapter *adapter,
const struct rte_flow_item pattern[],
const struct rte_security_session *session,
uint32_t type)
@@ -1819,7 +1819,7 @@ iavf_ipsec_flow_item_parse(struct rte_eth_dev *ethdev,
goto flow_cleanup;
}
- if (!iavf_ipsec_crypto_action_valid(ethdev, session,
+ if (!iavf_ipsec_crypto_action_valid(adapter, session,
ipsec_flow->spi))
goto flow_cleanup;
@@ -1972,7 +1972,7 @@ iavf_ipsec_flow_parse(struct iavf_adapter *ad,
const struct rte_security_session *session = parsed_actions.actions[0]->conf;
uint32_t type = (uint64_t)(item->meta);
- fi = iavf_ipsec_flow_item_parse(ad->vf.eth_dev, pattern, session, type);
+ fi = iavf_ipsec_flow_item_parse(ad, pattern, session, type);
}
rte_free(item);
diff --git a/drivers/net/intel/iavf/iavf_ipsec_crypto.h b/drivers/net/intel/iavf/iavf_ipsec_crypto.h
index 795b75a624d..3d4b1da127a 100644
--- a/drivers/net/intel/iavf/iavf_ipsec_crypto.h
+++ b/drivers/net/intel/iavf/iavf_ipsec_crypto.h
@@ -127,13 +127,13 @@ int iavf_security_get_pkt_md_offset(struct iavf_adapter *adapter);
/**
* Destroy security context
*/
-int iavf_security_ctx_destroy(struct iavf_adapter *adapterv);
+int iavf_security_ctx_destroy(struct iavf_adapter *adapter);
/**
* Verify that the inline IPsec Crypto action is valid for this device
*/
uint32_t
-iavf_ipsec_crypto_action_valid(struct rte_eth_dev *ethdev,
+iavf_ipsec_crypto_action_valid(struct iavf_adapter *adapter,
const struct rte_security_session *session, uint32_t spi);
/**
diff --git a/drivers/net/intel/iavf/iavf_vchnl.c b/drivers/net/intel/iavf/iavf_vchnl.c
index 57488512f43..26dae423a48 100644
--- a/drivers/net/intel/iavf/iavf_vchnl.c
+++ b/drivers/net/intel/iavf/iavf_vchnl.c
@@ -314,13 +314,14 @@ iavf_read_msg_from_pf(struct iavf_adapter *adapter, uint16_t buf_len,
opcode, vf->cmd_retval);
if (opcode == VIRTCHNL_OP_EVENT) {
+ struct rte_eth_dev *dev = iavf_get_eth_dev(adapter);
struct virtchnl_pf_event *vpe =
(struct virtchnl_pf_event *)event.msg_buf;
result = IAVF_MSG_SYS;
switch (vpe->event) {
case VIRTCHNL_EVENT_LINK_CHANGE:
- iavf_handle_link_change_event(vf->eth_dev, vpe);
+ iavf_handle_link_change_event(dev, vpe);
break;
case VIRTCHNL_EVENT_RESET_IMPENDING:
/*
@@ -335,8 +336,8 @@ iavf_read_msg_from_pf(struct iavf_adapter *adapter, uint16_t buf_len,
iavf_set_no_poll(adapter, false);
iavf_dev_watchdog_enable(adapter);
if (adapter->devargs.no_poll_on_link_down)
- iavf_dev_tx_drain(vf->eth_dev);
- iavf_dev_event_post(vf->eth_dev,
+ iavf_dev_tx_drain(dev);
+ iavf_dev_event_post(dev,
RTE_ETH_EVENT_INTR_RESET,
NULL, 0);
}
--
2.52.0
More information about the dev
mailing list