From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD32E524A8; Mon, 8 Jan 2024 15:43:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="lvGR/LUn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C005FC433C9; Mon, 8 Jan 2024 15:43:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1704728625; bh=dABz2Od2sPEktQd+vKr8cSZIhYykIYL+Jh3yYQZjEWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lvGR/LUnB3qCVf8r0Tpg2Zyi5365iyj20sLJWDYI66UQAk3w5YF+frj+a9Hq+RofK LXl49eLV1jdXlJOLdl62V4iI3OFo9WVCu2W96at40hbOpNuQzwQaL5E600r8zypyry 9/HVZRB/M72oPZWzqcli8MqNSoYldPGHCgO1fWlg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sumanth Korikkar , Gerald Schaefer , David Hildenbrand , Alexander Gordeev , "Aneesh Kumar K.V" , Anshuman Khandual , Heiko Carstens , kernel test robot , Michal Hocko , Oscar Salvador , Vasily Gorbik , Andrew Morton , Sasha Levin Subject: [PATCH 6.1 119/150] mm/memory_hotplug: fix error handling in add_memory_resource() Date: Mon, 8 Jan 2024 16:36:10 +0100 Message-ID: <20240108153516.674993414@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240108153511.214254205@linuxfoundation.org> References: <20240108153511.214254205@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sumanth Korikkar [ Upstream commit f42ce5f087eb69e47294ababd2e7e6f88a82d308 ] In add_memory_resource(), creation of memory block devices occurs after successful call to arch_add_memory(). However, creation of memory block devices could fail. In that case, arch_remove_memory() is called to perform necessary cleanup. Currently with or without altmap support, arch_remove_memory() is always passed with altmap set to NULL during error handling. This leads to freeing of struct pages using free_pages(), eventhough the allocation might have been performed with altmap support via altmap_alloc_block_buf(). Fix the error handling by passing altmap in arch_remove_memory(). This ensures the following: * When altmap is disabled, deallocation of the struct pages array occurs via free_pages(). * When altmap is enabled, deallocation occurs via vmem_altmap_free(). Link: https://lkml.kernel.org/r/20231120145354.308999-3-sumanthk@linux.ibm.com Fixes: a08a2ae34613 ("mm,memory_hotplug: allocate memmap from the added memory range") Signed-off-by: Sumanth Korikkar Reviewed-by: Gerald Schaefer Acked-by: David Hildenbrand Cc: Alexander Gordeev Cc: Aneesh Kumar K.V Cc: Anshuman Khandual Cc: Heiko Carstens Cc: kernel test robot Cc: Michal Hocko Cc: Oscar Salvador Cc: Vasily Gorbik Cc: [5.15+] Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- mm/memory_hotplug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index d02722bbfcf33..3b9d3a4b43869 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1382,7 +1382,7 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) ret = create_memory_block_devices(start, size, mhp_altmap.alloc, group); if (ret) { - arch_remove_memory(start, size, NULL); + arch_remove_memory(start, size, params.altmap); goto error; } -- 2.43.0