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 9B3F83FC2 for ; Sun, 30 Nov 2025 08:52:23 +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=1764492743; cv=none; b=oOk3F/MvI0CnQCbMu6l8k4jJcPgQ9WIUHZuR/fczNz9ScW2vbC9I2ioTQC78z//9rW2t7VtUeoE/38ANnTq6bJQdemB87FveKwz/vX21OIvkWBE+1eAIMO/Hz9PIUHnDhY/hMwRq2liHntEBzOA52ZJCgnSSY+k6u0k9KNmCt1E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764492743; c=relaxed/simple; bh=GDfpz+XHBgaz5Oe6M3Qx04ZeGNYSuRXkIueya0mVaMQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=O6CmgLQPVOw+gztSQ1VnOSfeN69gZNXzm//iHoZnEY3h7vQOWwrh7fVBL6AzAZ2Rej0LnrJw1aeuykk9KK+2qoCkeP1bYgrha0Pckdr2I9/K7EihYUv04Hrr9yaeMa/s3hDHGHVCOVh7H+JUuDa0dnOm9XacRrNiKyf/0Hdm5Cs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Dfs6iEG/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Dfs6iEG/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E98D5C4CEF8; Sun, 30 Nov 2025 08:52:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764492743; bh=GDfpz+XHBgaz5Oe6M3Qx04ZeGNYSuRXkIueya0mVaMQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Dfs6iEG/Ea2gytBgh62gwoEMtevcbfEdafzwJqBjEx5i0w0fohwgiNdgaGqYo6EPn g8yKhJcPthPnzMguLO+AEmkTVX4TTdC7pTxDzHRk1BlLat6TmhsqYis+nyCpgKG9lh 1NaHOamVKTDIhCZC+Ct+d5TldBjf5myxhBI0LHexiUFJyed1+oNpAPovCLPbvOAEVM wkuZzxGR9CSkGyooyVDbNYeXJXJMDb9HfswH3v9SCTQN/wHVJUGXywE/5rM/kRcs0q mnbkQ6jbslWupbWE3lswF8HNjO0KwlKi2M5hkvMVLWfdyhro69/6CAz9XLqUIkxm/F 7/jAmiAv49R2Q== Date: Sun, 30 Nov 2025 10:52:16 +0200 From: Mike Rapoport To: Usama Arif Cc: Andrew Morton , kas@kernel.org, changyuanl@google.com, graf@amazon.com, leitao@debian.org, thevlad@meta.com, pratyush@kernel.org, dave.hansen@linux.intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: Re: [PATCH v3 2/2] mm/memblock: only mark/clear KHO scratch memory when needed Message-ID: References: <20251128173257.969322-1-usamaarif642@gmail.com> <20251128173257.969322-3-usamaarif642@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251128173257.969322-3-usamaarif642@gmail.com> On Fri, Nov 28, 2025 at 05:29:34PM +0000, Usama Arif wrote: > The scratch memory for kexec handover is used to bootstrap the > kexec'ed kernel. Only the 1st 1MB is used as scratch, and its a > hack to get around limitations with KHO. It is only needed when > CONFIG_KEXEC_HANDOVER is enabled and only if it is a KHO boot > (both checked by is_kho_boot). Add check to prevent marking a KHO > scratch region unless needed. I'm going to rewrite the changelog and queue this for upstream: The scratch memory for kexec handover is used to bootstrap the kexec'ed kernel and it is only needed when it is a KHO boot, i.e. a kexec boot with handover data passed from the previous kernel. Currently x86 marks the first megabyte of memory as KHO scratch even for non-KHO boots if CONFIG_KEXEC_HANDOVER is enabled. Add check to prevent marking a KHO scratch regions unless they are actually needed. > Fixes: a2daf83e10378 ("x86/e820: temporarily enable KHO scratch for memory below 1M") > Reported-by: Vlad Poenaru > Signed-off-by: Usama Arif > Reviewed-by: Pratyush Yadav > --- > mm/memblock.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/mm/memblock.c b/mm/memblock.c > index 8b13d5c28922a..913cf322eb89a 100644 > --- a/mm/memblock.c > +++ b/mm/memblock.c > @@ -20,8 +20,8 @@ > > #ifdef CONFIG_KEXEC_HANDOVER > #include > -#include > #endif /* CONFIG_KEXEC_HANDOVER */ > +#include > > #include > #include > @@ -1126,8 +1126,10 @@ int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t > */ > __init int memblock_mark_kho_scratch(phys_addr_t base, phys_addr_t size) > { > - return memblock_setclr_flag(&memblock.memory, base, size, 1, > - MEMBLOCK_KHO_SCRATCH); > + if (is_kho_boot()) > + return memblock_setclr_flag(&memblock.memory, base, size, 1, > + MEMBLOCK_KHO_SCRATCH); > + return 0; > } > > /** > @@ -1140,8 +1142,10 @@ __init int memblock_mark_kho_scratch(phys_addr_t base, phys_addr_t size) > */ > __init int memblock_clear_kho_scratch(phys_addr_t base, phys_addr_t size) > { > - return memblock_setclr_flag(&memblock.memory, base, size, 0, > - MEMBLOCK_KHO_SCRATCH); > + if (is_kho_boot()) > + return memblock_setclr_flag(&memblock.memory, base, size, 0, > + MEMBLOCK_KHO_SCRATCH); > + return 0; > } > > static bool should_skip_region(struct memblock_type *type, > -- > 2.47.3 > -- Sincerely yours, Mike.