From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 899A123816C for ; Thu, 4 Dec 2025 19:27:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764876456; cv=none; b=RrKADopeVoIc+gcB5qhOP2uOXTXc2ig5WRybFHj4OCd4xfIiqSEPNEpPfGYX0NjtV1aNoN4GwWVdwqD1HmX68QCAQS0NmIkDhh/oaWPhQRU6sCbsIYEcnrwlBMrJ7oA6dcD4f1IYxvJlmpOiPrHF/2n5oXFPGcb63Pb/gsKtU1k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764876456; c=relaxed/simple; bh=bdCoR51JNbOphDdP7d/JxI9QT4Q0Ytd5TwTqQztn2o8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=hZt7T5Njs1BfGyIOmaSwIGnrDzUJIugW22Gi54yJ+PFGOs9FyLWbXbfy05ghBwbMVsetFQzesZdPDjk4Lp1gd0O9p7hj2MWzr0N7XFz//T1wPeEuMjRJ1BnysJLa1Uffv/ISeD2AQVOklTvreTY8IujUR0/pz8RYcuiRq261H5k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UY3gCqYz; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UY3gCqYz" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-47118259fd8so13156415e9.3 for ; Thu, 04 Dec 2025 11:27:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764876453; x=1765481253; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=aZyl8snVqn5fbIv/iSI7+O5vLuMCaEEyOp0Rl9YwHhg=; b=UY3gCqYz2/7S+a8dd5XXBfnjXtUCNAOxq6XRoNRF8OZWZDeRtrb6KValuWuHPbEyQY g+XGhwWRRPOBuu+RenxO+dtu3cIQ/DvcxSD4smMxn/TyvsPlUlpzywXEBCsdjHDcBld5 YRbsCpstkyuzSIX4NU/Bc4sU7b4o7aMp4VdL9UEDtcxVQVdSSgr4p1zr60U7z8uiJRTm sutF/u1SzUy2gpT3VsvmnZIWFkw6aOCn8MwRbSHOfVi/J8nu0n3iDauxPcGMIo1Ho32X P4bqJiv+23zsFN7aNCByAI4Eie9RhD3T14qq6+ecdwgY2UDVg25GDzyRFKXndhBRpjP6 YUAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764876453; x=1765481253; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=aZyl8snVqn5fbIv/iSI7+O5vLuMCaEEyOp0Rl9YwHhg=; b=gS7CGcNcePJ9tTM0s/HTOcynBW9kJ8CfQnNr5HQM1iwzpNYxasVm8/jx8WxaJQuzO3 bjjt75Qe1aJDTqX3+Yz3NBmGW7HuBgNVUBaacRs1Xu+Ag7d361/mE3ZMV4jhSdKjPz42 TlzwyxCcEBwJt7eHr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OXA== X-Received: by 2002:a05:600c:4e90:b0:479:2a0b:180d with SMTP id 5b1f17b1804b1-4792f259c46mr42195745e9.11.1764876452519; Thu, 04 Dec 2025 11:27:32 -0800 (PST) Received: from ?IPV6:2a02:6b6f:e750:1800:450:cba3:aec3:a1fd? ([2a02:6b6f:e750:1800:450:cba3:aec3:a1fd]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4792b04e03bsm43362195e9.7.2025.12.04.11.27.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Dec 2025 11:27:31 -0800 (PST) Message-ID: <657d2356-126d-452b-ba7f-5c0761f4f832@gmail.com> Date: Thu, 4 Dec 2025 19:27:29 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 2/2] mm/memblock: only mark/clear KHO scratch memory when needed Content-Language: en-GB To: Mike Rapoport Cc: Pasha Tatashin , 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 References: <20251128173257.969322-1-usamaarif642@gmail.com> <20251128173257.969322-3-usamaarif642@gmail.com> From: Usama Arif In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 04/12/2025 17:52, Mike Rapoport wrote: > Hi Usama, > > On Thu, Dec 04, 2025 at 02:51:00PM +0000, Usama Arif wrote: >>> On Sun, Nov 30, 2025 at 3:52 AM Mike Rapoport wrote: >>>> >>>> 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 >>> >>> This patch causes panic with my tests in linux-next. >>> >>> [ 0.000000] Kernel panic - not syncing: Cannot allocate 17280 bytes >>> for node 0 data >>> [ 0.000000] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted >>> 6.18.0-next-20251203 #2 PREEMPT(undef) >>> [ 0.000000] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), >>> BIOS 0.1 11/11/2019 >>> [ 0.000000] Call Trace: >>> [ 0.000000] >>> [ 0.000000] ? dump_stack_lvl+0x4e/0x70 >>> [ 0.000000] ? vpanic+0xcf/0x2b0 >>> [ 0.000000] ? panic+0x66/0x66 >>> [ 0.000000] ? alloc_node_data+0x32/0x90 >>> [ 0.000000] ? numa_register_nodes+0x82/0x100 >>> [ 0.000000] ? numa_init+0x36/0x120 >>> [ 0.000000] ? setup_arch+0x667/0x7f0 >>> [ 0.000000] ? start_kernel+0x58/0x640 >>> [ 0.000000] ? x86_64_start_reservations+0x24/0x30 >>> [ 0.000000] ? x86_64_start_kernel+0xc5/0xd0 >>> [ 0.000000] ? common_startup_64+0x13e/0x148 >>> [ 0.000000] >>> [ 0.000000] ---[ end Kernel panic - not syncing: Cannot allocate >>> 17280 bytes for node 0 data ]--- >>> PANIC: early exception 0x0d IP 10:ffffffff89007a13 error 763 cr2 >>> 0xffff991090a01000 >>> >> >> Thanks for reporting this and sorry for the bug! >> >> So the patch was designed to remove the memblock_mark_kho_scratch in e820__memblock_setup if not >> in KHO boot. But it broke memblock_mark_kho_scratch in kho_populate. >> Moving kho_in.fdt_phys = fdt_phys to before the memblock_mark_scratch >> should fix it. I dont have a setup where I can easily test KHO, but I think below >> should fix it? > > This might, but this is too late for v6.19-rc1. > For now I'm dropping this series from memblock/for-next. > We can resume working on this after merge window closes. > Yes makes sense. How would you like me to proceed with the fix? Should I send just the fix now, or these 2 patches plus the fix after the merge window closes? Thanks! >> TBH using fdt_phys to check if the boot is KHO might be a bit hacky? Is it possible >> to have a better check for this? > > Presence of KHO FDT is a clear indication that it is a KHO boot. > The issue is that during early boot ordering is hard and it's not always > clear in which order features and configuration are detected and used. > ack >> diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c >> index 9dc51fab604f1..c331749e6452e 100644 >> --- a/kernel/liveupdate/kexec_handover.c >> +++ b/kernel/liveupdate/kexec_handover.c >> @@ -1483,6 +1483,7 @@ void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len, >> goto out; >> } >> >> + kho_in.fdt_phys = fdt_phys; >> /* >> * We pass a safe contiguous blocks of memory to use for early boot >> * purporses from the previous kernel so that we can resize the >> @@ -1513,7 +1514,6 @@ void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len, >> */ >> memblock_set_kho_scratch_only(); >> >> - kho_in.fdt_phys = fdt_phys; >> kho_in.scratch_phys = scratch_phys; >> kho_scratch_cnt = scratch_cnt; >> pr_info("found kexec handover data.\n"); >> @@ -1524,7 +1524,10 @@ void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len, >> if (scratch) >> early_memunmap(scratch, scratch_len); >> if (err) >> + { >> + kho_in.fdt_phys = 0; >> pr_warn("disabling KHO revival: %d\n", err); >> + } >> } >