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 3881746BF1; Wed, 23 Jul 2025 15:13:20 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4CC2C40BA0; Wed, 23 Jul 2025 15:13:19 +0200 (CEST) Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) by mails.dpdk.org (Postfix) with ESMTP id 5C87D40B98 for ; Wed, 23 Jul 2025 15:13:17 +0200 (CEST) Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-6fd0a91ae98so33531126d6.1 for ; Wed, 23 Jul 2025 06:13:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uetpeshawar-edu-pk.20230601.gappssmtp.com; s=20230601; t=1753276397; x=1753881197; 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=18XoZ7PpOPaAR7h3oRJMlBCParVic3MYuafB/ogHp6s=; b=bLgRmDvRZ/CkQ6rTgxMJZdT5QONZC7xQ1CHtlAlmVhutlIwX3llEapZ68ZUkUhlgSz s5jSb6Q4miEpjLu4VPpstJ7NKhD++BUqwyMjgOaWpQqSppWOc1aHReyJQeyH1Bb4+vth VdZnEBM3OtwZGMy0S2qjXpl99PKzoAzJ8D1oEc3Zgn/Wi+znonbq4OmEKsVRPn/DGnm/ wArHBlHF5kVUbc37JKZTzRX7CS/zhAtLPLEqoCrq9BylxwpBGHWm5yzw+zjUFLrpbWJ2 kueuJEv5lZGoQ/kvnG8iYqdFLWVlSeI0gnInNqhhL1kqMnyqZofz5frByM8/xcASAdm3 WwTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753276397; x=1753881197; 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=18XoZ7PpOPaAR7h3oRJMlBCParVic3MYuafB/ogHp6s=; b=V+wE1kN2hjGFyQEazrNEUDeABZOU0Otl8N/o1p/TxfMpTBLscqVQkdlOLZUuyhWaYq 719vlJBPuVnCDgNR0MdGxfSQVZjIOycK1T+vFr9G4tFpgQahNpc485xQ+DjKVZlAe7SG l35v7SECWhWjGv+DToGBZCQnTkd+xFVJk+Ha585k/dYHiCb5BrxlWWDSLVvypPrwvzBD JRTZU2iX8VXwkvnwRZqYLqrj8twXaSzo1OaDJw8Wy2zr42WbD9GIGkDXuzs/Muyq0XLO H12+j2T0BdhMDpCCVBXUUjxDD4+rlgWJMokfd4wLvRookp05sRmsn3lrySPk5Xd0xCCT mG0w== X-Gm-Message-State: AOJu0YxfJSb0zzTCZi7mzymNPlgLGqD6RQLxEVarNrK4PXoGd93rQPwQ 3ckkFdd0XSEWBPt06hptZrD06BlYO8n70e5+Ywrhc8KdkIlG6qvhNa28NT32JX2ETNP76lYdOZc g3L0cBX5OGO8GPzcmaAEVLOMOlJWFUBFAuxhoODJ2+g== X-Gm-Gg: ASbGncs5Q+8z44MGLptpUtzSb4qegc5yJC4HW37lLQ/+PX23sCqSiOfUGNKNF4DhWft pMO3gZ7zD7LjM5mkFEfHwfn6uiHCCgpfOUsSyCn2J+ey11FJpR56OzKaZIfTNSICiRb/cu7ZL1p K8l2ZEnhD5sSYRQIhw/rKjVU/oRBFKpV0onxscdpWzz4JsUZOShucaww2ooq6OtKGfx1IcoZkVq 7yW+IIbeg== X-Google-Smtp-Source: AGHT+IGp94aCLlEXFD7RzFpmE9Wlfzti+L+liKdomjUn2Y6DtkVhuGdgB5zQjh4Y2uwzSNELvLC68VkjJTVAyGi0Vug= X-Received: by 2002:a05:6214:2aab:b0:706:aae8:ad48 with SMTP id 6a1803df08f44-7070069b97amr43045506d6.35.1753276396563; Wed, 23 Jul 2025 06:13:16 -0700 (PDT) MIME-Version: 1.0 References: <20250722115439.1353573-1-14pwcse1224@uetpeshawar.edu.pk> <20250723045022.1580829-1-14pwcse1224@uetpeshawar.edu.pk> In-Reply-To: From: Khadem Ullah <14pwcse1224@uetpeshawar.edu.pk> Date: Wed, 23 Jul 2025 18:13:04 +0500 X-Gm-Features: Ac12FXxwsyBD2bedYTjw6u699lzrD8Lzxm88_8M9AIHOKBuaKdtcKetW-m9VYog 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="000000000000cfb6b6063a987827" 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 --000000000000cfb6b6063a987827 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Please check v3 of this patch. On Wed, Jul 23, 2025 at 5:19=E2=80=AFPM Khadem Ullah <14pwcse1224@uetpeshaw= ar.edu.pk> wrote: > Secondary application not only breaking on device closing, > it's also getting segfault when we do "show device info all" from seconda= ry > 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@uetpeshawar.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 >> >> > > -- > Engr. Khadem Ullah, > Software Engineer, > Dreambig Semiconductor Inc > https://dreambigsemi.com/ > --=20 Engr. Khadem Ullah, Software Engineer, Dreambig Semiconductor Inc https://dreambigsemi.com/ --000000000000cfb6b6063a987827 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Please check v3 of this patch.

On Wed= , Jul 23, 2025 at 5:19=E2=80=AFPM Khadem Ullah <14pwcse1224@uetpeshawar.edu.pk> wrote:
=
Secondary application not only breaking on device closing,
it's a= lso getting segfault when we do "show device info all" from secon= dary
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=3D101dDriver name: mlx5_pci
Devargs:
Connect to socket: 0

Segmentat= ion fault (core dumped)

This patch prevents these crashes and it see= ms 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 U= llah <14pwcse1224@uetpeshawar.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 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
=


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