From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF69A606A327 for ; Wed, 2 Dec 2026 11:14:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=29udaOzx; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=U8762WTv DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: Message-ID:Date:References:In-Reply-To:Subject:Cc:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=d7Uvzzp3SR8Q0ESf0LGAjLXxxd8UGwcNk6ArtMo/JQY=; b=29udaOzxzUlmk55XDFhewQc/wD MnXkQZS2Ii5OlWTFAyeNjDUIC/Xi4gExcBlfrbcLX+VigTFbnz6uapDacVVaftOCwQH7JT3p82l4z WkojAFPJy3ysj21VR2co9CdZAFcTDafVOZJ/MnwjWhLtqi6MDxykCiKsM0phYULMCsY4DaiDyWwNz SD/BfKLW/ABG3G79Vg/KFb4ahHjk8jGt+8GNtvoWjLnaw/9JoiFHhPK7yuuimNvNL9l2b6jhNBq+t s+8qS+R+Vi8fcssVLi0TkIzFq3bYPtwLnN6HjGZwckjj9SL/8QDPw2C2EY6uBFUUJC0PObJoB0TDI sdN6JndQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYiHt-0000000BHRH-2DB1; Wed, 02 Dec 2026 11:14:13 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYiHs-0000000BHR1-3ctS for kexec@lists.infradead.org; Wed, 02 Dec 2026 11:14:13 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 4EE6844321; Wed, 2 Dec 2026 11:14:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B7491F00893; Wed, 2 Dec 2026 11:14:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796210052; bh=d7Uvzzp3SR8Q0ESf0LGAjLXxxd8UGwcNk6ArtMo/JQY=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=U8762WTvZji08h7Z0UB/Rh7lXRv8u5kZn/6y/VKO6J3G3tsaU2y44zIj0lR4TTlJs d+5f8c+b7CH3JnxxAzaVzlBwPLP1V9Mc7pCyIn67CXo891Jx9dKa0hTk4oNKQfAB9z 9g7DbfU1d0gkg9CK6J1T0ob6C9x9WZmD9jrftOYg5AXimwLPL30RBFAW4IoH++B/Xm rb2BLARgeQ/B/12CKYzP27Mc+iKqLln5qUE5uVdHHaOrvhCV1YTAXE7sfuZBrCuDFV o3fIOWoRuVX0vqqSb6PlzsR4a+urNwZA/UObisMPwYCGajlGwv+PEGDyroyvgSTwJD wNUxfD17SNywg== From: Pratyush Yadav To: Chris Down Cc: rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, graf@amazon.com, kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: Re: [PATCH v2 2/2] kho: drop the handover if preserved memory can't be reserved In-Reply-To: <58bd4ca045b33b71cec8509e893f4ff81e372dc7.1796126791.git.chris@chrisdown.name> (Chris Down's message of "Tue, 01 Dec 2026 22:32:11 -0800") References: <58bd4ca045b33b71cec8509e893f4ff81e372dc7.1796126791.git.chris@chrisdown.name> Date: Wed, 02 Dec 2026 11:14:08 +0000 Message-ID: <2vxzfqwgue7z.fsf@kernel.org> User-Agent: Gnus/5.13 (Gnus v5.13) X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Tue, Dec 01 2026, Chris Down wrote: > kho_preserved_memory_reserve() reserves each range of preserved memory > in memblock and marks it noinit, but ignores both return values. Either > can fail when memblock has to grow its reserved array and can't find > room for the new one, which is unlikely but possible. The boot then > goes on as if the range were reserved, and two things can follow: > > - If the reservation failed, memblock_free_all() hands the range to the > page allocator with the previous kernel's data still in it, while its > KHO user still expects to restore it. A memfd preserved through LUO > can then get back pages that belong to someone else. Oh dear! > - If only the noinit marking failed, the struct pages can be > initialised later, wiping the KHO magic, so restoring the range fails. > > Let's return the error instead. The walk then stops, and > kho_mem_retrieve() logs the failure and drops the handover. The boot > carries on without it. Ranges that the walk had already reserved stay > reserved, since freeing them would need the same array growth that > just failed. The rest of the preserved memory is released like any > other free memory. > > reserve_mem= revives its regions from the handover before > mm_core_init(), and relies on the walk to reserve them. They have to > stay reserved when the handover is dropped, so make > reserve_mem_kho_revive() reserve its region itself. > > Fixes: fc33e4b44b27 ("kexec: enable KHO support for memory preservation") > Signed-off-by: Chris Down > --- > kernel/liveupdate/kho_core.c | 18 +++++++++++++++--- > mm/memblock.c | 8 ++++++++ > 2 files changed, 23 insertions(+), 3 deletions(-) > [...] > diff --git a/mm/memblock.c b/mm/memblock.c > index a450092a80fb..7b29b657a348 100644 > --- a/mm/memblock.c > +++ b/mm/memblock.c > @@ -2746,6 +2746,14 @@ static bool __init reserve_mem_kho_revive(const char *name, phys_addr_t size, > return false; > } > > + /* KHO reserves preserved memory, but not if it drops the handover. */ Nit: I find this comment hard to read. Perhaps: KHO reserves the preserved memory, but that happens later. Handover failures can leave it unreserved. Or something to the tune of this? Other than this, Reviewed-by: Pratyush Yadav > + err = memblock_reserve(*p_start, size); > + if (err) { > + pr_warn("KHO reserve-mem '%s' could not be reserved: %d\n", > + name, err); > + return false; > + } > + > reserved_mem_add(*p_start, size, name); > pr_info("Revived memory reservation '%s' from KHO\n", name); -- Regards, Pratyush Yadav