From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384950; b=CoH+kqfzMXaWShjwv3zL9oi38DemwPwkzlZJ47s6vc6Zw6ALAWS9VKLI2dmyU7Bpz94h gJTRFPAY9SFst3OKZyngfqRNMY3Idbo35opRj+IjjDicnPOiB3NG7g4uo9Zg/Qkjmo1NL ncI7by1/vkLXDzp6HWzeB1tSZ1o7fXGCeZxPvh9X0bJOEvqUn3JRl+y31OboeKeiTZD2R Sx3HA7OksEeK3pzCXq4h8cMyHg86ertOK5nZhJqAS8jTUfxpYILT5mHMASLV7jfAtVc2A icnn056RSHBfpxU2PyfYEmq7l12roAttEeIw2miHTzBbr4RHTVHtPy09U3dPiSyLs/w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384950; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=b5t5JtpmEq8j3ZcJfSdBC9+mRwpL8ZOS0Jx+Ktg/SuM=; b=H8RXnq8F4w4TVM0QAwyWrPOjkAX/JpZJD9h7Dr6n1oGgQAnSLNBbVfLKJdBK8wq1Mmmr 7nleIaYRy/u07QYq+Sma7B16F9H2nxRxx1rNoo3KhHxXoiZ1ZRua5VhV6Nd1h67tjIlQo X5Yc8mkTbSyJdFbxE6o71xRFSJK3bpuJZl05IaqcdgVB6ItP+NFseNEaosPiKtO4D2mrg hH0pqeEmbMzotk8ehTyBImhQRsqxkQuCpVfs+gy9BP8e+Zq1vrz2g6PCm0zNXZFps7UBG NHyVMub+59iNIoOQbaNwu8BhltYF259U9C7ptfgRtU6oilUgwGkw9vi0EF3W2+u6MOA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=EguPImhT; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E803606A32C; Fri, 4 Dec 2026 11:49:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=EguPImhT Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2C191F000C2; Fri, 4 Dec 2026 11:49:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384950; bh=b5t5JtpmEq8j3ZcJfSdBC9+mRwpL8ZOS0Jx+Ktg/SuM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EguPImhToCk2zxkt5jxZTWBaMDIJnqA20KcMfgkjX33MzUhxYNdMKtsgOzy8cbSI6 AqrMg7ZSzsIVLjratyGE6nbPsaOSo/XqnbFD5HP0k2372jIW7VAorJPzY7Xgl/B3Q/ DTkCJXzNkeI3SZ4L6nTE5OeNgLeZeW4vpPwg0dZE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Muchun Song , Lance Yang , "David Hildenbrand (Arm)" , Sasha Levin Subject: [PATCH 6.6 0359/1167] mm/memory_hotplug: fix missing rollback in __add_pages() Date: Fri, 4 Dec 2026 18:56:26 +0900 Message-ID: <20261204100711.336555555@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lance Yang [ Upstream commit c31bb839fb829958101250ee5acfa4f94fdb7ecd ] __add_pages() returns on a sparse_add_section() failure without removing the sections already added in the same request. For memremap_pages(), the failed range is not counted in pgmap->nr_range, so memunmap_pages() skips it. The sections already added in that range retain their vmemmap mappings and subsection bits. Retrying a section-aligned range can then fail with -EEXIST. Save the initial PFN and remove [start_pfn, pfn) on failure. For a vmemmap population failure, section_activate() already cleans up the current section, so the rollback excludes it. If the first section fails, __remove_pages() receives an empty range and does nothing. Link: https://lore.kernel.org/all/BAD58999-1EDD-4A37-ABA0-DB1BD8AB3453@linux.dev/ Suggested-by: Muchun Song Signed-off-by: Lance Yang Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug") Acked-by: Muchun Song Link: https://patch.msgid.link/20260930160432.5564-1-lance.yang@linux.dev Signed-off-by: David Hildenbrand (Arm) [ sashal: Dropped the params->pgmap argument from the __remove_pages() rollback call, and adjusted the hunk context for the __ref on __add_pages(). ] Signed-off-by: Sasha Levin --- mm/memory_hotplug.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 08444c40ed650..931879ec2c96f 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -369,6 +369,7 @@ EXPORT_SYMBOL_GPL(pfn_to_online_page); int __ref __add_pages(int nid, unsigned long pfn, unsigned long nr_pages, struct mhp_params *params) { + const unsigned long start_pfn = pfn; const unsigned long end_pfn = pfn + nr_pages; unsigned long cur_nr_pages; int err; @@ -402,8 +403,10 @@ int __ref __add_pages(int nid, unsigned long pfn, unsigned long nr_pages, SECTION_ALIGN_UP(pfn + 1) - pfn); err = sparse_add_section(nid, pfn, cur_nr_pages, altmap, params->pgmap); - if (err) + if (err) { + __remove_pages(start_pfn, pfn - start_pfn, altmap); break; + } cond_resched(); } vmemmap_populate_print_last(); -- 2.53.0