Skip to content

KVM: arm64: Fixes for a vCPU caught in a disallowed AArch32 mode

Fuad Tabba kvmarm linux-arm-kernel lkml sashiko-reviews stable 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3KVM: arm64: Don't call kvm_setup_vcpu() again once a vCPU has runarch/arm64/kvm/arm.c+4 -10 replies
2/3KVM: arm64: Reject KVM_RUN on a vCPU that's no longer initializedarch/arm64/kvm/arm.c+3 -01 reply
3/3KVM: arm64: Don't run a protected vCPU that was caught in AArch32arch/arm64/kvm/hyp/nvhe/hyp-main.c arch/arm64/kvm/hyp/nvhe/switch.c+7 -40 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/3] KVM: arm64: Fixes for a vCPU caught in a disallowed AArch32 mode

Hi folks,

KVM marks a vCPU as uninitialized once its guest has entered a disallowed AArch32 mode, and the VMM has to call KVM_ARM_VCPU_INIT before it can run the vCPU again. This series fixes how KVM_ARM_VCPU_INIT and KVM_RUN handle such a vCPU.

KVM_ARM_VCPU_INIT sets the vCPU up a second time, as if it never ran. For a nested vCPU, this can free the VNCR page that the virtual timer still reads, and for any vCPU it resets MPIDR_EL1 and CLIDR_EL1 a second time. With the first patch, a vCPU that has run is only reset.

KVM_RUN checks that a vCPU is initialized only when the thread issuing it changes, so the same thread can still run the vCPU. The second patch makes KVM_RUN check every time. For a protected vCPU, EL2 marks its own copy of the vCPU but never checks it. With the third patch, EL2 doesn't run a vCPU that it has marked.

Tested on QEMU. The KASAN report in the first patch is from a host booted with kvm-arm.mode=nested, with fault injection failing the nested MMU allocation when the VMM calls KVM_ARM_VCPU_INIT again. With the series, KVM_ARM_VCPU_INIT doesn't reach that allocation, MPIDR_EL1 keeps the value that the VMM wrote, and a protected guest that enters AArch32 EL0 doesn't run again.

Based on Linux 7.4-rc3 (aebb727447640).

Cheers,
/fuad

Fuad Tabba (3):
KVM: arm64: Don't call kvm_setup_vcpu() again once a vCPU has run
KVM: arm64: Reject KVM_RUN on a vCPU that's no longer initialized
KVM: arm64: Don't run a protected vCPU that was caught in AArch32

 arch/arm64/kvm/arm.c               | 8 +++++++-
 arch/arm64/kvm/hyp/nvhe/hyp-main.c | 4 ++++
 arch/arm64/kvm/hyp/nvhe/switch.c   | 7 +++----
 3 files changed, 14 insertions(+), 5 deletions(-)

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3

Signature · 1 line
2.47.3