mbox series

[0/2] Propagate accurate MSR access failures to userspace

Message ID 20180829234241.103002-1-pshier@google.com (mailing list archive)
Headers show
Series Propagate accurate MSR access failures to userspace | expand

Message

Peter Shier Aug. 29, 2018, 11:42 p.m. UTC
KVM_GET/SET_MSRS ioctls do not enable userspace clients to differentiate
between ioctl execution errors (e.g. bad pointer, memory allocation
failure) and MSR access errors (e.g. bad MSR parameter, unknown MSR).

This series repurposes kvm_msrs.pad to return the error from the first
failed msr access. It enables callers to use a sequence such as:

struct kvm_msrs msrs;
... init msrs ...
r = ioctl(vcpu_fd, KVM_GET_MSRS, &msrs);
if (r < 0) {
      	check errno for ioctl execution error
} else if (r < msrs.nmsrs) {
        if r > 0
	        reading msrs.entries[0]..msrs.entries[r-1] succeeded
        reading msrs.entries[r] failed
	msrs.errno has the reason
}

The second patch changes code that handles ranges of MSRs to return -ENOENT
when it encounters an unknown MSR. Prior to this it was not possible for
userspace to differentiate between unknown MSRs and other MSR access
errors.

The patches do not change any existing API contracts or guest-visible
exceptions.

Peter Shier (2):
  kvm: x86: propagate KVM_GET/SET_MSRS failures to userspace
  kvm: x86: differentiate unrecognized MSRs from errors

 Documentation/virtual/kvm/api.txt | 12 ++++++++---
 arch/x86/include/uapi/asm/kvm.h   |  2 +-
 arch/x86/kvm/hyperv.c             | 16 +++++++--------
 arch/x86/kvm/lapic.c              |  2 +-
 arch/x86/kvm/mtrr.c               | 10 ++++++---
 arch/x86/kvm/pmu_amd.c            | 24 ++++++++++++----------
 arch/x86/kvm/pmu_intel.c          |  5 +++--
 arch/x86/kvm/vmx.c                |  4 ++--
 arch/x86/kvm/x86.c                | 34 +++++++++++++++++++------------
 9 files changed, 65 insertions(+), 44 deletions(-)