Commit e12caa0
authored
openhcl/tdx: fix bytecode issue in reset vector s.t. mailbox is gated by kernel (#2341)
## Context
OpenHCL implements the ACPI Mailbox protocol for starting APs in TDX
CVMs. The implementation involves spinning in the reset vector, until we
receive a message to jump to a wakeup vector in the kernel. The kernel
communicates that we should start by sending an apic_id, and then a
start command.
There is an intermittent issue where APs will fail to start, and the
kernel failure log suggests that we are never exiting the reset vector
(#2334)
## Bug
There is a spinloop in the reset vector, where we wait until the kernel
writes the APIC_ID of the AP into the `id` field of the mailbox page,
and then a `0x1` to the `command` field.
This spinloop works by reading the `command` field into `ebx`, and
comparing it to a fixed value of `1` in `dx`. However, the instruction
that moves the fixed WORD into `dx` has the wrong bytecode, it is
instead writing a fixed DWORD into `edx`. The instruction thus considers
the next WORD in the reset vector, which is a cmp instruction, to be
part of the operand to the mov, and never executes it.
Normally this type of issue would be obvious and lead to a crash, but
there are two reasons this code worked most of the time:
1. The cmp instruction after the mov was exactly two bytes, and those
two bytes were read as part of a constant. During execution, the reset
vector smoothly moves to the instruction after the cmp, and the value in
`edx` is not used again.
2. The kernel is still gating the reset vector with the APIC_ID; the APs
still start serially when the kernel selects them, just not at the
timing expected by the kernel.
## Fix
Explicitly compare to a constant DWORD, as that is the size of the
`command` register written by the kernel.1 parent 096c3a4 commit e12caa0
File tree
2 files changed
+9
-5
lines changed- vm/loader/igvmfilegen/src
- vp_context_builder
2 files changed
+9
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1287 | 1287 | | |
1288 | 1288 | | |
1289 | 1289 | | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
1293 | 1293 | | |
1294 | 1294 | | |
1295 | 1295 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
380 | 380 | | |
381 | 381 | | |
382 | 382 | | |
383 | | - | |
384 | | - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
385 | 389 | | |
386 | 390 | | |
387 | 391 | | |
| |||
0 commit comments