KVM: PPC: Don't alias unclassified guest state IDs onto bit 0
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest2 patches 0 repliesNew
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | KVM: PPC: Reject unknown guest state IDs in kvmppc_gse_parse()arch/ | +9 | 0 replies | |
| 2/2 | KVM: PPC: Don't map unclassified guest state IDs onto bit 0arch/ | +34 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/2] KVM: PPC: Don't alias unclassified guest state IDs onto bit 0
The Guest State Buffer helpers map a guest state ID to a bitmap position with kvmppc_gse_flatten_iden(). For an ID that does not belong to any guest state class, it returns 0, which is also the valid position of KVMPPC_GSID_BLANK. Such an ID therefore silently aliases bit 0, and because ID 0 is the terminator of the kvmppc_gsbm_for_each() and kvmppc_gsp_for_each() iterators, a stray bit 0 makes them stop before visiting any other element. Nothing reports an error.
I found this while debugging an L2 guest that failed to start under a nestedv2 L1 with trap = 0xffffffea (-EINVAL) and an all-zero vCPU state. The cause was a new guest state ID, defined by a change that is not in mainline, without a matching class. Setting the corresponding register marked bit 0 dirty in the vCPU message bitmap, the message iterator then stopped at once, and nothing was flushed to L0. These patches make the helpers fail visibly instead of aliasing bit 0 when an ID has no class, which is easy to hit when adding a new ID.
- Patch 1 closes the only path by which an unclassified ID can arrive from L0:
kvmppc_gse_parse() accepts a zero-length element with such an ID, because kvmppc_gsid_size() returns 0 for it. It now rejects the element with -EINVAL.
- Patch 2 fixes the root cause. kvmppc_gse_flatten_iden() returns -1 instead of 0 for an unclassified ID, and its users handle that. This protects callers that pass IDs chosen by the kernel itself, such as when marking state dirty, where a missing class used to silently corrupt the bitmap. Those cases now warn once and do nothing. The warnings can only come from a kernel bug, because patch 1 filters IDs from L0 before they reach these helpers. That is also why patch 2 must be applied after patch 1.
IDs defined in mainline today all have a class, so existing behaviour is unchanged. The series makes a missing class fail visibly instead of silently aliasing bit 0.
Testing: with a nestedv2 L1 running under QEMU TCG as L0, the L2 guest fails with trap = 0xffffffea without this series. With it applied, the L2 guest boots and the new WARN_ON_ONCE() reports the ID that has no class.
On a Power10 LPAR (PowerVM as L0), with the series applied on top of a mainline kernel, L2 guests boot and reboot normally. A kernel build run as a workload inside the KVM guest completed with no problems seen.
Amit Machhiwal (2):
KVM: PPC: Reject unknown guest state IDs in kvmppc_gse_parse()
KVM: PPC: Don't map unclassified guest state IDs onto bit 0
arch/powerpc/kvm/guest-state-buffer.c | 51 ++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 8 deletions(-)
base-commit: 693c2e04e3f1d4c59af236e1211b7b8cb165a790
Signature · 1 line
2.54.0 (Apple Git-157)