Skip to content

KVM: arm64: Fix host/hyp tracking on share/unshare hypercall failure

[email protected] kvmarm linux-arm-kernel lkml 2 versions In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 1 replyIn review
  2. v12 patches 9 repliesSuperseded

Changes in v2 from the cover letter

- New patch 3: roll back partial shares in kvm_share_hyp(); document the deliberate leak-on-WARN in kvm_unshare_hyp() (Vincent, Marc).
- Patches 1 and 2 functionally unchanged (patch 2 gains the call-site comment).
- v1: https://lore.kernel.org/all/[email protected]/

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3KVM: arm64: Free hyp-share tracking node when share hypercall failsarch/arm64/kvm/mmu.c+4 -00 replies
2/3KVM: arm64: Avoid host/hyp share desync on unshare hypercall failurearch/arm64/kvm/mmu.c+12 -30 replies
3/3KVM: arm64: Roll back partial shares on kvm_share_hyp() failurearch/arm64/kvm/mmu.c+17 -30 replies

Reviews trailers per patch

None of the 3 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchVincent Donnefort
SeriesR-b
1/3
2/3
3/3

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/3] KVM: arm64: Fix host/hyp tracking on share/unshare hypercall failure

Hi folks,

The first two started as bugs I found testing Sashiko locally with fixes to review-prompts. The third grew out of the v1 discussion.

share_pfn_hyp() and unshare_pfn_hyp() in arch/arm64/kvm/mmu.c maintain a host-side RB-tree mirroring the set of pages shared with EL2. The hypercalls they wrap can fail (page-state mismatch, EL2 refcount still held), and neither the per-pfn helpers nor the multi-page wrappers cleaned up correctly on failure:

- share_pfn_hyp() left its tracking node in the tree on failure, leaking the allocation and presenting a phantom share to a later unshare (patch 1).

- unshare_pfn_hyp() erased its tracking node before the hypercall, so on failure the host lost its record while EL2 still owned the share (patch 2).

- kvm_share_hyp() returned on the first per-page failure, stranding the pages already shared by that call: the caller treats the whole range as failed and never unshares them (patch 3).

As Vincent and Marc noted on v1, none of this compromises isolation. A page that cannot be unshared is simply leaked: it stays shared with the hypervisor and is no longer reusable for pKVM. So kvm_share_hyp() now rolls back on failure, and the unshare WARN_ON()s are left non-fatal and documented rather than promoted to BUG_ON(). The system keeps running, and only later pKVM reuse of a leaked page would fail. We do not expect any of these paths to trigger in practice.

Severity is low and this can wait for 7.2. Patch 3 builds on patch 2, otherwise they are independent.

Changes since v1:
- New patch 3: roll back partial shares in kvm_share_hyp(); document the deliberate leak-on-WARN in kvm_unshare_hyp() (Vincent, Marc).
- Patches 1 and 2 functionally unchanged (patch 2 gains the call-site comment).
- v1: https://lore.kernel.org/all/[email protected]/

Cheers,
/fuad

Fuad Tabba (3):
KVM: arm64: Free hyp-share tracking node when share hypercall fails
KVM: arm64: Avoid host/hyp share desync on unshare hypercall failure
KVM: arm64: Roll back partial shares on kvm_share_hyp() failure

 arch/arm64/kvm/mmu.c | 39 +++++++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)
Signature · 1 line
2.54.0.929.g9b7fa37559-goog