Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/memory_hotplug: Factor out altmap freeing checks
@ 2026-05-11  8:43 Muchun Song
  2026-05-11  9:00 ` David Hildenbrand (Arm)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Muchun Song @ 2026-05-11  8:43 UTC (permalink / raw)
  To: David Hildenbrand, Oscar Salvador, Andrew Morton, linux-mm
  Cc: muchun.song, linux-cxl, linux-kernel, Muchun Song

Use a small helper to centralize altmap freeing after verifying that all
vmemmap pages were released. This keeps the check consistent between the
normal teardown path and the memory hotplug error paths.

Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
 mm/memory_hotplug.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 462d8dcd636d..af5489f03771 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1403,6 +1403,12 @@ bool mhp_supports_memmap_on_memory(void)
 }
 EXPORT_SYMBOL_GPL(mhp_supports_memmap_on_memory);
 
+static void altmap_free(struct vmem_altmap *altmap)
+{
+	WARN_ONCE(altmap->alloc, "Altmap not fully unmapped");
+	kfree(altmap);
+}
+
 static void remove_memory_blocks_and_altmaps(u64 start, u64 size)
 {
 	unsigned long memblock_size = memory_block_size_bytes();
@@ -1427,12 +1433,8 @@ static void remove_memory_blocks_and_altmaps(u64 start, u64 size)
 		put_device(&mem->dev);
 
 		remove_memory_block_devices(cur_start, memblock_size);
-
 		arch_remove_memory(cur_start, memblock_size, altmap, NULL);
-
-		/* Verify that all vmemmap pages have actually been freed. */
-		WARN(altmap->alloc, "Altmap not fully unmapped");
-		kfree(altmap);
+		altmap_free(altmap);
 	}
 }
 
@@ -1463,7 +1465,7 @@ static int create_altmaps_and_memory_blocks(int nid, struct memory_group *group,
 		/* call arch's memory hotadd */
 		ret = arch_add_memory(nid, cur_start, memblock_size, &params);
 		if (ret < 0) {
-			kfree(params.altmap);
+			altmap_free(params.altmap);
 			goto out;
 		}
 
@@ -1472,7 +1474,7 @@ static int create_altmaps_and_memory_blocks(int nid, struct memory_group *group,
 						  params.altmap, group);
 		if (ret) {
 			arch_remove_memory(cur_start, memblock_size, params.altmap, NULL);
-			kfree(params.altmap);
+			altmap_free(params.altmap);
 			goto out;
 		}
 	}

base-commit: e98d21c170b01ddef366f023bbfcf6b31509fa83
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/memory_hotplug: Factor out altmap freeing checks
  2026-05-11  8:43 [PATCH] mm/memory_hotplug: Factor out altmap freeing checks Muchun Song
@ 2026-05-11  9:00 ` David Hildenbrand (Arm)
  2026-05-11  9:02 ` Oscar Salvador
  2026-05-11  9:12 ` Donet Tom
  2 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand (Arm) @ 2026-05-11  9:00 UTC (permalink / raw)
  To: Muchun Song, Oscar Salvador, Andrew Morton, linux-mm
  Cc: muchun.song, linux-cxl, linux-kernel

On 5/11/26 10:43, Muchun Song wrote:
> Use a small helper to centralize altmap freeing after verifying that all
> vmemmap pages were released. This keeps the check consistent between the
> normal teardown path and the memory hotplug error paths.
> 
> Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
> ---

Acked-by: David Hildenbrand (Arm) <david@kernel.org>

-- 
Cheers,

David


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/memory_hotplug: Factor out altmap freeing checks
  2026-05-11  8:43 [PATCH] mm/memory_hotplug: Factor out altmap freeing checks Muchun Song
  2026-05-11  9:00 ` David Hildenbrand (Arm)
@ 2026-05-11  9:02 ` Oscar Salvador
  2026-05-11  9:12 ` Donet Tom
  2 siblings, 0 replies; 4+ messages in thread
From: Oscar Salvador @ 2026-05-11  9:02 UTC (permalink / raw)
  To: Muchun Song
  Cc: David Hildenbrand, Andrew Morton, linux-mm, muchun.song,
	linux-cxl, linux-kernel

On Mon, May 11, 2026 at 04:43:07PM +0800, Muchun Song wrote:
> Use a small helper to centralize altmap freeing after verifying that all
> vmemmap pages were released. This keeps the check consistent between the
> normal teardown path and the memory hotplug error paths.
> 
> Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>

Acked-by: Oscar Salvador <osalvador@suse.de>

 

-- 
Oscar Salvador
SUSE Labs


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/memory_hotplug: Factor out altmap freeing checks
  2026-05-11  8:43 [PATCH] mm/memory_hotplug: Factor out altmap freeing checks Muchun Song
  2026-05-11  9:00 ` David Hildenbrand (Arm)
  2026-05-11  9:02 ` Oscar Salvador
@ 2026-05-11  9:12 ` Donet Tom
  2 siblings, 0 replies; 4+ messages in thread
From: Donet Tom @ 2026-05-11  9:12 UTC (permalink / raw)
  To: Muchun Song, David Hildenbrand, Oscar Salvador, Andrew Morton,
	linux-mm
  Cc: muchun.song, linux-cxl, linux-kernel


On 5/11/26 2:13 PM, Muchun Song wrote:
> Use a small helper to centralize altmap freeing after verifying that all
> vmemmap pages were released. This keeps the check consistent between the
> normal teardown path and the memory hotplug error paths.
>
> Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>


looks good to me.

Reviewed-by: Donet Tom <donettom@linux.ibm.com>

-Donet

> ---
>   mm/memory_hotplug.c | 16 +++++++++-------
>   1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index 462d8dcd636d..af5489f03771 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -1403,6 +1403,12 @@ bool mhp_supports_memmap_on_memory(void)
>   }
>   EXPORT_SYMBOL_GPL(mhp_supports_memmap_on_memory);
>   
> +static void altmap_free(struct vmem_altmap *altmap)
> +{
> +	WARN_ONCE(altmap->alloc, "Altmap not fully unmapped");
> +	kfree(altmap);
> +}
> +
>   static void remove_memory_blocks_and_altmaps(u64 start, u64 size)
>   {
>   	unsigned long memblock_size = memory_block_size_bytes();
> @@ -1427,12 +1433,8 @@ static void remove_memory_blocks_and_altmaps(u64 start, u64 size)
>   		put_device(&mem->dev);
>   
>   		remove_memory_block_devices(cur_start, memblock_size);
> -
>   		arch_remove_memory(cur_start, memblock_size, altmap, NULL);
> -
> -		/* Verify that all vmemmap pages have actually been freed. */
> -		WARN(altmap->alloc, "Altmap not fully unmapped");
> -		kfree(altmap);
> +		altmap_free(altmap);
>   	}
>   }
>   
> @@ -1463,7 +1465,7 @@ static int create_altmaps_and_memory_blocks(int nid, struct memory_group *group,
>   		/* call arch's memory hotadd */
>   		ret = arch_add_memory(nid, cur_start, memblock_size, &params);
>   		if (ret < 0) {
> -			kfree(params.altmap);
> +			altmap_free(params.altmap);
>   			goto out;
>   		}
>   
> @@ -1472,7 +1474,7 @@ static int create_altmaps_and_memory_blocks(int nid, struct memory_group *group,
>   						  params.altmap, group);
>   		if (ret) {
>   			arch_remove_memory(cur_start, memblock_size, params.altmap, NULL);
> -			kfree(params.altmap);
> +			altmap_free(params.altmap);
>   			goto out;
>   		}
>   	}
>
> base-commit: e98d21c170b01ddef366f023bbfcf6b31509fa83


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-05-11  9:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-11  8:43 [PATCH] mm/memory_hotplug: Factor out altmap freeing checks Muchun Song
2026-05-11  9:00 ` David Hildenbrand (Arm)
2026-05-11  9:02 ` Oscar Salvador
2026-05-11  9:12 ` Donet Tom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox