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 A7DC0194A45; Tue, 27 May 2025 16:50:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748364635; cv=none; b=cYx8KYhCko1qHSP1+wEt9Izy5tx9UYE5klzNVdn16NmtbbrqWCAQSswY7+IoMQl1phmTD/ZqqWBtbGiemCDI19ADdqP3CYEhvxrogH7s+jO/xEsEU7R/YGDiQTh6oQFgdJg5NUVURTGi6+9rMt9Qln8qP5n6Y9JTamHWPPCjc6A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748364635; c=relaxed/simple; bh=TNTlFeKM2vq5PxrEU8qDKwcyqzU7wknDK2BeysJmQmA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e7+SfTFQU3yat9NZsabwQHCZtbVoKs5ltdJxl2c2LfoaCueM1Gvts4lVRxA6mq7FPgmU34JIcK+v9VmbDyFFdV15V8orC2JfQnAs2RzjLKOZqImO1EZVSWIC5tnaSWaBNL1RYpZ8+OKq4xy5E3GpeavWvrArVCtUEoC7dGlBdws= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=tf8ExFxB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="tf8ExFxB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D586C4CEE9; Tue, 27 May 2025 16:50:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1748364635; bh=TNTlFeKM2vq5PxrEU8qDKwcyqzU7wknDK2BeysJmQmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tf8ExFxBb5hGv8m+IeuTqf7nI7F76gsdYDpc1J0VYXlap6xfk3/cDnEEt1Stw1M0/ wibP4NoD/OXifS/6HJzjZZJIYNFKCL9/iY3r+RXcz8QFkgEsiG8khHoA05Ta6iEESp OMmAhlnR9QQ6ZcH3dkOFnc00Z4As6YwtApNj9bQ8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Philip Redkin , Ingo Molnar , Dave Hansen , Rik van Riel , "H. Peter Anvin" , Sasha Levin Subject: [PATCH 6.12 111/626] x86/mm: Check return value from memblock_phys_alloc_range() Date: Tue, 27 May 2025 18:20:04 +0200 Message-ID: <20250527162449.546737011@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527162445.028718347@linuxfoundation.org> References: <20250527162445.028718347@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Philip Redkin [ Upstream commit 631ca8909fd5c62b9fda9edda93924311a78a9c4 ] At least with CONFIG_PHYSICAL_START=0x100000, if there is < 4 MiB of contiguous free memory available at this point, the kernel will crash and burn because memblock_phys_alloc_range() returns 0 on failure, which leads memblock_phys_free() to throw the first 4 MiB of physical memory to the wolves. At a minimum it should fail gracefully with a meaningful diagnostic, but in fact everything seems to work fine without the weird reserve allocation. Signed-off-by: Philip Redkin Signed-off-by: Ingo Molnar Cc: Dave Hansen Cc: Rik van Riel Cc: "H. Peter Anvin" Link: https://lore.kernel.org/r/94b3e98f-96a7-3560-1f76-349eb95ccf7f@rarity.fan Signed-off-by: Sasha Levin --- arch/x86/mm/init.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index 101725c149c42..9cbc1e6057d3c 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -645,8 +645,13 @@ static void __init memory_map_top_down(unsigned long map_start, */ addr = memblock_phys_alloc_range(PMD_SIZE, PMD_SIZE, map_start, map_end); - memblock_phys_free(addr, PMD_SIZE); - real_end = addr + PMD_SIZE; + if (!addr) { + pr_warn("Failed to release memory for alloc_low_pages()"); + real_end = max(map_start, ALIGN_DOWN(map_end, PMD_SIZE)); + } else { + memblock_phys_free(addr, PMD_SIZE); + real_end = addr + PMD_SIZE; + } /* step_size need to be small so pgt_buf from BRK could cover it */ step_size = PMD_SIZE; -- 2.39.5