From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 0378318C332 for ; Thu, 4 Dec 2025 14:51:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764859867; cv=none; b=cIAmxIG13TF4NrY2FAedoVniBd1OsN5kpKYS/y7D498m/PpeUC926lopSDuANrd0PjPXg2Z4gKuyVJO1zWNEiwuF+HsTvcjl84c3skJvUrbDo1xgTwKftVqPQwyc76vyr5pZXPNEw5/qqSlb1cJ+FGx1AEbp0OMLAM9Gv6X1a3w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764859867; c=relaxed/simple; bh=3ycW9HWAlyxYi+XW7H/PYLLm5bNRBJWlR4J4ZoayMnY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=IDFGS/4Cmv42mmLHuiFlRr9PAn5YNppHRuO6NU4NHypOIKSWo0KGpwJRobFTnGgOk8lxo2bJ2YM0d6b4yPT6CRJ0u9LqPTNFxGh6lh1sGVOQjh3KOkCuBRYx7zEO60eOk7SP9+kzlD5zy74n+ajcexrwdu9upaoEE5fvYW2NPrw= 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=NiG5nePO; arc=none smtp.client-ip=209.85.221.43 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="NiG5nePO" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-42e2e77f519so818976f8f.2 for ; Thu, 04 Dec 2025 06:51:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764859864; x=1765464664; 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=ow5IwXw2xGmPvayEhI3mpOX/A9rxj1tnVvZcYdHjxYE=; b=NiG5nePOk8MREubkBvJ95M5f23+eNfRcRvRYgv2exrEO7rwjIMfpyuWZKMSY9DIivJ GON+YuvA33Cnz4xcrgB+QQ0SBP2XCQqBmw+NDqIEb13ExSQhRDnMDG44J5ccORy80h9X 5qkeoFEinh2bp+9ST4Lw80z8ZEUal+Y+Kmri9xAW47DAqxqHBvmka2ynyoBOR7VvHtd8 poWBfzVfZx7Wbu4Y0xMP3nhnoSEalt6C6BZOF5sTeYr1TpG82FGzNS48mXkAxLcqWmBG KQvsv0Iy78Cpg+zBbZxwQdpa32GEzbsryDIQzmcxTjm027Z8opYFZkykt/2/c6g1LdlI m4mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764859864; x=1765464664; 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=ow5IwXw2xGmPvayEhI3mpOX/A9rxj1tnVvZcYdHjxYE=; b=SR9sunaplwCfpGSJXmPveLEID8ecv89YWf3TI3LE4O1oM1O0EYGy5Cjimb1Fu6hyeN BKs5BP3P5lDTU5/7kwzjuffRz2KhNoiheIHhJXxr+e8m1ydT3sn4vKEthd/ZrbcmqMTT wfI4mtNCWTHCvNSjRJtKn7ziyfztaY8KM2d2UBi60bCyTOcXpyaRV5dJPdWfSANQXwPp G1ko6XqYMLc+38V4EqsxeQVFZaz+nfkNLbrnnQxaf7awVYUxkeGxTPhkk0m0ieIyt3OP 2C1iGTZmrdJ95cSPX+a8Cam3ZVgW6jqAgB5WkMMD7YPOh0LzfRePhOt9/X9y+RHAwHMR TsOw== X-Forwarded-Encrypted: i=1; AJvYcCUO3VAIHvre8ZiPkb/S48uJLAZxcHMVDkgwRPKy2ykDTcmdFF3yFzhSu4bKvMoyOZXbGDq37LOOqpDZzqA=@vger.kernel.org X-Gm-Message-State: AOJu0YzsNtc//91IQJvl8l8eGLa3syDSodlBGjuwFO6Dp2SCDWo4/cUP DwZ+b1gLorfq22QLiuCpPDi3GEq9iUf0BzUEuHFlzFOanUoFVBPCz34GGdj10Q== X-Gm-Gg: ASbGncstvhc0UJg7SFW75i0dH+QHMOU1AL3ZFyKvlO7l1qjH0XOWF42WSe9znzq+a0E E8azjuXFxBa7GOgl5575VSN0b236bjS+UEaIPgnhWGXeH4c+LmDNbJpdOF4SzJK7NMQ2qjMW6U6 Xuqu6SLxR1l6m/rcmP4HMMpV7K90aPJHNv3MEsfM2mS3R6+ggYucLHajEbs7aATWeVaxaZXEI4r SRRU8+etUZ+CPqDPF6xzIbu5zQQl3iJKf9xJQ+DnofNkG+bnRbq7FF0fo2ang8z3d/so3j3oxG7 IMEMUuLaTh6XKMx1gfLaTHumXCU8LrrhO0NiWZEpwIsvnn5uNw1SatKKwUYlrY2Z30uggNhWdAm viTMKQt8pMDhs8VJel3LRz9uyc3FzBmc+ENxW0O6ZoY5Tj51g1DiUJodkkHWmen1eF3xFXNm1eQ ONk34ce73RiCho2C7NHs3uUoKNaOZjSr5GypOOzwre9qvdvDxdD6/iGIAuP6LLfDw= X-Google-Smtp-Source: AGHT+IGvV1Zswwu1oJG2QS2fyLuIDHh1tQIO2KS4R5I6TQImGVCLVLw7PButGZXPhz76RrnPilswUQ== X-Received: by 2002:a05:6000:2c08:b0:428:52c7:feae with SMTP id ffacd0b85a97d-42f79848239mr3355142f8f.32.1764859863970; Thu, 04 Dec 2025 06:51:03 -0800 (PST) Received: from ?IPV6:2a03:83e0:1126:4:ce0:a4eb:eabc:d420? ([2620:10d:c092:500::7:99d1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42f7cbfeae9sm3763136f8f.13.2025.12.04.06.51.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Dec 2025 06:51:03 -0800 (PST) Message-ID: Date: Thu, 4 Dec 2025 14:51:00 +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: Pasha Tatashin , Mike Rapoport 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 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 14:04, Pasha Tatashin 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? 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? 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); + } } > >>> --- >>> 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()) > > Looks like memblock_mark_kho_scratch() is called before is_kho_boot() > is working: > > [ 0.000000] memblock_mark_kho_scratch: is_kho_boot: 0 > [ 0.000000] memblock_mark_kho_scratch: is_kho_boot: 0 > [ 0.000000] memblock_mark_kho_scratch: is_kho_boot: 0 > [ 0.000000] KHO: kho_populate: is_kho_boot: 1 > [ 0.000000] memblock_mark_kho_scratch: is_kho_boot: 1 > [ 0.000000] memblock_clear_kho_scratch: is_kho_boot: 1 > ... > > --- a/kernel/liveupdate/kexec_handover.c > +++ b/kernel/liveupdate/kexec_handover.c > @@ -1514,6 +1514,7 @@ void __init kho_populate(phys_addr_t fdt_phys, > u64 fdt_len, > memblock_set_kho_scratch_only(); > > kho_in.fdt_phys = fdt_phys; > + pr_err("%s: is_kho_boot: %d\n", __func__, is_kho_boot()); > kho_in.scratch_phys = scratch_phys; > kho_scratch_cnt = scratch_cnt; > pr_info("found kexec handover data.\n"); > diff --git a/mm/memblock.c b/mm/memblock.c > index 87e7495a68c1..f55b5cdba5dd 100644 > --- a/mm/memblock.c > +++ b/mm/memblock.c > @@ -1126,6 +1126,7 @@ 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) > { > + pr_err("%s: is_kho_boot: %d\n", __func__, is_kho_boot()); > if (is_kho_boot()) > return memblock_setclr_flag(&memblock.memory, base, size, 1, > MEMBLOCK_KHO_SCRATCH); > @@ -1142,6 +1143,7 @@ __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) > { > + pr_err("%s: is_kho_boot: %d\n", __func__, is_kho_boot()); > if (is_kho_boot()) > return memblock_setclr_flag(&memblock.memory, base, size, 0, > MEMBLOCK_KHO_SCRATCH); > >>> + 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. >>