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 3364246C38 for ; Mon, 28 Jul 2025 23:46:04 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2482C406B7; Mon, 28 Jul 2025 23:46:04 +0200 (CEST) Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) by mails.dpdk.org (Postfix) with ESMTP id A1E6E40693 for ; Mon, 28 Jul 2025 23:46:01 +0200 (CEST) Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-702cbfe860cso41153966d6.1 for ; Mon, 28 Jul 2025 14:46:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1753739161; x=1754343961; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=gI+wpg9UXR3ub4H9KijptGv1RosZdVpkFhL5TD8teqw=; b=Ul/yU1gWXL4N+QiDEeoiNQAywYhxCjeRF4t9HIekwnWcT6Plyp3v6FGKPf9QrSXV72 mqV7elYOR3vz3m4YenqXYk7jGhGjfy71QGkH/mntkfbJDuP8Hb3vRHXA91Ir0GrFBE7q Q+bw+1RI+LUqGyZHWcesR7LUGOCzMuWR4f8lpc8O65tbMHbcBFpiQYH1+5UyR5YY57Fq Y5WMoSMLmIqvDmTvPmZH/sypKfP3EtR+9AHPGGIkrzmz0hYoMNBAXJbBFjAClLScDCaR zhw1QT3ld9MxVY+0oIwuV1wgziQV5X+A71fnkybG/eyopd4OEtqlV3qhCKFpG1ttQbAp FvBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753739161; x=1754343961; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gI+wpg9UXR3ub4H9KijptGv1RosZdVpkFhL5TD8teqw=; b=WvN8DZ2319twVEEeg6+cFLNAJx1ayXYI3I+JhktFyQfmKpCQVl2khwREqmN97MPZ3z vmDNmtNwGLUwILPMDLwZTpZlfYklAXhScfPPcF8ehA4Oa7oQN5BFr2kTzq8Iun0sNbkH wOlYtFjcOzRfu7JWWIYKeVax3Zc7LbeXDnKfUQtg4CvuIDTIVDz9c89isgBPrTkR8i3T V0xZ99lQzxRy7tFSfUXSebkVwL3EMwh7ErNimQVFzG80fN38VXj7Pi+K/hvY6z+8i5bY KVOVwguWc/mJ+zP9NWf6PUZ62JiehvahL/s/tYJPWqLcNmYgvwx16OkF9gpdpUiy1Ytk ceyA== X-Forwarded-Encrypted: i=1; AJvYcCVpH5VbLsY7Vkm5Ha13Yoxhm5J+wWk9xwET38bDEMcXrEN7zsFw8D6SgYId7M5OZLJrC6ruHPA=@dpdk.org X-Gm-Message-State: AOJu0YxhWyaejdf7hcENL4DPunRWvvdqPVT015Y/Qg3/b7KWC+e6fKBv /WbYokKf4rKcWj7yjcgjfTmTSoTc7zUd9naBdBoACdKLqdXv695edARc+V7ucpcUIvA= X-Gm-Gg: ASbGncvRNtxSBuxUEQ9q9381MGhwG8rT/y/Q9iZRQvyBte+r5+nhC+s6KTEARRC/xrM srArZhaJJ3YCf0GRE2do2dBnzlIHWkjgzaoLwo7V+w63dbJJxCZZV1xnzMwMgcHLTdDi1MLXG3L dAC8qatPZRRBjm6WedH3DyuNzfairmdt8dp7/XKvBmO9XfY4gGVU9E5THhClGcJGMd6hidq6Rep XlrYRI5NT/C8HwwobkL8KCxJjfP2oDBfC+512hEZHzKS5UaGq94mQfI3lar4f86Ad7dyT0gpUmB VW/e5wRRqP/zOzP88D1ljddtMGzNCVFSimuwsvJ7NAF08+gZ1Wel+dIVuDTfRQ7V9Wv3MLV2ziY g9Gss2juEDUsrGI+Yb1f/vWK3FZ0JwhQFggQrbHk/ZGv2J+PgpBddZ+nCa2VvMHwVX5z3JoMAj7 g= X-Google-Smtp-Source: AGHT+IEwpJu6z7jEVPjsB8aOkhB1Kt2D9oECYgd8ubeuys0YVMCJwdo5rAo4nrFwbGie/yDU8yg/dg== X-Received: by 2002:a05:6214:2689:b0:704:f7d8:edfc with SMTP id 6a1803df08f44-7072060236emr177412916d6.49.1753739160874; Mon, 28 Jul 2025 14:46:00 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-70729c15a4bsm36685576d6.60.2025.07.28.14.45.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jul 2025 14:46:00 -0700 (PDT) Date: Mon, 28 Jul 2025 14:45:52 -0700 From: Stephen Hemminger To: Khadem Ullah <14pwcse1224@uetpeshawar.edu.pk> Cc: thomas@monjalon.net, ferruh.yigit@amd.com, andrew.rybchenko@oktetlabs.ru, dev@dpdk.org, stable@dpdk.org Subject: Re: [PATCH] [PATCH v4] lib/ethdev: fix segfault in secondary process by validating dev_private pointer Message-ID: <20250728144552.361c17e4@hermes.local> In-Reply-To: <20250725125526.2340233-1-14pwcse1224@uetpeshawar.edu.pk> References: <20250723131049.1703172-1-14pwcse1224@uetpeshawar.edu.pk> <20250725125526.2340233-1-14pwcse1224@uetpeshawar.edu.pk> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 On Fri, 25 Jul 2025 08:55:26 -0400 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. > > The secondary process not only crashes on device close but also segfaults > when executing commands like "show device info all" after the primary has > exited. > > This patch adds a mechanism in testpmd to monitor the primary process from the > secondary using `rte_eal_primary_proc_alive()`, and introduces safety > checks before dereferencing 'dev_private'. The `rte_mem_virt2phy()` call > is also guarded to avoid access to invalid memory regions, with > `unlikely()` hints to minimize impact in the fast path. > > Fixes: bdad90d12ec8 ("ethdev: change device info get callback to return int") > Cc: stable@dpdk.org > > Signed-off-by: Khadem Ullah <14pwcse1224@uetpeshawar.edu.pk> > --- > app/test-pmd/testpmd.c | 56 ++++++++++++++++++++++++++++++++++++++--- > lib/ethdev/rte_ethdev.c | 15 ++++++++++- > 2 files changed, 66 insertions(+), 5 deletions(-) The test-pmd monitoring is good, and should have done back when secondary support was added. Please submit just that part of the patch and add a Fixes tag. You can use the f_quit flag like the signal handler. The use of volatile and standard atomic overlap. Testpmd is older code so just uses volatile so you don't need to use rte_atomic there. Just set f_quit in the alarm handler and avoid restarting alarm if primary exits. In future, want to add something like: rte_eal_primary_proc_notifier(void (*cb)(void *), void *); and use some variation of pidfd or inotify to call the function when primary dies either by termination or abort. The ethdev part is not necessary, and really won't address the race; leave it out.