From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794383621; b=NKdCnc18MIBH+XjrlfyAMYn55Fwu0Va2RHvIQbdsa350Ev8bv/tQOiLk3weRF3GjOgSo d4Gkv4I7Cc6VIxAe3QOVYRevJSTrHry7ZemLIVL76v7LLXi+NEK7r3WqReAMIu1x/yFDd 6/SnOyCTRnRx/cW3f+9SC80jBX3BoJpYB8Yngv7xwsTxiWJGZl/eNJXpldp3lxmW7udQZ dC+Fza+rDtCn2AIf6jMeG3ChFtBu/j3v0xPZSoTd+j5odPzoEnmUgAnhFLCbah3SUnv0y DnS83XjyQsMZfZWOfsdSfeNX4SRz9tDrtf6VdnL7IvMtJAB7cx2p+qEr76NZi/rvsJQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794383621; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To:User-Agent; bh=sK/H9HvHFSTiGugEGJQyMUnIkFUyigqct4WxtQyCZAI=; b=Ru4vo4WHQFBBM+nlRBH+5W0qtY40fP9oXL+mFUVx447bGAyTJX5Kyj4Dukwg8tbhceME WDYVx4WKlem2FQYlvrOUhDmp0LFgbgmRYzgGX1aH/1zrfqmukk3yxhIzLVAeKmZgPsKp/ /Bnibv7mDZJNf2b20KTk2RnGH3BBr4fkflcT0oY/NVSzOdlioH9L6MGqJa2W79jb+ObRQ aIT0yFYM2uM+MvIEZH22Xxjw8TlzHuYpQ5Ki15S8p2dHOctClSzHAAQx86HraUbPUL8m/ ki9x3dMPqw/WA7P24FhUtUXf0hU6+JLVu/3vIzAaVJuVuIIyYrnpqESHA/MvVlX2r+Q== 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=xaDRSLAB; arc=none smtp.remote-ip=209.85.210.179 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 9E81060A2611 for ; Wed, 11 Nov 2026 07:53:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9E81060A2611 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=xaDRSLAB Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-8b904d10882so1303137b3a.0 for ; Tue, 10 Nov 2026 23:53:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1794383620; x=1794988420; darn=vger.kernel.org; h=user-agent:in-reply-to:content-disposition:content-type :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to:content-type; bh=sK/H9HvHFSTiGugEGJQyMUnIkFUyigqct4WxtQyCZAI=; b=xaDRSLABpfcz35+Jp7pKiITUvAgjZWk7/Jh/8WetpYrTZp9CkHwV1EFlgkfEgMjmYv CAloFN3rxioko73QaTac1MJq4Cz7jyUCaeLiA6+2dXFCbPQpfk0fEAMmN6TJuRIhT/jM r4DvfBb3kH3jy0wwVbSjIj9ATNuoAA338rnD8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794383620; x=1794988420; h=user-agent:in-reply-to:content-disposition:content-type :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=sK/H9HvHFSTiGugEGJQyMUnIkFUyigqct4WxtQyCZAI=; b=unIrOR7dy+rD9dikGMtbw3ZaPZ230z2AwbtwVqtLsZozdOu0fUR3b4N18GpLgC1fft YQju1uvLDyOZo3TNdIC3TGz3OePcAAfHgaJ1pVn/4r1+ULZyjbMMuJ0clcfJ6DPq9U/I /eJB8JxaRXzBd+D8Qq/sj5sN4T+8GssB8i3A5657ykpFWJKvg3LIMw16SjaJNPiGP5VU sr0JiPcj/PkjYVGMbVtcey+tIdYcbuOUAVyuPbVVzO5+MmKafmC018UN6+uMprmr4IXz 8QrCe1fPonYvCMAcCMLrYQTNI9Ggb/RTACyR725LrnpnJ9sJXRRGo/SLovZEIPLbIZVa T2fw== X-Forwarded-Encrypted: i=1; AL+hErE4B7JfBeVSGvEeWC0jxaXF3/Rpr8QHHvCC53am1OMeYWw9hJ0r7I6MzTIgI+i201kKhbmEbzL5Pq+yMyk=@vger.kernel.org X-Gm-Message-State: APuU4Z//glNWIpku/P/6J7CaQjsOJCDOj1Gx3t4MY8kl6zu5X8CFWmvQ TByK6TqP4boil3fUtj4trtLj55sW0Mpj1CfsIFPrwSaHi5cK7mQjTD6IZMwPyU6UvNk= X-Gm-Gg: AYBFou3Z6cT+DGn1tlakO1rYlR+fOS9AJffQMXhYUzisgHdxCom38OOKQv1kb6sYLCy S17o3DBWBxWxtiDWc72iRj1QmW4VufbP1h9LSpN6ENDlqjX+RwZ6sDiH7BV5Fg/e4LuYG8uakCe CXFW2xMz0KBXPCRTcmhbEbHWYEEFtTlZOONX/RRY8AxalkHSZy7HUO8c3W3EtnbpRVeVDUL1Uxq jXWR4TYBD7fSLWYIvehVQe8mQkuM9cC/Q7LJuNWnUEJCRgwcwcMXcs9y0VMBYgOXsJ5QFso7sGQ T8bQKx8OO5Pd1EwcUxR9UYe2f4y4ctdajc1AK4+xB9MdpXsr1AB4vRQIDz2mQOW3X2PSM1euCzz zOqzjEt2BBPzZCtMfkYGiqvOjCynA/Ud/VIVz0Z2m0yzYfJTP0KhFt5Yc6v9yEgDWOj5Yy0X35z 6MDq5NoucHz5J7OXzG1UKcpgrTxlA80gE7wrIhYshD8V3yJVBRczyDMNM9IqOwJim+Yyhj42bft 2QhTvGnBXNx4jifub7lv/d8lNsfsu/ra4nmIAQAjlYe4GSjMF42wZifAhYlBsjF/s7FRtQbCaUS IQOJ1MibFOXjMaNd99+NFQD96mMEBZl7dHn+3Plpwh3KeY9kvEYhb0knbnaSI/mBmfK0c/d4MPp rpgo9EX6YPzuK5vnifCHnEdXmwP2NWXdUT/uv6uhvN8jNrURgz4lo7kbWJKk48+WimiVxBp1Pwb cKWLjrmbMnkbpcyKN6ch5a7lYe1CZ1MvH6h6laTS5zexLD1zCvxajw/g== X-Received: by 2002:a05:6a00:2d2a:b0:8a0:1e49:71bb with SMTP id d2e1a72fcca58-8bc1ddf8792mr1803838b3a.57.1794383619946; Tue, 10 Nov 2026 23:53:39 -0800 (PST) Received: from localhost ([199.201.64.8]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8baaa2a6c51sm1842597b3a.14.2026.11.10.23.53.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2026 23:53:39 -0800 (PST) Date: Tue, 10 Nov 2026 23:53:35 -0800 From: Chris Down 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 Subject: [PATCH 7/9] kho: Report how much handover memory is preserved and restored Message-ID: <920192d01c6534b5754648e12840f73cdcfa73de.1794383544.git.chris@chrisdown.name> References: 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 In-Reply-To: User-Agent: Mutt/2.3.3 (9073d26d) (2026-06-12) 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/kexec/kho_incoming/. For example, after a live update preserving a 64 MiB memfd: preserved_size restored_size before retrieval 67403776 8192 after retrieval 67403776 67395584 The 8 KiB left are the incoming KHO FDT and LUO's FLB header. Signed-off-by: Chris Down --- .../ABI/testing/sysfs-kernel-kexec-kdump | 10 ++++++++ Documentation/admin-guide/mm/kho.rst | 3 +++ kernel/liveupdate/kexec_handover.c | 23 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-kernel-kexec-kdump b/Documentation/ABI/testing/sysfs-kernel-kexec-kdump index 5636cd060cb2..2b9f9917d2d4 100644 --- a/Documentation/ABI/testing/sysfs-kernel-kexec-kdump +++ b/Documentation/ABI/testing/sysfs-kernel-kexec-kdump @@ -79,3 +79,13 @@ Description: read only the walk of its preserved memory map. "failed" The kernel rejected the handover. User: system monitoring + +What: /sys/kernel/kexec/kho_incoming/preserved_size +What: /sys/kernel/kexec/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". +User: system monitoring diff --git a/Documentation/admin-guide/mm/kho.rst b/Documentation/admin-guide/mm/kho.rst index 9d74d4ce18b5..37a62daa7622 100644 --- a/Documentation/admin-guide/mm/kho.rst +++ b/Documentation/admin-guide/mm/kho.rst @@ -91,6 +91,9 @@ sysfs Interfaces ``/sys/kernel/kexec/kho_incoming/state`` Status of the incoming KHO handover. +``/sys/kernel/kexec/kho_incoming/preserved_size`` and ``restored_size`` + Bytes preserved by the previous kernel and bytes restored through KHO. + See Documentation/ABI/testing/sysfs-kernel-kexec-kdump for the sysfs ABI. debugfs Interfaces diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index dfd6fa7e4a71..fe6b66270124 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -110,6 +110,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; }; @@ -552,6 +554,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; } @@ -643,6 +646,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; } @@ -978,8 +982,26 @@ 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", (u64)kho_in.preserved_pages << PAGE_SHIFT); +} +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) +{ + u64 pages = atomic_long_read(&kho_in.restored_pages); + + return sysfs_emit(buf, "%llu\n", pages << PAGE_SHIFT); +} +static struct kobj_attribute restored_size_attr = __ATTR_RO(restored_size); + static struct attribute *kho_incoming_attrs[] = { &state_attr.attr, + &preserved_size_attr.attr, + &restored_size_attr.attr, NULL }; @@ -1785,6 +1807,7 @@ static void __init kho_mem_retrieve(void) 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) -- 2.54.0