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 990DD46BF2 for ; Wed, 23 Jul 2025 14:19:43 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8599E40B91; Wed, 23 Jul 2025 14:19:43 +0200 (CEST) Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) by mails.dpdk.org (Postfix) with ESMTP id 900DE402CC for ; Wed, 23 Jul 2025 14:19:41 +0200 (CEST) Received: by mail-qv1-f49.google.com with SMTP id 6a1803df08f44-6fd0a3cd326so70278386d6.1 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=Ub22e7dbFrdt8g7L41w4rCgO/HHB2mDEvX0ERnd8reGIh/kySxbzWwOpKw1/8YRqDL 7+AHRHUaSzYLyyrAdfgQKZ77JyXucMyMIG12FteU+vHFO2feoFFnjcEFGZ/6fRzpAmDP RwKPRr98+B0w3lSLXNXi+kAJijiQhBMU61ULrCOkcODTjKzN9CivDI2JdL0u+cBbO9Wd JkbW8iLNMvS6Ob59UJRUSoLigVABlIL7JSyJfIopFDgU+GY/gQmUOBrn58VNanSeHHjJ Z71IOqGq4PuOvR8Dd5CXx3IrgT+NtzyZtDIYXcRAQkmJykDgM7tOBXQdUEWHg7UuflPT xt8w== X-Forwarded-Encrypted: i=1; AJvYcCUKdDhw6yoz93VjXun9KKCQfAaoUe/yvfXyHfVn4ceTZtaaFKzcgJ8K74ykgR6ltx/Lz3RekJw=@dpdk.org X-Gm-Message-State: AOJu0YzVhKItIqyWwJ+vYnBXAhHE7i/oL8CdmoGj75pE8J0hBCgwRz+k z1KfeZY6/SgmtG0Tat1pdGdTdz/ZdEaKmWOh5EvJzqu9nbe9w/UTdNLnT/YDbtWdNaW3l8ELBk9 uc3/67Jli6/rCqpLIQeat4I55bE4AMw7yfayMnUEZNb31F6hgjDITXaoTnF7g X-Gm-Gg: ASbGncvHDQTpnNnkejI9ZuRvxMS7eeMmXbkQ+fbqTrY4DlRS63U5XivdHbQMgdq93/X t8N4AD3gDrYmgAhxfA7iX+02wemCIOpuR5cMp5w7IKbIyiKLxz1WF9oku0qRhhKK9xnXAKOTv4T KBvTBJOJulLM2EVjl3hbxRhkJRllSKj5yF9kpyj5ok3vy7vByjdeoWkG2OWmavMNh3bcBQVe9KL rZ9cKI6NQ== 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: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-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--