From nobody Mon Jun 15 19:14:02 2026 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA6E4362149 for ; Mon, 13 Apr 2026 09:15:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776071713; cv=none; b=CxAXGKCQhnJDepjDTKXmo6/3KfTG0znHF05HT2E2zQghCAIW0gkHOzCo0rSr3Qk7igdGFhPEs012LGOYDhkF1MrVLlmEpOJclw2KRI4RtrjxKQTOKSkDM60X0I52BxZfN25f3heqEvQEg0LkdakCJhLeCDjHxDX7ETiLwpjL10s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776071713; c=relaxed/simple; bh=lhwLF/JnX78Pkj03amG8XmD9cz7q71RxhYYKk2ZsJHw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=NfJ2F+3SItOBfPf/v63X4kIge83CNEaeJW0y9g3qh3ZseVnjrfAQNYi96xBpJb3fFhNf8JIKJ58RbMwToQMwyD39Bujr6g8zMo25MwQTeLqJFOppOD1Gaf+j/Nakx1uPz/N6klYPnAHpsPgdC0nYv1e2lAjCShLfwKLsUm8vPh0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iW9DVmPr; arc=none smtp.client-ip=209.85.215.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iW9DVmPr" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-c736261ee8dso1511024a12.1 for ; Mon, 13 Apr 2026 02:15:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776071711; x=1776676511; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=sVvly2PF4cqASTSkfAPhOU0sngUvFWG9o3pu6vpsY/k=; b=iW9DVmPrJZRo2r8mDj/nGBNCy7DgCv9pbxLt0cR2DN0vKvabhXLTlrQFaPHN+JpYaw fiRPIpGmusnh0n0su2KZQP1ajKvRPtfuKgxMbW68EzMEe6ea8QpK7xXfcPuAWdc/Fzbw f5mZouwjUSTlhwrD5DSJ46CM3hV/W59/AKSNb4Ds6NfX8t2Ir4Pz2NwdKV0mw24eDVRh en/SzxGJe9t/lqtL5heRVB9lcICAW1CFhRFvopzfm577zzB/B77WQ+1hRkok4x2RfYNA v0i0yO+3ZlD04qaoxNkHXcOvswsS6eu7hhRC4D9sLnDjflp9TkwD4Dqs02WsSrClgS16 pjVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776071711; x=1776676511; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=sVvly2PF4cqASTSkfAPhOU0sngUvFWG9o3pu6vpsY/k=; b=XgZcdX/0av+MgQiEu4IKX6hWQPecOW2GgZmOeggzDQi6zQoR+Jp2BIiBdPwjAQqlzv 9GDqGBjtzBZAIKg5aXoFCmJYUA2rWZV+AhUan+do6H9exLUQaS0r3KJga496Sh6AE8aG q8ciis+W1d5VfhTM1Wm2bieT0bIOrOx29sYDOuphPREvDecrHk7zv3F02HTATI7xfWII 9PjdojexPxUB7xnOYXnDOlIqvBu+JNY9gRiXkkhGxStoM1zlfxkSf1QPf66B4EWUvVyB JladAay6X9vsBbDP9PKF5X/+TbvJ8A7tksMQyAUs5TPD1iStTsdB46UJwgGO8F5Z8/LA Ig7g== X-Forwarded-Encrypted: i=1; AFNElJ8fwjEBQ2arGPEmQEIeP69HMB/Ayc09BaDQMyxuVCZbE9e5qDy2QV9T0JfibP5Zpd7dIIKl/UdLp8w44K4=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0GWbi1d+4GPuPJrQqsYL0irM14Y9U3FLXvT5gubQ4Iz1/QtlT MszgTAEOsMZkPJiMmEMvmmhkjG1IzKXJ2CJT+gKpDoGIp1wphmoGUnBBtNLxVXos99s= X-Gm-Gg: AeBDieulabemo09bskXjuSKQ/15IpoBQXmfRQZBygPumqR771SZe+1kkEJLqzV6BYpf pYHZk2R+NlJVhB7mUZjEb97U5Z8R391T2iJYAs3sJxm8DS9Y8MxHqVGRKOBhaze3SCF6Rek50sS /oOkSRfkPk9ITfXvNcoqg4SGnFqNAPDk+QHEchVD6wJuojK82BbgaUU96K2Z7aak8DxzNGiTk+a Llky3jMJPhtiaetBTvIC4BlxIUYaEiOijbdW0WdERSDL1wa/rq/rPziPkrAyRDBncs6SrR0D91o 5rctAtIMj2OWHZkeWzbMKWyE9EGFDu8pK+Ya7c4tn8oq1CLwuk005/6Uu9ifQyvKVfPdczEo09E xPfoPuE+CiQbrY9Tdjpil745/X7vfQB3Nl8jXGup1rxE2IcoJLzZctVC6gsDzP8MwVSXH/+YuEC 6gsWrLMSemds+LfFylzzHk8XZBXiU= X-Received: by 2002:a05:6a20:748b:b0:39b:9644:6ea4 with SMTP id adf61e73a8af0-39fe3cf20c5mr13988935637.16.1776071711131; Mon, 13 Apr 2026 02:15:11 -0700 (PDT) Received: from potato.. ([192.19.252.250]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c79216fedfdsm10138849a12.4.2026.04.13.02.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Apr 2026 02:15:10 -0700 (PDT) From: priyanshukumarpu@gmail.com To: rppt@kernel.org Cc: akpm@linux-foundation.org, changyuanl@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Priyanshu Kumar Subject: [PATCH] tools/testing/memblock: fix stale NUMA reservation tests Date: Mon, 13 Apr 2026 09:14:58 +0000 Message-ID: <20260413091458.774770-1-priyanshukumarpu@gmail.com> X-Mailer: git-send-email 2.43.0 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 Content-Type: text/plain; charset="utf-8" From: Priyanshu Kumar memblock allocations now reserve memory with MEMBLOCK_RSRV_KERN and, on NUMA configurations, record the requested node on the reserved region. Several memblock simulator NUMA tests still expected merges that only worked before those reservation semantics changed, so the suite aborted even though the allocator behavior was correct. Update the NUMA merge expectations in the memblock_alloc_try_nid() and memblock_alloc_exact_nid_raw() tests to match the current reserved region metadata rules. For cases that should still merge, create the pre-existing reservation with matching nid and MEMBLOCK_RSRV_KERN metadata. Also strengthen the memblock_alloc_node() coverage by checking the newly created reserved region directly instead of re-reading the source memory node descriptor. Finally, drop the stale README/TODO notes that still claimed memblock_alloc_node() could not be tested. The memblock simulator passes again with NUMA enabled after these updates. Signed-off-by: Priyanshu Kumar --- tools/testing/memblock/README | 5 +-- tools/testing/memblock/TODO | 4 +- .../memblock/tests/alloc_exact_nid_api.c | 29 +++++++----- tools/testing/memblock/tests/alloc_nid_api.c | 44 +++++++++++++------ 4 files changed, 53 insertions(+), 29 deletions(-) diff --git a/tools/testing/memblock/README b/tools/testing/memblock/README index 7ca437d81806..b435f48d8a70 100644 --- a/tools/testing/memblock/README +++ b/tools/testing/memblock/README @@ -104,10 +104,7 @@ called at the beginning of each test. Known issues =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 -1. Requesting a specific NUMA node via memblock_alloc_node() does not work= as - intended. Once the fix is in place, tests for this function can be adde= d. - -2. Tests for memblock_alloc_low() can't be easily implemented. The functio= n uses +1. Tests for memblock_alloc_low() can't be easily implemented. The functio= n uses ARCH_LOW_ADDRESS_LIMIT marco, which can't be changed to point at the low memory of the memory_block. =20 diff --git a/tools/testing/memblock/TODO b/tools/testing/memblock/TODO index e306c90c535f..c13ad0dae776 100644 --- a/tools/testing/memblock/TODO +++ b/tools/testing/memblock/TODO @@ -1,5 +1,5 @@ TODO =3D=3D=3D=3D=3D =20 -1. Add tests for memblock_alloc_node() to check if the correct NUMA node i= s set - for the new region +1. Add tests for memblock_alloc_low() once the simulator can model + ARCH_LOW_ADDRESS_LIMIT against the low memory in memory_block diff --git a/tools/testing/memblock/tests/alloc_exact_nid_api.c b/tools/tes= ting/memblock/tests/alloc_exact_nid_api.c index 6e14447da6e1..3f5ab994f63a 100644 --- a/tools/testing/memblock/tests/alloc_exact_nid_api.c +++ b/tools/testing/memblock/tests/alloc_exact_nid_api.c @@ -368,7 +368,8 @@ static int alloc_exact_nid_bottom_up_numa_part_reserved= _check(void) max_addr =3D memblock_end_of_DRAM(); total_size =3D size + r1.size; =20 - memblock_reserve(r1.base, r1.size); + ASSERT_EQ(0, __memblock_reserve(r1.base, r1.size, nid_req, + MEMBLOCK_RSRV_KERN)); allocated_ptr =3D memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES, min_addr, max_addr, nid_req); @@ -831,14 +832,17 @@ static int alloc_exact_nid_numa_large_region_generic_= check(void) * | | r2 | new | r1 | | * +-------------+----+-----------------------+----+------------------+ * - * Expect to merge all of the regions into one. The region counter and tot= al - * size fields get updated. + * Expect to allocate the requested node as a separate kernel-reserved reg= ion. + * The neighboring reservations remain distinct because the new region rec= ords + * the requested NUMA node and MEMBLOCK_RSRV_KERN flag. */ static int alloc_exact_nid_numa_reserved_full_merge_generic_check(void) { int nid_req =3D 6; int nid_next =3D nid_req + 1; - struct memblock_region *new_rgn =3D &memblock.reserved.regions[0]; + struct memblock_region *left_rgn =3D &memblock.reserved.regions[0]; + struct memblock_region *new_rgn =3D &memblock.reserved.regions[1]; + struct memblock_region *right_rgn =3D &memblock.reserved.regions[2]; struct memblock_region *req_node =3D &memblock.memory.regions[nid_req]; struct memblock_region *next_node =3D &memblock.memory.regions[nid_next]; void *allocated_ptr =3D NULL; @@ -871,13 +875,18 @@ static int alloc_exact_nid_numa_reserved_full_merge_g= eneric_check(void) ASSERT_NE(allocated_ptr, NULL); ASSERT_MEM_NE(allocated_ptr, 0, size); =20 - ASSERT_EQ(new_rgn->size, total_size); - ASSERT_EQ(new_rgn->base, r2.base); - - ASSERT_LE(new_rgn->base, req_node->base); - ASSERT_LE(region_end(req_node), region_end(new_rgn)); + ASSERT_EQ(left_rgn->base, r2.base); + ASSERT_EQ(left_rgn->size, r2.size); + ASSERT_EQ(right_rgn->base, r1.base); + ASSERT_EQ(right_rgn->size, r1.size); + ASSERT_EQ(new_rgn->base, req_node->base); + ASSERT_EQ(new_rgn->size, size); + ASSERT_EQ(new_rgn->flags, MEMBLOCK_RSRV_KERN); + ASSERT_EQ(memblock_get_region_node(new_rgn), nid_req); + ASSERT_LE(req_node->base, new_rgn->base); + ASSERT_LE(region_end(new_rgn), region_end(req_node)); =20 - ASSERT_EQ(memblock.reserved.cnt, 1); + ASSERT_EQ(memblock.reserved.cnt, 3); ASSERT_EQ(memblock.reserved.total_size, total_size); =20 test_pass_pop(); diff --git a/tools/testing/memblock/tests/alloc_nid_api.c b/tools/testing/m= emblock/tests/alloc_nid_api.c index 562e4701b0e0..3d7a8c370844 100644 --- a/tools/testing/memblock/tests/alloc_nid_api.c +++ b/tools/testing/memblock/tests/alloc_nid_api.c @@ -1965,7 +1965,8 @@ static int alloc_nid_bottom_up_numa_part_reserved_che= ck(void) max_addr =3D memblock_end_of_DRAM(); total_size =3D size + r1.size; =20 - memblock_reserve(r1.base, r1.size); + ASSERT_EQ(0, __memblock_reserve(r1.base, r1.size, nid_req, + MEMBLOCK_RSRV_KERN)); allocated_ptr =3D run_memblock_alloc_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, nid_req); =20 @@ -2382,14 +2383,17 @@ static int alloc_nid_numa_large_region_generic_chec= k(void) * | | r2 | new | r1 | | * +-------------+----+-----------------------+----+------------------+ * - * Expect to merge all of the regions into one. The region counter and tot= al - * size fields get updated. + * Expect to allocate the requested node as a separate kernel-reserved reg= ion. + * The neighboring reservations remain distinct because the new region rec= ords + * the requested NUMA node and MEMBLOCK_RSRV_KERN flag. */ static int alloc_nid_numa_reserved_full_merge_generic_check(void) { int nid_req =3D 6; int nid_next =3D nid_req + 1; - struct memblock_region *new_rgn =3D &memblock.reserved.regions[0]; + struct memblock_region *left_rgn =3D &memblock.reserved.regions[0]; + struct memblock_region *new_rgn =3D &memblock.reserved.regions[1]; + struct memblock_region *right_rgn =3D &memblock.reserved.regions[2]; struct memblock_region *req_node =3D &memblock.memory.regions[nid_req]; struct memblock_region *next_node =3D &memblock.memory.regions[nid_next]; void *allocated_ptr =3D NULL; @@ -2421,13 +2425,18 @@ static int alloc_nid_numa_reserved_full_merge_gener= ic_check(void) ASSERT_NE(allocated_ptr, NULL); assert_mem_content(allocated_ptr, size, alloc_nid_test_flags); =20 - ASSERT_EQ(new_rgn->size, total_size); - ASSERT_EQ(new_rgn->base, r2.base); - - ASSERT_LE(new_rgn->base, req_node->base); - ASSERT_LE(region_end(req_node), region_end(new_rgn)); + ASSERT_EQ(left_rgn->base, r2.base); + ASSERT_EQ(left_rgn->size, r2.size); + ASSERT_EQ(right_rgn->base, r1.base); + ASSERT_EQ(right_rgn->size, r1.size); + ASSERT_EQ(new_rgn->base, req_node->base); + ASSERT_EQ(new_rgn->size, size); + ASSERT_EQ(new_rgn->flags, MEMBLOCK_RSRV_KERN); + ASSERT_EQ(memblock_get_region_node(new_rgn), nid_req); + ASSERT_LE(req_node->base, new_rgn->base); + ASSERT_LE(region_end(new_rgn), region_end(req_node)); =20 - ASSERT_EQ(memblock.reserved.cnt, 1); + ASSERT_EQ(memblock.reserved.cnt, 3); ASSERT_EQ(memblock.reserved.total_size, total_size); =20 test_pass_pop(); @@ -2496,15 +2505,18 @@ static int alloc_nid_numa_split_all_reserved_generi= c_check(void) =20 /* * A simple test that tries to allocate a memory region through the - * memblock_alloc_node() on a NUMA node with id `nid`. Expected to have the - * correct NUMA node set for the new region. + * memblock_alloc_node() on a NUMA node with id `nid`. Expected to allocate + * the region within the requested node and mark the new reservation with = the + * correct NUMA node. */ static int alloc_node_on_correct_nid(void) { int nid_req =3D 2; void *allocated_ptr =3D NULL; #ifdef CONFIG_NUMA + struct memblock_region *new_rgn =3D &memblock.reserved.regions[0]; struct memblock_region *req_node =3D &memblock.memory.regions[nid_req]; + phys_addr_t req_node_end =3D region_end(req_node); #endif phys_addr_t size =3D SZ_512; =20 @@ -2515,7 +2527,13 @@ static int alloc_node_on_correct_nid(void) =20 ASSERT_NE(allocated_ptr, NULL); #ifdef CONFIG_NUMA - ASSERT_EQ(nid_req, req_node->nid); + ASSERT_EQ(memblock.reserved.cnt, 1); + ASSERT_EQ(new_rgn->size, size); + ASSERT_EQ(new_rgn->base, (phys_addr_t)allocated_ptr); + ASSERT_EQ(new_rgn->flags, MEMBLOCK_RSRV_KERN); + ASSERT_EQ(nid_req, memblock_get_region_node(new_rgn)); + ASSERT_LE(req_node->base, new_rgn->base); + ASSERT_LE(region_end(new_rgn), req_node_end); #endif =20 test_pass_pop(); --=20 2.43.0