From nobody Sun May 24 17:48:00 2026 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A5C93438B5 for ; Sun, 24 May 2026 14:04:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779631478; cv=none; b=PeVnYvHXfFd8Pgl1+raXpYjsp5W2KJNicNOjl1VThC6fVfWUgF00H4DMXj/0NKz9GUNS+G0zltN8Q5Wn1AyOvVTOGngEAIbB4WaLz43PCcE7GAeJLVrgQMM+kKIjoPuUNaaul445kxrnTO9aUiZErhoSJmtPEE03/VH654dj/n8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779631478; c=relaxed/simple; bh=/nTwn86qnq9XTaDwhB03+le8L7cunBJppSI2o915qMs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=rPkZuF/K1aKEiR9DCAr4/7w2lYy46jPh1N0hgKra9ZARA5rowy6stolCxDwFU6vbFBr0F6CkYLP5vR4s4dfH0YIiqLTUKxVM047gy22O1mCediiZN2Lg1VObFo+3OAzLhHeltTh+BdAU3wW8l9nWamaywvA+U9PwUbWhUtcHR1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=fyGIIUYL; arc=none smtp.client-ip=91.218.175.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="fyGIIUYL" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1779631473; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=mk78eHnFhgUgCvO8WVCiSQYNQ2D/doAI48Qx25lC6wY=; b=fyGIIUYLLA89SpMTUFz9YhI4OAucJpEoDj7GveEnaMTTKYToiuiISshEcXVqKtr1rmsAts vAb6R5Lw8KuKAZ2JeLKRuZdjrDoOvwi2wzPgPnmPcDMYd89XvwcR18WqvV002F+y/gtTav 9xYr0PFBQXqgNoEdSXAJblx2FjpUCkc= From: Kaitao Cheng To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com Cc: minchan@kernel.org, digetx@gmail.com, jhubbard@nvidia.com, gregkh@linuxfoundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kaitao Cheng , Muchun Song , Muchun Song Subject: [PATCH] mm/cma_sysfs: Skip inactive CMA areas in sysfs Date: Sun, 24 May 2026 22:04:20 +0800 Message-ID: <20260524140420.61864-1-kaitao.cheng@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Kaitao Cheng cma_activate_area() can fail after a CMA area has already been added to cma_areas[]. In that case the area is left in the global array, but it does not reach the point where CMA_ACTIVATED is set. cma_sysfs_init() currently walks all cma_area_count entries and creates sysfs files for every area, including ones that failed activation. These areas are not usable CMA areas and should not be exposed to userspace as valid CMA regions. If such an inactive area is exposed, userspace sees a CMA directory whose read-only accounting files report zeros. total_pages and available_pages report zero because the failed activation path clears cma->count and cma->available_count, while the allocation and release counters also stay at zero because the area cannot service CMA allocations. This makes the failed area look like a valid but empty CMA region and can mislead tests, monitoring, and diagnostics. Skip CMA areas that did not reach CMA_ACTIVATED when creating the sysfs objects. Since inactive entries can now be skipped, make the error unwind tolerate entries that never had cma_kobj initialized. Suggested-by: David Hildenbrand (Arm) Suggested-by: Muchun Song Acked-by: Muchun Song Signed-off-by: Kaitao Cheng --- Changelog: Changes in v2: - Revise commit log Link to v1: https://lore.kernel.org/linux-mm/20260522131434.78532-1-kaitao.cheng@linux.= dev/ --- mm/cma_sysfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/cma_sysfs.c b/mm/cma_sysfs.c index f52b696bc46d..d5bf792c6245 100644 --- a/mm/cma_sysfs.c +++ b/mm/cma_sysfs.c @@ -117,13 +117,16 @@ static int __init cma_sysfs_init(void) return -ENOMEM; =20 for (i =3D 0; i < cma_area_count; i++) { + cma =3D &cma_areas[i]; + if (!test_bit(CMA_ACTIVATED, &cma->flags)) + continue; + cma_kobj =3D kzalloc_obj(*cma_kobj); if (!cma_kobj) { err =3D -ENOMEM; goto out; } =20 - cma =3D &cma_areas[i]; cma->cma_kobj =3D cma_kobj; cma_kobj->cma =3D cma; err =3D kobject_init_and_add(&cma_kobj->kobj, &cma_ktype, @@ -138,7 +141,8 @@ static int __init cma_sysfs_init(void) out: while (--i >=3D 0) { cma =3D &cma_areas[i]; - kobject_put(&cma->cma_kobj->kobj); + if (cma->cma_kobj) + kobject_put(&cma->cma_kobj->kobj); } kobject_put(cma_kobj_root); =20 --=20 2.50.1 (Apple Git-155)