Skip to content

KVM: Avoid literal numbers as return values

Juergen Gross kvm linux-coco lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest10 patches 6 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/10KVM: Switch coalesced_mmio_in_range() to return boolvirt/kvm/coalesced_mmio.c+7 -70 replies
2/10KVM/x86: Use bool for the err parameter of kvm_complete_insn_gp()arch/x86/include/asm/kvm_host.h arch/x86/kvm/svm/svm.c arch/x86/kvm/vmx/main.c +3 more+7 -70 replies
3/10KVM/x86: Let x86_emulate_ops.set_cr() return a boolarch/x86/include/asm/kvm_host.h arch/x86/kvm/kvm_emulate.h arch/x86/kvm/smm.c +3 more+43 -430 replies
4/10KVM/x86: Let x86_emulate_ops.set_dr() return a boolarch/x86/include/asm/kvm_host.h arch/x86/kvm/emulate.c arch/x86/kvm/kvm_emulate.h +3 more+12 -120 replies
5/10KVM/x86: Add KVM_MSR_RET_* defines for values 0 and 1arch/x86/kvm/x86.c arch/x86/kvm/x86.h+10 -24 replies
6/10KVM/x86: Use defines for APIC related MSR emulationarch/x86/kvm/lapic.c+24 -240 replies
7/10KVM/x86: Use defines for Hyper-V related MSR emulationarch/x86/kvm/hyperv.c+55 -550 replies
8/10KVM/x86: Use defines for VMX related MSR emulationarch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/pmu_intel.c arch/x86/kvm/vmx/tdx.c +1 more+79 -790 replies
9/10KVM/x86: Use defines for SVM related MSR emulationarch/x86/kvm/svm/pmu.c arch/x86/kvm/svm/svm.c+28 -280 replies
10/10KVM/x86: Use defines for common related MSR emulationarch/x86/kvm/mtrr.c arch/x86/kvm/pmu.c arch/x86/kvm/x86.c +1 more+107 -1070 replies

Reviews trailers per patch

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

Read the v1 thread

Cover letter [PATCH 00/10] KVM: Avoid literal numbers as return values

This series is the first part of replacing the use of literal numbers (0 and 1) as return values with either true/false or with defines.

This work is a prelude of getting rid of the magic value "1" for "return to guest". I started in x86 KVM host code doing that and soon stumbled over lots of other use cases of the magic "1" as return value, especially in MSR emulation where a comment even implied this "1" was due to the "return to guest" semantics.

A detailed analysis of all related code paths revealed that there was indeed a rather clean interface between the functions using the MSR emulation "1" and those using the "return to guest" "1".

A few functions just using "0" and "1" instead of bool are changed, tooi (patches 1-4).

The rest of the series is cleaning up the MSR emulation code by using new proper defines for return values 0 and 1.

The whole series should not result in any functional change.

Juergen Gross (10):
KVM: Switch coalesced_mmio_in_range() to return bool KVM/x86: Use bool for the err parameter of kvm_complete_insn_gp() KVM/x86: Let x86_emulate_ops.set_cr() return a bool KVM/x86: Let x86_emulate_ops.set_dr() return a bool KVM/x86: Add KVM_MSR_RET_* defines for values 0 and 1 KVM/x86: Use defines for APIC related MSR emulation KVM/x86: Use defines for Hyper-V related MSR emulation KVM/x86: Use defines for VMX related MSR emulation KVM/x86: Use defines for SVM related MSR emulation KVM/x86: Use defines for common related MSR emulation

 arch/x86/include/asm/kvm_host.h |  14 +-
 arch/x86/kvm/emulate.c          |   2 +-
 arch/x86/kvm/hyperv.c           | 110 +++++++-------
 arch/x86/kvm/kvm_emulate.h      |   4 +-
 arch/x86/kvm/lapic.c            |  48 +++----
 arch/x86/kvm/mtrr.c             |  12 +-
 arch/x86/kvm/pmu.c              |  12 +-
 arch/x86/kvm/smm.c              |   2 +-
 arch/x86/kvm/svm/pmu.c          |  12 +-
 arch/x86/kvm/svm/svm.c          |  54 +++----
 arch/x86/kvm/vmx/main.c         |   2 +-
 arch/x86/kvm/vmx/nested.c       |  18 +--
 arch/x86/kvm/vmx/pmu_intel.c    |  20 +--
 arch/x86/kvm/vmx/tdx.c          |  18 +--
 arch/x86/kvm/vmx/tdx.h          |   2 +-
 arch/x86/kvm/vmx/vmx.c          | 122 ++++++++--------
 arch/x86/kvm/x86.c              | 246 ++++++++++++++++----------------
 arch/x86/kvm/x86.h              |  10 +-
 arch/x86/kvm/xen.c              |  14 +-
 virt/kvm/coalesced_mmio.c       |  14 +-
 20 files changed, 372 insertions(+), 364 deletions(-)
Signature · 1 line
2.51.0