Skip to content

KVM: x86: Allow userspace to disable the emulator

Sean Christopherson kvm lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest13 patches 25 repliesIn review
  2. v113 patches 0 repliesSuperseded

Changes in v2 from the cover letter

- Rebase to kvm/queue, 2c2787938512 ("KVM: selftests: Stop ...")

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/13KVM: x86: Refactor I/O emulation helpers to provide vcpu-only variantarch/x86/kvm/x86.c+24 -151 reply
2/13KVM: x86: Explicitly pass an exception struct to check_interceptarch/x86/include/asm/kvm_host.h arch/x86/kvm/svm.c arch/x86/kvm/vmx/vmx.c +1 more+10 -70 replies
3/13KVM: x86: Move emulation-only helpers to emulate.carch/x86/kvm/emulate.c arch/x86/kvm/x86.h+11 -111 reply
4/13KVM: x86: Refactor R/W page helper to take the emulation contextarch/x86/kvm/x86.c+4 -41 reply
5/13KVM: x86: Refactor emulated exception injection to take the emul contextarch/x86/kvm/x86.c+5 -41 reply
6/13KVM: x86: Refactor emulate tracepoint to explicitly take contextarch/x86/kvm/trace.h arch/x86/kvm/x86.c+19 -165 replies
7/13KVM: x86: Refactor init_emulate_ctxt() to explicitly take contextarch/x86/kvm/x86.c+5 -51 reply
8/13KVM: x86: Dynamically allocate per-vCPU emulation contextarch/x86/include/asm/kvm_emulate.h arch/x86/include/asm/kvm_host.h arch/x86/kvm/x86.c+55 -95 replies
9/13KVM: x86: Move kvm_emulate.h into KVM's private directoryarch/x86/include/asm/kvm_host.h arch/x86/kvm/emulate.c arch/x86/kvm/kvm_emulate.h +3 more+8 -22 replies
10/13KVM: x86: Shrink the usercopy region of the emulation contextarch/x86/kvm/kvm_emulate.h arch/x86/kvm/x86.c+11 -94 replies
11/13KVM: x86: Add helper to "handle" internal emulation errorarch/x86/kvm/x86.c+14 -181 reply
12/13KVM: x86: Add variable to control existence of emulatorarch/x86/include/asm/kvm_host.h arch/x86/kvm/svm.c arch/x86/kvm/vmx/vmx.c +1 more+23 -61 reply
13/13KVM: x86: Allow userspace to disable the kernel's emulatorarch/x86/kvm/x86.c+2 -10 replies

Reviews trailers per patch

8 of 13 patches have a Reviewed-by or Acked-by.

PatchVitaly Kuznetsov
1/13R-b
2/13
3/13R-b
4/13R-b
5/13R-b
6/13
7/13R-b
8/13
9/13R-b
10/13
11/13R-b
12/13R-b
13/13

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 00/13] KVM: x86: Allow userspace to disable the emulator

The primary intent of this series is to dynamically allocate the emulator and get KVM to a state where the emulator *could* be disabled at some point in the future. Actually allowing userspace to disable the emulator was a minor change at that point, so I threw it in.

Dynamically allocating the emulator shrinks the size of x86 vcpus by ~2.5k bytes, which is important because 'struct vcpu_vmx' has once again fattened up and squeaked past the PAGE_ALLOC_COSTLY_ORDER threshold. Moving the emulator to its own allocation gives us some breathing room for the near future, and has some other nice side effects.

As for disabling the emulator... in the not-too-distant future, I expect there will be use cases that can truly disable KVM's emulator, e.g. for security (KVM's and/or the guests). I don't have a strong opinion on whether or not KVM should actually allow userspace to disable the emulator without a concrete use case (unless there already is a use case?), which is why that part is done in its own tiny patch.

Running without an emulator has been "tested" in the sense that the selftests that don't require emulation continue to pass, and everything else fails with the expected "emulation error".

v2:
- Rebase to kvm/queue, 2c2787938512 ("KVM: selftests: Stop ...")

Sean Christopherson (13):
KVM: x86: Refactor I/O emulation helpers to provide vcpu-only variant
KVM: x86: Explicitly pass an exception struct to check_intercept
KVM: x86: Move emulation-only helpers to emulate.c
KVM: x86: Refactor R/W page helper to take the emulation context
KVM: x86: Refactor emulated exception injection to take the emul
context
KVM: x86: Refactor emulate tracepoint to explicitly take context
KVM: x86: Refactor init_emulate_ctxt() to explicitly take context
KVM: x86: Dynamically allocate per-vCPU emulation context
KVM: x86: Move kvm_emulate.h into KVM's private directory
KVM: x86: Shrink the usercopy region of the emulation context
KVM: x86: Add helper to "handle" internal emulation error
KVM: x86: Add variable to control existence of emulator
KVM: x86: Allow userspace to disable the kernel's emulator

 arch/x86/include/asm/kvm_host.h             |  12 +-
 arch/x86/kvm/emulate.c                      |  13 +-
 arch/x86/{include/asm => kvm}/kvm_emulate.h |   9 +-
 arch/x86/kvm/mmu/mmu.c                      |   1 +
 arch/x86/kvm/svm.c                          |   5 +-
 arch/x86/kvm/trace.h                        |  22 +--
 arch/x86/kvm/vmx/vmx.c                      |  15 +-
 arch/x86/kvm/x86.c                          | 193 +++++++++++++-------
 arch/x86/kvm/x86.h                          |  12 +-
 9 files changed, 183 insertions(+), 99 deletions(-)
 rename arch/x86/{include/asm => kvm}/kvm_emulate.h (99%)
Signature · 1 line
2.24.1