RE: [PATCH] x86/boot/tboot: Fix off-by-one AP WFS wait count and timeout check
From: Sun, Ning
Date: Fri Dec 04 2026 - 12:58:54 EST
> -----Original Message-----
> From: Hansen, Dave <dave.hansen@xxxxxxxxx>
> Sent: Friday, December 4, 2026 7:30 AM
> To: Sun, Ning <ning.sun@xxxxxxxxx>; Thomas Gleixner <tglx@xxxxxxxxxxxxx>; Ingo Molnar <mingo@xxxxxxxxxx>; Borislav Petkov
> <bp@xxxxxxxxx>; H. Peter Anvin <hpa@xxxxxxxxx>
> Cc: Frederic Weisbecker <frederic@xxxxxxxxxx>; x86@xxxxxxxxxx; tboot-devel@xxxxxxxxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx
> Subject: Re: [PATCH] x86/boot/tboot: Fix off-by-one AP WFS wait count and timeout check
>
> On 12/3/26 21:39, Sun, Ning wrote:
> > In tboot_dying_cpu(), ap_wfs_count is incremented before checking
> > whether this is the last secondary CPU going offline and calling
> > tboot_wait_for_aps(). However, the currently dying CPU is still
> > executing the hotplug teardown path and has not yet halted into
> > Wait-For-SIPI (WFS) mode.
> >
> > Consequently, tboot->num_in_wfs can only equal (ap_wfs_count - 1)
> > at this point, causing tboot_wait_for_aps() to unconditionally busy-wait
> > for the full AP_WAIT_TIMEOUT duration (1 second) and fail when
> > offlining the final secondary CPU.
> >
> > Furthermore, tboot_wait_for_aps() checks `if (timeout)` instead of
> > `if (!timeout)` when logging a timeout warning-an inverted condition
> > that was previously masked because the off-by-one bug always forced
> > `timeout` down to zero.
> >
> > Pass `atomic_read(&ap_wfs_count) - 1` to tboot_wait_for_aps() in
> > tboot_dying_cpu() (while keeping ap_wfs_count incremented for the
> > subsequent WFS transition), and fix the inverted timeout warning
> > condition in tboot_wait_for_aps().
> >
> > Tested on an Intel TXT platform with tboot 1.12.2 by offlining all
> > secondary CPUs and verifying that no timeout warning occurs.
>
> The changelog appears to have become rather contaminated with AI
> detritus. Could you clean it up a bit please?
Hello Dave, apologies for the noise; I will clean up and update the changelog in v3.
>
> What is the end user visible effect of this bug and of the fix?
The bug causes a 1-second delay and `-EBUSY` in `dmesg` when offlining the last secondary CPU on Intel TXT/tboot systems, alongside inverted timeout warning logic. The fix resolves both issues.
>
> What's up with this fixes tag?
>
> How long has this bug been there, how did you find it, and why do you
> think it persisted so long?
>
> Fixes: 5527c230f3d7 ("intel_txt: Intel(R) TXT and tboot kernel support")
>
> linux.git$ git show 5527c230f3d7
> fatal: ambiguous argument '5527c230f3d7': unknown revision or path ...
>
> My tree has:
>
> commit 3162534069597e34dd0ac9eb711be8dc23835ae7
> Author: Joseph Cihula <joseph.cihula@xxxxxxxxx>
> Date: Tue Jun 30 19:30:59 2009 -0700
>
> x86, intel_txt: Intel TXT boot support
>
> but that doesn't match the SHA1 *or* the commit summary exactly.
>
> What's up?
That `Fixes` tag was incorrect; the code dates back to 2009 (commit 316253406959). I will update it and send a v3 shortly.