Skip to content

KVM: x86: VMX: Fix MSR namespacing

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 Latest15 patches 1 replyIn review
  2. v115 patches 0 repliesSuperseded

Changes in v2 from the cover letter

- Rebased to kvm/queue, commit e1ba1a15af73 ("KVM: SVM: Enable INVPCID feature on AMD").

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/15KVM: x86: Rename "shared_msrs" to "user_return_msrs"arch/x86/include/asm/kvm_host.h arch/x86/kvm/vmx/vmx.c arch/x86/kvm/x86.c+60 -560 replies
2/15KVM: VMX: Prepend "MAX_" to MSR array size definesarch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+9 -90 replies
3/15KVM: VMX: Rename "vmx_find_msr_index" to "vmx_find_loadstore_msr_slot"arch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+14 -141 reply
4/15KVM: VMX: Rename the "shared_msr_entry" struct to "vmx_uret_msr"arch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+35 -350 replies
5/15KVM: VMX: Rename vcpu_vmx's "nmsrs" to "nr_uret_msrs"arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+4 -40 replies
6/15KVM: VMX: Rename vcpu_vmx's "save_nmsrs" to "nr_active_uret_msrs"arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+12 -120 replies
7/15KVM: VMX: Rename vcpu_vmx's "guest_msrs_ready" to "guest_uret_msrs_loaded"arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+5 -50 replies
8/15KVM: VMX: Rename "__find_msr_index" to "__vmx_find_uret_msr"arch/x86/kvm/vmx/vmx.c+8 -80 replies
9/15KVM: VMX: Check guest support for RDTSCP before processing MSR_TSC_AUXarch/x86/kvm/vmx/vmx.c+5 -30 replies
10/15KVM: VMX: Move uret MSR lookup into update_transition_efer()arch/x86/kvm/vmx/vmx.c+21 -140 replies
11/15KVM: VMX: Add vmx_setup_uret_msr() to handle lookup and swaparch/x86/kvm/vmx/vmx.c+18 -310 replies
12/15KVM: VMX: Rename "find_msr_entry" to "vmx_find_uret_msr"arch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+7 -70 replies
13/15KVM: VMX: Rename "vmx_set_guest_msr" to "vmx_set_guest_uret_msr"arch/x86/kvm/vmx/vmx.c+4 -30 replies
14/15KVM: VMX: Rename "vmx_msr_index" to "vmx_uret_msrs_list"arch/x86/kvm/vmx/vmx.c+8 -80 replies
15/15KVM: VMX: Rename vmx_uret_msr's "index" to "slot"arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+5 -50 replies

Reviews trailers per patch

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

Read the v2 thread

Cover letter [PATCH v2 00/15] KVM: x86: VMX: Fix MSR namespacing

This series attempts to clean up VMX's MSR namespacing, which is in unimitigated disaster (keeping things PG).

There are a variety of ways VMX saves and restores guest MSRs, all with unique properties and mechanisms, but with haphazard namespacing (assuming there is any namespacing at all). Some fun collisions:

__find_msr_index(), find_msr_entry() and vmx_find_msr_index()

vmx_set_guest_msr() and vmx_set_msr()

structs vmx_msrs, vmx_msr_entry, shared_msr_entry, kvm_shared_msrs and kvm_shared_msrs_values

vcpu_vmx fields guest_msrs, msr_autoload.guest and msr_autostore.guest

Probably the most infurating/confusing nomenclature is "index", which can mean MSR's ECX index, index into one of several VMX arrays, or index into a common x86 array. __find_msr_index() even manages to mix at least three different meanings in about as many lines of code.

The biggest change is to rename the "shared MSRs" mechanism to "user return MSRs" (details in patch 1), most everything else is either derived from that rename or is fairly straightforward cleanup.

No true functional changes, although the update_transition_efer() change in patch 10 dances pretty close to being a functional change.

v2:
- Rebased to kvm/queue, commit e1ba1a15af73 ("KVM: SVM: Enable INVPCID feature on AMD").

Sean Christopherson (15):
KVM: x86: Rename "shared_msrs" to "user_return_msrs"
KVM: VMX: Prepend "MAX_" to MSR array size defines
KVM: VMX: Rename "vmx_find_msr_index" to "vmx_find_loadstore_msr_slot"
KVM: VMX: Rename the "shared_msr_entry" struct to "vmx_uret_msr"
KVM: VMX: Rename vcpu_vmx's "nmsrs" to "nr_uret_msrs"
KVM: VMX: Rename vcpu_vmx's "save_nmsrs" to "nr_active_uret_msrs"
KVM: VMX: Rename vcpu_vmx's "guest_msrs_ready" to
"guest_uret_msrs_loaded"
KVM: VMX: Rename "__find_msr_index" to "__vmx_find_uret_msr"
KVM: VMX: Check guest support for RDTSCP before processing MSR_TSC_AUX
KVM: VMX: Move uret MSR lookup into update_transition_efer()
KVM: VMX: Add vmx_setup_uret_msr() to handle lookup and swap
KVM: VMX: Rename "find_msr_entry" to "vmx_find_uret_msr"
KVM: VMX: Rename "vmx_set_guest_msr" to "vmx_set_guest_uret_msr"
KVM: VMX: Rename "vmx_msr_index" to "vmx_uret_msrs_list"
KVM: VMX: Rename vmx_uret_msr's "index" to "slot"

 arch/x86/include/asm/kvm_host.h |   4 +-
 arch/x86/kvm/vmx/nested.c       |  22 ++--
 arch/x86/kvm/vmx/vmx.c          | 184 ++++++++++++++++----------------
 arch/x86/kvm/vmx/vmx.h          |  24 ++---
 arch/x86/kvm/x86.c              | 101 +++++++++---------
 5 files changed, 168 insertions(+), 167 deletions(-)
Signature · 1 line
2.28.0