From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795890464; b=mBMQ/dKhJQDAkxQiZ3emStyiDadY4iJzMvR2hb+/Cu7X04Q0gdiDz+E8MGcDNs94n0LX nUqE6p3fDzitilkeCpF1sIOxvwxWoFSNvHGWM31MEUUSsg9f2Q0WotSDGU5zbXk93Zmb0 9Jr+v2CuZxslQV8LBzue5YGFk3BIdFLjflxpTscQU3mLBBdSiZNSRb3oNanHodBcTNkkD b20AS6Gvg1D1PZRO1DKUlhGuXlSuVUtbF9avY5N9rNCSEo666H4FKW7E/Aj5Z7jBY+4tI eBtgWdJXmEwOYr0qBpMpBZZ2WdOFRRiTtRmkjvD3TMP6yfCNqw1L+qpJo4gPWxNrwkQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795890464; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:Message-ID:In-Reply-To:References:From:Subject:To:Cc: MIME-Version:Content-Type:Content-Disposition:User-Agent; bh=1BuqhSIPxOjAmCucDj7na1oR1XC2SnDbOY7PDeOt/i0=; b=FfuFmFJvUAp5qWksp+kEeF2F1buPOgaUlq2xaOl9KsK7P+RVuhrorwuL3DfFJKGNlXn8 WFPRtaJZPjagI+q44oPpf21U/VxtUQIxTcCfG0RsVG9IYa2ECihhm3z1YyjMwWfoG1JSY sKTgHgpmPfDdUHLA75NmD7UAZzQkJkWLrF9aBOR5+BunRmK63UsBY+h7Vu35iofaF8kT2 WpGAwnhxYyDzfql1khB43NULsjuzIUnmFRqQeKU30oAcIrq51LXHbAJ0i6BRqDBPoXlfh 8Gtnlnk9vgBq8/bICy8ZB2R/VVJGoej6pW2d4mY7DB5YxDBaRGRJxBUW3umYdxhyGYA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass header.d=chrisdown.name header.i=@chrisdown.name header.a=rsa-sha256 header.s=google header.b=hguNE+q6; arc=none smtp.remote-ip=209.85.128.172 Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4C74606A6BA for ; Sat, 28 Nov 2026 18:27:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B4C74606A6BA Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.a=rsa-sha256 header.s=google header.b=hguNE+q6 Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-8b0dba37a7fso73899927b3.0 for ; Sat, 28 Nov 2026 10:27:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1795890463; x=1796495263; darn=vger.kernel.org; h=user-agent:content-disposition:content-type:mime-version:cc:to :subject:from:references:in-reply-to:message-id:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=1BuqhSIPxOjAmCucDj7na1oR1XC2SnDbOY7PDeOt/i0=; b=hguNE+q6q05/XBHcliywefCJlNDeWWQLkFTRDw85ekN3eQwvpRPCw5iiEcIZ967ALx 1tw/GMP2t2Ja7XCrJXQ423Ijej5fK0ME1bUzbtHvQLZ00cxcQ70TS+SAdohdqdxNN0LI vYgpkZCfBencE0LEWGJez4R2bpW/3TSoCwMcI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795890463; x=1796495263; h=user-agent:content-disposition:content-type:mime-version:cc:to :subject:from:references:in-reply-to:message-id:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=1BuqhSIPxOjAmCucDj7na1oR1XC2SnDbOY7PDeOt/i0=; b=24K5xbKlb3ssZIFPnGnOfduVw1lXLNCX0VqNsjCMwPZ4AFi2rFl9vtHO6lMwvnCyBp 693g11aADHKKJvcs8sVxhrDWCWVheXzAtqn7TUROPnsg+fenb0vzN5sYlWSpIxmFares QUpaDzIWJMZ6JNjORO5QyhPcC2hcTk39i7rqJBzReyKU1amNAuVtN1aOSOI3nu5zsiCI CJDIYvnMXl6Jn3i3qSCKY0omETQEQU/KWZIsjqIpjBUJgq6qLTU/duj3ngeaZatCCttZ jMyoI1xbN1Y2rr1RVMTlbDRMUyb5XZlS+Suvd41fGpackxzM/MvOsUeEydPSdrRAJaai ItVg== X-Forwarded-Encrypted: i=1; AL+hErGyYmGBGtgUpU6aImBbaajhJq81/7juRkpaiTEXXoWFrTjtxUSk836i9ykfJ4+tQi7YIwx433JumGII+w4=@vger.kernel.org X-Gm-Message-State: APuU4Z/c+xVbrZykzqQ83V83Q3FkVwDH9PHDTkE8MvvJuB+PWGDmAxaI Ck7X2NJry6mWApz6f4aVIoQtz9aTp5+gf1xKiSLXqVdFHj8p9ZR0tmEw7uUlMbGYQsk= X-Gm-Gg: AZFdTZdX7zm4XOoADkb619x55PNvUcRJchBzS3g+GLQFI9kMbOUj91PXw3tpkO72HtI CBtrIOt+h+lqZSEHqygqjf8n2EeE1Bo0xdgvdUPsVA4onl5JvD8mObsXHSm8FB260DfGO4W/bEv B0wwahH4SG2T12OxfM2N8XvYoqGuEGeEiHBGTToW6O59xXJ/vwTtjgIBB6M23RxxoO7AaTbjBXV xzoEMiW7Xew2Ro7VKZhASXvKtcROFeLiOsjqSZjT3IepnStqsUdjJorg7SwV1AUSBpt+dDVjFHm zqj4X01irRHmuV7TFVdVQqu8I25I0ToIV7cu9H8A/Dqwquo/XeYaNjUuYBV+PaIDbEvV3lLdNGC 6P5eoD2fl9+1adZWeu6OgNXJs0mElRiOiE22T00baSaoVbmQQ0dTeX1RrMxVIRh2UxX3EDHkQJK jyp9yjzo12F2nAUFWyJYV8v2CYZj9ZXjJOoLho0uHwfwTiS5p0ID95oiinrCED+3+iAftc2jtGC +SWRzcC2m+bQueUJjS8d1FL4XNjIVku7vDgZxKdYajg6z+QNft9Xfb6is/nW49x68JmVsYx4N3T XK7d37Rvi3xq167haM3GToCEAHNewFkNr6E08OzQ218jAeE9wgVGKF5IX4sPPR+YscBYL8+QPZh seUlLSPmrILUAdVXQpKMwZImu7eH8XZfTeBzW7DHwA2maPYgQrDKbiEMRCftCmNQo8llhQN3k1v EgAzXOdaEzk05Tfq7pVFAq0Hww4UFMs/dd81LdfJ8izQWZzUwr5fl44LaJ237VK4fL4/cMtrqB1 F0Al3JlSqRXLKZCDxbppzK4eOnvS9z+oFSV9uR6D1Is X-Received: by 2002:a05:690c:6a12:b0:8b0:c673:993c with SMTP id 00721157ae682-8b52042d88amr87827227b3.21.1795890462742; Sat, 28 Nov 2026 10:27:42 -0800 (PST) Received: from [172.20.0.3] (c-73-207-185-9.hsd1.ga.comcast.net. [73.207.185.9]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8b5202c089dsm107728577b3.22.2026.11.28.10.27.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2026 10:27:41 -0800 (PST) Date: Sat, 28 Nov 2026 10:27:40 -0800 Message-ID: <1b0354d4bd39765d151632c0d7ab38bbae96dffa.1795857773.git.chris@chrisdown.name> In-Reply-To: References: From: Chris Down Subject: [PATCH v2 5/7] kho: Report how much handover memory is preserved and restored To: Pasha Tatashin , Mike Rapoport , Pratyush Yadav Cc: Alexander Graf , Baoquan He , Jonathan Corbet , Shuah Khan , kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-team@meta.com, Breno Leitao , sashiko-bot@kernel.org X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/2.4.3 (cc9e3943) (2026-10-09) Most memory the previous kernel preserved stays reserved until its user restores it through KHO, either to use it again or to free it. If nothing does, it stays reserved for as long as the kernel runs. On a hypervisor host that can be gigabytes, but amusingly nothing really shows it reliably. The host simply has less memory than it should, which is not exactly obvious. All preserved memory is reserved in kho_preserved_memory_reserve(), and everything restored through KHO goes through kho_restore_page(), so KHO can count both easily. Let's add preserved_size and restored_size, in bytes, to /sys/kernel/kho/incoming/. For example, after a live update preserving a 64 MiB memfd: preserved_size restored_size before retrieval 67403776 8192 after finish 67403776 67395584 The 8 KiB left are the incoming KHO FDT and LUO's FLB header. Signed-off-by: Chris Down --- Documentation/ABI/testing/sysfs-kernel-kho | 10 ++++++++++ Documentation/admin-guide/mm/kho.rst | 3 +++ kernel/liveupdate/kexec_handover.c | 15 +++++++++++++++ kernel/liveupdate/kexec_handover_internal.h | 2 ++ kernel/liveupdate/kho_sysfs.c | 16 ++++++++++++++++ 5 files changed, 46 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-kernel-kho b/Documentation/ABI/testing/sysfs-kernel-kho index 21488e35d1f3..a8251d663ce6 100644 --- a/Documentation/ABI/testing/sysfs-kernel-kho +++ b/Documentation/ABI/testing/sysfs-kernel-kho @@ -9,3 +9,13 @@ Description: read only the walk of its preserved memory map. "failed" The kernel rejected the handover. Users: system monitoring + +What: /sys/kernel/kho/incoming/preserved_size +What: /sys/kernel/kho/incoming/restored_size +Date: Nov 2026 +Contact: kexec@lists.infradead.org +Description: read only + Bytes preserved by the previous kernel and bytes restored + through KHO, respectively. Both are 0 unless the incoming + state is "revived". +Users: system monitoring diff --git a/Documentation/admin-guide/mm/kho.rst b/Documentation/admin-guide/mm/kho.rst index 8810813a5d0a..a12c1398eff2 100644 --- a/Documentation/admin-guide/mm/kho.rst +++ b/Documentation/admin-guide/mm/kho.rst @@ -87,6 +87,9 @@ sysfs Interfaces ``/sys/kernel/kho/incoming/state`` Status of the incoming KHO handover. +``/sys/kernel/kho/incoming/preserved_size`` and ``restored_size`` + Bytes preserved by the previous kernel and bytes restored through KHO. + See Documentation/ABI/testing/sysfs-kernel-kho for the sysfs ABI. debugfs Interfaces diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index aff96aa401f8..5d9b724ab754 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -103,6 +103,8 @@ struct kho_in { char previous_release[__NEW_UTS_LEN + 1]; u32 kexec_count; enum kho_incoming_state state; + unsigned long preserved_pages; + atomic_long_t restored_pages; struct kho_debugfs dbg; struct kho_radix_tree radix_tree; }; @@ -545,6 +547,7 @@ static struct page *kho_restore_page(phys_addr_t phys, bool is_folio, kho_init_pages(page, nr_pages); adjust_managed_page_count(page, nr_pages); + atomic_long_add(nr_pages, &kho_in.restored_pages); return page; } @@ -636,6 +639,7 @@ static int __init kho_preserved_memory_reserve(unsigned long key, void *data) info.magic = KHO_PAGE_MAGIC; info.order = order; page->private = info.page_private; + kho_in.preserved_pages += 1UL << order; return 0; } @@ -1746,6 +1750,7 @@ err: kho_in.fdt_phys = 0; kho_in.radix_tree.root = NULL; kho_in.state = KHO_INCOMING_FAILED; + kho_in.preserved_pages = 0; } static __init int kho_out_fdt_setup(void) @@ -1777,6 +1782,16 @@ enum kho_incoming_state kho_in_state(void) return kho_in.state; } +u64 kho_in_preserved_size(void) +{ + return (u64)kho_in.preserved_pages << PAGE_SHIFT; +} + +u64 kho_in_restored_size(void) +{ + return (u64)atomic_long_read(&kho_in.restored_pages) << PAGE_SHIFT; +} + static void __init kho_in_kexec_metadata(void) { struct kho_kexec_metadata *metadata; diff --git a/kernel/liveupdate/kexec_handover_internal.h b/kernel/liveupdate/kexec_handover_internal.h index b559f5d43116..9e2d1b0ef753 100644 --- a/kernel/liveupdate/kexec_handover_internal.h +++ b/kernel/liveupdate/kexec_handover_internal.h @@ -29,6 +29,8 @@ enum kho_incoming_state { }; enum kho_incoming_state kho_in_state(void); +u64 kho_in_preserved_size(void); +u64 kho_in_restored_size(void); #ifdef CONFIG_KEXEC_HANDOVER_DEBUGFS int kho_debugfs_init(void); diff --git a/kernel/liveupdate/kho_sysfs.c b/kernel/liveupdate/kho_sysfs.c index eb2e4ce72f20..e87a417d9254 100644 --- a/kernel/liveupdate/kho_sysfs.c +++ b/kernel/liveupdate/kho_sysfs.c @@ -21,8 +21,24 @@ static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr, } static struct kobj_attribute state_attr = __ATTR_RO(state); +static ssize_t preserved_size_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%llu\n", kho_in_preserved_size()); +} +static struct kobj_attribute preserved_size_attr = __ATTR_RO(preserved_size); + +static ssize_t restored_size_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%llu\n", kho_in_restored_size()); +} +static struct kobj_attribute restored_size_attr = __ATTR_RO(restored_size); + static struct attribute *incoming_attrs[] = { &state_attr.attr, + &preserved_size_attr.attr, + &restored_size_attr.attr, NULL }; -- 2.56.1