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 03BFB45F93; Wed, 1 Jan 2025 13:34:49 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3C280402AB; Wed, 1 Jan 2025 13:34:48 +0100 (CET) Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by mails.dpdk.org (Postfix) with ESMTP id C10BC40151; Wed, 1 Jan 2025 13:34:46 +0100 (CET) Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-43675b1155bso92689315e9.2; Wed, 01 Jan 2025 04:34:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735734886; x=1736339686; 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=r1YGQQ0QSaJUFwWXHcfi9Bv44zONiB8jY+u/RhDYeho=; b=bnl08qoSJ4/IXjQJ9/G4w78cCJwlZLdvuBE2Vq84VvL7mVBjCerC2/wng2qD7AkjSD CpyEVrZbrFBNWLW4se7mwaqE4EEjuOs1ieX5MfTuTglJyWC6+cMk4Nbhf+GQKnvV/ygO S7BWzMOsY1rCsg/1i7X3xCVTxjZqSw2E56JKqJFREH7zcbwEvwJai43uvM/pSGfjgFld O+8+bNRuhh+w7r44iC1DwpJbsDgDQH+b39tofRp1vDspennacxufZqeRWZT98pXCoMpo fXnNM7xHS8s3lwoFEH/vWSOj47rZH4T+wBqFdSpeg9/St1poKREw7ZEhWmsXd5o+HHGj ezuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735734886; x=1736339686; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :sub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== X-Google-Smtp-Source: AGHT+IHTK+1NMGWGprv7IA+eYYw+n/6q1Hn866B+xV/7H+2Z2Uk8YtrxMtMNLqJvRKATlq19egpocg== X-Received: by 2002:a05:600c:4f84:b0:434:f7ea:fb44 with SMTP id 5b1f17b1804b1-43668644255mr357301135e9.14.1735734885945; Wed, 01 Jan 2025 04:34:45 -0800 (PST) Received: from sovereign (broadband-109-173-43-194.ip.moscow.rt.ru. [109.173.43.194]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43656b11495sm450964005e9.19.2025.01.01.04.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jan 2025 04:34:44 -0800 (PST) Date: Wed, 1 Jan 2025 15:34:42 +0300 From: Dmitry Kozlyuk To: Yang Ming Cc: Anatoly Burakov , dev@dpdk.org, stable@dpdk.org Subject: Re: [PATCH] Fix unused memseg length for memory issue Message-ID: <20250101153442.35d80b1a@sovereign> In-Reply-To: <20241226081020.3479-1-ming.1.yang@nokia-sbell.com> References: <20241226081020.3479-1-ming.1.yang@nokia-sbell.com> X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 2024-12-26 16:10 (UTC+0800), Yang Ming: > Fix the issue where OS memory is mistakenly freed with rte_free > by setting the length (len) of unused memseg to 0. >=20 > When eal_legacy_hugepage_init releases the VA space for unused > memseg lists, it does not reset their length to 0. As a result, > mlx5_mem_is_rte may incorrectly identify OS memory as DPDK > memory. This can lead to mlx_free calling rte_free on OS memory, > causing an "EAL: Error: Invalid memory" log and failing to free > the OS memory. >=20 > This issue is occasional and occurs when the DPDK program=E2=80=99s > memory map places the heap address range between 0 and len(32G). > In such cases, malloc may return an address less than len, > causing mlx5_mem_is_rte to incorrectly treat it as DPDK memory. >=20 > Fixes: 66cc45e293ed ("mem: replace memseg with memseg lists") > Cc: anatoly.burakov@intel.com > Cc: stable@dpdk.org >=20 > Signed-off-by: Yang Ming > --- > lib/eal/linux/eal_memory.c | 1 + > 1 file changed, 1 insertion(+) >=20 > diff --git a/lib/eal/linux/eal_memory.c b/lib/eal/linux/eal_memory.c > index 45879ca743..9dda60c0e1 100644 > --- a/lib/eal/linux/eal_memory.c > +++ b/lib/eal/linux/eal_memory.c > @@ -1472,6 +1472,7 @@ eal_legacy_hugepage_init(void) > mem_sz =3D msl->len; > munmap(msl->base_va, mem_sz); > msl->base_va =3D NULL; > + msl->len =3D 0; > msl->heap =3D 0; > =20 > /* destroy backing fbarray */ Hi Yang, It seems the bug affects more than just mlx5 PMD. Consider how the MSL with `base_va =3D=3D NULL` ends up in `mlx5_mem_is_rte= ()`. It comes from `rte_mem_virt2memseg_list()` which iterates MSLs and checks that an address belongs to [`base_va`; `base_va+len`) without checking whether `base_va =3D=3D NULL` i.e. that the MSL is inactiv= e. Your patch also corrects `rte_mem_virt2memseg_list()` behavior. Please mention this in the commit message. Acked-by: Dmitry Kozlyuk