Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH 0/2] KVM: PPC: Don't alias unclassified guest state IDs onto bit 0
@ 2026-12-02 18:16 Amit Machhiwal
  2026-12-02 18:16 ` [PATCH 1/2] KVM: PPC: Reject unknown guest state IDs in kvmppc_gse_parse() Amit Machhiwal
  2026-12-02 18:16 ` [PATCH 2/2] KVM: PPC: Don't map unclassified guest state IDs onto bit 0 Amit Machhiwal
  0 siblings, 2 replies; 4+ messages in thread
From: Amit Machhiwal @ 2026-12-02 18:16 UTC (permalink / raw)
  To: Madhavan Srinivasan, linuxppc-dev
  Cc: Amit Machhiwal, Gautam Menghani, Harsh Prateek Bora,
	Nicholas Piggin, Michael Ellerman, Christophe Leroy (CS GROUP),
	Ritesh Harjani (IBM), Shrikanth Hegde, Jordan Niethe, kvm, stable

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
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-02 18:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 18:16 [PATCH 0/2] KVM: PPC: Don't alias unclassified guest state IDs onto bit 0 Amit Machhiwal
2026-12-02 18:16 ` [PATCH 1/2] KVM: PPC: Reject unknown guest state IDs in kvmppc_gse_parse() Amit Machhiwal
2026-12-02 18:16 ` [PATCH 2/2] KVM: PPC: Don't map unclassified guest state IDs onto bit 0 Amit Machhiwal
2026-12-02 18:21   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox