From nobody Sat Jun 13 03:31:07 2026 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 7336439D6E2 for ; Mon, 11 May 2026 08:43:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778489008; cv=none; b=QD0NE9Fm1qOu163DzhWRbXxekgzjS2Rk4pL+si6UaJEAcOCA91Yrlwr3a/gLoxagrUlMN4RcmDOBIa8WJwdqnoNGRj1fw77evXnKgPAG17DJr0td2iLFEkfOkyh2+kVmvISxN6/AylFc8ugqoAqkfyPQJebW5wpL9IBl78Cw4H8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778489008; c=relaxed/simple; bh=abKRP8Hq8LvHYhe2eiwHeT7AAr7qOth4sC+8vuMIMJ4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=RKd43PqfeTvczhcX2x/V2qiV6P6t7+WNKbBFaIfP0nsvfwWJ0SEEJKRTwZx/CWb0OPCHtCj/fS6hXuNZ9Jca7Dqtc7pCn8MfhhPAIwK+fHX0KCXBd6j3oPzFdx/RiVX/A5fL6U0vstR16cBC5AzMtroj04/XioKPtTgFsenfPw4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=NUsGpqSi; arc=none smtp.client-ip=209.85.216.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="NUsGpqSi" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-3665a90bcd3so2404150a91.1 for ; Mon, 11 May 2026 01:43:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1778489004; x=1779093804; 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=NSVJMcCRDCZ65VHh5kS3ZBwZuxCk7Ny7ZgL99/YO4W8=; b=NUsGpqSiNFlouxky6VXPNvL1lTf8f68QbRzRxIC/vkeejuzAfBGVd0pACRO5Q0tHKx aDoZSUhuYl9tzi0aStzi4G97aRzBJ8DOhudUu0wfcHr+ZZdnb845sQdVX55inPbOLD+7 SQlUrISWYbRpYJQ0bFFCqWYY27zPPgC0ZyQXg7ek2oIvjZWlDsBkfR7mZaYXHNhrpV5v 03//hG+AEvbp3T36OpJ3leKnBL6mnZ4PfBGTvpBNAbBfL1GDtsMOXs0pHVI0Yr2vGpYR zcWPEHDY7Z+4ks2dpOjWAxpkUTIQjRrshlKWhnf7MNrd9+TI2+d7FuHRdy6lNJ+LpNcm NWJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778489004; x=1779093804; 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=NSVJMcCRDCZ65VHh5kS3ZBwZuxCk7Ny7ZgL99/YO4W8=; b=i70+0maqFp8dzRM6yNMeQYXOT0oWhAvocfNE2TmkGpM7Rpww9GpDjfe8MRwBlIKCC6 cnynPaEGViAeULvvYKeC4FMNlHNb462PYajg4T3lQhh7PazUEZB6aP/fHfckjhS5JQum zsibIUFaQ4A+B+POVzWjLLXmoI1avpKDyMWiftvt5LmvF4Kq+oR3+NOjQO6DgxS7AtCE Zp0+RzlaRzGkEOh4Gnn2OpI6TAbVUy7FopFiCPZ2qdpo9BgW6fqlCxG13cpBoAM9E6g4 1ylPPyeB2MNssR3x6/qYFbzE7yt+oYMGuBNf9VFKRnPj9aDBbbBuGL4u2KglLa0WtSSi izug== X-Forwarded-Encrypted: i=1; AFNElJ9EE+Wavw2LmZpwltnrGJmp+2Vw7ZE60dqHeS82X3y+fZh6tdiE+Wh8H3CFCVGYSKhR7TnMUN9QxK0qwYc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7hjWgG8t3zfqrBoO+kRX3+8v9PODJNVXBXNgNCBgflRGMnAuY 5Eud3dYZkGFV9phLOC9neYOp3jyklczFHuesM0P7jWtbAfQVvO0Fl4UrnJ5bMD0DQvo= X-Gm-Gg: Acq92OEpiLfHSRmvtQgykn7Kx/PouUZ8LaTSiUmW3UTfpVNKWWpdt9UJtMfTdl48HNG oov6PQPS3Gj5aMmSXKE9nRLVixJaaez3stcL9g7XLu5Pd8Us1xdBKtcA/WcGG7TMuKrR4e/UAud KQE2M2b8uhgTM6Oi2EjmeZEnJiqLOEA32/sJ2HQ4nwcD4s5f46TV2L8Zcrcm5PIs9GOYF55nB8P Q6daRYe1x+peRkGaJJ2m6qyKG7V/64d5n9N8zeO7Rx4g5DijHVGKdoBAvTOB1h4LBqVXnK4te+F QenaPz0UK+MfHIUKG2upn3rz1+uldSSkbq4757Mb6g1r9RbL56pr28T7HOg0Bn3eRtPnlvCB4Ec NHh9UPdAApsdu0OTlkfw62LPXwzF+R/FA6lF6GqU7mZWNSNY//PcnGALPeBiKVHYIZIem4eDY4m sZDt4yPEfYF5nS1ifl/YR30mAWHEaB7LmXx+A+K8vEBUxQ6GjuOfZOTg== X-Received: by 2002:a17:903:1aae:b0:2b7:88f9:9c3d with SMTP id d9443c01a7336-2bc7a9a0d0emr95547205ad.12.1778489004370; Mon, 11 May 2026 01:43:24 -0700 (PDT) Received: from n232-176-004.byted.org ([36.110.163.97]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e35bcfsm94125535ad.38.2026.05.11.01.43.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 01:43:23 -0700 (PDT) From: Muchun Song To: David Hildenbrand , Oscar Salvador , Andrew Morton , linux-mm@kvack.org Cc: muchun.song@linux.dev, linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH] mm/memory_hotplug: Factor out altmap freeing checks Date: Mon, 11 May 2026 16:43:07 +0800 Message-Id: <20260511084307.1827127-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.20.1 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" 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) Signed-off-by: Muchun Song Acked-by: David Hildenbrand (Arm) Acked-by: Oscar Salvador Reviewed-by: Donet Tom --- 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); =20 +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 =3D memory_block_size_bytes(); @@ -1427,12 +1433,8 @@ static void remove_memory_blocks_and_altmaps(u64 sta= rt, u64 size) put_device(&mem->dev); =20 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); } } =20 @@ -1463,7 +1465,7 @@ static int create_altmaps_and_memory_blocks(int nid, = struct memory_group *group, /* call arch's memory hotadd */ ret =3D arch_add_memory(nid, cur_start, memblock_size, ¶ms); if (ret < 0) { - kfree(params.altmap); + altmap_free(params.altmap); goto out; } =20 @@ -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 --=20 2.20.1