From: Ning Sun <ning.sun@intel.com>
To: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@intel.com>,
"H . Peter Anvin" <hpa@zytor.com>
Cc: Frederic Weisbecker <frederic@kernel.org>,
x86@kernel.org, tboot-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, Ning Sun <ning.sun@intel.com>
Subject: [PATCH v3] x86/tboot: Fix AP wait count and timeout reporting
Date: Sun, 6 Dec 2026 14:58:56 +0800 [thread overview]
Message-ID: <20261206065856.8459-1-ning.sun@intel.com> (raw)
In-Reply-To: <b7a73c94-07cc-47a8-9666-7bd028effde6@intel.com>
On Intel TXT systems using tboot, offlining the last secondary CPU
can busy-wait until the AP wait timeout expires. The hotplug core then
reports that the x86/tboot:dying callback failed with -EBUSY, although
the CPU still goes offline.
This was found while reviewing Frederic Weisbecker's patch,
"[PATCH 46/47] x86/boot/tboot: Move CPUHP_AP_X86_TBOOT_DYING post
stop_machine()".
The wait target includes the outgoing CPU, which has not yet entered
tboot's wait-for-SIPI (WFS) state. The target also increases on every
offline operation but is never reduced when a CPU comes back online.
Replace the counter with a cpumask. Clear a CPU's bit in the starting
callback and use the mask weight before setting the outgoing CPU's bit
as the wait target.
Also fix the inverted timeout warning condition and use a single final
WFS count check for both the warning and the return value.
The exact count comparison and timeout budget are unchanged. APs
parked by tboot but never brought online by Linux, and failures before
the starting callback, remain accounting limitations.
Tested on an Intel TXT system with tboot 1.12.2 running Linux 6.18.64
by performing three complete secondary CPU offline/online cycles.
The stall and -EBUSY warning no longer occur. S3 was not tested because
the platform supports only s2idle.
Signed-off-by: Ning Sun <ning.sun@intel.com>
---
Changes in v3:
- Replace ap_wfs_count with a cpumask cleared from a new starting
callback so the wait target tracks offline/online cycles.
- Exclude the outgoing CPU by reading cpumask_weight() before
setting its bit.
- Base both the timeout warning and -EBUSY return on a single final
WFS count check.
- Shorten the commit message, describe the user-visible failure, and
omit the unverified Fixes tag.
arch/x86/kernel/tboot.c | 39 ++++++++++++++++++++++++++++-----------
1 file changed, 28 insertions(+), 11 deletions(-)
diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
index 46b8f1f16676..cc5265f3055c 100644
--- a/arch/x86/kernel/tboot.c
+++ b/arch/x86/kernel/tboot.c
@@ -314,7 +314,8 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
return -ENODEV;
}
-static atomic_t ap_wfs_count;
+/* CPUs expected in tboot WFS after offline, cleared on CPU startup. */
+static struct cpumask tboot_wfs_cpus;
static int tboot_wait_for_aps(int num_aps)
{
@@ -327,19 +328,35 @@ static int tboot_wait_for_aps(int num_aps)
timeout--;
}
- if (timeout)
+ if (atomic_read((atomic_t *)&tboot->num_in_wfs) != num_aps) {
pr_warn("tboot wait for APs timeout\n");
+ return -EBUSY;
+ }
+
+ return 0;
+}
- return !(atomic_read((atomic_t *)&tboot->num_in_wfs) == num_aps);
+static int tboot_starting_cpu(unsigned int cpu)
+{
+ /* tboot drops this CPU from num_in_wfs when it is woken by SIPI. */
+ cpumask_clear_cpu(cpu, &tboot_wfs_cpus);
+ return 0;
}
static int tboot_dying_cpu(unsigned int cpu)
{
- atomic_inc(&ap_wfs_count);
- if (num_online_cpus() == 1) {
- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
- return -EBUSY;
- }
+ /*
+ * This callback runs on the outgoing CPU, which enters tboot's
+ * wait-for-SIPI only later from play_dead(). Exclude it from the
+ * wait target.
+ */
+ int num_aps = cpumask_weight(&tboot_wfs_cpus);
+
+ cpumask_set_cpu(cpu, &tboot_wfs_cpus);
+
+ if (num_online_cpus() == 1)
+ return tboot_wait_for_aps(num_aps);
+
return 0;
}
@@ -417,9 +434,9 @@ static __init int tboot_late_init(void)
tboot_create_trampoline();
- atomic_set(&ap_wfs_count, 0);
- cpuhp_setup_state(CPUHP_AP_X86_TBOOT_DYING, "x86/tboot:dying", NULL,
- tboot_dying_cpu);
+ cpumask_clear(&tboot_wfs_cpus);
+ cpuhp_setup_state_nocalls(CPUHP_AP_X86_TBOOT_DYING, "x86/tboot:dying",
+ tboot_starting_cpu, tboot_dying_cpu);
#ifdef CONFIG_DEBUG_FS
debugfs_create_file("tboot_log", S_IRUSR,
arch_debugfs_dir, NULL, &tboot_log_fops);
base-commit: 28a23309c8e40d651faf4cc3cc9b71458a11b987
--
2.53.0
prev parent reply other threads:[~2026-12-06 6:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 5:39 [PATCH] x86/boot/tboot: Fix off-by-one AP WFS wait count and timeout check Sun, Ning
2026-12-04 15:30 ` Dave Hansen
2026-12-04 17:58 ` Sun, Ning
2026-12-06 6:58 ` Ning Sun [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=20261206065856.8459-1-ning.sun@intel.com \
--to=ning.sun@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@intel.com \
--cc=frederic@kernel.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tboot-devel@lists.sourceforge.net \
--cc=tglx@linutronix.de \
--cc=x86@kernel.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®