From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E463646BF1; Wed, 23 Jul 2025 14:19:42 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 71F6740A89; Wed, 23 Jul 2025 14:19:42 +0200 (CEST) Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) by mails.dpdk.org (Postfix) with ESMTP id 8CFA040264 for ; Wed, 23 Jul 2025 14:19:41 +0200 (CEST) Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-6fada2dd785so67692996d6.2 for ; Wed, 23 Jul 2025 05:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uetpeshawar-edu-pk.20230601.gappssmtp.com; s=20230601; t=1753273181; x=1753877981; darn=dpdk.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=FxZF51/YpELT6mthkP9CoKvjjb7MOGZvZSCMnzgee2Q=; b=t/iEZLNGOizI4MPF4Ij904SNybMSsXlJkfG8mTVuQzESwH54pY9pJEYz14390yKlZU e+xFZofXmIgXgrbZp3FeD5n3mIamAoU5vq8G5YbE4BrwUpEQ+oWsW5UJHKc/X4D6TE9J fdzRjLx7FJYa1rgcnBGKnKqTYqeDY+VWzGqketCdgLl7iY9dHPJRRrDNppNIUr/xBrBZ oFaLx+66vYe6fs8e3OmmMnAlcb+tTfiiXqYDu321YwOhaTbN0hYTGJtwuaUgut4/cLXF hPFlbT7eVZ0NpPCnNiZC7htPmxhtIXYg+HdVhzZLvYjUX7M4ZyICCCmRUPCnSCPY8rV8 zvUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753273181; x=1753877981; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FxZF51/YpELT6mthkP9CoKvjjb7MOGZvZSCMnzgee2Q=; b=flkG3kJ+N8GBFxKRw8H6tB6yEHU34xWRU5AG7ysFScv614S0+TY68w3XOpbKs1lDdu hw0Tl+Wn7PVJ/oRaTR9GUVjD10ElQSDnT5gK90XRENi8ND42wJls2vwjfMoyLnlc9gO5 iDqlihFsNQB+qS5vQbMpJuH/uneX6Q5PlH0xcB0QE4/PkKLc9PS1p9nPeRxo7O/DOUdq 7LnoWhxu89ZC/E7fMkbqpgzRCMPFbYRvjuw1JDCaqA4PCZWOHlIL9Ri8GOkYEBEG8Cxd A1l+0trRyI4v9N+zOv0L7LR2mJ3SkCynWv85kseOAQajEVbw5/hxKi5PKEIyfVhHcOiD C/kg== X-Gm-Message-State: AOJu0YyIDDm13ebrczYjIoDyzeJbtZP7oiVGB5KEXF11IfnNopUVGBli 0gFURiR/oBEfCF3iBoK35alYxar99iJKaCHJAx09uR1mnLX3ezRjsxpwAaPd4cQSOpB3Qw+I6y4 oO/5qPJy+nEDtyFJ+ndbY5LQ7mskS1bIFJdA8IBcBhQ== X-Gm-Gg: ASbGncsFLUzp/HcJjBoIMP3XGSLkvJ/w7xw+a4+p/uecL3EIrXNuiXLndzkPmgp1/hH zhd3cOlwoGHCWcKLZn2UzNFbF1BZURlwgR7iuZj0VFgqzMO2vACMUUdj6yBAEDPnDtzexzDGumw HwHT6ep1Dc8HLiUZvSn5r5RiUyRXTh9e/zS4ug3zwI6NTtAo8fJCCuYOdhbrohN+0XYvJs6FxxM tl1bTIHyQ== X-Google-Smtp-Source: AGHT+IG7jz+WHqCBaeslFVuO7QRYbQVoJ3TbDh9tlufyxxCVV6tqcFEmYkefrqwZE6xmd+OYNXPZQrtCIZ3FciaRLdI= X-Received: by 2002:a05:6214:500d:b0:6fb:4e82:6e8 with SMTP id 6a1803df08f44-7070051b347mr33495346d6.14.1753273180788; Wed, 23 Jul 2025 05:19:40 -0700 (PDT) MIME-Version: 1.0 References: <20250722115439.1353573-1-14pwcse1224@uetpeshawar.edu.pk> <20250723045022.1580829-1-14pwcse1224@uetpeshawar.edu.pk> In-Reply-To: <20250723045022.1580829-1-14pwcse1224@uetpeshawar.edu.pk> From: Khadem Ullah <14pwcse1224@uetpeshawar.edu.pk> Date: Wed, 23 Jul 2025 17:19:29 +0500 X-Gm-Features: Ac12FXzbnDQF2DmtYc27CMpOl1KWs-KBadPL5cCY-goWoOKmcswNHB5xV79TKFg Message-ID: Subject: Re: [PATCH v2] lib/ethdev: fix segfault in secondary process by validating dev_private pointer To: stephen@networkplumber.org, thomas@monjalon.net, ferruh.yigit@amd.com, andrew.rybchenko@oktetlabs.ru Cc: dev@dpdk.org, stable@dpdk.org Content-Type: multipart/alternative; boundary="00000000000022b5d2063a97b91f" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org --00000000000022b5d2063a97b91f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Secondary application not only breaking on device closing, it's also getting segfault when we do "show device info all" from secondary after primary closes: testpmd> show device info all ********************* Infos for device 0000:03:00.0 ********************* Bus name: pci Bus information: vendor_id=3D15b3, device_id=3D101d Driver name: mlx5_pci Devargs: Connect to socket: 0 Segmentation fault (core dumped) This patch prevents these crashes and it seems that these fixes should be in PMD along with the ethdev layer. Some more checks will be added in the next version to prevent "show device info all" crash. On Wed, Jul 23, 2025 at 9:50=E2=80=AFAM Khadem Ullah <14pwcse1224@uetpeshaw= ar.edu.pk> wrote: > In secondary processes, directly accessing 'dev->data->dev_private' can > cause a segmentation fault if the primary process has exited or if the > shared memory is no longer accessible. > > This patch adds a safety check using rte_mem_virt2phy(), with an > unlikely() branch hint to minimize performance impact in the fast path. > This ensures 'dev_private' is still valid before accessing it. > > Fixes: bdad90d12ec8 ("ethdev: change device info get callback to return > int") > Cc: stable@dpdk.org > > Signed-off-by: Khadem Ullah <14pwcse1224@uetpeshawar.edu.pk> > --- > lib/ethdev/rte_ethdev.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c > index dd7c00bc94..ef5dc55f2e 100644 > --- a/lib/ethdev/rte_ethdev.c > +++ b/lib/ethdev/rte_ethdev.c > @@ -4079,6 +4079,13 @@ rte_eth_dev_info_get(uint16_t port_id, struct > rte_eth_dev_info *dev_info) > > if (dev->dev_ops->dev_infos_get =3D=3D NULL) > return -ENOTSUP; > + if (rte_eal_process_type() =3D=3D RTE_PROC_SECONDARY && > + unlikely(rte_mem_virt2phy(dev->data->dev_private) =3D=3D > RTE_BAD_PHYS_ADDR)) { > + RTE_ETHDEV_LOG_LINE(ERR, > + "Secondary: dev_private not accessible (primary > exited?)"); > + rte_errno =3D ENODEV; > + return -rte_errno; > + } > diag =3D dev->dev_ops->dev_infos_get(dev, dev_info); > if (diag !=3D 0) { > /* Cleanup already filled in device information */ > -- > 2.43.0 > > --=20 Engr. Khadem Ullah, Software Engineer, Dreambig Semiconductor Inc https://dreambigsemi.com/ --00000000000022b5d2063a97b91f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Secondary application not onl=
y breaking on device closing,
it's also getting segfault when we do = "show device info all" from secondary
after primary closes:
testpmd> show device info all

********************* Infos fo= r device 0000:03:00.0 *********************
Bus name: pci
Bus informa= tion: vendor_id=3D15b3, device_id=3D101d
Driver name: mlx5_pci
Devarg= s:
Connect to socket: 0

Segmentation fault (core dumped)

T= his patch prevents these crashes and it seems that these fixes should be in= PMD along with the ethdev layer. Some more checks will be added in the nex= t version to prevent "show device info all" crash.


On Wed, Jul 23, 2025 at 9:50=E2=80=AFAM Khadem Ullah <<= a href=3D"mailto:14pwcse1224@uetpeshawar.edu.pk">14pwcse1224@uetpeshawar.ed= u.pk> wrote:
In secondary processes, directly accessing 'dev->data->dev_pr= ivate' can
cause a segmentation fault if the primary process has exited or if the
shared memory is no longer accessible.

This patch adds a safety check using rte_mem_virt2phy(), with an
unlikely() branch hint to minimize performance impact in the fast path.
This ensures 'dev_private' is still valid before accessing it.

Fixes: bdad90d12ec8 ("ethdev: change device info get callback to retur= n int")
Cc: stable@dpdk.org

Signed-off-by: Khadem Ullah <
14pwcse1224@uetpeshawar.edu.pk>
---
=C2=A0lib/ethdev/rte_ethdev.c | 7 +++++++
=C2=A01 file changed, 7 insertions(+)

diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index dd7c00bc94..ef5dc55f2e 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -4079,6 +4079,13 @@ rte_eth_dev_info_get(uint16_t port_id, struct rte_et= h_dev_info *dev_info)

=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (dev->dev_ops->dev_infos_get =3D=3D NU= LL)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -ENOTSUP; +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (rte_eal_process_type() =3D=3D RTE_PROC_SECO= NDARY &&
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unlikely(rte_mem_vi= rt2phy(dev->data->dev_private) =3D=3D RTE_BAD_PHYS_ADDR)) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0RTE_ETHDEV_LOG_LINE(ERR,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0"Secondary: dev_private not accessible (primary exited?)&quo= t;);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0rte_errno =3D ENODEV;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0return -rte_errno;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0 =C2=A0 =C2=A0 diag =3D dev->dev_ops->dev_infos_get(dev,= dev_info);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (diag !=3D 0) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* Cleanup already = filled in device information */
--
2.43.0



--
Engr. Khadem Ullah,
= Software Engineer,
<= span style=3D"color:rgb(12,100,192)">Dreambig Semiconductor Inc
=
--00000000000022b5d2063a97b91f--