<div dir="auto">Hi Ivan, agree. I think we can atleast currently guard all the known crashes.<div dir="auto"><br></div><div dir="auto">Sure, I will check the macro and get back to you. </div><div dir="auto"><br></div><div dir="auto">Thank you!</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Wed, Jul 23, 2025, 18:19 Ivan Malov <<a href="mailto:ivan.malov@arknetworks.am">ivan.malov@arknetworks.am</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Khadem,<br>
<br>
On Wed, 23 Jul 2025, Khadem Ullah wrote:<br>
<br>
> In secondary processes, directly accessing 'dev->data->dev_private' can<br>
> cause a segmentation fault if the primary process has exited or if the<br>
> shared memory is no longer accessible.<br>
><br>
> Secondary application not only breaking on device closing,<br>
> but also getting segfault when we do "show device info all" from secondary<br>
> after primary closes.<br>
><br>
> This patch adds safety checks while using rte_mem_virt2phy(), with an<br>
> unlikely() branch hint to minimize performance impact in the fast path.<br>
> This ensures 'dev_private' is still valid before accessing it.<br>
><br>
> Fixes: bdad90d12ec8 ("ethdev: change device info get callback to return int")<br>
> Cc: <a href="mailto:stable@dpdk.org" target="_blank" rel="noreferrer">stable@dpdk.org</a><br>
><br>
> Signed-off-by: Khadem Ullah <<a href="mailto:14pwcse1224@uetpeshawar.edu.pk" target="_blank" rel="noreferrer">14pwcse1224@uetpeshawar.edu.pk</a>><br>
> ---<br>
> lib/ethdev/rte_ethdev.c | 15 ++++++++++++++-<br>
> 1 file changed, 14 insertions(+), 1 deletion(-)<br>
><br>
> diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c<br>
> index dd7c00bc94..343e156a4f 100644<br>
> --- a/lib/ethdev/rte_ethdev.c<br>
> +++ b/lib/ethdev/rte_ethdev.c<br>
> @@ -4079,6 +4079,13 @@ rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)<br>
><br>
>       if (dev->dev_ops->dev_infos_get == NULL)<br>
>               return -ENOTSUP;<br>
> +     if (rte_eal_process_type() == RTE_PROC_SECONDARY &&<br>
> +             unlikely(rte_mem_virt2phy(dev->data->dev_private) == RTE_BAD_PHYS_ADDR)) {<br>
> +                     RTE_ETHDEV_LOG_LINE(ERR,<br>
> +                     "Secondary: dev_private not accessible (primary exited?)");<br>
> +                     rte_errno = ENODEV;<br>
> +                     return -rte_errno;<br>
> +     }<br>
>       diag = dev->dev_ops->dev_infos_get(dev, dev_info);<br>
>       if (diag != 0) {<br>
>               /* Cleanup already filled in device information */<br>
> @@ -4307,7 +4314,13 @@ rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr)<br>
>                       port_id);<br>
>               return -EINVAL;<br>
>       }<br>
> -<br>
> +     if (rte_eal_process_type() == RTE_PROC_SECONDARY &&<br>
> +             (dev->data->mac_addrs == NULL)) {<br>
> +                     RTE_ETHDEV_LOG_LINE(ERR,<br>
> +                     "Secondary: dev_private not accessible (primary exited?)");<br>
> +                     rte_errno = ENODEV;<br>
> +                     return -rte_errno;<br>
> +     }<br>
>       rte_ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);<br>
><br>
>       rte_eth_trace_macaddr_get(port_id, mac_addr);<br>
<br>
I see one more API has been augmented with the check. But community members may<br>
still argue this is not robust, as many other APIs will also fail. So, even if<br>
the task was to augment as many APIs as possible with the check, then the check<br>
would still be required to be factorised/generalised somehow. What do you think?<br>
<br>
Please also note that there are already macro invocations in many of these APIs,<br>
for example, RTE_ETH_VALID_PORTID_OR_ERR_RET. Could be convenient.<br>
<br>
Thank you.<br>
<br>
> -- <br>
> 2.43.0<br>
><br>
><br>
</blockquote></div>