Skip to content

KVM: Fold kvm_arch_sched_in() into kvm_arch_vcpu_load()

Sean Christopherson kvm kvm-riscv kvmarm linux-arm-kernel linux-mips linux-riscv linuxppc-dev lkml loongarch 2 versions – Applied

Status from this message: Applied to kvm-x86 generic, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest6 patches 9 repliesApplied
  2. v14 patches 3 repliesSuperseded

Changes in v2 from the cover letter

- Add scheduled_out flag instead of passing a bool to kvm_arch_vcpu_load(). [Oliver]
- Tack on patches to clean up x86's setting of l1tf_flush_l1d in kvm_arch_sched_load() (the code looked slightly less weird when the flag was being set by kvm_arch_sched_in()).

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/6KVM: Add a flag to track if a loaded vCPU is scheduled outinclude/linux/kvm_host.h virt/kvm/kvm_main.c+5 -01 reply
2/6KVM: VMX: Move PLE grow/shrink helpers above vmx_vcpu_load()arch/x86/kvm/vmx/vmx.c+32 -320 replies
3/6KVM: x86: Fold kvm_arch_sched_in() into kvm_arch_vcpu_load()arch/x86/include/asm/kvm-x86-ops.h arch/x86/include/asm/kvm_host.h arch/x86/kvm/svm/svm.c +4 more+16 -274 replies
4/6KVM: Delete the now unused kvm_arch_sched_in()arch/arm64/include/asm/kvm_host.h arch/loongarch/include/asm/kvm_host.h arch/mips/include/asm/kvm_host.h +7 more+3 -171 reply
5/6KVM: x86: Unconditionally set l1tf_flush_l1d during vCPU loadarch/x86/kvm/x86.c+5 -61 reply
6/6KVM: x86: Drop now-superflous setting of l1tf_flush_l1d in vcpu_run()arch/x86/kvm/vmx/vmx.c arch/x86/kvm/x86.c+4 -40 replies

Reviews trailers per patch

4 of 6 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchOliver UptonKai HuangBibo Mao
SeriesA-b
1/6R-b
2/6
3/6A-b
4/6R-b
5/6A-b
6/6

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v2 thread

Cover letter [PATCH v2 0/6] KVM: Fold kvm_arch_sched_in() into kvm_arch_vcpu_load()

Drop kvm_arch_sched_in() and instead add and use kvm_vcpu.scheduled_out to communicate to kvm_arch_vcpu_load() that the vCPU is being scheduling back in.

While fiddling with an idea for optimizing state management on AMD CPUs, I wanted to skip re-saving certain host state when a vCPU is scheduled back in, as the state (theoretically) shouldn't change for the task while it's scheduled out. Actually doing that was annoying and unnecessarily brittle due to having a separate API for the kvm_sched_in() case (the state save needed to be in kvm_arch_vcpu_load() for the common path).

The other motivation for this is to avoid yet another arch hook, and more arbitrary ordering, if there's a future need to hook kvm_sched_out() (we've come close on the x86 side several times). E.g. kvm_arch_vcpu_put() can simply check kvm_vcpu.scheduled_out if it needs to something specific for the vCPU being scheduled out.

v2:
- Add scheduled_out flag instead of passing a bool to kvm_arch_vcpu_load(). [Oliver]
- Tack on patches to clean up x86's setting of l1tf_flush_l1d in kvm_arch_sched_load() (the code looked slightly less weird when the flag was being set by kvm_arch_sched_in()).

v1: https://lore.kernel.org/all/20240430193157.419425-1-seanjc at google.com

Sean Christopherson (6):
KVM: Add a flag to track if a loaded vCPU is scheduled out
KVM: VMX: Move PLE grow/shrink helpers above vmx_vcpu_load()
KVM: x86: Fold kvm_arch_sched_in() into kvm_arch_vcpu_load()
KVM: Delete the now unused kvm_arch_sched_in()
KVM: x86: Unconditionally set l1tf_flush_l1d during vCPU load
KVM: x86: Drop now-superflous setting of l1tf_flush_l1d in vcpu_run()

 arch/arm64/include/asm/kvm_host.h     |  1 -
 arch/loongarch/include/asm/kvm_host.h |  1 -
 arch/mips/include/asm/kvm_host.h      |  1 -
 arch/powerpc/include/asm/kvm_host.h   |  1 -
 arch/riscv/include/asm/kvm_host.h     |  1 -
 arch/s390/include/asm/kvm_host.h      |  1 -
 arch/x86/include/asm/kvm-x86-ops.h    |  1 -
 arch/x86/include/asm/kvm_host.h       |  2 -
 arch/x86/kvm/pmu.c                    |  6 +-
 arch/x86/kvm/svm/svm.c                | 11 +---
 arch/x86/kvm/vmx/main.c               |  2 -
 arch/x86/kvm/vmx/vmx.c                | 80 +++++++++++++--------------
 arch/x86/kvm/vmx/x86_ops.h            |  1 -
 arch/x86/kvm/x86.c                    | 22 +++-----
 include/linux/kvm_host.h              |  3 +-
 virt/kvm/kvm_main.c                   |  5 +-
 16 files changed, 59 insertions(+), 80 deletions(-)

base-commit: 4aad0b1893a141f114ba40ed509066f3c9bc24b0

Signature · 1 line
2.45.0.215.g3402c0e53f-goog