From: Chris Down <chris@chrisdown.name>
To: Pasha Tatashin <pasha.tatashin@soleen.com>,
Mike Rapoport <rppt@kernel.org>,
Pratyush Yadav <pratyush@kernel.org>
Cc: Alexander Graf <graf@amazon.com>,
Baoquan He <baoquan.he@linux.dev>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
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 9/9] selftests/liveupdate: Check handover revival, sequence and memory stats
Date: Tue, 10 Nov 2026 23:53:45 -0800 [thread overview]
Message-ID: <738fbfd19034ce495de9b22c705a7815a236907d.1794383544.git.chris@chrisdown.name> (raw)
In-Reply-To: <cover.1794383544.git.chris@chrisdown.name>
Extend the handover stats test to cover the new files. On the first
boot, kho_incoming/state should be none, liveupdate_num 0, and both KHO
sizes 0. After the kexec, the handover should be revived and
liveupdate_num should be 1.
restored_size should grow by at least a page each time a memfd is
retrieved or dropped. The memfd in the unclaimed session is retrieved
last, once everything else is done.
Signed-off-by: Chris Down <chris@chrisdown.name>
---
.../selftests/liveupdate/luo_handover_stats.c | 74 +++++++++++++++++--
1 file changed, 67 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/liveupdate/luo_handover_stats.c b/tools/testing/selftests/liveupdate/luo_handover_stats.c
index f18df79dda55..2863630b823e 100644
--- a/tools/testing/selftests/liveupdate/luo_handover_stats.c
+++ b/tools/testing/selftests/liveupdate/luo_handover_stats.c
@@ -10,6 +10,7 @@
#include <libliveupdate.h>
#define INCOMING_DIR "/sys/class/misc/liveupdate/incoming/"
+#define KHO_INCOMING_DIR "/sys/kernel/kexec/kho_incoming/"
#define SESSION_CLAIMED "stats-claimed"
#define SESSION_UNCLAIMED "stats-unclaimed"
@@ -28,13 +29,13 @@
/* The first open starts deserialization. */
static char state_before_open[16];
-static void read_incoming(const char *name, char *buf, size_t len)
+static void read_sysfs(const char *dir, const char *name, char *buf, size_t len)
{
char path[128];
ssize_t n;
int fd;
- snprintf(path, sizeof(path), INCOMING_DIR "%s", name);
+ snprintf(path, sizeof(path), "%s%s", dir, name);
fd = open(path, O_RDONLY);
if (fd < 0)
fail_exit("open %s", path);
@@ -54,6 +55,11 @@ static void read_incoming(const char *name, char *buf, size_t len)
buf[n - 1] = '\0';
}
+static void read_incoming(const char *name, char *buf, size_t len)
+{
+ read_sysfs(INCOMING_DIR, name, buf, len);
+}
+
static void expect_state(const char *state, const char *expected)
{
if (strcmp(state, expected))
@@ -61,13 +67,13 @@ static void expect_state(const char *state, const char *expected)
expected);
}
-static unsigned long long read_number(const char *name)
+static unsigned long long read_number(const char *dir, const char *name)
{
unsigned long long val = 0;
char buf[32];
char *p;
- read_incoming(name, buf, sizeof(buf));
+ read_sysfs(dir, name, buf, sizeof(buf));
for (p = buf; *p >= '0' && *p <= '9'; p++) {
if (val > (ULLONG_MAX - (*p - '0')) / 10)
break;
@@ -75,19 +81,45 @@ static unsigned long long read_number(const char *name)
}
if (p == buf || *p)
ksft_exit_fail_msg("%s%s reads '%s', not a 64-bit unsigned number\n",
- INCOMING_DIR, name, buf);
+ dir, name, buf);
return val;
}
static void expect_count(const char *name, unsigned long long expected)
{
- unsigned long long val = read_number(name);
+ unsigned long long val = read_number(INCOMING_DIR, name);
if (val != expected)
ksft_exit_fail_msg("%s is %llu, expected %llu\n", name, val,
expected);
}
+static void expect_kho_state(const char *expected)
+{
+ char state[16];
+
+ read_sysfs(KHO_INCOMING_DIR, "state", state, sizeof(state));
+ if (strcmp(state, expected))
+ ksft_exit_fail_msg("kho_incoming/state is '%s', expected '%s'\n",
+ state, expected);
+}
+
+static unsigned long long kho_size(const char *name)
+{
+ return read_number(KHO_INCOMING_DIR, name);
+}
+
+static unsigned long long expect_more_restored(unsigned long long prev)
+{
+ unsigned long long restored = kho_size("restored_size");
+
+ if (restored < prev + getpagesize() ||
+ restored > kho_size("preserved_size"))
+ ksft_exit_fail_msg("restored_size went from %llu to %llu\n",
+ prev, restored);
+ return restored;
+}
+
static void expect_counts(long retrieved, long dropped)
{
char state[16];
@@ -111,6 +143,10 @@ static void run_stage_1(int luo_fd)
expect_state(state_before_open, "none");
expect_count("sessions", 0);
expect_count("files", 0);
+ expect_count("liveupdate_num", 0);
+ expect_kho_state("none");
+ if (kho_size("preserved_size") || kho_size("restored_size"))
+ ksft_exit_fail_msg("KHO sizes aren't 0 on a cold boot\n");
create_state_file(luo_fd, STATE_SESSION_NAME, STATE_MEMFD_TOKEN, 2);
@@ -144,11 +180,16 @@ static void run_stage_1(int luo_fd)
static void run_stage_2(int luo_fd, int state_session_fd)
{
- int claimed_fd, mfd, stage;
+ int claimed_fd, unclaimed_fd, mfd, stage;
+ unsigned long long restored;
ksft_print_msg("[STAGE 2] Checking state before and after the first open...\n");
expect_state(state_before_open, "pending");
expect_counts(0, 0);
+ expect_count("liveupdate_num", 1);
+ expect_kho_state("revived");
+ if (!kho_size("preserved_size"))
+ ksft_exit_fail_msg("kho_incoming/preserved_size is 0\n");
restore_and_read_stage(state_session_fd, STATE_MEMFD_TOKEN, &stage);
if (stage != 2)
@@ -163,6 +204,7 @@ static void run_stage_2(int luo_fd, int state_session_fd)
if (claimed_fd < 0)
fail_exit("luo_retrieve_session for '%s'", SESSION_CLAIMED);
+ restored = kho_size("restored_size");
mfd = restore_and_verify_memfd(claimed_fd, MFD_RETRIEVED_TOKEN,
MFD_RETRIEVED_DATA);
if (mfd < 0)
@@ -170,6 +212,7 @@ static void run_stage_2(int luo_fd, int state_session_fd)
MFD_RETRIEVED_TOKEN);
close(mfd);
expect_counts(2, 0);
+ restored = expect_more_restored(restored);
ksft_print_msg("[STAGE 2] Finishing '%s'...\n", SESSION_CLAIMED);
if (luo_session_finish(claimed_fd) < 0)
@@ -177,6 +220,7 @@ static void run_stage_2(int luo_fd, int state_session_fd)
close(claimed_fd);
expect_counts(2, 1);
+ expect_more_restored(restored);
ksft_print_msg("[STAGE 2] Finishing the state session...\n");
if (luo_session_finish(state_session_fd) < 0)
@@ -185,6 +229,22 @@ static void run_stage_2(int luo_fd, int state_session_fd)
/* Finishing the state session must not drop anything. */
expect_counts(2, 1);
+ restored = kho_size("restored_size");
+
+ ksft_print_msg("[STAGE 2] Retrieving the memfd in '%s'...\n",
+ SESSION_UNCLAIMED);
+ unclaimed_fd = luo_retrieve_session(luo_fd, SESSION_UNCLAIMED);
+ if (unclaimed_fd < 0)
+ fail_exit("luo_retrieve_session for '%s'", SESSION_UNCLAIMED);
+ mfd = restore_and_verify_memfd(unclaimed_fd, MFD_UNCLAIMED_TOKEN,
+ MFD_UNCLAIMED_DATA);
+ if (mfd < 0)
+ fail_exit("restore_and_verify_memfd for token %#x",
+ MFD_UNCLAIMED_TOKEN);
+ close(mfd);
+ close(unclaimed_fd);
+ expect_counts(3, 1);
+ expect_more_restored(restored);
ksft_print_msg("\n--- HANDOVER STATS TEST PASSED ---\n");
}
--
2.54.0
prev parent reply other threads:[~2026-11-11 7:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 7:52 [PATCH 0/9] kho, liveupdate: KHO/LUO observability Chris Down
2026-11-11 7:52 ` [PATCH 1/9] kho: Reclaim the metadata page left reserved after kexec Chris Down
2026-11-11 11:08 ` Breno Leitao
2026-11-11 22:29 ` Pasha Tatashin
2026-11-13 8:30 ` Chris Down
2026-11-11 7:53 ` [PATCH 2/9] kho: Make bootmem reservations visible to fleet monitoring Chris Down
2026-11-11 23:14 ` Pasha Tatashin
2026-11-13 8:30 ` Chris Down
2026-11-15 19:11 ` Mike Rapoport
2026-11-11 7:53 ` [PATCH 3/9] liveupdate: Make failed retrieves distinguishable from dropped files Chris Down
2026-11-11 7:53 ` [PATCH 4/9] selftests/liveupdate: Catch incorrect file accounting across kexec Chris Down
2026-11-11 7:53 ` [PATCH 5/9] selftests/kho: Catch missing or zero bootmem reports before kexec Chris Down
2026-11-11 7:53 ` [PATCH 6/9] kho: Expose rejected handovers that look like cold boots Chris Down
2026-11-11 7:53 ` [PATCH 7/9] kho: Report how much handover memory is preserved and restored Chris Down
2026-11-11 7:53 ` [PATCH 8/9] liveupdate: Expose the sequence number for consecutive live updates Chris Down
2026-11-11 7:53 ` Chris Down [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=738fbfd19034ce495de9b22c705a7815a236907d.1794383544.git.chris@chrisdown.name \
--to=chris@chrisdown.name \
--cc=baoquan.he@linux.dev \
--cc=corbet@lwn.net \
--cc=graf@amazon.com \
--cc=kernel-team@meta.com \
--cc=kexec@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pasha.tatashin@soleen.com \
--cc=pratyush@kernel.org \
--cc=rppt@kernel.org \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®