In secondary processes, accessing 'dev->data->dev_private' directly can
cause a segmentation fault if the primary process has exited or the
shared memory is unavailable.

This patch adds a check for dev/data/dev_private and uses
rte_mem_virt2phy to ensure the pointer is still valid.

Fixes: 690175ee51bf ('net/ice: support getting device information')
Cc: sta...@dpdk.org

Signed-off-by: Khadem Ullah <14pwcse1...@uetpeshawar.edu.pk>
---
 drivers/net/intel/ice/ice_ethdev.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/net/intel/ice/ice_ethdev.c 
b/drivers/net/intel/ice/ice_ethdev.c
index 513777e372..f0ba3626bb 100644
--- a/drivers/net/intel/ice/ice_ethdev.c
+++ b/drivers/net/intel/ice/ice_ethdev.c
@@ -4090,6 +4090,15 @@ ice_dev_info_get(struct rte_eth_dev *dev, struct 
rte_eth_dev_info *dev_info)
 {
        struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
        struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
+               (dev == NULL || dev->data == NULL ||
+               dev->data->dev_private == NULL ||
+               rte_mem_virt2phy(dev->data->dev_private) == RTE_BAD_PHYS_ADDR)) 
{
+                       PMD_DRV_LOG(ERR,
+                       "Secondary: dev_private not accessible (primary 
exited?)");
+                       rte_errno = ENODEV;
+                       return -rte_errno;
+       }
        struct ice_vsi *vsi = pf->main_vsi;
        struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
        bool is_safe_mode = pf->adapter->is_safe_mode;
-- 
2.43.0

Reply via email to