From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.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 818CA318EE7 for ; Fri, 24 Apr 2026 02:56:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776999399; cv=none; b=FaOAyKiShlrQgmrrG7lAONir+PNPm+Ccx4OIVkvOn6NyTycanYaZiciyotk3yNQ9bK/K9A8JEBapqtkbCsI7HtlBR2K1DtAg9UjWfFWBq2+QBqKx4rZccUj5ZL8ii6Nplx5rqE6vf7ndCzgWgM/xauriJcE3bTG7dV6uZFH0OBo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776999399; c=relaxed/simple; bh=r35P7VtdnoMm5CPZyedfG2y5OKFJTV7Ok/2IPFA7IVo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lvxtCP7xb6w0/0i9ojC65cxPnARKNE/EI0bf1lXDhY56j1WChoiWwh/iuB54+fIS2qRfBuFxlSsEPQe6aW3xvRi4nQg7VFfFJ2ZU/TZlVY7bGMSU57s1+TiA9CtOAssKnajdxi795gK++oKmLR0f2VND929Bo7h2AzsFiJremAQ= 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=aEWXrsnf; arc=none smtp.client-ip=209.85.214.180 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="aEWXrsnf" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2ad9f316d68so33166765ad.2 for ; Thu, 23 Apr 2026 19:56:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1776999392; x=1777604192; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ETx/tSKnTC+n/nV2wgCSbp2pIhIkVNUTkv0q633meJ0=; b=aEWXrsnfZZRGZugtsOuXvA8OsdJCIueaxpVSW9zWxtmJX0NrNBVxJzpVa8w1akSyj2 Qg3PDwx2XsXeGa3Owo9BEAaLdhH7V+2STs4IYj79Z2JOsAx785OmnHmbcPkshN2dxUzG t3+ZAeMiCMhvZAs+IxXLXb1l+7G1GPy1hWxCbiyL6In5a7F9L4gwpdaza1OOwu6ZAMab v59V0Jz17IdO4spUhspS4bpggsrEX4hzPYxoUi4QGURtuYC1N5yxjQdQ2x6uGSc0dqjq W7VF40G36VrpjJU0jIzRh2p7PiYSj/Vx14wCtjV6w+imB41MVuovp4D3GTaMlNpio8yd iHfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776999392; x=1777604192; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ETx/tSKnTC+n/nV2wgCSbp2pIhIkVNUTkv0q633meJ0=; b=gpbbdSHFeLGu1o87Fnmwodoi51DFgpSd8fOagTgrXphw5hZQO2c+5Vdu/BpJ1b5AYh lMhLCpG3MCytwRdHzswIeEOlp79x4EylXApAqbeB6xcvm+nuL7IVQbY1F3H6o6snmSgM u6nbq2c8+gaMsiZUdaea8Jf2qwgZLI3RC7hb+XpXvXKfd0EXD0KTd/FAS27Z10iuHzf/ 8AIlkDwHC4HUHTA0ZjeVTe09Tr83pY4wrej5vBfCOdDByQz3QKdGcDwoVrcm+gn7UNlB uOPq/iPsFaf7j423v89hSKANV9guZ8aVCZuCfmyWUYF0qFaV876KIHyFWGw6UhoYq4HL FZng== X-Forwarded-Encrypted: i=1; AFNElJ8Yrvszt/6nSnEpnFfyDCEuMJPEGl6cgF2MdObQfSTDjVJJ7uc6NUtTcxyJzLZVDyDaU9p3E7FrpCNYjBw=@vger.kernel.org X-Gm-Message-State: AOJu0YyQQdDPOMOKbbB7RbCB46iZVGanpreRvCLt0daZGRFTfAl7mw2g xIE3u3TK55NZ/r8Hyg0iIRav6/p/rP66cKgMbupvHS8ULyvSWUzb74WXTdUaGVYo9xE= X-Gm-Gg: AeBDietgObyjwgZMWTy9m1YoUlYsTaX27/R7vWF5vp2H/1OdsDdUPXjtz4UhjKuwNd0 l2rniKdDE/apcfLPPpOZkRsZt56RtvKioQOh2uSWW+3hD4XbBv6cxVOkoT/v1ySZKB3+CT0zeJw CBF4fZ9JijiMIWWnGUP5H4pS72wFWvgkEuWQa8YSBm1IETHWcE04LoWEVXwCVowQLx2BoRsXByp dKgbwjwV2ByN9/vCki91SvyQDjnGvP+Y/hqPpP4ytt6TitoK7MNRy64xYOsXUh4lc8jZytj2jz/ XP01Nu+AVmuSyWYurLgbKJd8aV7cb1BLwAN7WVJxjLBLZYbaAb6V+fW14ECqO8mA61j7qpXKBbP d793US1blGQzDfQ70tdWNzB4XXEI8HNlHFuMl2WhuOAB0PkOAa5HKfx8+muCwuKWlQVAnep1dva rshFS9rIeooyt2V1yR2nhp+IiWDlWaw39TFpZyaVpOdWcTlbUm7N6bf7wZGPG3pXRn6w== X-Received: by 2002:a17:902:6bc2:b0:2b0:9101:1b77 with SMTP id d9443c01a7336-2b5f9eaf6a6mr216777385ad.17.1776999392104; Thu, 23 Apr 2026 19:56:32 -0700 (PDT) Received: from n232-176-004.byted.org ([36.110.163.102]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b5fab20d33sm221668325ad.63.2026.04.23.19.56.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 19:56:31 -0700 (PDT) From: Muchun Song To: Andrew Morton , David Hildenbrand , Muchun Song , Oscar Salvador , Michael Ellerman , Madhavan Srinivasan Cc: Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Nicholas Piggin , Christophe Leroy , aneesh.kumar@linux.ibm.com, joao.m.martins@oracle.com, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH v6 7/7] mm/memory_hotplug: Factor out altmap freeing checks Date: Fri, 24 Apr 2026 10:55:47 +0800 Message-Id: <20260424025547.3806072-8-songmuchun@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20260424025547.3806072-1-songmuchun@bytedance.com> References: <20260424025547.3806072-1-songmuchun@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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 7bfdc3a99688..ee150d312bd9 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(); @@ -1425,12 +1431,8 @@ static void remove_memory_blocks_and_altmaps(u64 start, u64 size) mem->altmap = NULL; 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); } } @@ -1461,7 +1463,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, ¶ms); if (ret < 0) { - kfree(params.altmap); + altmap_free(params.altmap); goto out; } @@ -1470,7 +1472,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; } } -- 2.20.1